// JavaScript Document
function onsub(){
	
	if(document.email.fname.value=="")
	{
		alert("Enter the first name");
		document.email.fname.focus();
		return false;
	}

	if(isAlpha(document.email.fname.value)==false)
	{
		
		alert("Enter the valid first name");
		document.email.fname.value="";
		document.email.fname.focus();
		return false;
	}
		
	if(document.email.lname.value=="")
	{
		alert("Enter the last name");
		document.email.lname.focus();
		return false;
	}
	if(isAlpha(document.email.lname.value)==false)
	{
		
		alert("Enter the valid last name");
		document.email.lname.value="";
		document.email.lname.focus();
		return false;
	}
	
	if(document.email.Birthday.value!="")
	{
		if(isValidDate(document.email.Birthday.value)==false){
		return;
		}
	}

	if(document.email.Phone.value!=""){
	if(isAmt(document.email.Phone.value)==false)
	{
		
		alert("Enter the valid phoneno");
		document.email.Phone.value="";
		document.email.Phone.focus();
		return ;
	}
	}
	
	if(document.email.email.value=="")
	{
		alert("Enter the email");
		document.email.email.focus();
		return false;
	}
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   	var address = document.email.email.value;
   	if(reg.test(address) == false) {
      alert('Invalid Email Address');
	  document.email.email.value="";
	  document.email.email.focus();
      return false;

	}
	if(document.email.Zipcode.value!="")
	{
		if(isNaN(document.email.Zipcode.value))
		{
			alert("Enter the valid Zipcode");
			document.email.Zipcode.focus();
			return ;
		}
	}
	
	if(document.email.Howlongyears.value!="")
	{
		if(isNaN(document.email.Howlongyears.value))
		{
			alert("Enter the valid Howlongyears");
			document.email.Howlongyears.focus();
			return ;
		}
	}
	if(document.email.Howlongmonth.value!="")
	{
		if(isNaN(document.email.Howlongmonth.value))
		{
			alert("Enter the valid Howlongmonth");
			document.email.Howlongmonth.focus();
			return ;
		}
	}
	if(document.email.Pre_Howlongyears.value!="")
	{
		if(isNaN(document.email.Pre_Howlongyears.value))
		{
			alert("Enter the valid Howlongyears");
			document.email.Pre_Howlongyears.focus();
			return ;
		}
	}
	if(document.email.Pre_Howlongmonth.value!="")
	{
		if(isNaN(document.email.Pre_Howlongmonth.value))
		{
			alert("Enter the valid Howlongmonth");
			document.email.Pre_Howlongmonth.focus();
			return ;
		}
	}
	
	if(document.email.Pre_zipcode.value!="")
	{
		if(isNaN(document.email.Pre_zipcode.value))
		{
			alert("Enter the valid Zipcode");
			document.email.Pre_zipcode.focus();
			return ;
		}
	}
	frmchange(1);	
}
var num = '0123456789 .-';
var lwr = 'abcdefghijklmnopqrstuvwxyz ';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ';

function isValid(parm,val) {
if (parm == "") return true;
for (i=0; i<parm.length; i++) {
if (val.indexOf(parm.charAt(i),0) == -1) return false;
}
return true;
}

function isAlpha(parm){ return isValid(parm,lwr+upr); }

function isAmt(parm){ return isValid(parm,num); }

function isValidDate(dateStr) {

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;


var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("Date is not in a valid format.")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
return false;
   }
}
return true;  // date is valid
}


// JavaScript Document
function onsub1(){
	
	if(document.email.Employe_howlongyears.value!="")
	{
		if(isNaN(document.email.Employe_howlongyears.value))
		{
			alert("Enter the valid Howlongyears");
			document.email.Employe_howlongyears.focus();
			return ;
		}
	}
	if((document.email.Employe_howlongmonth.value!=""))
	{
		if(isNaN(document.email.Employe_howlongmonth.value))
		{
			alert("Enter the valid Howlongmonth");
			document.email.Employe_howlongmonth.focus();
			return ;
		}
	}
	if((document.email.Employe_phone.value!="")||(document.email.Employe_phone1.value!=""))
	{
		if((isAmt(document.email.Employe_phone.value)==false)||(isAmt(document.email.Employe_phone1.value)==false))
		{
			alert("Enter the valid phoneno");
			//document.email.Empphone.focus();
			return ;
		}
	}
	if(document.email.Employe_gross.value!=""){
	if(isAmt(document.email.Employe_gross.value)==false)
	{
		
		alert("Enter the valid gross amount");
		document.email.Empgross.value="";
		document.email.Empgross.focus();
		return ;
	}
	}
	
	if(document.email.Gross_Monthly_Inc.value!=""){
		//alert(document.email.Gross_Monthly_Inc.value);
		if(isAmt(document.email.Gross_Monthly_Inc.value)==false)
		{
			alert("Enter the valid Gross Monthly Income amount");
			document.email.Gross_Monthly_Inc.value="";
			document.email.Gross_Monthly_Inc.focus();
			return ;
		}
	}
	if(document.email.Additional_Income.value!=""){
		if(isAmt(document.email.Additional_Income.value)==false)
		{
		
			alert("Enter the valid Additional Income amount");
			document.email.Additional_Income.value="";
			document.email.Additional_Income.focus();
			return ;
		}	
	}
	if(document.email.Gross_Additional_Inco.value!=""){
		if(isAmt(document.email.Gross_Additional_Inco.value)==false)
		{
		
			alert("Enter the valid Gross Additional Income amount");
			document.email.Gross_Additional_Inco.value="";
			document.email.Gross_Additional_Inco.focus();
			return ;
		}	
	}
	
	frmchange(2);
}
function onsub3(){
	
	if(document.email.Second_App_birth.value!="")
	{
		if(isValidDate(document.email.Second_App_birth.value)==false){
		return;
		}
	}
	if(document.email.Second_App_Phone.value!=""){
	if(isAmt(document.email.Second_App_Phone.value)==false)
	{
		
		alert("Enter the valid phoneno");
		document.email.Second_App_Phone.value="";
		document.email.Second_App_Phone.focus();
		return ;
	}
	}
	if(document.email.Second_App_Mail.value!=""){
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   	var address = document.email.Second_App_Mail.value;
   	if(reg.test(address) == false) {
      alert('Invalid Email Address');
	  document.email.email.value="";
	  document.email.email.focus();
      return false;

	}
	}
	if(document.email.Employer_Phone1.value!=""){
	if(isAmt(document.email.Employer_Phone1.value)==false)
	{
		
		alert("Enter the valid phoneno");
		document.email.Employer_Phone1.value="";
		document.email.Employer_Phone1.focus();
		return ;
	}
	}
	if(document.email.Second_Information_Gross_Income.value!=""){
	if(isAmt(document.email.Second_Information_Gross_Income.value)==false)
	{
		
		alert("Enter the valid gross amount");
		document.email.Second_Information_Gross_Income.value="";
		document.email.Second_Information_Gross_Income.focus();
		return ;
	}
	}
	if(document.email.Gross_Monthly_Income.value!=""){
		//alert(document.email.Gross_Monthly_Inc.value);
		if(isAmt(document.email.Gross_Monthly_Income.value)==false)
		{
			alert("Enter the valid Gross Monthly Income amount");
			document.email.Gross_Monthly_Income.value="";
			document.email.Gross_Monthly_Income.focus();
			return ;
		}
	}
	if(document.email.Additional_Income_Source.value!=""){
		if(isAmt(document.email.Additional_Income_Source.value)==false)
		{
		
			alert("Enter the valid Additional Income amount");
			document.email.Additional_Income_Source.value="";
			document.email.Additional_Income_Source.focus();
			return ;
		}	
	}
	if(document.email.Gross_Additional_Income.value!=""){
		if(isAmt(document.email.Gross_Additional_Income.value)==false)
		{
		
			alert("Enter the valid Gross Additional Income amount");
			document.email.Gross_Additional_Income.value="";
			document.email.Gross_Additional_Income.focus();
			return ;
		}	
	}
	frmchange(3);
}
	
function onsub4()
{
	if(document.email.Contractprice.value!=""){
	if(isAmt(document.email.Contractprice.value)==false)
	{
		
		alert("Enter the valid Contractprice");
		document.email.Contractprice.value="";
		document.email.Contractprice.focus();
		return ;
	}
	}
	if(document.email.Downpayment.value!=""){
	if(isAmt(document.email.Downpayment.value)==false)
	{
		
		alert("Enter the valid Downpayment");
		document.email.Downpayment.value="";
		document.email.Downpayment.focus();
		return ;
	}
	}
	if(document.email.Amount_req.value!=""){
	if(isAmt(document.email.Amount_req.value)==false)
	{
		
		alert("Enter the valid Amount_req");
		document.email.Amount_req.value="";
		document.email.Amount_req.focus();
		return ;
	}
	}
}
