function GetCookie_Whereis(name)
{
	var label = name + "=" ;
	var labelLen = label.length ;
	var cLen = document.cookie.length;
	var i = 0;
	while (i < cLen){
		var j = i + labelLen;
		if (document.cookie.substring(i,j) == label) {
			var cEnd = document.cookie.indexOf(";",j);
			if (cEnd == -1){
				cEnd = document.cookie.length;
            		}
			return unescape(document.cookie.substring(j,cEnd));
        	}
		i++;
	}
	return "";
}
function GetParam_Whereis(str, name)
{
	//str.replace(/\\/g,"");
	var label = name + "=" ;
	var labelLen = label.length ;
	var cLen = str.length;
	var i = 0;
	while (i < cLen){
		var j = i + labelLen;
		if (str.substring(i,j) == label) {
			var cEnd = str.indexOf("|",j);
			if (cEnd == -1){
				cEnd = str.length;
            		}
            
			return unescape(str.substring(j,cEnd));
        	}
		i++;
	}
	return "";
}
///////////////////////// Ajax Login ///////////////////////
var httprequest = false;
	
if (window.XMLHttpRequest) {
	httprequest = new XMLHttpRequest();
	httprequest.onload = function() {
		// todo (ASync)
	};
}

if (window.ActiveXObject) {
	httprequest = new ActiveXObject("Microsoft.XMLHTTP");
}

if (httprequest) {
	httprequest.onreadystatechange = function() {
		if (httprequest.readyState==4) {
			// todo (ASync)
		}
	}
}

function requestPost(url, query) {
	if (httprequest) {
		try {
			httprequest.open("POST", url, false);
			httprequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			httprequest.send(query);
		} catch(error){
			alert(error.message);
		}
	}
}

function parseXML(params) {
	if (httprequest.status == 200) {
		var result = new Array();
		response = httprequest.responseXML;
		
		if (typeof(params) == 'string') {
			return response.documentElement.getAttribute(params);
		} else {
			for(attnm in params) {
				result[result.length] =  response.documentElement.getAttribute(params[attnm]);          
			}
			return result;
		}

	} else {
		alert('There was a problem with the request.');
	}
}
function parseText(params) {
	if (httprequest.status == 200) {
		
		var result = new Array();
		response = httprequest.responseText;
		
		for(i=0; i<params.length; i++ ) {
			result[i] = GetParam_Whereis(response, params[i]);
		}
		return result;
	} else {
		return "";
	}
}
function getLoginBoxInfo() {
	var user_id = GetCookie_Whereis("USER_ID");
	
	if( user_id != "" ) {
		
		requestPost("/loginBoxInfo.aspx", "id=" + user_id);
		//var res = parseXML(new Array('favorite_cnt', 'maplink_cnt', 'route_cnt', 'theme_cnt', 'memorialday_cnt', 'memo_date', 'memo_subject', 'memorial_remain_day', 'memorial_pkid'));
		var res = parseText(new Array('favorite_cnt', 'maplink_cnt', 'route_cnt', 'theme_cnt', 'memorial_remain_day', 'memo_date', 'memo_subject', 'memorial_pkid', 'user_name'));
		
		if((!res[0])||(!res[1])){
			//alert ("·Î±×ÀÎ Á¤º¸°¡ Á¤È®ÇÏÁö ¾Ê°Å³ª, ¼­¹ö¿ÍÀÇ Åë½ÅÀÌ ¿øÈ°ÇÏÁö ¾Ê½À´Ï´Ù.\n\nÀá½Ã ÈÄ ´Ù½Ã ÀÌ¿ëÇØ ÁÖ¼¼¿ä.");
			//ÀÌÀ¯¾øÀÌ ÃÊ±â ·Î±×ÀÎ½Ã Æ¯Á¤ºê¶ó¿ìÀú¿¡¼­¸¸(IE8-Æ¯Á¤»ç¿ëÀÚ)¹è¿­°ªÀÌ ¾È³Ñ¾î¿È.»õ·Î°íÄ§ÇÏ¸é °ª ¼ÂÆÃ µû¶ó¼­ ¾Æ·¡
			//reload()ÄÚµå ³Ö¾îÁÜ 2009.11.19
			printLogoutHtml();
			location.reload();
		} else {
		
			// set value
			printLoginHtml(res[0],res[1],res[2],res[3],res[4],res[5],res[6],res[7],res[8]);
		}
	} else {
		printLogoutHtml();
	}
	
}

function printLogoutHtml() {

	document.write("<table width='170' border='0' cellspacing='0' cellpadding='0'>                                                                                                              \n");
	document.write("  <script language='javascript'>                                                                                                                                            \n");
	document.write("  <!--                                                                                                                                                                      \n");
	document.write("  	function chkLogin(frm) {                                                                                                                                                \n");
	document.write("  		if(frm.id.value == '') {                                                                                                                                              \n");
	document.write("  			alert('¾ÆÀÌµð¸¦ ÀÔ·ÂÇÏ¼¼¿ä');                                                                                                                                       \n");
	document.write("  			frm.id.focus();                                                                                                                                                     \n");
	document.write("  			return false;                                                                                                                                                       \n");
	document.write("  		}                                                                                                                                                                     \n");
	document.write("  		if(frm.pwd.value == '') {                                                                                                                                             \n");
	document.write("  			alert('ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä');                                                                                                                                     \n");
	document.write("  			frm.pwd.focus();                                                                                                                                                    \n");
	document.write("  			return false;                                                                                                                                                       \n");
	document.write("  		}                                                                                                                                                                     \n");
	document.write("  		if(frm.saveid.checked == true) {                                                                                                                                      \n");
	document.write("  			setCookie('SAVED_USERID', frm.id.value, 30);                                                                                                                        \n");
	document.write("  		} else {                                                                                                                                                              \n");
	document.write("  			setCookie('SAVED_USERID', frm.id.value, -1);                                                                                                                        \n");
	document.write("  		}                                                                                                                                                                     \n");
	document.write("  	}                                                                                                                                                                       \n");
	document.write("  	function showUserid() {                                                                                                                                                 \n");
	document.write("		var sid = ReadCookie('SAVED_USERID');                                                                                                                                 \n");
	document.write("  		frm = document.loginForm;                                                                                                                                             \n");
	document.write("  		if(sid != '') {                                                                                                                                                        \n");
	document.write("  			frm.id.value = sid;                                                                                                                                                 \n");
	document.write("  		}                                                                                                                                                                   \n");
	document.write("  	}                                                                                                                                                                       \n");
	document.write("  //-->                                                                                                                                                                     \n");
	document.write("  </script>                                                                                                                                                                 \n");
    document.write(" <table width='175' height='115px' border='0' cellspacing='0' cellpadding='0'>                                                  \n");
    document.write("     <tr>                                                                                                                       \n");
    document.write("  	<form name='loginForm' action='https://member.whereis.co.kr/Login.aspx' method='post' onSubmit='return chkLogin(this);'>    \n");
    document.write("  	<input name='rurl' type='hidden' value='/' >                                                                                \n");
    document.write(" 	<td height='32'><img src='/Images/Main/LoginTitle.gif' width='175' height='32'></td>                                        \n");
    document.write("     </tr>                                                                                                                      \n");
    document.write("     <tr>                                                                                                                       \n");
    document.write(" 	<td>                                                                                                                        \n");
    document.write(" 	    <table width='100%' border='0' cellspacing='0' cellpadding='0'>                                                         \n");
    document.write(" 		<tr>                                                                                                            \n");
    document.write(" 		    <td width='115' height='24' valign='top'>                                                                   \n");
    document.write(" 			<input name='id' type='text' tabindex='1' class='inputbox01' style='width: 110px'></td>                     \n");
    document.write(" 		    <td width='58' class='smalltxt01'>                                                                          \n");
    document.write(" 			<input name='saveid' tabindex='3' type='checkbox' checked>IDÀúÀå</td>                                       \n");
    document.write(" 		</tr>                                                                                                           \n");
    document.write(" 		<tr>                                                                                                            \n");
    document.write(" 		    <td height='20'>                                                                                            \n");
    document.write(" 			<input name='pwd' type='password' tabindex='2'class='inputbox01' style='width: 110px'></td>                 \n");
    document.write(" 		    <td>                                                                                                        \n");
    document.write(" 			<input type=image src='/Images/Main/BtnLogin.gif' width='58' height='18'></td>                              \n");
    document.write(" 		</tr>                                                                                                           \n");
    document.write(" 	    </table>                                                                                                                \n");
    document.write(" 	</td>                                                                                                                       \n");
    document.write("     </tr>                                                                                                                      \n");
    document.write("     <tr>                                                                                                                       \n");
    document.write(" 	<td height='1' background='/Images/Main/DotLine01.gif'>                                                                     \n");
    document.write(" 	    <img src='/Images/Main/DotLine01.gif' width='4' height='1'></td>                                                        \n");
    document.write("     </tr>                                                                                                                      \n");
    document.write("     <tr>                                                                                                                       \n");
    document.write(" 	<td height='25' align='center' valign='bottom'>                                                                             \n");
    document.write(" 	    <table border='0' cellspacing='0' cellpadding='0'>                                                                              \n");
    document.write(" 		<tr>                                                                                                                            \n");
    document.write(" 		    <td>                                                                                                                        \n");
    document.write(" 			<table border='0' cellspacing='0' cellpadding='0'>                                                                          \n");
    document.write(" 			    <tr>                                                                                                                    \n");
    document.write(" 				<td>                                                                                                                    \n");
    document.write(" 				    <a href='/Scripts/Member/IdFind.aspx'><img src='/Images/Main/BtnFind.gif' width='112' height='18'></a></td>         \n");
    document.write(" 				<td width='5'>                                                                                                          \n");
    document.write(" 				</td>                                                                                                                   \n");
    document.write(" 				<td>                                                                                                                    \n");
    document.write(" 				    <a href='/Scripts/Member/RegStep01.aspx'><img src='/Images/Main/BtnJoin.gif' width='58' height='18'></a></td>       \n");
    document.write(" 			    </tr>                                                                                                                   \n");
    document.write(" 			</table>                                                                                                                    \n");
    document.write(" 		    </td>                                                                                                                       \n");
    document.write(" 		</tr>                                                                                                                           \n");
    document.write(" 	    </table>                                                                                                                        \n");
    document.write(" 	</td>                                                                                                                               \n");
    document.write("     </tr>                                                                                                                              \n");
    document.write(" </table>															                                                                    \n");					
	
}

function printLoginHtml(favorite_cnt, maplink_cnt, route_cnt, theme_cnt, memorial_remain_day, memo_date, memo_subject, memorial_pkid, user_name) {
	
	var memo_str = "";
	var memo_img = "";
	
	//alert(memo_subject);
	//memo_subject = memo_subject.replace(/\\/g,"");
	
	if(memorial_remain_day == '-1') {
			memo_str = "<a href='/Scripts/MyPage/CarDiary/MemorialList.aspx' title='¿À´Ã ±â¾ïÇÒ ±â³äÀÏÀÌ ¾ø½À´Ï´Ù.'>±â³äÀÏ : ¹Ìµî·Ï</a>";
			memo_img = "/Images/Main2/off_btn.gif";
	} else {
		if(memorial_remain_day == 0) {
			memo_str = "<a href='/Scripts/MyPage/CarDiary/MemorialWrite.aspx?cmd=view&pkid=" + memorial_pkid + "' title='" + memo_subject + " (" + memo_date + ")" + "'><b>±â³äÀÏ : </b>¿À´Ã</a>";
			memo_img = "/Images/Main/today_btn.gif";
		}
		else {
			memo_str = "<a href='/Scripts/MyPage/CarDiary/MemorialWrite.aspx?cmd=view&pkid=" + memorial_pkid + "' title='" + memo_subject + " (" + memo_date + ")" + "'><b>±â³äÀÏ : </b>" + memorial_remain_day + "ÀÏÀü</a>";
			memo_img = "/Images/Main2/on_btn.gif";
		}
	}
	
    document.write(" <table width='175' height='120px' border='0' cellspacing='0' cellpadding='0'>                                                                                  \n");
    document.write("     <tr>                                                                                                                                                       \n");
    document.write(" 	<td height='25'>                                                                                                                                        \n");
    document.write(" 	    <b>"+user_name+"</b>´Ô, ¾È³çÇÏ¼¼¿ä!</td>                                                                                                            \n");
    document.write("     </tr>                                                                                                                                                      \n");
    document.write("     <tr>                                                                                                                                                       \n");
    document.write(" 	<td height='1' background='/Images/Main/DotLine01.gif'>                                                                                                 \n");
    document.write(" 	    <img src='/Images/Main/DotLine01.gif' width='4' height='1'></td>                                                                                    \n");
    document.write("     </tr>                                                                                                                                                      \n");
    document.write("     <tr>                                                                                                                                                       \n");
    document.write(" 	<td height='5'>                                                                                                                                         \n");
    document.write(" 	</td>                                                                                                                                                   \n");
    document.write("     </tr>                                                                                                                                                      \n");
    document.write("     <tr>                                                                                                                                                       \n");
    document.write(" 	<td>                                                                                                                                                    \n");
    document.write(" 	    <table width='100%' border='0' cellspacing='0' cellpadding='0'>                                                                                     \n");
    document.write(" 		<tr>                                                                                                                                            \n");
    document.write(" 		    <td height='20' class='smalltxt01'>                                                                                                         \n");
    document.write(" 			³»°¡ µî·ÏÇÑ Á¤º¸</td>                                                                                                                   \n");
    document.write(" 		</tr>                                                                                                                                           \n");
    document.write(" 		<tr>                                                                                                                                            \n");
    document.write(" 		    <td>                                                                                                                                        \n");
    document.write(" 			<table width='100%' border='0' cellspacing='0' cellpadding='0'>                                                                         \n");
    document.write(" 			    <tr>                                                                                                                                \n");
    document.write(" 				<td height='19' class='smalltxt01'>                                                                                             \n");
    document.write(" 				    <a href='/Scripts/MyPage/MyMap/MaplinkList.aspx'>¾àµµ : <span class='smalltxt02'>"+ maplink_cnt +"</span>°Ç</a></td>        \n");
    document.write(" 				<td class='smalltxt01'>                                                                                                         \n");
    document.write(" 				    <a href='/Scripts/MyPage/MyTheme/MyTheme.aspx'>¸¶ÀÌÅ×¸¶ : <span class='smalltxt02'>"+ theme_cnt +"</span>°Ç</a></td>          \n");
    document.write(" 			    </tr>                                                                                                                               \n");
    document.write(" 			    <tr>                                                                                                                                \n");
    document.write(" 				<td height='19' class='smalltxt01'>                                                                                             \n");
    document.write(" 				    <a href='/Scripts/MyPage/MyMap/RouteList.aspx'>°æ·Î : <span class='smalltxt02'> "+ route_cnt +"</span>°Ç</a></td>           \n");
    document.write(" 				<td class='smalltxt01'>                                                                                                         \n");
    document.write(" 				    <a href='/Scripts/MyPage/MyMap/FavList.aspx'>Áñ°ÜÃ£±â : <span class='smalltxt02'>"+ favorite_cnt +"</span>°Ç</a></td>       \n");
    document.write(" 			    </tr>                                                                                                                               \n");
    document.write(" 			</table>                                                                                                                                \n");
    document.write(" 		    </td>                                                                                                                                       \n");
    document.write(" 		</tr>                                                                                                                                           \n");
    document.write(" 	    </table>                                                                                                                                            \n");
    document.write(" 	</td>                                                                                                                                                   \n");
    document.write("     </tr>                                                                                                                                                      \n");
    document.write("     <tr>                                                                                                                                                       \n");
    document.write(" 	<td height='5'>                                                                                                                                         \n");
    document.write(" 	</td>                                                                                                                                                   \n");
    document.write("     </tr>                                                                                                                                                      \n");
    document.write("     <tr>                                                                                                                                                       \n");
    document.write(" 	<td height='1' background='/Images/Main/DotLine01.gif'>                                                                                                 \n");
    document.write(" 	    <img src='/Images/Main/DotLine01.gif' width='4' height='1'></td>                                                                                    \n");
    document.write("     </tr>                                                                                                                                                      \n");
    document.write("     <tr>                                                                                                                                                       \n");
    document.write(" 	<td height='30' align='center'>                                                                                                                         \n");
    document.write(" 	    <table border='0' cellspacing='0' cellpadding='0'>                                                                                                  \n");
    document.write(" 		<tr>                                                                                                                                            \n");
    document.write(" 		    <td>                                                                                                                                        \n");
    document.write(" 			<table border='0' cellspacing='0' cellpadding='0'>                                                                                      \n");
    document.write(" 			    <tr>                                                                                                                                \n");
    document.write(" 				<td>                                                                                                                            \n");
    document.write(" 				    <a href='/Scripts/Member/RegStep02Update.aspx'>                                                                             \n");
    document.write(" 					<img src='/Images/Main/BtnInfoModify.gif' width='85' height='18'></a></td>                                              \n");
    document.write(" 				<td width='5'>                                                                                                                  \n");
    document.write(" 				</td>                                                                                                                           \n");
    document.write(" 				<td>                                                                                                                            \n");
    document.write(" 				    <a href='https://member.whereis.co.kr/Logout.aspx'><img src='/Images/Main/BtnIogout.gif' width='85' height='18'></a></td>   \n");
    document.write(" 			    </tr>                                                                                                                               \n");
    document.write(" 			</table>                                                                                                                                \n");
    document.write(" 		    </td>                                                                                                                                       \n");
    document.write(" 		</tr>                                                                                                                                           \n");
    document.write(" 	    </table>                                                                                                                                            \n");
    document.write(" 	</td>                                                                                                                                                   \n");
    document.write("     </tr>                                                                                                                                                      \n");
    document.write(" </table>																			\n");
	

}