// 로그인 스크립트
//	2009.07.17 
// 박형록

				
var xmlhttp;


function Logout(LoginType){
	
	var	LoginType;
	
	xmlhttp = getXmlHttpRequest();
	
	xmlurl = "/xml/comm/logout.asp"
	xmlhttp.open("GET",xmlurl, true);
	xmlhttp.onreadystatechange = function()
	 {
	 // 통신이 완료된 상태
		if(xmlhttp.readyState == 4)
			{
				var XmlResult = xmlhttp.responseText;
					if (LoginType=="0"){
						history.go(-1);
					}else{
						//window.location.reload();
						location.href="/";
					}
			}
	}
	xmlhttp.send(null);
}


function CheckLogin(LoginType,LoginRtnUrl){

var 	LoginId;
var	LoginPass;
var	LoginType;
var	SaveId;


LoginId	=	document.LoginForm.LoginId.value;
LoginPass	=	document.LoginForm.LoginPass.value;
SaveId	=	document.LoginForm.SaveId.value;

if (!LoginId){
	document.LoginForm.LoginId.focus();
	return;
}
if (!LoginPass){
	document.LoginForm.LoginPass.focus();
	return;
}
// XMLHttpRequest 객체 생성
xmlhttp = getXmlHttpRequest();

var xmlurl;

xmlurl = "/xml/comm/login.asp?LoginId="+LoginId+"&LoginPass="+LoginPass;

xmlhttp.open("GET",xmlurl, true);
xmlhttp.onreadystatechange = function()
	 {
	 // 통신이 완료된 상태
		if(xmlhttp.readyState == 4) {

			if(xmlhttp.status == 200) {
				var XmlResult = xmlhttp.responseXML;

				var xmlDoc = XmlResult.getElementsByTagName("BODY");
				var nodeLength= xmlDoc.length;
				
				var HtmlResult ="";
				var Recordlist	=	xmlDoc.item(0);
				var Result;
				var ResultMsg;
				
				 Result	=	Recordlist.getElementsByTagName("RESULT").item(0).firstChild.nodeValue;
				 ResultMsg	=	Recordlist.getElementsByTagName("MESSAGE").item(0).firstChild.nodeValue;
					 

					 
					if (LoginType=="0"){
						if (Result==0)
						{
							//history.go(-1);
							if (SaveId="1"){
								notice_setCookie( "SaveId", LoginId , 30);// 쿠키 설정	
							}
							location.href=LoginRtnUrl;
						}else{
							alert(ResultMsg);
						}
					}else{
						if (Result==0)
						{
							notice_setCookie( "SaveId", LoginId , 30);
							window.location.reload();
						}else{
							alert(ResultMsg);
						}
					}
												

				}
			}
		}
	
xmlhttp.send(null);
}

function notice_setCookie( name, value, expiredays ) 
  { 
        var todayDate = new Date(); 
        todayDate.setDate( todayDate.getDate() + expiredays ); 
        document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";" 
  } 




