var bAlpha   = (location.host.indexOf('dev-') >= 0) || (location.host.indexOf('alpha') >= 0);
var bJustAlpha   = (location.host.indexOf('alpha') >= 0);
var bDev = (location.host.indexOf('dev-') >= 0);
var bBeta     = (location.host.indexOf('beta') >= 0);
var sIdsURL     = (bAlpha) ? 'http://alpha-id.hanjamaru.com' : (bBeta) ? 'http://beta-id.hanjamaru.com' : 'http://id.hanjamaru.com';
var sIdsSSLURL  = (bDev) ? 'http://dev-id.hanjamaru.com' : (bJustAlpha) ? 'http://alpha-id.hanjamaru.com' : (bBeta) ? 'http://beta-ids.hanjamaru.com' : 'https://ids.hanjamaru.com';
var sMemberURL  = (bAlpha) ? 'https://alpha-members.hanjamaru.com' : (bBeta) ? 'https://beta-members.hanjamaru.com' : 'https://members.hanjamaru.com';
var sMembersURL  = (bAlpha) ? 'https://alpha-members.hanjamaru.com' : (bBeta) ? 'https://beta-members.hanjamaru.com' : 'https://members.hanjamaru.com';
var sWwwURL	  	= (bAlpha) ? 'http://alpha-www.hanjamaru.com' : (bBeta) ? 'http://beta-www.hanjamaru.com' : 'http://www.hanjamaru.com';
/******** Login Form ***********/
// Dependency modual : common.js 

function openPopupLoginAfterReload() {
		openPopupLoginAfterCommon('', 'Y', 'N');
}

function openPopupLoginAfterMove(nxtURL) {
		openPopupLoginAfterCommon(nxtURL, 'Y', 'Y');
}

function openPopupLoginAfterSelfMove(nxtURL) {
		openPopupLoginAfterCommon(nxtURL, 'N', 'Y');
}

function openPopupLoginAfterCommon(nxtURL, popclose, closemove) {

		var url = sIdsURL +"/wlogin.nhn?popup=true";
		
		if (nxtURL == null || nxtURL == undefined || nxtURL == '') {
			url = url + "&popclose=Y&nxtURL=";
		} else {
			url = url + "&nxtURL=" + nxtURL + "&popclose=" + popclose + "&closemove=" + closemove;
		}
		
		//sURL, sWindowName, w, h, sScroll, reSize, status (common.js)
		openWin(url, "Wlogin", 388, 420, "no", "yes", "no");
}

function openPopupLoginAfterForMembers() {

	var url = sIdsURL +"/wlogin.nhn?popup=true";

	url = url + "&popclose=Y&closemove=Y&from=SSL";
	
	//sURL, sWindowName, w, h, sScroll, reSize, status (common.js)
	
	openWin(url, "Wlogin", 388, 420, "no", "yes", "no");
}

function goLogin() {
	top.location.href = sIdsURL + '/wlogin.nhn';
}

function goLogout() {
	top.location.href = sIdsURL + '/logout.nhn';
}
///////////////////////////
// LOGIN FORM
//////////////////////////
// Login Form View
function enableLoginButton() {
	if (document.getElementById('submitTD') != null) {
			document.getElementById('submitTD').style.display  = "none";
			document.getElementById('normalTD').style.display = "inline";
	}
}

// Login Form Value Check
function loadcatcookie(iperr) {
	if(iperr != "error.login.ip" && checkSSLCookie())
		document.loginform.ssl.checked = true;	
}	
	
function idFocus() {
	if (document.loginform.strmemberid.value.length == 0) {
		document.loginform.strmemberid.focus();
	}
}

function setSSLcheck(form) {
	if(checkSSLCookie()) {
		form.ssl.checked = true;
	}
}

function checkSSLCookie() {
	return document.cookie.indexOf("EDU_LOGIN_FORM=N")==-1 ? true : false;	//보안접속쿠키 
}

function resetText(inputGbn) {
	if (inputGbn == 'id') {
		document.getElementById("idObj").style.backgroundImage = '';
	} else if (inputGbn == 'pw') {
		document.getElementById("pwdObj").style.backgroundImage = '';	
	}
}


function showText(gbn) {
	var inputObj;
	if (gbn == 'id') {
		inputObj = document.getElementById("idObj");
		if (inputObj.value == '')
			inputObj.style.backgroundImage = 'url(http://images.hanjamaru.co.kr/nhn/hanjamaru/img/main/t_id.gif)';
	} else if (gbn == 'pw') {
		inputObj = document.getElementById("pwdObj");
		if (inputObj.value == '')
			inputObj.style.backgroundImage = 'url(http://images.hanjamaru.co.kr/nhn/hanjamaru/img/main/t_pw.gif)';
	}
}

function goServiceMenu(menu, addString) {
   if(menu=="register") {
		targetURL(sMemberURL + '/register/register.nhn');			
   } else if (menu=="findid") {  
		targetURL(sMemberURL + '/searchId/searchMyId.nhn');
   } else if (menu=="findpassword") { 
		targetURL(sMemberURL + '/searchId/searchMyPassword.nhn');
   } else if (menu=="iphelp") {   // IP보안 POPUP
   		openWin(sIdsURL + '/iphelp.nhn','edu',388,420);
   } else if (menu=="mappingMessage") {   // 부모자녀 연결 안내팝업
   		return openWin(sWwwURL + '/memberMap/memberMap.nhn?m=searchMessage&decorator=popupLayout&confirm=true','edu',388,400);		   
   }
}


function targetURL(sURL) {
	try {
		if (typeof(opener) == "object" && opener != null) {
			try {
				if (opener.top.location.href.indexOf("hanjamaru.com") >= 0) {
					opener.top.location.href = sURL;
					window.close();
				} else {
					top.location.href = sURL;
				}
			} catch (e) {
				top.location.href = sURL;
			}
		} else {
			top.location.href = sURL;
		}
	}catch(e) {
		window.open( sURL );
	}
}

function enterSubmit_key(n) {
	if (event.keyCode==13) {
		if (n==0) {	document.loginform.strpassword.focus();
		} else { enterLoginSubmit();	}
	}
}

function enterLoginSubmit() {
	var f = document.getElementById("loginform");
	
	if (f.strmemberid.value.length==0) {
		alert('아이디를 입력해 주세요');
		return;
	} 
	
	if (f.strpassword.value.length==0) {
		alert('비밀번호를 입력해 주세요');
		return;
	} else if (f.strpassword.value.length > 15) {
		alert('비밀번호는 최대 15자리입니다.\n비밀번호 자리 수를 확인해 주세요.');
		f.strpassword.value = "";
		return;
	} 
	
	f.action = sIdsSSLURL + "/login.nhn";
	f.nxtURL.value = (f.nxtURL.value=="")? top.document.URL : f.nxtURL.value;
	var sslgbn = f.ssl.checked;
	f.force.value = sslgbn ? "Y" : "N";	

	enableLoginButton();		
	f.submit();
}

/////////////////////////
// < CapsLock Notice Alarm
/////////////////////////
// CapsLock Notice
function checkCapsLock() {
	var e = event;
	var myKeyCode=0;
	var myShiftKey=false;

	if ( document.all ) {					// Internet Explorer 4+
		myKeyCode=e.keyCode; myShiftKey=e.shiftKey;	
	} else if ( document.layers ) {			// Netscape 4
		myKeyCode=e.which;	myShiftKey=( myKeyCode == 16 ) ? true : false;
	} else if ( document.getElementById ) {	// Netscape 6
		myKeyCode=e.which; myShiftKey=( myKeyCode == 16 ) ? true : false;
	}
	capslockNotice();
	//alert('myKeyCode='+myKeyCode+',myShiftKey='+myShiftKey);
	// Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
	if ( ( myKeyCode >= 65 && myKeyCode <= 90 ) && !myShiftKey ) { 
		setCapslockInfoOn();
	// Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
	} else if ( ( myKeyCode >= 97 && myKeyCode <= 122 ) && myShiftKey ) {
		setCapslockInfoOn();
	} 

}

function capslockNotice(){
	var noticestr = "<img src='http://images.hangame.co.kr/hangame/renewal_2007/common/main_new/capslock.gif' width=176 height=26 alt='CapsLock설정되어있습니다.'>";	
	noticestr = "<p><em>CapsLock</em> 이 켜져 있습니다.</p>";
	try{
		document.all.CapslockInfo.innerHTML = noticestr;
	}catch(e){
		top.document.getElementById("CapslockInfo").innerHTML =noticestr;
	}
}

function setCapslockInfoOn() {
	try{
		document.getElementById('CapslockInfo').style.display  = "inline";
	}catch(e){
		top.document.getElementById('CapslockInfo').style.display  = "inline";
	}
	setTimeout("setCapslockInfoOff()", 2000);
}
function setCapslockInfoOff() {	
	try{
		document.getElementById('CapslockInfo').style.display  = "none";
	}catch(e){
		top.document.getElementById('CapslockInfo').style.display  = "none";
	}
}

/////////////////////////
// CapsLock Notice Alarm >
/////////////////////////

//////// Main Login Form ///////////
function mainLoginForm() {
	var loginstr = "";
	loginstr += "	<form name='loginform' id='loginform' method='post' action=''>";
	loginstr += "	<input type='hidden' name='nxtURL'  value=''>";
	loginstr += "	<input type='hidden' name='force'   value=''>";
	loginstr += "	<legend>login</legend>";
	loginstr += "	<p class='id'><input type='text' name='strmemberid' id='idObj'";
	loginstr += "			maxlength=12 value='' tabindex=1"; 
	loginstr += "			onkeydown='enterSubmit_key(0)'"; 
	loginstr += "			style='background: url(http://images.hanjamaru.co.kr/nhn/hanjamaru/img/main/t_id.gif) no-repeat left top;' onClick=resetText('id'); onFocus=resetText('id');  onBlur=showText('id');></p>";
	loginstr += "	<p class='pw'><input type='password' name='strpassword' id='pwdObj'";
	loginstr += "        	value='' tabindex=2";
	loginstr += "			onKeyPress='checkCapsLock();' onkeydown='enterSubmit_key(1)'";
	loginstr += "        	style='background:url(http://images.hanjamaru.co.kr/nhn/hanjamaru/img/main/t_pw.gif) no-repeat left top;' onClick=resetText('pw'); onFocus=resetText('pw'); onBlur=showText('pw');></p>";
	loginstr += "   <div id='submitTD' style='display:inline;' class='loginBtn'><a href='javascript:void(enterLoginSubmit());'><img src='http://images.hanjamaru.co.kr/nhn/hanjamaru/img/main/btn_login.gif' width=58 height=55 alt='로그인'></a></div>";
	loginstr += "   <div id='normalTD' style='display:none;' class='loginBtn'><img src='http://images.hanjamaru.co.kr/nhn/hanjamaru/img/main/btn_login.gif' width=58 height=55 alt='로그인'></div>";
	loginstr += "	<div class='btn'>";
	loginstr += 	"<label class='security'><input type='checkbox' name='ssl' value='Y' " + (checkSSLCookie() ? 'checked' : '') + " tabindex=3 onkeydown='enterSubmit_key(1)'><a href=\"#\" onclick=\"goServiceMenu('iphelp');return false;\"><img src='http://images.hanjamaru.co.kr/nhn/hanjamaru/img/main/text_ip.gif' width=30 height=15 alt='IP보안'></a></label>";
	loginstr += "<a href=\"#\" onclick=\"goServiceMenu('register'); return false;\"><img src='http://images.hanjamaru.co.kr/nhn/hanjamaru/img/main/btn_join.gif' width=45 height=15 alt='회원가입'></a><a ";
	loginstr += "href=\"#\" onclick=\"goServiceMenu('findid'); return false;\"><img src='http://images.hanjamaru.co.kr/nhn/hanjamaru/img/main/btn_id_search.gif' width=42 height=15 alt='ID찾기'></a><a ";
	loginstr += "href=\"#\" onclick=\"goServiceMenu('findpassword'); return false;\"><img src='http://images.hanjamaru.co.kr/nhn/hanjamaru/img/main/btn_pw_search.gif' width=35 height=15 alt='PW찾기'></a>";	
	loginstr += "</div>";
	loginstr += "<div id='CapslockInfo' class='layer_caps' style='display:none; position:absolute; overflow:hidden; top:57px; left:0px; width:180px; height:30px;'>";
	loginstr += "<table border='0' cellpadding='0' cellspacing='0'>";
	loginstr += "<tr><td id='capslockNotice'></td></tr>";
	loginstr += "</table>";
	loginstr += "</div>";
	
	document.write(loginstr);
}	
