// JavaScript Document
/************************************************************************************************************
	@Author - Jayshankar Singh (PHP Programmer)(singh.jayshankar@gmail.com)
	@Date   - 05-04-2010
	@Verson - 1.0

	All the variables are very impotant , so please do not delete any variable.
	Legent -> 	EOF - END OF FUNCTION
************************************************************************************************************/

var action          	= "";
var recdIdGlobal        = "";
var functionName		= "";

function validateLogin()
      {			   
		   
      		if(document.getElementById('txtusername').value == "")
			{
				alert("Please, Enter Username");
				document.getElementById('txtusername').focus();
				return false;
			}
			
			/*var invalid=/\W/;     //Alphanumeric characters and Underscore permitted
			if(invalid.test(document.getElementById('txtusername').value)){
				alert("Username contain Invalid characters!");
				document.getElementById('txtusername').focus();
				return false;
			}*/
			
			if(document.getElementById('txtpassword').value == "")
			{
				alert("Please, Enter Password");
				document.getElementById('txtpassword').focus();
				return false;
			}
			
			if(document.getElementById('txtpassword').value.length < 6){
				alert("Password must contain atleast 6 letters!");
				document.getElementById('txtpassword').focus();
				return false;
			}
			
			/*var invalid=/[\W_]/;     //Alphabets and digits only allowed
			if(invalid.test(document.getElementById('txtpassword').value)){
				alert("Password contain Inalid characters!");
				document.getElementById('txtpassword').focus();
				return false;
			}*/
	
	document.getElementById('messageDiv').innerHTML	= "Please wait while checking Login Credentials ...";
	var username  = document.getElementById('txtusername').value;
	var password  = document.getElementById('txtpassword').value;
	var authority = document.getElementById('cmbAuthority').value;
	
	displayWaitImageInCenter();
	action   = "CheckLogin";
	url      = "include/php/ajax/loginAS.php?action="+action+"&username="+username+"&password="+password+"&authority="+authority;

	var http = zXmlHttp.createRequest();
	
	http.open("GET", url, false);
	http.send(null);
	results = http.responseText;
	
	if(results !="True"){
		hideWaitImageInCenter();
		document.getElementById('messageDiv').innerHTML	= "Login Failed !!";
		alert("Username and Password Mismatched.");
		document.getElementById("txtusername").value = "";
		document.getElementById("txtpassword").value = "";
		document.getElementById("cmbAuthority").options[0].selected = true;
		document.getElementById("txtusername").focus();
		return false;
	}
	hideWaitImageInCenter();	
    //parent.location.href = "master.php?mi=1";
	parent.location.href = "../master.php";	
	//	checkRemindersForToday();
}
