
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					
	}
	
	 function chkBlank()
  	{
	

	 var FName = document.form1.txtFName.value;
   	 FName1=FName.replace(/^\s+/,'').replace(/\s+$/,'');
	    if(FName1=="")
	{
	alert("Please enter first name!");	
	document.form1.txtFName.value="";			
	document.form1.txtFName.focus();
	return false;
	}
	
	var emailID=document.form1.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("You have not entered your Email Address");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}	

	
	 var Address = document.form1.txtAddress123.value;
   	 Address1=Address.replace(/^\s+/,'').replace(/\s+$/,'');
	    if(Address1=="")
	{
	alert("Please enter address!");	
	document.form1.txtAddress123.value="";			
	document.form1.txtAddress123.focus();
	return false;
	}
	 if(document.form1.txtAddress123.length>250)
	{
		alert("Address must be 250 char long.");
		document.form1.txtAddress123.focus();
		return false;
	}
	
		 if(document.form1.state.value=="")
	{
		alert("Please select your City/State");
		document.form1.state.focus();
		return false;
	}
	//alert(isnumeric(document.form1.txtZip.value))
    if(isnumeric(document.form1.txtZip.value)==false)
	{
		alert("Please enter numeric digits for pin code!");
		document.form1.txtZip.focus();
 		return false;
	}	
	
	 var Tel = document.form1.txtTel.value;
   	 Tel1=Tel.replace(/^\s+/,'').replace(/\s+$/,'');
	    if(Tel1=="")
	{
	alert("Please enter mobile number!");	
	document.form1.txtTel.value="";			
	document.form1.txtTel.focus();
	return false;
	}
	if(isnumeric(document.form1.txtTel.value)==false)
	{
	alert("Please Enter Valid Number")
	document.form1.txtTel.focus();
	return false;
	}
	var chek=document.getElementsByName("opt[]");
	var chklen=chek.length;
	var che=0;
	var chi;
	while(che<chklen)
	{
		 if(chek[che].checked==true)
		 {
			 chi=true;
			 break;
		 }
		
	che++;
	}
	if(chi!=true)
	{
		alert("please select Strategies");
		return false;
	}
	
	 if(document.form1.payment_type.value=="")
	{
		alert("Please select your Payment Type");
		document.form1.payment_type.focus();
		return false;
	}
 var Bank =document.form1.txtBank.value;
 
//alert(Bank)		
   	 Bank1=Bank.replace(/^\s+/,'').replace(/\s+$/,'');
	    if(Bank1=="")
	{
	alert("You have not entered your Bank Name");	
	document.form1.txtBank.value="";			
	document.form1.txtBank.focus();
	return false;
	}
	 var branch =document.form1.branch.value;
 
//alert(Bank)		
   	 branch1=branch.replace(/^\s+/,'').replace(/\s+$/,'');
	    if(branch=="")
	{
	alert("You have not entered your branch");	
	document.form1.branch.value="";			
	document.form1.branch.focus();
	return false;
	}
	var dt=document.form1.edate;
	if (isDate(dt.value)==false)
	{
		dt.focus()
		return false
	}
 var ChqDDNo =document.form1.txtChqDDNo.value;
   	 ChqDDNo1=ChqDDNo.replace(/^\s+/,'').replace(/\s+$/,'');
	    if(ChqDDNo1=="")
	{
	alert("You have not entered your Cheque/DD No./ Cash Refrence No.");	
	document.form1.txtChqDDNo.value="";			
	document.form1.txtChqDDNo.focus();
	return false;
	}
	if(document.form1.amt.value=="0")
	{
	
	 alert("Please Select Amount");
	 document.form1.amt.focus();
	 return false;
	}
	 if(document.form1.chkIsRead.checked==false)
	{
		alert("Please accept our Terms & Conditions");
		document.form1.chkIsRead.focus();
		return false;
	}
		
				
		}
		
function isnumeric(a)
{
	len=a.length;
	for ( var i=0;i<len;i++ )
		{
			var x = a.substring(i,i+1);
			if (x>'9' || x<'0')
			{
				return false
			}	
		} 
		return true;
}	

function test()
{
//alert(document.form1.cmbPayMode.value)
	if(document.form1.cmbPayMode.value=="by Cheque / Demand Draft")
	{
		document.form1.txtBank.value="by Credit Card / NetBanking";
		document.form1.txtChqDDNo.value="by Credit Card / NetBanking";		
		document.form1.txtBank.readOnly=true;
		document.form1.txtChqDDNo.readOnly=true;
		return true;		
	}
	else if(document.form1.cmbPayMode.value=="by Cash")
	{
		document.form1.txtBank.value="";
		document.form1.txtChqDDNo.value="";		
		document.form1.txtBank.readOnly=false;
		document.form1.txtChqDDNo.readOnly=false;
		return false;
	}
	else if(document.form1.cmbPayMode.value=="0")
	{
		document.form1.txtBank.value="";
		document.form1.txtChqDDNo.value="";		
		document.form1.txtBank.readOnly=false;
		document.form1.txtChqDDNo.readOnly=false;
		return false;
	}
}
		


function valid()
{
if(document.frm.name.value=="")
{
alert("Please Enter the Name");
document.frm.name.focus();
return false;
}

if(document.frm.email.value=="")
     {
          alert('Enter Your Email Address');
		  document.frm.email.focus();
          return false;
     }
     else{
      var str=document.frm.email.value;
			var at="@"
			var dot="."
			var comma=","
			var lat=str.indexOf(at)
			var lstr=str.length
			var ldot=str.indexOf(dot)
			var cdot=str.indexOf(comma)
			if(cdot!=-1){
               alert("Invalid E-mail ID")
 	           document.frm.email.focus();
			   document.frm.email.value="";
			   return false;
			}
			if (str.indexOf(at)==-1){
               alert("Invalid E-mail ID")
		   	   document.frm.email.focus();
     	       document.frm.email.value="";
			   return false;
			}
			if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr-1){
               alert("Invalid E-mail ID.\n\n Eg: abc@def.ghi")
 	           document.frm.email.focus();
			   document.frm.email.value="";
			   return false;
			}
			if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr-1){
   	            alert("Invalid E-mail ID.\n\n Eg: abc@def.ghi")
			    document.frm.email.focus();
			    document.frm.email.value="";
				return false;
			}
			if (str.indexOf(at,(lat+1))!=-1){   // To check whether there is one @ character in an email id
   	            alert("Invalid E-mail ID.\n\n Eg: abc@def.ghi")
               	document.frm.email.focus();
			    document.frm.email.value="";
				return false;
			 }
			 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ // To check whether @. and .@
   	            alert("Invalid E-mail ID.\n\n Eg: abc@def.ghi")
				document.frm.email.focus();
		    	document.frm.email.value="";
				return false;
			 }
			 if (str.indexOf(dot,(lat+2))==-1){
   	            alert("Invalid E-mail ID.\n\n Eg: abc@def.ghi")
				document.frm.email.focus();
			    document.frm.email.value="";
				return false;
			 }
			 if (str.indexOf(" ")!=-1){
                alert("Invalid E-mail ID.\n\n Eg: abc@def.ghi")
				document.frm.email.focus();
			    document.frm.email.value="";
				return false;
			 }
}

 if(document.frm.desc.value=="")
 {
 alert("Please Enter The Message");
 document.frm.desc.focus();
 return false;
 }
}
function chk()
{
	 if(document.form1.Allthe.checked==true)
	{
		var allch=document.getElementsByName("opt[]");
		var len  =allch.length;
		var i=0;
		//alert(len)
		while(i<len)
		{
			allch[i].checked=true;
			i++;
		}
	}
	 if(document.form1.Allthe.checked==false)
	{
		var allch=document.getElementsByName("opt[]");
		var len  =allch.length;
		var i=0;
		//alert(len)
		while(i<len)
		{
			allch[i].checked=false;
			i++;
		}
	}
}

 //Start Date Validation
/**
 * DHTML date validation script for dd/mm/yyyy. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9")))
         return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
    //alert(dtStr);
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true

}

function addch()
{
var addch=document.getElementsByName("opt[]");
var addlen=addch.length;
var err;
	//alert(addlen);
	var i=0;
	while(i<addlen)
	{
		if(addch[i].checked==false)
		{
		err=true;
		break;
		}
		else
		{
		    err=false;
		}
		i++;
	}
	if(err==false)
    {
		document.form1.Allthe.checked=true;
    }
	if(err==true)
	{
		document.form1.Allthe.checked=false;
	}
}

