﻿    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////

    Scirpt: Main.js
    This script is having all the form validations,The script to download the Jad or Zip file

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    function validateForm()
    
{
  
  
    String.prototype.trim = function ()
    {
    return this.replace(/^\s*|\s*$/,"");
    }
    var Fname=document.frmAlertdtl.txtFirstName
    Fname.value=Fname.value.replace(/^\s*|\s*$/,"")

    var Lname=document.frmAlertdtl.txtLastName
    Lname.value=Lname.value.replace(/^\s*|\s*$/,"")

    var PhoneNum=document.frmAlertdtl.txtPhoneNum
    PhoneNum.value=PhoneNum.value.replace(/^\s*|\s*$/,"")

    var Email=document.frmAlertdtl.txtEmailID
    var filetype=document.frmAlertdtl.hdnFiletype


          if(Fname.value=="")
          {

           alert("Please Enter Your First Name")
           Fname.focus();
           return false

         }
      
      
           else if(!IsString(Fname.value))
         {

            alert("Please Enter Valid First Name")
            Fname.focus();
            return false
         }

         else if ( Lname.value=="" )
         {
            alert("Please Enter Your Last Name")
            Lname.focus();
            return false
         }

        else if(!IsString(Lname.value))
        {

            alert("Please Enter Valid Last Name")
            Lname.focus();
            return false
        }

        else if( Email.value=="")
        {
        
        alert("Please Enter the Email Address")
        Email.focus();
        return false
            
        }
        
        else if(!IsNumeric(PhoneNum.value))
        {
        alert("Please Enter Valid Phone Number")
        PhoneNum.focus();
        return false
        
        }
        else if(!IsEmail(Email.value))
        {

        alert("Please Enter Valid Email id")
        Email.focus();
        return false

        }


        else if (!echeck(Email.value))
        {
         return false
        }


        else
        {
 
         document.getElementById("detailsTableDiv").style.display="none"; 
         document.getElementById("successDiv").style.visibility="visible";
         return true;
       
        
        }            
        
}




function IsNumeric(sText)
{
    var ValidChars = "0123456789.-";
    var IsNumber=true;
    var Char;
    
    for (i = 0; i < sText.length && IsNumber == true; i++) 
    { 
     Char = sText.charAt(i); 
            if (ValidChars.indexOf(Char) == -1) 
            {
            IsNumber = false;
            }
    }
    return IsNumber;

}


 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
        }

        if (str.indexOf("..")!=-1)
        {
        alert("Invalid E-mail ID")
        return false
        }

    return true					
 }




 function IsString(sTextString)
{
    var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' .";
    var IsChar=true;
    var Char;
    
    for (i = 0; i < sTextString.length && IsChar == true; i++) 
    { 
    
    Char = sTextString.charAt(i); 
            if (ValidChars.indexOf(Char) == -1) 
            {
            IsChar = false;
            }
            
    }
    return IsChar;

 }



function IsEmail(sTextEmail)
 {
    
    var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_'.@1234567890";
    var IsEmail=true;
    var Char;
    
    for (i = 0; i < sTextEmail.length && IsEmail == true; i++) 
    { 
    
     Char = sTextEmail.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) 
        {
        IsEmail = false;
        }      
    }
    
    return IsEmail;

 }



/*Following functions validate textbox on keypress*/
/*To check Phone number text box*/
function KeyCheck(e)
{
    
    var KeyID = (window.event) ? event.keyCode : e.which;


    if((KeyID >= 65 && KeyID <= 90) || (KeyID >= 97 && KeyID <= 122) || (KeyID >= 33 && KeyID <= 47) ||
    (KeyID >= 58 && KeyID <= 64) || (KeyID >= 91 && KeyID <= 96) || (KeyID >= 123 && KeyID <= 126) )
    
    {
    return false;
    }
   
    return true;
}



/*To check Firstname and last name text boxes*/
function KeyCheckString(e)
{
     var KeyID = (window.event) ? event.keyCode : e.which;
     var control = document.getElementById("imgSubmit");  

    if((KeyID >= 65 && KeyID <= 90)|| (KeyID >= 97 && KeyID <= 122)|| (KeyID==39) || (KeyID==8) ||(KeyID==144) || (KeyID==32) || (KeyID==46) || (KeyID==13))

    {


            if((KeyID==13))
            {
            
            control.focus(); 
            return true;

            }

            else 
            {
            return true;
            }


    }
 

    return false;
}



/*To  Check Email text box*/
function KeyCheckEmail(e)
{
     var KeyID = (window.event) ? event.keyCode : e.which;
     var control = document.getElementById("imgSubmit");  

    if((KeyID >= 65 && KeyID <= 90)|| (KeyID >= 97 && KeyID <= 122)|| (KeyID==39) || (KeyID==64) || (KeyID==46) || (KeyID<=57 && KeyID>=48) ||  (KeyID==95) ||(KeyID==8) ||(KeyID==144) || (KeyID==13))

 {

            if((KeyID==13))
            {
            control.focus(); 
            return true;

            }

            else 
            {
            return true;

            }


 }


    return false;
}







