var req;
  
		function loginValidate(page)
		{
			var pagename=page
				
			var msg = document.getElementById("loginError");
			var username=document.getElementById('username').value;
			var password=document.getElementById('password').value;
			if(username.length==0)
			{
				alert("Please enter Login id");
				document.getElementById('username').focus();
				return false;
			}else if(!validator.isEmail(username)){
				
				alert("Please enter Valid Email ID");
				document.getElementById('username').focus();
				 return false;
			}
			if(password.length==0)
			{  
			   
				alert("Please Enter Password");
				document.getElementById('password').focus();
				return false;
			}
			
			else
			{
			  
			  
				var url = contextPath+"/faces/LoginValidateServlet?usrid="+username+"&usrpass="+password+"&method=login&time="+new Date().getTime();
				
									
			  try
			    {
			    // Firefox, Opera 8.0+, Safari
			    req=new XMLHttpRequest();
			    }
			  catch (e)
			    {
			    // Internet Explorer
			    try
			      {
			      req=new ActiveXObject("Msxml2.XMLHTTP");
			      }
			    catch (e)
			      {
			      try
			        {
			        req=new ActiveXObject("Microsoft.XMLHTTP");
			        }
			      catch (e)
			        {
			        //alert("Your browser does not support AJAX!");
			        return false;
			        }
			      }
			    }
											
				//alert("after url");
				req.open("GET", url, true);
				req.onreadystatechange = callback;
				req.send(null);

				if(pagename=='login')	{
			submitCookie()
			}
				
				
			}
		}
		
		function callback() 
		{
			
			if (req.readyState == 4) 
			{
				if (req.status == 200)
				{		
					parseMessage();
				}
			}
			else
			{
			}
		}
		
		function parseMessage()
		{
			var message = req.responseXML.getElementsByTagName("main")[0];
			//var msg = document.getElementById("loginError");
			//msg.innerHTML ="";	
			var errormsg=message.childNodes[0].childNodes[0].nodeValue;
			var msg = document.getElementById("loginError");
			
			if(errormsg=="success")
			{
				window.location.href=contextPath+"/faces/jsp/myDashBoard.jsp"
			}else if(errormsg =="AcountInactive"){
			  msg.innerHTML ="Your account has not been verified. Please check the email from admin@itsmyascent.com to verify your account.  &nbsp;&nbsp;&nbsp;&nbsp;<a href=javascript:void(0) onclick=resendConfirmationMail(); class='advancedsearch strong'>Resend confirmation Mail</a>";
			  
			}
			else if(errormsg =="MailSent"){
			  msg.innerHTML ="Your account activation mail has been sent to "+username.value+". Please check your mail to activate your account.";
			  
			}
			else if(errormsg =="MailException"){
			  msg.innerHTML ="Could not sent Mail due to System Error.";
			  
			}
			else if(errormsg =="profileNotUpdated"){
				window.location.href = contextPath+"/faces/jsp/candidateEditProfile.jsp";
			}else{

			msg.innerHTML =errormsg;	
			}

			
			document.getElementById('password').value="";
			document.getElementById('password').focus();

		}
		

function forgotPasswordVal(id){
	
	var name = document.getElementById(id+":emailid").value;
    
   if(name.length==0)
   {
     alert("Please enter E-Mail ID");
	  document.getElementById(id+":emailid").focus();
      return false;
   } else if(!validator.isEmail(name)){
      alert("Please enter valid  Email Id");
	  document.getElementById(id+":emailid").focus();
      return false;
   }
  
   return true;
}		


function signout(){
	var url = contextPath+"/faces/LoginValidateServlet?method=logout";
		 try  {
				 // Firefox, Opera 8.0+, Safari
				 req=new XMLHttpRequest();
			 }
		catch (e){
							 // Internet Explorer
				 try {
					 req=new ActiveXObject("Msxml2.XMLHTTP");
					 }
				 catch (e) {
						 try {
				    		  req=new ActiveXObject("Microsoft.XMLHTTP");
							 }
						 catch (e){
									//alert("Your browser does not support AJAX!");
									 return false;
					    		  }
							 }
				}
											
    	//alert("after url");
	    req.open("GET", url, true);
	    req.onreadystatechange = logoutResponse;
	    req.send(null);

	} // End of SignOut


function logoutResponse(){
	if (req.readyState == 4) {
 		    if (req.status == 200){		
					
					window.location.href=contextPath+"/faces/jsp/index.jsp"
						}
		}
	else{
		
		}
	}



	function submitCookie(userName,password)
{


	try
	{
		var _uidObj=userName;
		var _pwdObj=password;
		var  _uid=_uidObj.value;
		var  _pwd=_pwdObj.value;
		var  _isSave="Y";
		var path=null 
		var domain=null
		var secure=null
		var expires = new Date();
		expires.setTime (expires.getTime() + 365*24*60*60*1000)
		setCookie('_UID',_uid,expires,path,domain,secure)
		setCookie('_PWD',_pwd,expires,path,domain,secure)
		setCookie('_ISS',_isSave,expires,path,domain,secure)
		
	}
	catch(Exception){
	
		alert(Exception)
	}
	return;
}


function setCookieData(username)
{ 
	var  strTemp= getCookie('_ISS') 
	if(strTemp!=null && strTemp=="Y")
	{
		//var _isSave=document.loginfrm.chkSaveCookie;
		
		//_isSave.checked=true;
		

		var  strTemp= getCookie('_UID') 	
		if(strTemp!=null)
		{
			var _uid=document.getElementById(username);
			_uid.value=strTemp
			
			document.getElementById("chkSaveCookie").checked =true;
		}
		/*
		var  strTemp= getCookie('_PWD') 	
		if(strTemp!=null)
		{

			var _pwd=document.getElementById("loginFrm:password");	
			_pwd.value=strTemp
		}
		*/
	}
}


function candidateLoginValidation(){

var userName =document.getElementById("candidateLogin:username");
var password =document.getElementById("candidateLogin:password");
if(isEmpty$(userName)){
	alert("Please enter Login id.");
	userName.focus();
	return false;
}
if(!validator.isEmail(userName.value)){
	alert("Please enter Valid Email ID");
	userName.focus();
	return false;
}
if(isEmpty$(password)){
	alert("Please enter password.");
	password.focus();
	return false;
}

var chkBox =document.getElementById("chkSaveCookie").checked;
if(chkBox){
	submitCookie(userName,password)
}

return true;
}

function isEmpty$(el){
	if(typeof(el)=='string') 
		return (trim(el) == "" ? true : false);
	else if(typeof(el)=='object') 
	return (trim(el.value) == "" ? true : false);
}


function resendConfirmationMail()
		{
			
			
			var msg = document.getElementById("loginError");
			var userId=document.getElementById('username').value;
			
			if(userId.length>0)
			{
				
				var url = contextPath+"/faces/ResendConfirmationMailServlet?usrid="+userId+"&method=login&time="+new Date().getTime();
				
									
			  try
			    {
			    // Firefox, Opera 8.0+, Safari
			    req=new XMLHttpRequest();
			    }
			  catch (e)
			    {
			    // Internet Explorer
			    try
			      {
			      req=new ActiveXObject("Msxml2.XMLHTTP");
			      }
			    catch (e)
			      {
			      try
			        {
			        req=new ActiveXObject("Microsoft.XMLHTTP");
			        }
			      catch (e)
			        {
			        //alert("Your browser does not support AJAX!");
			        return false;
			        }
			      }
			    }
											
				//alert("after url");
				req.open("GET", url, true);
				req.onreadystatechange = callback;
				req.send(null);
			}
			
			
		}