//---------------------------------------
// Name   :  쿠키값 제어 함수
// Input  : 
// Output : 쿠키값에 저장된 ID 비밀번호 로딩
// Desc   : 쿠키값에 저장된 ID, 비밀번호가 있으면 input box에 저장된 값을 return
// Date   : 2005/10/29
// Writer : 김현주
//---------------------------------------
function fnInitLogin()
{
	var theForm = document.forms[0];
	var uid = fnGetCookie("login_id");
	var upw = fnGetCookie("login_pwd");

	if(uid != "" && uid != null )
	{
		if ( typeof( theForm.chkUserIDSave ) != "undefined" )
		{
			theForm.txtUserID.value = uid;
			theForm.chkUserIDSave.checked = "true";
		}
	}

	if(upw != "" && upw != null )
	{
		if ( typeof( theForm.chkPassWDSave ) != "undefined" )
		{
			theForm.txtPassWD.value = upw;
			theForm.chkPassWDSave.checked = "true";
		}
	}

	return false;
}

//---------------------------------------
// Name   :  쿠키값 칮기
// Input  : 
// Output : 
// Desc   : 
// Date   : 2005/10/29
// Writer : 김현주
//---------------------------------------
function fnGetCookieVal (offset)
{
	var endstr = document.cookie.indexOf (";", offset);

	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}


//---------------------------------------
// Name   :  쿠키 날짜를 새 날짜로 변경
// Input  : 
// Output : 
// Desc   : 
// Date   : 2005/10/29
// Writer : 김현주
//---------------------------------------
function fnFixCookieDate (date)
{
	var base = new Date(0);
	var skew = base.getTime(); // dawn of (Unix) time - should be 0

	if (skew > 0)  // Except on the Mac - ahead of its time
		date.setTime (date.getTime() - skew);
}

//---------------------------------------
// Name   :  쿠키값 칮기
// Input  : 
// Output : 
// Desc   : 
// Date   : 2005/10/29
// Writer : 김현주
//---------------------------------------
function fnGetCookie (name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;

	while (i < clen) {
		var j = i + alen;

		if (document.cookie.substring(i, j) == arg)
			return fnGetCookieVal (j);

		i = document.cookie.indexOf(" ", i) + 1;

		if (i == 0) break;
	}
			
	return null;
}

//---------------------------------------
// Name   :  쿠키값 굽기
// Input  : 
// Output : 
// Desc   : 
// Date   : 2005/10/29
// Writer : 김현주
//---------------------------------------
function fnSetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function fnDeleteCookie (name,path,domain) {
  if (fnGetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
//----------------------------------------------------------------

//----------------------------------------------------------------
// 아이디 패스워드 값 저장 함수
//----------------------------------------------------------------
function fnCheckLoginInfo()
{
	var theForm = document.forms[0];

	if( typeof( theForm.chkUserIDSave ) != "undefined" && theForm.chkUserIDSave.checked )
	{
		var expdate = new Date ();
		fnFixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
		expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now
		fnSetCookie ("login_id", theForm.txtUserID.value , expdate);
	}
	else
	{
		fnDeleteCookie ("login_id");
	}

	if( typeof( theForm.chkPassWDSave ) != "undefined" && theForm.chkPassWDSave.checked )
	{
		var expdate = new Date ();
		fnFixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
		expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now
		fnSetCookie ("login_pwd", theForm.txtPassWD.value , expdate);
	}
	else
	{
		fnDeleteCookie ("login_pwd");
	}

}

