//<![CDATA[
/*
* 로그인 상단바(By neoshim : 2006.12.08)
*
*/
var req;
var topbarTxt = "";
var xCoord = 0, yCoord = 0;
//document.onmousemove = checkwhere;

if(document.captureEvents){
    document.captureEvents(Event.MOUSEMOVE);
}

function checkwhere(e) 
{
    if(document.layers){
        xCoord = e.x;
        yCoord = e.y;
    }else if(document.all){
        xCoord = event.clientX;
        yCoord = event.clientY;
    }else if(document.getElementById){
        xCoord = e.clientX;
        yCoord = e.clientY;
    }
}

function check_login()
{
	if( document.getElementById("Loginbox").style.display == "")
		document.getElementById("Loginbox").style.display = "none";
	else{
		var wd;
		var sid;
		wd 	= document.body.clientWidth;
		sid = getCookie('TSSESSION_LOGINID');
		document.getElementById("Loginbox").style.left= wd - 300 + "px";
		document.getElementById("Loginbox").style.top = 35 + "px";
		document.getElementById("Loginbox").style.display = "";
		if( sid != null ){
			document.getElementById("usrid").value = getCookie('TSSESSION_LOGINID');
			document.getElementById("save").checked = true;
		}
	}
	return;
}

function login_valid(){
	var usrid, pass;

	usrid = document.getElementById("usrid").value;
	pass  = document.getElementById("pass").value;

	req = getXMLHttpRequest();
	if( req == null ) return false;
	
	req.onreadystatechange = processReqChange;
	req.open("POST", "/inc/chkid.php", true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send("loginid="+usrid+"&pwd="+pass);
}

function get_topbar(){
	req = getXMLHttpRequest();
	if( req == null ) return false;
	
	req.onreadystatechange = processReqTopbar;
	req.open("POST", "/inc/topbar.php", true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send("");
}

function go_login(ds){
	var usrid, pass, save;

	usrid = document.getElementById("usrid").value;
	pass  = document.getElementById("pass").value;

	if( document.getElementById("save").checked ) save  = 'true';
	else save = ''

	req = getXMLHttpRequest();
	if( req == null ) return false;

	req.onreadystatechange = processReqLogIn;
	req.open("POST", "/"+ds+"/login", true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

	req.send("loginid="+usrid+"&password="+pass+"&save="+save);
}

function getXMLHttpRequest() {
  var xmlreq = false;

  if (window.XMLHttpRequest) {
    xmlreq = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    try {
      xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e1) {
      try {
        xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
      }
    }
  }
  return xmlreq;
}

function processReqLogIn(){
	if (req.readyState == 4) {
	    if (req.status == 200) {
	    	document.location.reload();
	  	}
	}
}

function processReqTopbar(){
	if (req.readyState == 4) {
	    if (req.status == 200) {
	    	document.getElementById("full_menubar").innerHTML = req.responseText;
	  	}
	}
}

function processReqChange(){
	if (req.readyState == 4) {
	    if (req.status == 200) {	
	  		mainControl(); 
	  	}
	}
}

function mainControl() {
    var xmlData 	= req.responseXML;       					//XML응답.
    var itemNode 	= xmlData.getElementsByTagName("item");   	//아이템
    var codeNode 	= xmlData.getElementsByTagName("itemcode");	//아이템 응답코드
    var descNode 	= xmlData.getElementsByTagName("itemdesc");	//아이템 설명
    var itemLength 	= itemNode.length;      					//아이템 개수
    var resultXML 	= "", cd, ds;

    for (i=0; i<itemLength; i++) {
        cd = codeNode[i].childNodes[0].nodeValue;
        ds = descNode[i].childNodes[0].nodeValue;
        
        if( cd == "101" ){
        	go_login(ds);
        }else{
        	alert("아이디 또는 비밀번호가 일치하지 않습니다.");
        }   
    }
}

function getCookie (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 getCookieVal (j);
	      
	    i = document.cookie.indexOf(" ", i) + 1;
	    if (i == 0) break;
	}

	return null;
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}


document.write('<div id="full_menubar"  style="position:absolute; left:0px; top:0px; width:100%; z-index:1;display:;background-color:#99cccc;">');
document.write('</div><br><br>');
/*
myObj = document.getElementById("full_menubar"); 
if( isIE ) myObj.style.width = document.body.clientWidth;

window.onresize = function(){
  set_rezie();
}

function set_rezie(){
	myObj = document.getElementById("full_menubar"); 
	if( isIE ) myObj.style.width = document.body.clientWidth;
}
*/
document.write('<link rel="stylesheet" media="screen" type="text/css" href="/style/epi.css" />');

document.write('<div id="Loginbox" style="position:absolute; left:0px; top:0px; width:300px; height: 0; z-index:1;display:none;background-color:#99cccc;margin:0px;">');
document.write('<table style="width:300px; border:5px solid #BCD2E5; background-color:#fff;">');
document.write('<tr>');
document.write('  <td style="padding:10px;">');
document.write('    <table width="100%" border="0" cellspacing="0" cellpadding="0">');
document.write('      <tr>');
document.write('        <td style="font-size:12px; color:#333; padding:0 0 10px 5px;">');
document.write('			<div style="padding:2px; text-align:center; cursor:default;">');
document.write('			<font color="#000000"><b>에피소드 로그인</b></font>');
document.write('			</div>');
document.write('				<div style="float:left; text-align:right; width:50px; height:20px;">이 메 일</div><div style="text-align:left">');
document.write('					: <input type="text" class="eeepibox01" id="usrid" size="20" value=""></div>');
document.write('				<div style="float:left; text-align:right; width:50px;">비밀번호</div><div style="text-align:left">');
document.write('					: <input type="password" class="eeepibox01" id="pass" size="20" onkeydown="if(event.keyCode == 13) login_valid();"></div>');                                                            
document.write('				<center>');
document.write('				<a href="#" onclick="login_valid()">[로그인]</a>');
document.write('				<a href="#" onclick="check_login()">[취소]</a>');
document.write('				</center>');
document.write('				<div style="float:left; text-align:right; width:250px;">[이메일저장]<input type=checkbox name=save id=save></div>');
document.write('        </td>');
document.write('      </tr>');
document.write('    </table>');
document.write('  </td>');
document.write('</tr>');
document.write('</table>');
document.write('</div>');
document.write('<table><tr><td height="10"></td></tr></table>');
get_topbar();

