﻿// JScript File
//***************************************************************************************
//Program Name    :  SecurityEnquiry-Tooling.js
//Written By      :  Snehal Pawale
//Written On      :  02/08/2010
//Remarks         :  To validate Name,Email,Contact No.,City,State,Country,Product Name,Information Required.
//Called From     :  Send an Enquiry
//SRF No.         :  BIG1/1099
//'*************************************************************************************

function LTrim(str)
	{
		var whitespace = new String(" \t\n\r");
		var s = new String(str);

		if (whitespace.indexOf(s.charAt(0)) != -1) 
		{
			var j=0, i = s.length;
			while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
				j++;
			s = s.substring(j, i);
		}
		return s;
	}
	function RTrim(str)
	{
		var whitespace = new String(" \t\n\r");
		var s = new String(str);
		if (whitespace.indexOf(s.charAt(s.length-1)) != -1) 
		{

			var i = s.length - 1;       
			while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
			i--;
			s = s.substring(0, i+1);
		}
		return s;
	}
	function Trim(str)
	{
		return RTrim(LTrim(str));
	}
	
	

	
	
	
	
	
  function F_Space(A_Spaces)
	{
		var Ls_Return = '';
		for(var i=1;i<=A_Spaces;i++)
			{
				Ls_Return = Ls_Return + ' ';
			}
		return Ls_Return;
	}
	
 function validate()
    {
      
         
       if(document.getElementById("ucSendEnquiry_txtFirstName").value=="")
       {
             alert("Please enter name");
	         document.getElementById("ucSendEnquiry_txtFirstName").focus();
	         return false;       
       }
         else if(!CheckValid(document.getElementById('ucSendEnquiry_txtFirstName').value,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&_. "))
        {
            alert("Please enter a valid name");
		    document.getElementById("ucSendEnquiry_txtFirstName").focus();
	         return false;       
         }
         
var Elem=document.getElementById('ucSendEnquiry_txtFirstName');
	if((Trim(Elem.value)).length == 0)
        {
            alert("Please enter a valid name");
		    document.getElementById("ucSendEnquiry_txtFirstName").focus();
	         return false;       
         }
        
         if(document.getElementById("ucSendEnquiry_txtEmail").value=="")
        {
            alert("Please Enter Email");
	        document.getElementById("ucSendEnquiry_txtEmail").focus();
	        return false;
        }
         if(!IsValidEmail(document.getElementById("ucSendEnquiry_txtEmail").value))
        {
            alert('Enter valid Email  and try again.');
            document.getElementById("ucSendEnquiry_txtEmail").focus();
            return false;
        }
        
        


         
         
        if(document.getElementById("ucSendEnquiry_txtContactNo").value=="")
        {
            alert("Please Enter Contact No.");
	        document.getElementById("ucSendEnquiry_txtContactNo").focus();
	        return false;
        }
        
        if(!CheckValid(document.getElementById("ucSendEnquiry_txtContactNo").value,"+-0123456789"))
            {
                alert('Please Enter Valid Contact No.');
                document.getElementById("ucSendEnquiry_txtContactNo").focus();
                return false;          
            }
            
            
            
            
                 
                   Elem=document.getElementById('ucSendEnquiry_txtContactNo');
	            if((Trim(Elem.value)).length == 0)
            {
                alert('Please Enter Valid Contact No.');
                document.getElementById("ucSendEnquiry_txtContactNo").focus();
                return false;          
            }
            
            
            
         var field=document.getElementById("ucSendEnquiry_txtContactNo");
        if (field.value.length < 5) 
        {
             alert('Contact No. should be of minimum 5 digits');
             document.getElementById("ucSendEnquiry_txtContactNo").focus();
             return false;
        }
            
			if(document.getElementById("ucSendEnquiry_txtCity").value == "")
         {
            alert("Please Enter City");
            document.getElementById("ucSendEnquiry_txtCity").focus();
            return false;
         }
          else if(!CheckValid(document.getElementById("ucSendEnquiry_txtCity").value,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,&_. "))
          {
            alert("Please Enter Valid City");
            document.getElementById("ucSendEnquiry_txtCity").focus();
            return false;
          }
           
            
         if(document.getElementById("ucSendEnquiry_txtProductName").value=="")
        {
            alert("Please Enter Product Name");
	        document.getElementById("ucSendEnquiry_txtProductName").focus();
	        return false;
        }
         if (document.getElementById("ucSendEnquiry_txtProductName").value.length > 200)
        {		
            alert('Product Name should not be more than 200 characters');
           
            return false;
        }  
      if(CheckValid(document.getElementById('ucSendEnquiry_txtProductName').value," "))
        {
	         alert("Please Enter Valid Product Name");
		    document.getElementById("ucSendEnquiry_txtProductName").focus();
         return false;       
         }
         
         
         
         
         
         Elem=document.getElementById('ucSendEnquiry_txtProductName');
	            if((Trim(Elem.value)).length == 0)
        {
	         alert("Please Enter Valid Product Name");
		    document.getElementById("ucSendEnquiry_txtProductName").focus();
         return false;       
         }
         
         
         
         
         
        if(document.getElementById("ucSendEnquiry_txtInforRequest").value=="")
        {
            alert("Please Enter Information Required");
	        document.getElementById("ucSendEnquiry_txtInforRequest").focus();
	        return false;
        }
         if (document.getElementById("ucSendEnquiry_txtInforRequest").value.length > 500)
        {		
            alert("Information Required should not be more than 500 characters");
          document.getElementById("ucSendEnquiry_txtInforRequest").focus();
            return false;
        }  
      
    
           
          return true;     
     }
      function IsValidEmail(stremail,empty)
    {
     if(stremail=='' && empty)
            return true;
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    return filter.test(stremail);
    }
     
      function CheckValid(chars,validchars)
    {   
         var blnresult=true;
        for(var i=0;i<chars.length&&blnresult==true;i++)
            {
                 var cchar=chars.charAt(i);
                 if(validchars.indexOf(cchar)==-1)
                    {
                        blnresult=false;
                    }
        
            }
         return blnresult;
     }
     
   
    function Clear()
    { 
  
		
			document.getElementById("ucSendEnquiry_lblMessage").innerHTML = '';
            document.getElementById("ucSendEnquiry_txtFirstName").value=""; 
            document.getElementById("ucSendEnquiry_txtContactNo").value="";
            document.getElementById("ucSendEnquiry_txtEmail").value="";
	        document.getElementById("ucSendEnquiry_txtCity").value="";
            document.getElementById("ucSendEnquiry_txtProductName").value="";
            document.getElementById("ucSendEnquiry_txtInforRequest").value="";
		  return false;  	
 
	                 
     }
    
function textkey1Counter(maxlimit) 
   {
    var field=document.getElementById("ucSendEnquiry_txtInforRequest");
    if (field.value.length > maxlimit) 
    field.value = field.value.substring(0, maxlimit); 
   }


