//--------------------------cookie checking-------------------------
function checkCookie(){
	var key=readCookie("acclaim");
	var temp=key;
	if(key==null||key==""){
	toggleBox('checkingLogin',0);
	toggleBox('apDivLogin1',1);
	}else {	
        a = key.split(",");   
		sidX= a[1];
	    	cookieUserId=a[0];
		cname=cookieUserId;
		toggleBox('checkingLogin',0);
		loginSuccessLayer(a[0]);
		
	}
}


function loginSuccessLayer(str){
	toggleBox('apDivLogin1',0);		
	toggleBox('apDivLogin2',1);
	document.getElementById("welcomeUser").innerHTML= str;
}

//------------------------------end checking----------------------------

//-------------------------------------sign out---------------------------------
function signout1(){
	//alert("sigouy");

    var str=readCookie("acclaim");
	var val_arr=str.split(",");
	d = new Date();
	var timeUnique = d.getTime();
	var url="SignOut.jsp?t="+timeUnique+"&uname="+val_arr[0]+"&sesID="+val_arr[1];	
					
	xmlHttp=GetXmlHttpObject()
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

    	xmlHttp.onreadystatechange=function(){	
		if (xmlHttp.readyState==4){
        }
		

document.getElementById('loginUserId').value="";
document.getElementById('textfield').value="";

eraseCookie("acclaim");
    }
}



//------------------------------------end sign out-------------------------------------




var ActivationStateX;

function login(){
	var err=0;
						document.getElementById('errLoginID').innerHTML="";	
						document.getElementById('errLoginPW').innerHTML="";								
																	
						var userNameChk1=document.getElementById('loginUserId');
						var pwChk1=document.getElementById('textfield');
										
						if(isEmpty(userNameChk1, "User name should not be empty")==true){
						document.getElementById('errLoginID').innerHTML="User name should not be empty";	
						err =1;					
						}else if(isEmpty(pwChk1, "Password should not be empty")==true){	
						document.getElementById('errLoginPW').innerHTML="Password should not be empty";				
						err =1;					
						}
			
			if(err==0){

		document.getElementById('loginBtn').disabled=true;
	document.getElementById('loginBtn').style.cursor="wait";
document.body.style.cursor="wait";
		
			cname = document.getElementById('loginUserId').value;


			pwd = document.getElementById('textfield').value;
			
			
			xmlHttp=GetXmlHttpObject()		
			if (xmlHttp==null)
			{
			alert ("Your browser does not support AJAX!");
			return;
			} 
			d = new Date();
			var timeUnique = d.getTime();
			var url="BotsLogin.jsp?username="+cname+"&pwd="+pwd+"&t="+timeUnique;
            		xmlHttp.onreadystatechange=loginResponse;  
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			} 
			
}
	
	
function loginResponse(){ 
		if (xmlHttp.readyState==4){ 
					
						document.getElementById('loginBtn').disabled=false;
			document.getElementById('loginBtn').style.cursor="default";
document.body.style.cursor="default";
		
					var  resultStr=xmlHttp.responseText;
					
					var caX = resultStr.split('&');				
					var j=0;
					var b 
					var mycars =new Array
						for(var i=1;i <caX.length;i++){
							  b= caX[i].split('=');
							  mycars[j]=b[1];  
							  j++
						}
					  result=mycars[0];
					  sidX=mycars[1]
					  userIDX=mycars[2]
					  gstatusX=mycars[3]
					  AgeX=mycars[4]
					  EmailX=mycars[5]
					  CharNameX=mycars[6]

					  //alert(result);
								
					if (result=="0"){ 
						strs = cname+","+sidX+","+userIDX+","+gstatusX+","+CharNameX+","+ActivationStateX+","+EmailX+","+AgeX;
						createCookie("acclaim",strs,90);

						loginSuccessLayer(cname); // close the login, show the success window



					}else if (result=="1"){
						document.getElementById("errLoginPW").innerHTML= "User ID or Password is incorrect";
						}else if (result=="2"){
						document.getElementById("errLoginID").innerHTML= "User ID or Password is incorrect";
						}else if (result=="4"){
						document.getElementById("errLoginID").innerHTML= "Status not active.";
					} 	else if (result=="98"){
						document.getElementById("errLoginID").innerHTML= "Your Account locked, please try after 10 mins.";
					}
		}
}

function showInvite(){
	window.location="invite-friend.html";
}
function showHome(){
	window.location="index.html";
}

function linkCommunity(){
	window.location="http://phpbb.acclaim.com/acclaim/";
}

function loginSuccessLayer(str){
	closeAll();
	toggleBox('apDivLogin2',1);
	document.getElementById("welcomeUser").innerHTML= str;
}
function closeAll(){
	toggleBox('apDivLogin1',0);
	toggleBox('apDivLogin2',0);
	toggleBox('apDivForgotID1',0);
	toggleBox('apDivForgotID2',0);
	toggleBox('apDivForgotPW1',0);
	toggleBox('apDivForgotPW2',0);
}
function openLogin(){
closeAll();
	toggleBox('apDivLogin1',1);
}