// Custom Functions Created By Srangdal

function registerTeam(){
var xmlhttp = getXmlHttpObject();

//var params = "optString=2&teamname="+$("#rteamname").val()+"&password="+$("#rpassword").val()+"&email="+$("#email").val()+"&contactnum="+$("#contactnum").val();
var params = "optString=1&teamname="+$("#rteamname").val()+"&contactnum="+$("#contactnum").val();
params+="&member1="+$("#email").val()+"&password="+$("#rpassword").val();

xmlhttp.open("POST","TeamLoginAndRegistrastionServlet",true);
xmlhttp.onreadystatechange=function()
{
	
		if(xmlhttp.readyState==4)
		{
				var returnString = xmlhttp.responseText;
				if(returnString==0){
					$("#registerform").hide();
					$("#RegMessage").html("An activation link has been sent to the e-mail address provided by you.<br/>Please complete the registration by clicking the activation link.").show();
					//window.location.href=window.location.href;
					//disablePopup();
				}else{
					$("#RegMessage").html(returnString);
					$("#RegMessage").show();
					$("#registerform").hide();
				}
		}
}; 
//Send the proper header information along with the request
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(params); 
}


function doLogin(optmsg){
var xmlhttp = getXmlHttpObject();
//var params = "optString=0&teamname="+$("#teamname").val()+"&password="+$("#password").val();
var params = "optString=2&memEmail="+$("#teamname").val()+"&memPassword="+hex_md5($("#password").val());
toMem(this);
xmlhttp.open("POST","TeamLoginAndRegistrastionServlet",true);
xmlhttp.onreadystatechange=function()
{
	if(xmlhttp.readyState==4){			
		var returnString = xmlhttp.responseText;
		if(returnString=="true"){
			window.location.href="Play-IQuest.jsp";//playErathon.jsp";
		}else{
			document.getElementById("invalid_login").innerHTML="<label class='error'>Invalid username/password!</label>";
		}
	}				
}
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(params); 
}

function Gamelogout(){
	var xmlhttp = getXmlHttpObject();
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4){	
				window.location="./";
		}
	}
	//document.getElementById("login").style.display='none';
	//document.getElementById("logout").style.display='block';
	xmlhttp.open("POST","LoginAndRegistration",true);
	//Send the proper header information along with the request
	var params = "optString=1&teamname=&email=";
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
}


function makePWDForm(){
	document.getElementById("loginHeader").innerHTML="Reset your IQuest account password";
	$("#registerformlog").hide();
	$("#resetPwd").show();
}

function makeLoginForm(){
	document.getElementById("loginHeader").innerHTML="Login to your IQuest account";
	$("#resetPwd").hide();
	$("#registerformlog").show();
}
function forgotPassword(){
	var xmlhttp = getXmlHttpObject();
	var val1 = document.getElementById("fpteamname").value;
	var val2 = document.getElementById("fppassword").value;
	
	if(val1=="" || val2==""){
		Sexy.alert("U missed the required fields!"); 
	}else if(val2.indexOf("@")==-1 || val2.indexOf(".")==-1){
		Sexy.alert("Invalid MailId"); 
	}else{
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){	
				returnString = xmlhttp.responseText;
				Sexy.alert(returnString);
			}
		};
		//document.getElementById("login").style.display='none';
		//document.getElementById("logout").style.display='block';
		xmlhttp.open("POST","LoginAndRegistration",true);
		//Send the proper header information along with the request
		var params = "optString=4&teamname="+val1+"&email="+val2;
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.send(params); 
	}
	
}
