//이 페이지는 utf-8로 인코딩되어야 한다.

document.domain="joinsmsn.com";

var _frmList;
var _frmMap;

function fn_GetXmlHttpDocument(getUrl, getType, sendMethod, postXml)
{	
	var oXmlHttp;
	var strTemp;
	var strMethod;
	var strPostXml;
	var strGetType;
	try
	{
		strGetType = getType && getType.length > 0 ? getType.toUpperCase() : "";
		strMethod = sendMethod && sendMethod.length > 0 ? sendMethod.toUpperCase() : "";
		strPostXml = postXml && postXml.length > 0 ? postXml : null;

		if(strGetType.toUpperCase() != "TEXT" && strGetType.toUpperCase() != "HTML")
			strGetType = "TEXT"

		if(strMethod.toUpperCase() != "GET" && strMethod.toUpperCase() != "POST")
			strMethod = "GET"

		if(window.ActiveXObject)
		{
			oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else if(window.XMLHttpRequest)
		{
			oXmlHttp = new XMLHttpRequest();
		}

		oXmlHttp.open(strMethod, getUrl, false);
		oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oXmlHttp.send(postXml);

		if(oXmlHttp.status == 200)
		{
			if(strGetType == "TEXT")
				strTemp = oXmlHttp.responseText;
			else
				strTemp = oXmlHttp.responseHTML;
		}
		else
		{
			strTemp = "";
		}

		return strTemp;
	}
	catch(e){}
	finally
	{
		oXmlHttp = null;
	}
}

//Xml변환
function fn_GetXmlDomDocument(xmlContent)
{
	var oXmlDom;
	try
	{
		//oXmlDom = new ActiveXObject("Msxml2.DOMDocument.4.0");
		oXmlDom = new ActiveXObject("Microsoft.XMLDOM");
		oXmlDom.async = false;
		oXmlDom.loadXML(xmlContent);
	}
	catch(e)
	{
		try
		{
			var parser = new DOMParser();
			oXmlDom = parser.parseFromString(xmlContent, "text/xml");
		}
		catch(e2)
		{
			try
			{
				oXmlDom = document.implementation.createDocument("","",null);
				oXmlDom.async = false;
				oXmlDom.loadXML(xmlContent);
			}
			catch(e3)
			{
				oXmlDom = null
			}
		}
	}

	return oXmlDom;
}

//xml => Json으로 변환
//var oJsonXml = new Object();
//oJsonXml.xml2obj = function(xml)
function fn_XmlToJsonObject(xml)
{
	var obj = {}, que = [], depth = 0;

	// attribute를 해석하기 위한 함수 
	var parse_attr=function(oobj, str){str.replace(/([^=\s]+)\s*=\s*"([^"]*)"/g, function(a0,a1,a2) {oobj[a1] = a2;});}

	// 주석, XML선언, 태그 사이 공백 등의 의미 없는 코드를 삭제
	xml = xml.replace(/<(\?|\!-)[^>]*>/g,'').replace(/>\s+</g, '><');

	// 하위 노드가 없는 태그는 하나의 닫힌 태그로 수정
	xml = xml.replace(/<([^!][^ >]+)(\s[^>]*)?><\/\1>/g, '<$1$2 />').replace(/^\s+|\s+$/g, '');

	// 함수 객체를 정규 표현식 처리의 인자로 줘서 iterator로 사용
	xml = xml.replace(/<\/?([^\!][^ >]*)(\s[^>]*)?>(<\/$1>|<\!\[CDATA\[(?:(.|\s)*?)\]\]>|[^<>]*)/g, function(a0,a1,a2,a3)
	{
		if (typeof a1 == 'undefined') a1 = '';
		if (typeof a2 == 'undefined') a2 = '';
		if (typeof a3 == 'undefined') a3 = '';
  
		if (a0.substr(1,1) == '/')
		{
			// 현재 태그가 닫는 태그라면,
			// 깊이를 1만큼 감소
			depth--;
		}
		else if(que.length == 0)
		{
			// 객체 큐에 객체가 없다면,
			que[depth] = obj; // 초기의 객체를 큐에 넣고
			parse_attr(obj, a2); // attribute를 해석
		}
		else
		{
			var k  = a1, o = {}, is_closed = false;
			is_closed = (a2.substr(-1,1) == '/');
			if(a3.length > 0 || is_closed)
			{
				// 텍스트 노드가 있다면
				o = a3; // 추가할 객체는 문자열 객체

				// CDATA라면 전달받은 그대로 리턴하고
				// 그렇지 않다면 decode 해서 리턴
				//if(o.substr(0,9) == '<![CDATA[' && o.substr(-3,3) == ']]>')
				if(o.substr(0,9) == '<![CDATA[')
					o = o.substring(9, o.length-3);
				else
					o = o.replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&');
			}
   
			// 객체를 할당하기 전에 태그 이름이 이미 존재하는지 살펴보고
			// 이전에 존재하는 태그라면, 배열로 만든다. 이미 배열이라면 현재의 객체를 배열에 추가
			if(typeof que[depth][k] == 'undefined')
			{
				que[depth][k] = o;
			}
			else
			{    
				var v = que[depth][k];
				if (que[depth][k].constructor != Array)
					que[depth][k] = [v];
				que[depth][k].push(o);
			}

			// attribute를 해석
			parse_attr(o, a2);
   
			if (!is_closed)
				que[++depth] = o; 
		}
  
		return '';
	});
 
	return obj;
}
//String 의 공백을 모두 제거한다.
function fn_Trim(sourceString)
{
	var strResult ;
	try
	{
		strResult = sourceString.replace(/\s/g,"");
		return strResult;
	}
	catch(exception){}
}

//String 의 양쪽공백을 모두 제거한다.
function fn_RLTrim(strSource)
{
	try
	{
		return strSource.replace(/(^\s*)|(\s*$)/g, "");
	}
	catch(exception){}
}

//문자열 바꿈
function fn_ReplaceAll(oldStr,findStr,repStr)
{
	try
	{
		var srchNdx = 0;
		var newStr = ""; 
		while (oldStr.indexOf(findStr,srchNdx) != -1)  
		{
			newStr += oldStr.substring(srchNdx,oldStr.indexOf(findStr,srchNdx));
			newStr += repStr;
			srchNdx = (oldStr.indexOf(findStr,srchNdx) + findStr.length);
		}
		newStr += oldStr.substring(srchNdx,oldStr.length);
		return newStr;
	}
	catch(exception){}
}

//윈도우 창 가운데 열기
function fn_OpenCenterPopup(url, width, height, winName, feature)
{
	var nTop = 0;
	var nLeft = 0;
	var nHeight = height;
	var nWidth = width;
	var strFeature = "";
	try
	{
		if(feature != null && feature.length > 0)
			strFeature = "," + feature;
		else
			strFeature = strFeature;

		nTop = (window.screen.height / 2) - (nHeight / 2);
		nLeft = (window.screen.width / 2) - (nWidth / 2);
	
		window.open(url, winName, "width=" + nWidth + ",height=" + nHeight + ",top=" + nTop + ",left=" + nLeft + strFeature);
	}
	catch(e)
	{
		alert(e.description);
	}
}

//쿠키 설정
function fn_SetCookie(name, value, expires, path, domain, secure)
{
	var strCurCookie = "";	
	try
	{

		strCurCookie = name + "=" + escape(value) + 
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");

		if (!caution || (name + "=" + escape(value)).length <= 4000)
			document.cookie = strCurCookie;
		else
			if (confirm("Cookie exceeds 4KB and will be cut!"))
				document.cookie = strCurCookie;
	}
	catch(exception){}
}

//쿠키 가져오기
function fn_GetCookie(name)
{
	var strPrefix = "";
	var nCookieStartIndex = -1;
	var nCookieEndIndex = -1;
	
	try
	{
		strPrefix = name + "=";
		nCookieStartIndex = document.cookie.indexOf(strPrefix);
		
		if (nCookieStartIndex == -1)
			return null;
			
		nCookieEndIndex = document.cookie.indexOf(";", nCookieStartIndex + strPrefix.length);
		
		if (nCookieEndIndex == -1)
			nCookieEndIndex = document.cookie.length;
		
		return unescape(document.cookie.substring(nCookieStartIndex + strPrefix.length, nCookieEndIndex));
	}
	catch(exception){}
}

//모달팝업창을 띠운다.
function fn_OpenModalDialog(sUrl, sParam, sFeature)
{
	try
	{
		var strReturn = "";
		strReturn = window.showModalDialog("/_include/html/ModalDialog.html?" + sUrl, sParam, sFeature);
		return strReturn;
	}
	catch(exception){}
}

//모달리스팝업창을 띠운다.
function fn_OpenModelessDialog(sUrl, sParam, sFeature)
{
	try
	{
		var strReturn = "";
		strReturn = window.showModelessDialog("/_include/html/ModelessDialog.html?" + sUrl, sParam, sFeature);
		return strReturn;
	}
	catch(exception){}
}

