﻿var objXmlDom = null;				
var xmlHttp = false;
//var defultUrl = "http://www.w4c.go.kr:8080/pt/";
var defultUrl = "http://"+location.host+"/";
//var defultUrl = "http://192.168.2.10:8082/";
var sDefaultValue = "";
var sResultCtl = "";
//콤보박스 컨트롤 명칭을  할당할 변수.
var cboObj = null;

function getXMLHttpRequest()
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	var xmlHttpApp = false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	
	try {
	  xmlHttpApp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	  try {
	    xmlHttpApp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) {
	    xmlHttpApp = false;
	  }
	}
	
	@end @*/
	
	if (!xmlHttpApp && typeof XMLHttpRequest != 'undefined') {
	  xmlHttpApp = new XMLHttpRequest();
	}
	
	return xmlHttpApp;
}


function callServer(sUrl,sParams)
{				
		xmlHttp = getXMLHttpRequest();

		if(document.all)
		{
			xmlHttp.onreadystatechange  = updatePage;
		}
		else
		{
			xmlHttp.onload = updatePage;
		}
		
	  	// Open a connection to the server
		xmlHttp.open("POST",defultUrl  + sUrl,false);
		
	  // Tell the server you're sending it XML
  		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8')
	  	 
	  // Send the request
	  xmlHttp.send(sParams);
}

//*********************************************************************************************************
//스크립트명  : CallPage(url,sParams)
//설      명  : 넘겨받은 url 로 이동한다.  left.jsp 및 header.jsp 전용 함수.
//일      자  : 2009-11-05
//작  성  자  : 정종우
//*********************************************************************************************************
function CallPage()
{	
	if(xmlHttp.readyState == 4){
	
		if(xmlHttp.status == 200 ){
			if(sLocHref.split("?")[0] != "")	//넘겨받은 url
				location.href = sLocHref;
		}
	}
}

//*********************************************************************************************************
//스크립트명  : addSession(url,sParams)
//설      명  : 매개변수를 넘겨받아 세션에 추가한다.  left.jsp 및 header.jsp 전용 함수.
//전달  인자  : sParams  - 세션에 저장할 값.
//ex : Param1=A&Param2=B&Param3=C  ....
//일      자  : 2009-11-05
//작  성  자  : 정종우
//*********************************************************************************************************

var sLocHref ;
function addSession(url,sParams)
{	
	sLocHref = url + "?"+ sParams; 
	sLocParams=sParams;
	xmlHttp = getXMLHttpRequest();
	
	if(document.all)
	{
		xmlHttp.onreadystatechange  = CallPage;
	}
	else
	{
		xmlHttp.onload = CallPage;
	}

	// Open a connection to the server
	xmlHttp.open("POST",defultUrl + "comn/addSession.jsp", false);

 	 // Tell the server you're sending it XML
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8')
  	 
  	// Send the request
  	xmlHttp.send(sParams);
}

function updatePage()
{
 	if (xmlHttp.readyState == 4) {
	     if (xmlHttp.status == 200) {
	     
		     objXmlDom = xmlHttp.responseXML;
		}
   }
}

/*
	공통코드를  콤보박스에 바인딩 한다.
	sParams 	 - 메뉴 콤보를 조회하기  위한 조건.  대분류 코드,상위디테일 코드.
	objCombo - 조회된 정보를 바인딩할 컨트롤
	strDefaultValue - 초기값.
*/
function getComnCombo(sParams,strComboName,strDefaultValue)
{
	cboObj = strComboName;
	
	sDefaultValue = strDefaultValue;
	
	//xmlHTTP 객체 생성. 
	xmlHttp = getXMLHttpRequest();
	
	//콜백함수 설정.
	
	if(document.all)
	{
		xmlHttp.onreadystatechange  = setCombo;
	}
	else
	{
		xmlHttp.onload = setCombo;
	}

	//콤보박스를 바인딩할 기능을 포함한 페이지를 OPEN 한다. 
	xmlHttp.open("GET",defultUrl + "comn/Pt_GetComnCode.jsp?" +sParams,false);
	
	//호출한 페이지의 헤더타입을 XML 형식으로 변경한다.
  	xmlHttp.setRequestHeader("Content-Type","text/xml");
  	  	  	
  	//호출한 페이지에 postback 요청.
  	xmlHttp.send(null);
}


/*
	공통코드를  콤보박스에 바인딩 한다.
	sParams 	 - 메뉴 콤보를 조회하기  위한 조건.  대분류 코드,상위디테일 코드.
	objCombo - 조회된 정보를 바인딩할 컨트롤
	strDefaultValue - 초기값.
*/
function getCombo(sParams,strComboName,strDefaultValue)
{
	cboObj = strComboName;
	
	sDefaultValue = strDefaultValue;
	
	//xmlHTTP 객체 생성. 
	xmlHttp = getXMLHttpRequest();
	
	//콜백함수 설정.
	
	if(document.all)
	{
		xmlHttp.onreadystatechange  = setCombo;
	}
	else
	{
		xmlHttp.onload = setCombo;
	}

	//콤보박스를 바인딩할 기능을 포함한 페이지를 OPEN 한다. 
	xmlHttp.open("GET",defultUrl + "comn/Pt_GetComnCombo.jsp?" +sParams,false);
	
	//호출한 페이지의 헤더타입을 XML 형식으로 변경한다.
  	xmlHttp.setRequestHeader("Content-Type","text/xml");
  	  	  	
  	//호출한 페이지에 postback 요청.
  	xmlHttp.send(null);
}


//콤보박스 바인드.
function setCombo()
{


	/*호출한 페이지의 상태값을 체크한다. 
		0 - open  메서드 호출되지 않음. 
		1 - send  메서드가 호출되지 않은 상태.
		2 - status 와 헤더는 도착하지 않은 상태
		3 - 데이터 일부를 받은  상태
		4 - 데이터 전송 완료 상태 
	*/
	if(xmlHttp.readyState == 4){
		/*
			XMLHttpRequest.status 
			요청 결과상태를 코드로 리턴한다. 
			404 - page not found 
			200 - 정상.
			그외 많은 상태코드가 존재하지만 포괄적으로 처리한다.
		*/
		if(xmlHttp.status == 200 ){
			
			objXmlDom = xmlHttp.responseXML;
			var objOption  = "";
	
			var objElement = document.getElementById(cboObj);
			
			//콤보박스 초기
			fn_comboinit(objElement);
			
			//조회된 건 추가.
			var oChildLen = objXmlDom.childNodes[0].childNodes.length;
			for( i = 0 ; i < oChildLen ;  i ++)
			{
			 	objOption = document.createElement("option");
			 	
			 	if(document.all){	//IE 
				 	objOption.value = objXmlDom.childNodes[0].childNodes[i].childNodes[0].text ;			//코드
				 	objOption.innerText = objXmlDom.childNodes[0].childNodes[i].childNodes[1].text ;		//명칭.	
			 	}
			 	else		//IE 이외. 모질라, 불여우. 
			 	{
			 		objOption.value = objXmlDom.childNodes[0].childNodes[i].childNodes[0].textContent.replace(/(^\s*)|(\s*$)/gi, "")  ;			//코드
				 	objOption.text = objXmlDom.childNodes[0].childNodes[i].childNodes[1].textContent.replace(/(^\s*)|(\s*$)/gi, "")   ;		//명칭.
			 	}
			 	
			 	if(objOption.value == sDefaultValue){
			 	
		 			objOption.selected = "select";
		 		}
			 	
			 	objElement.appendChild(objOption);
			 }			 
		}
		else if(xmlHttp.status == 404 ){
			alert("URL doesn't exist!");
		}
		else
		{
			alert("Status is "+ xmlHttp.status);
		}
	}
}

//셀렉트 박스의 아이템을 초기화 한다.
function fn_comboinit(objcboBox)
{

	//기존 데이터를 전부 삭제한다.
	
	objcboBox.innerHTML = "";
	

	var 	objOption = document.createElement("option"); //기본 선택 추가.
	objOption.value = "";
			
	if(document.all){				
		objOption.innerText  = "선택";			//IE 
	}
	else
	{
		objOption.text = "선택";						//IE 이외. 모질라, 불여우. 
	}
	objcboBox.appendChild(objOption);

}

//*********************************************************************************************************
//스크립트명  : doNotChange()
//설         명  : 비번 등록(변경) 3개월 후 팝업의 나중에 변경 선택시 유저정보의 변경일자만 update
//일         자  : 
//작   성   자  : 
//*********************************************************************************************************
function doNotChange()
{				
		xmlHttp = getXMLHttpRequest();

		if(document.all){
			xmlHttp.onreadystatechange  = resDoNotChange;
		}else{
			xmlHttp.onload = chgPwSkip;
		}
		
	  	// Open a connection to the server
		xmlHttp.open("POST",defultUrl  + 'myPage/userProcess.jsp?',false);
		
	  // Tell the server you're sending it XML
  		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8')
	  	 
	  // Send the request
	  xmlHttp.send('mode=U_CHG_DT');
	  
}

//*********************************************************************************************************
//스크립트명  : doNotChange()
//설         명  : 비번 등록(변경) 3개월 후 팝업의 나중에 변경 선택시 유저정보의 변경일자만 update
//일         자  : 
//작   성   자  : 
//*********************************************************************************************************
function resDoNotChange()
{	
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200 ){
			//alert('난중에 하고 싶은것 올리기');
		}
	}
}
