﻿
function SendQuickMessage()
  {
    
    var qvalid = ValidateQPage();
        if(qvalid==true)
        { 
             document.getElementById('wait').style.display='block';
             var qname=document.getElementById("qname").value;
             var qmail=document.getElementById("qmail").value; 
             var qph=document.getElementById("qphone").value; 
             var qmessage=document.getElementById("qmessage").value; 
             var qcity=document.getElementById("qcity").value; 
             var qcountry=document.getElementById("qcountry").value;                   
             
             PageMethods.SendQuickMessage(qname,qmail,qph,qmessage,qcity,qcountry,ONS_SendQMessage)                  
                  
        }          
        else
        {
            return false;
        }   
   return false;
  }
  
  function ONS_SendQMessage(retval)
    {
        document.getElementById('wait').style.display='none';
        alert(retval);
        document.getElementById("qname").value="";
        document.getElementById("qmail").value="";                
        document.getElementById("qmessage").value="";
        document.getElementById("qphone").value="";
        document.getElementById("qcity").value="";
        document.getElementById("qcountry").value="";              
        return false;  
               
    }



function ValidateQPage()
{
        if (document.getElementById("qname").value == "" )
                {
                    alert("Please fill in the ' Name'." );
		            document.getElementById("qname").focus();
                    return false;		        
                } 
        if (document.getElementById("qmail").value.length== "" )
                 {
		             alert("Please Enter your Email ID")
		             document.getElementById("qmail").focus();
		             return false;	
	              }
	   if (echeck(document.getElementById("qmail").value)==false)
	              {
		                document.getElementById("qmail").value=""
		                document.getElementById("qmail").focus();
		               return false;		 
	              }	
	              if (document.getElementById("qphone").value.length== "") 
                 {
                     alert("Please enter Phone number.");
                    document.getElementById("qphone").focus();
                      valid = false;
		             return valid;
                  } 
      else if (chkNumeric(document.getElementById("qphone").value) == false) 
                  {
                      alert("Please check - non numeric value!");
                      document.getElementById("qphone").focus();
                      document.getElementById("qphone").value=""
                      valid = false;
		             return valid;
                  } 
	   if (document.getElementById("qmessage").value == "" )
                {
                    alert("Please fill in the ' Message'." );
		            document.getElementById("qmessage").focus();
                    return false;		        
                } 
	               return true;		
}
function chkNumeric(strString)  //  check for valid numeric strings	
 {
               var strValidChars = "0123456789.-";
               var strChar;
               var blnResult = true;

               if (strString.length == 0) return false;

               //  test strString consists of valid characters listed above
               for (i = 0; i < strString.length && blnResult == true; i++)
                  {
                  strChar = strString.charAt(i);
                  if (strValidChars.indexOf(strChar) == -1)
                     {
                     blnResult = false;
                     }
                  }
               return blnResult;
 }     
      
 function echeck(str) 
 {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}








