var ActivationStateX;

function hideBoth(){


	closeAll();
	checkCookie();
}

function checkCookie(){
	var key=readCookie("acclaim");
	var temp=key;
	if(key==null||key==""){
		toggleBox('checkingLogin',0);
		openLogin();
	}else {	
        a = key.split(",");   
		sidX= a[1];
	    cookieUserId=a[0];
		cname=cookieUserId;
		toggleBox('checkingLogin',0);
		var k, sk = 0;
	    td = a[3].split("|");
	    for (k=0; k<td.length && sk == 0; ++k)
		if (td[k] == "0") 
		sk = 1;
       	if(sk==1)
			loginSuccessLayer(a[0]);
		else
			botsexistform(a[0]);
	}
}

function openLogin(){
	closeAll();
	document.getElementById('loginUserId').value="";
	document.getElementById('textfield').value="";
	
	toggleBox('apDivLogin1',1);
}

function login(str){
			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";
			var loginInputsArr = new Array()
			var loginTwoInputs = str;	
			
				for(i=0; i<=1;i++)
				{
				index=loginTwoInputs.indexOf("|");				
				loginInputsArr[i]=loginTwoInputs.slice(0,index);			
				loginTwoInputs=loginTwoInputs.slice(index+1);	
				}
		
		
			cname = loginInputsArr[0]
			pwd = loginInputsArr[1]
			
			
			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]					  
								
			if (result=="0"){ 
				strs = cname+","+sidX+","+userIDX+","+gstatusX+","+CharNameX+","+ActivationStateX+","+EmailX+","+AgeX;
				createCookie("acclaim",strs,90);
						
				var k, sk = 0;
				td = gstatusX.split("|");
				for (k=0; k<td.length && sk == 0; ++k) 
				if (td[k] == "0") 
					sk = 1;
    				if(sk==1)
					loginSuccessLayer(cname);
					else
					botsexistform(cname);
			}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=="3"){
				document.getElementById("errLoginID").innerHTML= "Status not active.";
			}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 loginSuccessLayer(str){
	closeAll();		
	toggleBox('apDivLogin2',1);
	document.getElementById("welcomeUser_login").innerHTML= str;
}

function botsexistform(str){
	closeAll();		
	toggleBox('clicktoregister',1);// open welcome layer
	document.getElementById("welcomeUser").innerHTML= str;
}

function clicktoregister(){
	xmlHttp=GetXmlHttpObject()		
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	d = new Date();
	var timeUnique = d.getTime();
	var url="BotsExist.jsp?uname="+cname+"&gid=0&&sesID="+sidX+"&t="+timeUnique;
	xmlHttp.onreadystatechange=clicktoregisterResponse;  
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
	
	
function clicktoregisterResponse(){ 
	if (xmlHttp.readyState==4){ 
		var  resultStr=xmlHttp.responseText;
        key=readCookie("acclaim");
        sarray=key.split(",");
        var strs = sarray[0] + "," + sarray[1] + "," + sarray[2] + "," + sarray[3] + "|0" + "," + sarray[4] + "," + sarray[5] + "," + sarray[6] + "," + sarray[7];
        
		createCookie("acclaim", strs ,90);
		toggleBox('clicktoregister',0);
		loginSuccessLayer(sarray[0]);
	}
}


function play(){
	xmlHttpPlay=GetXmlHttpObject()		
	if (xmlHttpPlay==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	//cookieUserId taken from cookie
	d = new Date();
	var timeUnique = d.getTime();
	var url="BotsGetStatus.jsp?uname="+cname+"&sesID="+sidX+"&t="+timeUnique;
	xmlHttpPlay.onreadystatechange=playResponse;  
	xmlHttpPlay.open("GET",url,true);
	xmlHttpPlay.send(null);
} 

function playResponse(){ 
	if (xmlHttpPlay.readyState==4){ 
		var  resultStr=xmlHttpPlay.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];
			//alert("split of the result = "+b[0] )
			if (b[0]=="status")  {
				var status=b[1];
				// alert("status "+status)
			}else if (b[0]=="username")  {
			    var username=b[1];
				// alert("username "+username)
			}else if (b[0]=="pwd")  {
			    var pwd=b[1];
				// alert("pwd "+pwd)
			}else if (b[0]=="AgeFlag")  {
			    var AgeFlag=b[1];
				 // alert("AgeFlag "+AgeFlag)
			}
			j++
		}
		
		if (status == "Active"){
			if (username == "undefined" || pwd == "undefined" || username == "undefined" || pwd == "undefined"){
				alert("Launch problem. Please try again.")
			}else {
				//fscommand("start", );
				var strs = unescape(username)+";"+unescape(pwd);
				on_login(strs);
			}
		}else{
			if (status == "undefined" || status == undefined){
				alert("For security reasons, please click the Sign Out button and sign in again.")
			}else{
				alert("Sorry, you cannot play the game because your status is "+status);
			}
		}
	}
			
}
		
function on_login(arg){
	var agt=navigator.userAgent.toLowerCase(); 
	var arr=agt.split(";");
	var chk=arr[1].split(" ");
	var str="msie";
	if(chk[1]==str){
		var pluginFound=false;
		pluginFound = detectPlugin('GameLauncher');
		// if not found, try to detect with VisualBasic
		if(!pluginFound && detectableWithVB){
			pluginFound = detectActiveXControl('Acclaim Game Launcher');
		}
		if(pluginFound){
		var dataString;
		//alert(":::::"+arg);
	 	var st=arg.split(":");
 		Starter.LaunchGame(st[0], st[1],"0");
		}else{
			alert("The launch control must be installed for the Play button to work.");
			var d=readCookie("acclaimInstrcheck");
			if(d==null || d== -1){
				createCookie("acclaimInstrcheck","Visited",90);
				window.location="instructions.htm";   
			}
		}
	}else{
		alert("This function works only for IE users, See instructions below for other browsers.");
	}
}

// Activex detection
var detectableWithVB = false;
var pluginFound = false;
 
function goURL(daURL) {
    // if the browser can do it, use replace to preserve back button
    if(javascriptVersion1_1) {
 window.location.replace(daURL);
    } else {
 window.location = daURL;
    }
    return;
}
 
function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
 
    // check for redirection
    if( redirectURL && ((pluginFound && redirectIfFound) || 
 (!pluginFound && !redirectIfFound)) ) {
 // go away
 goURL(redirectURL);
 return pluginFound;
    } else {
 // stay here and return result of plugin detection
 return pluginFound;
    } 
}
 
function canDetectPlugins() {
    if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
 return true;
    } else {
 return false;
    }
}
 
function detectFlash(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Shockwave','Flash'); 
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
 pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}
 
function detectGameLauncher(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('GameLauncher');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
 pluginFound = detectActiveXControl('Acclaim Game Launcher');
    }
 
   
if(!pluginFound)
{

alert("pluginFound");
var d=readCookie("acclaimInstrcheck");
if(d==null || d== -1)
{
 // createCookie("acclaimInstrcheck","Visited",90);
 //redirectCheck(!pluginFound, redirectURL, redirectIfFound);
alert("accccfc");
document.write("<OBJECT CLASSID = 'clsid:69EF49E5-FE46-4B92-B5FA-2193AB7A6B8A' ID='Starter' CODEBASE='http://www.acclaim.com/cabs/acclaim_v5.cab#version=1,0,0,5'></OBJECT>");   
}
else
{
document.write("<OBJECT CLASSID = 'clsid:69EF49E5-FE46-4B92-B5FA-2193AB7A6B8A' ID='Starter' CODEBASE='http://www.acclaim.com/cabs/acclaim_v5.cab#version=1,0,0,5'></OBJECT>");
}
 
 
}
else
{
document.write("<OBJECT CLASSID = 'clsid:69EF49E5-FE46-4B92-B5FA-2193AB7A6B8A' ID='Starter' CODEBASE='http://www.acclaim.com/cabs/acclaim_v5.cab#version=1,0,0,5'></OBJECT>");
}
 
 
 
 
}
 
function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
 var pluginsArrayLength = navigator.plugins.length;
 // for each plugin...
 for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
     // loop through all desired names and check each against the current plugin name
     var numFound = 0;
     for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
  // if desired plugin name is found in either plugin name or description
  if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
      (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
      // this name was found
      numFound++;
  }   
     }
     // now that we have checked all the required names against this one plugin,
     // if the number we found matches the total number provided then we were successful
     if(numFound == daPlugins.length) {
  pluginFound = true;
  // if we've found the plugin, we can stop looking through at the rest of the plugins
  break;
     }
 }
    }
    return pluginFound;
} // detectPlugin
 

// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');
 
    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');
 
    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');
 

    document.writeln('</scr' + 'ipt>');
}
 
//detectGameLauncher("activex.htm","false");
 
