﻿// JScript File

function ContactUsCheckData()
{     
    if(!checkAllInputs())
    {
        return false;
    }
    
    if(!validateNotEmpty(document.getElementById("ctl00_cphMain_ContactUs_txtName").value))
    {
        str = 'Please enter "Name"';
        str1=true;
    }
    else
    {
        str="";
        str1=false;
    }
    
    if(!validateNotEmpty(document.getElementById("ctl00_cphMain_ContactUs_txtCompany").value))
    {
        str = str+'\nPlease enter "Name of the Company"';
        str2=true;
    }
    else
    {
        str2=false;
    }
    
    if(!validateNotEmpty(document.getElementById("ctl00_cphMain_ContactUs_txtPhonoNo").value))
    {
        str = str+'\nPlease enter "Contact Number"';
        str3=true;
    }
    else
    {
        str3=false;
    }
    
    if(!validateNotEmpty(document.getElementById("ctl00_cphMain_ContactUs_txtDate").value))
    {
        str = str+'\nPlease enter "Preferred Date"';
        str4=true;
    }
    else
    {
        str4=false;
    }
    
    if(!validateNotEmpty(document.getElementById("ctl00_cphMain_ContactUs_txtTimeHour").value))
    {
        str = str+'\nPlease enter "Preferred time"';
        str5=true;
    }
    else
    {
        str5=false;
    }
	 
    if(str!="")
    {
        alert(str);
        if(str1==true)
        {
            document.getElementById("ctl00_cphMain_ContactUs_txtName").focus();
            return false;
        } 
        if(str2==true)
        {
            document.getElementById("ctl00_cphMain_ContactUs_txtCompany").focus();
            return false;
        }    
        if(str3==true)
        {
            document.getElementById("ctl00_cphMain_ContactUs_txtPhonoNo").focus();
            return false;
        }
         if(str4==true)
        {
            //document.getElementById("ctl00_cphMain_ContactUs_txtDate").focus();
            return false;
        } 
        if(str5==true)
        {
            document.getElementById("ctl00_cphMain_ContactUs_txtTimeHour").focus();
            return false;
        }
        
    }
         
    if(!validateNotEmpty(document.getElementById("ctl00_cphMain_ContactUs_txtName").value))
    {
        alert('Please enter "Name"');
        document.getElementById("ctl00_cphMain_ContactUs_txtName").focus();
        return false;
    }
    else
    {	
        if(document.getElementById("ctl00_cphMain_ContactUs_txtName").value.trim()==0)
        {
            alert('"Name" should not have only zeroes');
            document.getElementById("ctl00_cphMain_ContactUs_txtName").focus();
            return false;
        }
        if(!validateContactName(document.getElementById("ctl00_cphMain_ContactUs_txtName").value.trim()))
        {
            alert('Please enter valid "Name"');
            document.getElementById("ctl00_cphMain_ContactUs_txtName").focus();
            return false;
        }	 		    
        var val=document.getElementById("ctl00_cphMain_ContactUs_txtName").value.trim();				
        var len=val.length;
        var Alpha = /^[a-zA-Z]+$/;			
        if(!Alpha.test(val.charAt(0)))
        {
            alert('Please enter valid "Name"');
            document.getElementById("ctl00_cphMain_ContactUs_txtName").focus();
            return false;
        }  
        if(!Alpha.test(val.charAt(len-1)))
        {
            alert('Please enter valid "Name"');
            document.getElementById("ctl00_cphMain_ContactUs_txtName").focus();
            return false;
        }
        if(len<2) 
        {
            alert('Please check "Name"... \nsingle characters input for "Name" is not allowed');
            document.getElementById("ctl00_cphMain_ContactUs_txtName").focus();
            return false;							
        }
        for(i=0;i<len-1;i++)
        {
            var Alpha = /^['\.]+$/;
            if((Alpha.test(val.charAt(i))) && (Alpha.test(val.charAt(i+1))))
            {
                alert('Please enter valid "Name"');
                document.getElementById("ctl00_cphMain_ContactUs_txtName").focus();
                return false;
            }  
        }
        var jointxtval;
        var firstsplit;
        var txtval=document.getElementById("ctl00_cphMain_ContactUs_txtName").value.trim();
        var allvalue=Array();
        var j=0;																		
        if(txtval!="")
        {
            txtsplit=txtval.split(" ");                                    
            for(i=0;i<txtsplit.length;i++)
            {           
                splitvalue=txtsplit[i];
                if(splitvalue!="")
                {
                    firstsplit=splitvalue.split("");
                    if(firstsplit!="")
                    {
                        firstsplitval=firstsplit[0];
                        firstsplitval=firstsplitval.toUpperCase( );
                        firstsplit[0]=firstsplitval;
                        jointxtval=firstsplit.join("");
                        allvalue[j]=jointxtval;
                        j=j+1;                    
                    }
                }            
            }
            allvaluejoin=allvalue.join(" ");
            document.getElementById("ctl00_cphMain_ContactUs_txtName").value=allvaluejoin;
        }	    
    } 
    
    if(!validateNotEmpty(document.getElementById("ctl00_cphMain_ContactUs_txtCompany").value))
    {
        alert('Please enter "Name of the Company"');
        document.getElementById("ctl00_cphMain_ContactUs_txtCompany").focus();
	    return false;
    }
    else
    {	        
        if(validateNumeric(document.getElementById("ctl00_cphMain_ContactUs_txtCompany").value.trim()))
        {
            alert('Please enter valid "Name of the Company"');
            document.getElementById("ctl00_cphMain_ContactUs_txtCompany").focus();
            return false;
        }
        if(validateSplChar(document.getElementById("ctl00_cphMain_ContactUs_txtCompany").value.trim()))
        {
            alert('Please enter valid "Name of the Company"');
            document.getElementById("ctl00_cphMain_ContactUs_txtCompany").focus();
            return false;
        }
        if(document.getElementById("ctl00_cphMain_ContactUs_txtCompany").value.trim()==0)
        {
            alert('"Name of the Company" should not have only zeroes');
            document.getElementById("ctl00_cphMain_ContactUs_txtCompany").focus();
            return false;
        }		    
        var val=document.getElementById("ctl00_cphMain_ContactUs_txtCompany").value.trim();				
        var len=val.length;
        var Alpha = /^[a-zA-Z0-9]+$/;			
        if(!Alpha.test(val.charAt(0)))
        {
            alert('Please enter valid "Name of the Company"');
            document.getElementById("ctl00_cphMain_ContactUs_txtCompany").focus();
            return false;
        }         
        if(len<2) 
        {            
            alert('Please check "Name of the Company"... \nsingle characters input for "Name of the Company" is not allowed');	
            document.getElementById("ctl00_cphMain_ContactUs_txtCompany").focus();
            return false;							
        }
        var jointxtval;
        var firstsplit;
        var txtval=document.getElementById("ctl00_cphMain_ContactUs_txtCompany").value.trim();
        var allvalue=Array();
        var j=0;																		
        if(txtval!="")
        {
            txtsplit=txtval.split(" ");                                    
            for(i=0;i<txtsplit.length;i++)
            {           
                splitvalue=txtsplit[i];
                if(splitvalue!="")
                {
                    firstsplit=splitvalue.split("");
                    if(firstsplit!="")
                    {
                        firstsplitval=firstsplit[0];
                        firstsplitval=firstsplitval.toUpperCase( );
                        firstsplit[0]=firstsplitval;
                        jointxtval=firstsplit.join("");
                        allvalue[j]=jointxtval;
                        j=j+1;                    
                    }
                }            
            }
            allvaluejoin=allvalue.join(" ");
            document.getElementById("ctl00_cphMain_ContactUs_txtCompany").value=allvaluejoin;
        }
     } 
         
	 if(!validateNotEmpty(document.getElementById("ctl00_cphMain_ContactUs_txtPhonoNo").value))
	 {
	    alert('Please enter "Contact Number"');
	    document.getElementById("ctl00_cphMain_ContactUs_txtPhonoNo").focus();
		return false;
	 }
	 else
     {
        if(!validateContactNumber(document.getElementById("ctl00_cphMain_ContactUs_txtPhonoNo").value.trim()))
        {
            alert('Please enter valid "Contact Number"');
            document.getElementById("ctl00_cphMain_ContactUs_txtPhonoNo").focus();
            return false;
        }      
     }    
    
	 if(validateNotEmpty(document.getElementById("ctl00_cphMain_ContactUs_txtTimeHour").value) || validateNotEmpty(document.getElementById("ctl00_cphMain_ContactUs_txtTimeMinutes").value))  
	 {
	    
	    if(!validateNotEmpty(document.getElementById("ctl00_cphMain_ContactUs_txtTimeHour").value))
	    {
	     alert('Please enter "Preferred time Hour"');
	    document.getElementById("ctl00_cphMain_ContactUs_txtTimeHour").focus();
	    return false;
	    }
	  
	    if(!validateNumeric(document.getElementById("ctl00_cphMain_ContactUs_txtTimeHour").value) && validateNotEmpty(document.getElementById("ctl00_cphMain_ContactUs_txtTimeHour").value))
	    {
	     alert('Please enter valid "Preferred time Hour"');
	    document.getElementById("ctl00_cphMain_ContactUs_txtTimeHour").focus();
	    return false;
	    }
	   
	   if(document.getElementById("ctl00_cphMain_ContactUs_txtTimeHour").value==0)
         {
        alert('Please enter valid "Preferred time Hour"');
         document.getElementById("ctl00_cphMain_ContactUs_txtTimeHour").focus();
         return false;
         }


	   if(document.getElementById("ctl00_cphMain_ContactUs_txtTimeHour").value<0 || document.getElementById("ctl00_cphMain_ContactUs_txtTimeHour").value >=13)
	    {
	   
	    alert('Please enter valid "Preferred time Hour"');
	    document.getElementById("ctl00_cphMain_ContactUs_txtTimeHour").focus();
	    return false;
	    }
	    
//	    if(!validateNotEmpty(document.getElementById("ctl00_cphMain_ContactUs_txtTimeMinutes").value))
//	    {
//	    alert('Please enter "Preferred time Minutes"');
//	    document.getElementById("ctl00_cphMain_ContactUs_txtTimeMinutes").focus();
//	    return false;
//	    }
	    
	    if(!validateNumeric(document.getElementById("ctl00_cphMain_ContactUs_txtTimeMinutes").value) && validateNotEmpty(document.getElementById("ctl00_cphMain_ContactUs_txtTimeMinutes").value))
	    {
	     alert('Please enter valid "Preferred time Minutes"');
	    document.getElementById("ctl00_cphMain_ContactUs_txtTimeMinutes").focus();
	    return false;
	    }
	   
	     if(document.getElementById("ctl00_cphMain_ContactUs_txtTimeMinutes").value<0 || document.getElementById("ctl00_cphMain_ContactUs_txtTimeMinutes").value >=60 && validateNotEmpty(document.getElementById("ctl00_cphMain_ContactUs_txtTimeMinutes").value))
	    {
	    alert('Please enter valid "Preferred time Minutes"');
	    document.getElementById("ctl00_cphMain_ContactUs_txtTimeMinutes").focus();
	    return false;
	    }
//	    if(document.getElementById("ctl00_cphMain_ContactUs_ddlSessionampm").value=="--Select--")
//	    {
//	    alert('Please enter valid "Preferred time am/pm"');
//	    document.getElementById("ctl00_cphMain_ContactUs_ddlSessionampm").focus();
//	    return false;
//	    }	  
     }
        document.getElementById("ctl00_cphMain_ContactUs_btnSubmit").disabled = true;
        document.getElementById("ctl00_cphMain_ContactUs_btnReset").disabled = true;
        document.getElementById("ctl00_cphMain_ContactUs_btnConClose").disabled = true;
     __doPostBack('ctl00$cphMain$ContactUs$btnSubmit','');
    return false;  	 
}
