function validate_form_login(thisform)
{
	if(thisform.username.value == '' || thisform.username.value == 'User name')	
		{
			alert("Woops! You forgot to fill in your User Name");
			thisform.username.focus();
			return false;
		}	
		
	if(thisform.password.value == '' || thisform.password.value == 'Password' )	
		{
			alert("Woops! You forgot to fill in your Password");
			thisform.password.focus();
			return false;
		}	
		
		authenticate_login(thisform.username.value,thisform.password.value)
	    return true;
}

function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }
	
function authenticate_login(thisVal1,thisVal2) {		
		
		var strURL="http://www.prisunicbuilders.com/admin/login-client.php?uname="+thisVal1+"&psw="+thisVal2;
		//alert(strURL)
		var req = getXMLHTTP();
		//alert(thisVal)
			if (req) {
				//document.getElementById('listClientDetails').style.display='block';
				req.onreadystatechange = function() {
					if (req.readyState == 4) {
						// only if "OK"
						if (req.status == 200) {	
						//alert(req.responseText)
						    if(req.responseText!=''){
							//document.getElementById('auth_msg').style.display='block';
							//document.getElementById('result').style.display='none';
							//document.getElementById('auth_msg').innerHTML=req.responseText;	
							alert(req.responseText);
							}else{
								//alert("Login success")
								window.location ='http://www.prisunicbuilders.com/admin/index.php';}
														
						} else {
							alert("There was a problem while using XMLHTTP:\n" + req.statusText);
						}
					}				
				}			
				req.open("POST", strURL, true);
				req.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
				req.send(strURL);
			}			
		
	}
	
function validate_email(entered,alertbox) {

   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = entered.value;
   if(reg.test(address) == false) {
     if (alertbox!="") alert(alertbox,entered);
      return false;
   }
}

function IsNumeric(strString)
{
   var strValidChars = "0123456789-(). ";
   var strChar;
   var blnResult = true;
   if (strString.length == 0) return false;

   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         	{
        	 blnResult = false;
         	}
      }
   return blnResult;
}
