function login(email,password)
{
	alert("test");
	/*if( $.browser.msie )
		{
			if(isLoggedIn == true || isSendPasswd == true)
				return;
		}
	*/
	var email = document.getElementById("emailTextBox");		
	var password = document.getElementById("passwdTextBox");
	
	var xmlhttpLogin;
    var url = "login.php";
    var params = "method=login&email="+email+"&password="+password;

	alert(url+" - "+params);

	document.getElementById("loginWait").style.display = "block";
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttpLogin=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttpLogin=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttpLogin.onreadystatechange=function()
      {
          if (xmlhttpLogin.readyState==4 && xmlhttpLogin.status==200)
          {
				//alert(xmlhttpLogin.responseText);
				if(xmlhttpLogin.responseText=="success")
				{
					window.location.reload();
				}
				else
				{
					alert("Invalid user information");
				}

				document.getElementById("loginWait").style.display = "none";
          }
      }

    xmlhttpLogin.open("POST",url,true);
	xmlhttpLogin.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttpLogin.setRequestHeader("Connection", "close");
    xmlhttpLogin.send(params);
	isLoggedIn = true;
}



function validateEmail(elementId)
{
   if ( $.browser.msie )
	   {
			if(isSendPasswd==true)
				return;
	   }
	  
	var email = document.getElementById(elementId);

    validate(email,"Email");

    if(email.getAttribute("class")=="isValid")
    {
        //email is valid ... call ajax function to send the password
        sendPassword(email.value);
        return true;
    }

    //email is invalid
    return false;

}


//Ajax function to send the password
function sendPassword(email)
{
  
	
	var url = "retrievepasswd/forgot-passwordck.php";
    var param = "email="+email;
    document.getElementById("messageDiv").innerHTML="";
    document.getElementById("forgotPwdWait").style.display="block";

    var xmlhttp_sendPassword;

    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
         xmlhttp_sendPassword=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp_sendPassword=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp_sendPassword.onreadystatechange=function()
    {
        if (xmlhttp_sendPassword.readyState==4 && xmlhttp_sendPassword.status==200)
        {
           //do something with the result
			//alert($(".forgotPwdMessage").html());
			
		   if(xmlhttp_sendPassword.responseText.length<=3)
           {
			if($("#hiddenSelectedLanguage").attr("value")=="french" || $("#hiddenSelectedLanguage").attr("value")=="_fr") {
				var txtpaswdsend = "<br><br>Nouveau mot de passe envoyé avec succès!!";
			} else {
				var txtpaswdsend = "<br><br>New Password Sent Succefully!!";
			}
                document.getElementById("messageDiv").innerHTML= txtpaswdsend;
				$(".forgotPwdMessage").show().html(txtpaswdsend);
           }
           else
           {
               document.getElementById("messageDiv").innerHTML= xmlhttp_sendPassword.responseText;
			   $(".forgotPwdMessage").show().html(xmlhttp_sendPassword.responseText);
           }

           //document.getElementById("forgotDiv").style.display="none";
           document.getElementById("messageDiv").style.display="block";
		   //document.getElementById("cover").style.display="block";
		   document.getElementById("forgotPwdWait").style.display="none";
           //document.getElementById("txtForgotPwdEmail").value="";

        }
    }

    xmlhttp_sendPassword.open("POST",url,true);

    xmlhttp_sendPassword.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp_sendPassword.setRequestHeader("Content-length", param.length);
    xmlhttp_sendPassword.setRequestHeader("Connection", "close");
    xmlhttp_sendPassword.send(param);
	isSendPasswd = true;
}


function enterKeypressed(event,object){

    if(event.keyCode=="13")
		{
			if(object.id=="passwdTextBox")
			{
				var enterEmail = document.getElementById("emailTextBox").value;
				var passwd = document.getElementById("passwdTextBox").value;
				login(enterEmail,passwd);
			}
			else if(object.id=="centeredPasswordTextBox")
			{
				var enterEmail = document.getElementById("centeredEmailTextBox").value;
				var passwd = document.getElementById("centeredPasswordTextBox").value;
				login(enterEmail,passwd);
			}
			else if(object.id=="enterEmailTextBox")
			{
				
				return validateEmail('enterEmailTextBox');
			}
		}
}