
var fwdpage = null ;
function submitSignUplogin(){

	showLoadin();

		flag=true;
			if(!checkAvailabilityUname()){
						flag=false;
			}
			if(!checkAvailabilityPassword()){
					flag=false;
			}
			if(flag){
				var user=document.getElementById("userid").value;
				var pass=document.getElementById("password").value;
				fwdpage=document.getElementById("fwdpage").value;
				var checkField="notchecked";
					if(document.getElementById('check').checked == true)
					{
							checkField = "checked";
					}
				var url = "../web/home/ValidateServlet?username="+encodeURIComponent(user)+"&password="+encodeURIComponent(pass)+"&check="+encodeURIComponent(checkField);
				req=GetXmlHttpObject();	
				req.open("GET", url, true);
				req.onreadystatechange = callbackLogin;
				req.send(null);
				return true;
			}// flag fails
			else{
				return flag;
			}
}

function callbackLogin() {
		if (req.readyState == 4) {
			if (req.status == 200) {
				if(req.responseXML!=null)
				{
					parseMessageLogin(req.responseXML);
				}
			}
		}
		else{
					
		}
}

function GetXmlHttpObject(){
		var xmlHttp=null;
		try{
				  // Firefox, Opera 8.0+, Safari
				  xmlHttp=new XMLHttpRequest();
		}
		catch (e){
				  // Internet Explorer
				  try{
						xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
					}
				  catch (e){
						xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
					}
		 }
	return xmlHttp;
}

 function parseMessageLogin(responseXML) {
		var message = null;
		message = responseXML.getElementsByTagName("message")[0];					
		if(message!=null)
		{
			var checkmsg =message.childNodes[0].nodeValue;
			if(checkmsg=="invalid"){
					clearfields();
					document.getElementById('invalidPart').style.display = "block";
					document.getElementById('nactivatePart').style.display = "none";
			}
			if (checkmsg =="notactivated"){
				clearfields();
				document.getElementById('nactivatePart').style.display = "block";
				document.getElementById('invalidPart').style.display = "none";
			}
		}
		else
		 {	

				
				//var userdetails = responseXML.getElementsByTagName("USERDETAILS")[0];
				//var firstName = userdetails.getElementsByTagName('FIRST_NAME')[0].firstChild.data;
				//var lastName=userdetails.getElementsByTagName('LAST_NAME')[0].firstChild.data;
				//var balance = userdetails.getElementsByTagName('MY_CREDIT_BALANCE')[0].firstChild.data;
				if (fwdpage =="null"){
					window.location.href="gamesnew.jsp";
				}else{
					window.location.href=fwdpage+"?isSearch=true&searchHandsetID=0";
				}
				
				//showDetails(firstName,lastName,balance);
		}
	}

	function showDetails(name,lname,balance)  
	{	
		document.getElementById('topPart1').style.display = "block";
		document.getElementById('topPart').style.display = "none";
	}
	function clearfields(){
		document.getElementById("userid").value="";
		document.getElementById("password").value="";
		document.getElementById("userid").focus();
	}


	function showLoadin(){
		document.getElementById('loginPart').style.display = "none";
		document.getElementById('loadin').style.display = "block";
		
	}




function checkAvailabilityUname(){
		var username = document.getElementById("userid").value;
		if(username==""){
			 	document.getElementById('invalidPart').style.display = "none";
				document.getElementById('unamePart').style.display = "block"; 
				document.getElementById('nactivatePart').style.display = "none";
				return false;
		}
		 document.getElementById('unamePart').style.display = "none";
		 return true;
}

function checkAvailabilityPassword(){
		var password = document.getElementById("password").value;
		if(password==""){
			 	document.getElementById('pwdPart').style.display = "block";
				document.getElementById('nactivatePart').style.display = "none";
				return false;
		}
		 document.getElementById('pwdPart').style.display = "none";
		 return true;
}

function signout(){
		var checkField="signout";
		var url = "../web/home/SignOutServlet?check="+encodeURIComponent(checkField);
		req=GetXmlHttpObject();	
		req.open("GET", url, true);
		req.onreadystatechange = callback2;
		req.send(null);
}

function signoutTata(){
		var checkField="signoutTata";
		var url = "../web/home/SignOutServlet?check="+encodeURIComponent(checkField);
		req=GetXmlHttpObject();	
		req.open("GET", url, true);
		req.onreadystatechange = callback2;
		req.send(null);
}

function callback2() {
		if (req.readyState == 4) {
			if (req.status == 200){
					if(req.responseXML!=null)
					{
							parseMessage2(req.responseXML);
					}
			}
		}
}

function parseMessage2(responseXML) {
		
		var inmessage = null;
		inmessage = responseXML.getElementsByTagName("message")[0];					
		if(inmessage!=null)
		{
			var checkdmsg =inmessage.childNodes[0].nodeValue;
			if (checkdmsg == "signoutpartially")
			{
						//window.location.reload();
					window.location.replace("gamesnew.jsp");
			
					//document.getElementById('loginPart').style.display = "block";
					//document.getElementById('logoutPart').style.display = "none";
					
			}
			else if(checkdmsg == "signoutCompletely"){	
						window.location.href="gamesnew.jsp";
					//window.location.reload();
					//document.getElementById('loginPart').style.display = "block";
					//document.getElementById('logoutPart').style.display = "none";
			}else{
				window.location.href="http://partner.vsnl.com/CallMe.aspx?vendorid=TICPEN0001042&action=authenticate";
			}
		}
	}

	function signoutcmplt() {	
		var checkField="signoutcmplt";
		var url = "../web/home/SignOutServlet?check="+encodeURIComponent(checkField);
		if (typeof XMLHttpRequest != "undefined") {
			req = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
		req.open("GET", url, true);
		req.onreadystatechange = callback2;
		req.send(null);
	}

	
