﻿function clean_calendar(str)
{
    document.getElementById(str).value="";
}
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("Format of Email ID is incorrect")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Format of Email ID is incorrect")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Format of Email ID is incorrect")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Format of Email ID is incorrect")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Format of Email ID is incorrect")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Format of Email ID is incorrect")
		    return false
		 }

 		 return true					
	}
function ValidateForm()
{

var emailID=document.getElementById("ctl00_cph_txtEmailId").value; //Added by Prityalok Dated 30-Sept-2009
var stdCode=document.getElementById("ctl00_cph_txtStdCode").value; //document.forms[0].txtStdCode;
var PhNo=document.getElementById("ctl00_cph_txtNo").value;  //document.forms[0].txtNo;

 if(document.getElementById("ctl00_cph_txtPolicyNo").value == '' )
      {
			alert("Please enter Policy No.");
			document.getElementById("ctl00_cph_txtPolicyNo").focus();
			return false;
		}
		
if(document.getElementById("ctl00_cph_txtPremiumAmt").value != '')
{
    var summoney = document.getElementById("ctl00_cph_txtPremiumAmt").value;
    var numericExpression = /^[0-9]+$/;
    	if( ! summoney.match(numericExpression))
			{
			    alert("Premimum amount can accept only numeric values");
			    document.getElementById("ctl00_cph_txtPremiumAmt").focus();
			    return false;
			}
}		
if(document.getElementById("ctl00_cph_txtNo").value != '')
{
    var landline = document.getElementById("ctl00_cph_txtNo").value;
    var numericExpression = /^[0-9]+$/;
    	if( ! landline.match(numericExpression))
			{
			    alert("Landline can accept only numeric values");
			    document.getElementById("ctl00_cph_txtNo").focus();
			    return false;
			}
}		
	
if (document.getElementById("ctl00_cph_txtPolicyID").value == '' && document.getElementById("ctl00_cph_txtDOB").value ==  ''  && document.getElementById("ctl00_cph_txtPremiumAmt").value == '')
		{
			alert('Please enter any one  of the following fields: \n\n 1) Policy Holder ID \n 2) Policy Holder Date of Birth \n 3) Premium Amount');
			return false;
		}
		if(document.getElementById("ctl00_cph_txtMobileNo").value != '')
         {
			var mobno = document.getElementById("ctl00_cph_txtMobileNo").value;
			var numericExpression = /^[0-9]+$/;
			if( ! mobno.match(numericExpression))
			{
			alert("Mobile No can accept only numeric values");
			document.getElementById("ctl00_cph_txtMobileNo").focus();
			return false;
			}
			if( mobno.length <10 )
{
			alert("Mobile No cannot be less than 10 digits");
			document.getElementById("ctl00_cph_txtMobileNo").focus();
			return false;
			}
		}
	
if ((document.getElementById("ctl00_cph_txtEmailId").value==null)||(document.getElementById("ctl00_cph_txtEmailId").value==""))

{
		alert("Email Id cannot be blank")
		document.getElementById("ctl00_cph_txtEmailId").focus();
		return false
	}
	if (echeck(document.getElementById("ctl00_cph_txtEmailId").value)==false){
		document.getElementById("ctl00_cph_txtEmailId").value="";
		document.getElementById("ctl00_cph_txtEmailId").focus();
		return false
	}
		if(document.getElementById("ctl00_cph_txtStdCode").value != '')
         {
			var stdcode = document.getElementById("ctl00_cph_txtStdCode").value;
			var numericExpression = /^[0-9]+$/;
			var zeroExpression= /^[0-0]+$/;
			if( ! stdcode.match(numericExpression))
			{
			alert(" STD code can accept only numeric values.");
			return false;
			txtStdCode.focus();
			}
			if( document.getElementById("ctl00_cph_txtStdCode").match(zeroExpression))
			{
			alert("STD code can not be zero.");
			document.getElementById("ctl00_cph_txtStdCode").focus();
			return false;
			
			}
			if ((PhNo.value==null)||(PhNo.value==""))
      {
		alert("Landline No  can not be blank ")
		PhNo.focus()
		return false
	}
		if(document.getElementById("ctl00_cph_txtNo").value != '')
         {
			var phno = document.getElementById("ctl00_cph_txtNo").value;
			var numericExpression = /^[0-9]+$/;
			if( ! phno.match(numericExpression))
			{
			alert("  Landline No can contain only numeric values.");
			document.getElementById("ctl00_cph_txtNo").focus();
			return false;
			
			}
			 if (phno.charAt(0)=="0")
           {
                alert("Landline No cannot start with 0.");
                return false
           }
		}
			
		}
}

