﻿// JavaScript Document
var ID_stu=null;
var ID_tec=null;
var ty=null;
var ck=null;
var stuchess_content="";
var stuchess_obj="";
var stuchess_reobj="";
var stuchess_recontent="";
var tecchess_content="";
var tecchess_recontent="";
var pgn_content="";
var redirected;
function golog(who){
if(parent.toshowloginfo.innerHTML!=""){alert("您已登录！如果要重新登录，请先退出登录！");return;}
if(who==1){

	if(parent.loginmain==2){
		parent.member_tecselect.style.display="none";
		parent.member_stuselect.style.display="none";	
		if(stu_id.value=="" || stu_psw.value=="")
		{
		 	stushowloginfo.innerHTML="☆ 学号或密码不得为空!";
			ID_stu=null;
			return;
		}
		else{stushowloginfo.innerHTML="☆ 正在登录...";check_stumem(stu_id.value,stu_psw.value,2);
		}
		

	}else if(parent.loginmain==1){
		if(stu_id.value=="" || stu_psw.value=="")
		{
			stushowloginfo.innerHTML="☆ 学号或密码不得为空!";
			ID_stu=null;
			return;
		}
		else{stushowloginfo.innerHTML="☆ 正在登录...";check_stumem(stu_id.value,stu_psw.value,1);
		}
	
	}
}
if(who==2){
	if(parent.loginmain==2){
		parent.member_stuselect.style.display="none";
		parent.member_tecselect.style.display="none";
		if(tec_id.value=="" || tec_psw.value=="")
		{
		 	tecshowloginfo.innerHTML="☆ 用户名或密码不得为空!";
			ID_tec=null;
			return;
		}
		else{tecshowloginfo.innerHTML="☆ 正在登录...";
			check_tecmem(tec_id.value,tec_psw.value,2);
		}
		
	}else if(parent.loginmain==1){
		
		if(tec_id.value=="" || tec_psw.value=="")
		{
			tecshowloginfo.innerHTML="☆ 用户名或密码不得为空!";
			ID_tec=null;
			return;
		}
		else{tecshowloginfo.innerHTML="☆ 正在登录...";
			check_tecmem(tec_id.value,tec_psw.value,1);
		}		
	}
}


}


function check_stumem(idd,psww,where){
   var idd,psww,where;
   var xmlobj = null;
   var stuin=idd+"|"+psww;
   var savepwd=document.getElementById("savepwd").checked;
   
   xmlobj = createxmlhttp();
   xmlobj.open("get", "checkmem.asp?act=ck_ck&stuin="+stuin, true);
   xmlobj.onreadystatechange = function()
   {
      if(xmlobj.readyState == 4)
      {
         if(xmlobj.status == 200)
         {
			 var v = xmlobj.responseText;

			 if(v=="Wrong in System"){alert("在将您转为正式学员的操作上出现错误，请速联络HI-CHESS客服中心！");stushowloginfo.innerHTML="☆ 出现错误,请速联络HI-CHESS客服！";return;}
             if(v!="Not_mem"){	
					
			 		if(where==1){
						redirected=1;
						if (savepwd){SetCookieValues("hichessuser",stuin);}else{parent.window.location="stu_members.asp";}
						
					}else{
						var pgg=v.split("~");
			 			ty=pgg[1];
						ck=pgg[2];
						ID_stu=idd;
						stushowloginfo.innerHTML="☆ 登录成功,欢迎您!";
						parent.member_tecselect.style.display="none";
						parent.member_stuselect.style.display="block";
						parent.cango_2.style.display="none";
						parent.cango_3.style.display="none";
						parent.cango_4.style.display="none";
						redirected=0;
						if (savepwd){SetCookieValues("hichessuser",stuin);}
					}

			 }else {
				 if(where==1){stushowloginfo.innerHTML="☆ 登录失败,若您不是会员,请先注册!"; stu_psw.value="";return;}
				 	ty=null;
					ck=null;
					ID_stu=null;
					stushowloginfo.innerHTML="☆ 登录失败,若您不是会员,请先注册!"; 
					parent.cango_2.style.display="none";
					parent.cango_3.style.display="none";
					parent.cango_4.style.display="none";
					parent.member_tecselect.style.display="none";
					parent.member_stuselect.style.display="none";					
					stu_psw.value="";


			 }
		 }
	  }
   }
   xmlobj.send();	
}




function check_tecmem(idd,psww,where){
   var idd,psww,where;
   var xmlobj = null;

   var tecin=idd+"|"+psww;

   xmlobj = createxmlhttp();
   xmlobj.open("get", "checkmem.asp?act=tk_tk&tecin="+tecin, true);
   xmlobj.onreadystatechange = function()
   {
      if(xmlobj.readyState == 4)
      {
         if(xmlobj.status == 200)
         {
			 var v = xmlobj.responseText;

			 if(v=="System Wrong"){alert("在将您转为正式教员的操作上出现错误，请速联络HI-CHESS客服中心！");tecshowloginfo.innerHTML="☆ 出现错误,请速联络HI-CHESS客服！";return;}
             if(v!="Not_mem"){
			 	if(where==1){parent.window.location="tec_members.asp";return;}
					var pgg=v.split("~");
					ty=null;
					ck=pgg[1];
					ID_tec=idd;
					tecshowloginfo.innerHTML="☆ 登录成功,欢迎您!";
					parent.member_stuselect.style.display="none";
					parent.member_tecselect.style.display="block";
					parent.cango_2.style.display="none";
					parent.cango_3.style.display="none";
					parent.cango_4.style.display="none";

			 }else {
				 if(where==1){tecshowloginfo.innerHTML="☆ 登录失败,若您不是会员,请先注册!"; tec_psw.value="";return;}
				 	ty=null;
					ck=null;
					ID_tec=null;
					tecshowloginfo.innerHTML="☆ 登录失败,若您不是会员,请先注册!"; 
					parent.cango_2.style.display="none";
					parent.cango_3.style.display="none";
					parent.cango_4.style.display="none";
					parent.member_tecselect.style.display="none";
					parent.member_stuselect.style.display="none";					
					tec_psw.value=""

			 }
		 }
	  }
   }
   xmlobj.send();	
}

function logout(which){
if(!confirm("您确定要退出登录吗？"))return;
var xmlobj = null;
  xmlobj = createxmlhttp();	
   if(which==1)xmlobj.open("get", "main/logout.asp?act=logout", true);
   if(which==2)xmlobj.open("get", "logout.asp?act=logout", true);
   xmlobj.onreadystatechange = function()
   {
      if(xmlobj.readyState == 4)
      {
         if(xmlobj.status == 200)
         {
			 var v = xmlobj.responseText; 
			 if(v=="Not member"){alert("您尚未登录！");return;}
			 if(v=="stu logout"){
				 	alert("您已退出登录！期待您下次光临！");
					if(which==1){window.location="index.asp";}else{window.location="../index.asp";}
			 }
			 if(v=="tec logout"){
				 	alert("感谢您的支持！期待您下次光临！");
					if(which==1){window.location="index.asp";}else{window.location="../index.asp";}
			 }
		 }
	  }
   }
   xmlobj.send();
}
//new main
function click_log(t){
 	var t;
	document.getElementById('l_'+current_tab).className="moveout";
	document.getElementById('t_'+current_tab).style.display="none";
	document.getElementById('l_'+t).className="moveover";
	document.getElementById('t_'+t).style.display="block";
	current_tab=t;
}

var curs="c_1";
function ccolor(whi,thiss){
if(thiss==curs)return;
if(whi==0)document.getElementById(thiss).style.backgroundColor="#cccccc";else document.getElementById(thiss).style.backgroundColor="#eeeeee"
}
function scolor(thiss){
clk=true;
var kk=[];
kk=thiss.split("_");
curs=thiss;
document.getElementById(thiss).style.backgroundColor="#900000";
document.getElementById(thiss).style.color="#ffffff";
document.getElementById("k_"+kk[1]).style.display="block";
for(var i=1; i<7;i++){
if("c_"+i!=curs){
	document.getElementById("c_"+i).style.backgroundColor="#eeeeee";
	document.getElementById("c_"+i).style.color="#000000";
	document.getElementById("k_"+i).style.display="none";
}
}
}
function sscolor(thiss){
var ll="c_"+thiss;
curs=ll;
document.getElementById(ll).style.backgroundColor="#900000";
document.getElementById(ll).style.color="#ffffff";
document.getElementById("k_"+thiss).style.display="block";
for(var i=1; i<7;i++){
if("c_"+i!=curs){
	document.getElementById("c_"+i).style.backgroundColor="#eeeeee";
	document.getElementById("c_"+i).style.color="#000000";
	document.getElementById("k_"+i).style.display="none";
}
}
}


function showGame() {
if(fen==""||fen==undefined){var pgndata=pgn;}else{var pgndata=fen+" "+pgn;} 
var ds = '';
var cc="pgndata=" + encodepgn(pgndata);
ds = '<embed type="application/x-shockwave-flash" name= "FlashVars" src="main/flashPgnViewer/pgnreader-553.swf" width="555" height="369" FlashVars="'+cc+ '"></embed>';

var ds2='<div style="width:555px;height:369px;border:3px silver solid;"><a href="http://www.hi-chess.com" target="_blank">'+ds+'</a></div>';
insertCode=ds2;

ds = '<div style="height:20px;"></div><div style="width:555px;height:369px;border:3px silver solid;">'+ds+'</div>';
document.getElementById("showGames").innerHTML=ds;

}
function encodepgn(txt) {
ntxt = txt.replace(/\'/g, '?'); 
ntxt = ntxt.replace(/&/g, ' '); 
ntxt = ntxt.replace(/\n/g,' '); 
ntxt = ntxt.replace(/\r/g,' '); 
ntxt = ntxt.replace(/\+/g,'%2B'); 
ntxt = ntxt.replace(/\"/g,'\''); 
ntxt = ntxt.replace(/\ /g,'%20'); 
ntxt = ntxt.replace(/\%20%20/g,'%20');
if (ntxt.indexOf("]")>0){
ntxt = ntxt.replace(/]/g,']^');
ntxt = ntxt.replace(/\^%20%20/g,'^}%20%20');
ntxt=ntxt.replace(/\^%20/g,'^');
}
return ntxt;
}
function showPgnText(){
var pgndata=hrd+ "\r\n"+pgn;
document.getElementById("pgnForCopy").innerText=pgndata;
document.getElementById("pgnForCopy").style.fontFamily="Courier New";
document.getElementById("Layer1").style.display="block";
}
function showPgnInsert(){
document.getElementById("pgnForCopy").innerText=insertCode;
document.getElementById("pgnForCopy").style.fontFamily="Courier New";
document.getElementById("Layer1").style.display="block";
}
function closePgn(){
document.getElementById("Layer1").style.display="none";
}


window.onload = function ()
{
        var oBox = document.getElementById("box");
        var oList = oBox.getElementsByTagName("ul")[0];
        var aImg = oBox.getElementsByTagName("img");
        var timer = playTimer = null;
        var index = i = 0;
        var bOrder = true;
        var aTmp = [];
        var aBtn = null;
		clk=false;
        
        //生成数字按钮
        for (i = 0; i < aImg.length; i++) aTmp.push("<li>" + (i + 1) + "</li>");
        
        //插入元素
        var oCount = document.createElement("ul");
        oCount.className = "count";
        oCount.innerHTML = aTmp.join("");
        oBox.appendChild(oCount);        
        aBtn = oBox.getElementsByTagName("ul")[1].getElementsByTagName("li");
        
        //初始化状态
        cutover();
        
        //按钮点击切换
        for (i = 0; i < aBtn.length; i++)
        {
                aBtn[i].index = i;
                aBtn[i].onmouseover = function ()
                {
                        index = this.index;
                        cutover()
						if(clk==false)sscolor(index+1);
                }
        }
        
        function cutover()
        {
                for (i = 0; i < aBtn.length; i++) aBtn[i].className = "";
                aBtn[index].className = "current";                        
                startMove(-(index * aImg[0].offsetHeight))
        }
        
        function next()
        {
                bOrder ? index++ : index--;
                index <= 0 && (index = 0, bOrder = true);
                index >= aBtn.length - 1 && (index = aBtn.length - 1, bOrder = false)
                cutover()
				if(clk==false){sscolor(index+1);}
        }
        
        playTimer = setInterval(next, 3000);
        
        //鼠标移入展示区停止自动播放
        oBox.onmouseover = function ()
        {
				clk=false;
                clearInterval(playTimer)
        };
        
        //鼠标离开展示区开始自动播放
        oBox.onmouseout = function ()
        {
                playTimer = setInterval(next, 3000)
        };
        function startMove(iTarget)
        {
                clearInterval(timer);
                timer = setInterval(function ()
                {
                        doMove(iTarget)
                }, 30)        
        }
        function doMove (iTarget)
        {                
                var iSpeed = (iTarget - oList.offsetTop) / 10;
                iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);                
                oList.offsetTop == iTarget ? clearInterval(timer) : oList.style.top = oList.offsetTop + iSpeed + "px"
        }
};

