var todo ='';// added by manoj 
var itemId ='';// added by manoj 
function loginValidation()
{
		var txtEmail 		=	 document.frm_Login.txtEmail.value;			
		var txtPassword		= 	document.frm_Login.txtPassword.value;
		var  reff			= 	document.frm_Login.reff.value;
		if(document.frm_Login.chkRememberMe.checked == true)
		var chkRememberMe 	=	document.frm_Login.chkRememberMe.checked

		if ( txtEmail.length <= 0 )
		{
			document.getElementById('div_error').innerHTML = "Email can not be empty."
			return false
		}
		else if( txtPassword.length <= 0)
		{
			document.getElementById('div_error').innerHTML = "Password can not be empty."
			return false
		}
		else
		document.getElementById('div_error').innerHTML ="<div style='padding-left:100px' ><img src='images/ajax-loader.gif' /><font color='red'> <b>Loading....</b></font></div>"

		Login(txtEmail , txtPassword, reff)
		return false
}

function trim(stringToTrim) 
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
var xmlHttp;

function Login(txtEmail , txtPassword ,reff)
{
	if (txtEmail.length == 0 || txtPassword == 0)
	  { 
		  document.getElementById("div_error").innerHTML="";
		  return;
	  }
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  } 
	var url= ""+siteURL+"userLogin.php";
	url=url+"?txtEmail="+txtEmail;
	url=url+"&vb_login_md5password="+txtPassword;
	url=url+"&todo="+todo;
	url=url+"&itemId="+itemId;
	url=url+"&reff="+reff;
	if(document.frm_Login.chkRememberMe.checked == true)
	{
		var chkRememberMe 	=	document.frm_Login.chkRememberMe.checked
		url=url+"&chkRememberMe=yes";
	}
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateChanged() 
{ 
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
		 if(xmlHttp.responseText != 1 )
		 {
			 document.getElementById("div_error").innerHTML=xmlHttp.responseText;
		 }
		 else
		 {	
		 
		 	if(todo=='addInstitute')
			{
				setTimeout("alert('Institute Successfully Added to your list of saved institutes on My '"+sitetitle+"')",1000)
			}
			if(todo=='addInternationalInstitute')
			{
				setTimeout("alert('Institute Successfully Added to your list of saved institutes on My '"+sitetitle+"')",1000)
			}
		 	if(todo=='addCourse')
			{
				setTimeout("alert('Course Successfully Added to your list of saved courses on My '"+sitetitle+"')",1000)
			}
		 	if(todo=='addEvent')
			{
				setTimeout("alert('Event Successfully Added to your list of saved events on My '"+sitetitle+"')",500)
			}

			var  reff		= document.frm_Login.reff.value;
			window.location=reff
			
		 	
			$.unblockUI();
		 }
	 } 
}

function forgetPassword(txtEmail)
{
	var txtEmailForgot	=	document.getElementById("txtEmailForgot").value
	
	if (txtEmailForgot == '')
	  { 
		  document.getElementById("div_error_Valid").innerHTML="Please Enter Your email!";
		  return false;
	  }
	  document.getElementById('div_error_Valid').innerHTML = "<div style='padding-left:100px' ><img src='images/ajax-loader.gif' /><font color='red'> <b>Loading....</b></font></div>"
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  } 
	var url=""+siteURL+"forgotPassword.php";
	url=url+"?txtEmail="+txtEmailForgot;
	//url=url+"&reff="+reff;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChangedForgot;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateChangedForgot() 
{ 
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
		 if(xmlHttp.responseText != 1 )
		 {
			 document.getElementById("div_error_Valid").innerHTML=xmlHttp.responseText;
		 }
		 else
		 {
		 document.getElementById("div_error_Valid").innerHTML ='Your password has been sent on your email';
		 }
	 } 
}

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 GoToBack(val)
{
	if(val == 0)
	{
		if(document.getElementById("b") != null)
			document.getElementById("b").style.display = "none";
			
		if(document.getElementById("a")!= null)
			document.getElementById("a").style.display = "block";
	}
	else
	{
		if(document.getElementById("b")!= null)
			document.getElementById("b").style.display = "block";
			
		if(document.getElementById("a")!= null)
			document.getElementById("a").style.display = "none";
	}
}
