
//alert("hi");
var  emsg="";
var nosubmit = false;	
var jointapp=-1;
var count=24;
var recount=0;

//setInterval(settabindex,2000);
window.onload ="settabindex";


function settabindex()
{
	var frm =document.contact;
	for (i=0; i<frm.elements.length;i++)
	 frm.elements[0].tabIndex=i;
	 
	frm.cFname.focus();
}

function validate()
{
		//alert("hi");
		frm=document.contact;
//		dropDownMenu(frm.cState,"Please choose the title");
		IsNull112(frm.cFname.value,"Please Enter First Name","cFname");
		IsNull112(frm.cLname.value,"Please Enter Last Name","cLname");
//		dropDownMenu(frm.gender,"Please choose the Gender");
		//IsNull(frm.house_name.value,"Please Enter House number / street number");
		
		IsNull112(frm.cEmail.value,"Please Enter Email Id","cEmail");
		if (frm.cEmail.value.length>0 && frm.cEmail.value!="" ) 
		{ 
		checkMail112(frm.cEmail.value,"Please Enter Valid Email ID","cEmail");
		}
		IsNull112(frm.cAddr1.value,"Please Enter Address","cAddr1");
		IsNull112(frm.cCity.value,"Please Enter name of Town/city","cCity");
		dropDownMenu112(frm.cState,"Please choose the state","cState");
		IsNull112(frm.cZip.value,"Please Post code","cZip");
		checkradio112(frm.cArmed,"Do you belong to US Military","cArmed");
//		dropDownMenu(frm.county,"Please choose the County");
		dropDownMenu112(frm.cDOBM,"Please choose Month of Date of Birth","cDOB");
		dropDownMenu112(frm.cDOBM,"Please choose Day of Date of Birth","cDOB");
		dropDownMenu112(frm.cDOBM,"Please choose Year of Date of Birth","cDOB");
		
		IsNull112(frm.cHphone.value,"Please Enter Home Telephone Number","cHphone");
		 if (frm.cHphone.value != "" && frm.cHphone.value.length>0 )
		 {
			 if (!usphone(frm.cHphone.value))
			 {
			   emsg += '-- Please Enter  Valid Phone number'+'\n';
			      nosubmit=true;
			 }
		 }
		
		if ( frm.cSsn1.value=="" || frm.cSsn1.value.length==0 || frm.cSsn2.value=="" || frm.cSsn2.value.length==0 || frm.cSsn3.value=="" || frm.cSsn3.value.length==0 )
		{
			   var x="l_cSsn1";
			   document.getElementById(x).style.color="#cc0000";
			      nosubmit=true;
			//emsg += 'Please Enter  SSN Number'+'\n'
		}
		
		if ( frm.cSsn1.value!="" && frm.cSsn1.value.length!=0 && frm.cSsn2.value!="" && frm.cSsn2.value.length!=0 && frm.cSsn3.value!="" && frm.cSsn3.value.length!=0 )
		{
			   var x="l_cSsn1";
			  var xx=isValidSSN(frm.cSsn1.value+frm.cSsn2.value+frm.cSsn3.value);
			  
			  if  (!xx) 
			  {
				  emsg += '-- Please Enter  Valid SSN Number'+'\n';
				  document.getElementById(x).style.color="#cc0000";
				     nosubmit=true;
			  }
			  else
			  document.getElementById(x).style.color="#000000";
			  
			   //
			//emsg += 'Please Enter  SSN Number'+'\n'
		}
		
		dropDownMenu112(frm.cDlstate,"Please choose Your DL status","cDlstate");
		
		IsNull112(frm.cDlno.value,"Please Enter your DL  Number","cDlno");
		IsNull112(frm.cLoan.value,"Please Enter Loan Amount Required","cLoan");
        checkradio112(frm.cEmptype,"Please choose your type of empoyement","cEmptype");
		 dropDownMenu112(frm.cIncometype,"Please choose your type of Income","cIncometype"); 
		 checkradio112(frm.cPayrolltype,"How do you receive your pay checque","cPayrolltype");
		  dropDownMenu112(frm.cPayrollperiod,"How Often you receive your pay cheque","cPayrollperiod"); 
		   checkradio112(frm.cBankruptcy,"Have you filed for Bankruptcy or Planning to?","cBankruptcy");
		   //dropDownMenu112(frm.cGross,"What is Gross pay per cheque","cGross"); 
		   IsNull112(frm.cGross,"What is Gross pay per cheque","cGross");
		   
		   dropDownMenu112(frm.cwfromD,"Working From : Please choose Month of Pay Date","cwfrom");
		dropDownMenu112(frm.cwfromM,"Working From : Please choose Day of Pay Date","cwfrom");
		dropDownMenu112(frm.cwfromY,"Working From : Please choose Year of Pay Date","cwfrom");
		 
		   dropDownMenu112(frm.cLpaydateM,"Last Pay Date : Please choose Month of Pay Date","cLpaydateM");
		dropDownMenu112(frm.cLpaydateD,"Last Pay Date : Please choose Day of Pay Date","cLpaydateM");
		dropDownMenu112(frm.cLpaydateY,"Last Pay Date : Please choose Year of Pay Date","cLpaydateM");
		  
		 dropDownMenu112(frm.cNpaydateM,"Next Pay Date : Please choose Month of Pay Date","cNpaydateM");
		dropDownMenu112(frm.cNpaydateD,"Next Pay Date : Please choose Day of Pay Date","cNpaydateM");
		dropDownMenu112(frm.cNpaydateY,"Next Pay Date : Please choose Year of Pay Date","cNpaydateM");
		
		 dropDownMenu112(frm.cSpaydateM,"Second Pay Date : Please choose Month of Pay Date","cSpaydateM");
		dropDownMenu112(frm.cSpaydateD,"Second Pay Date : Please choose Day of Pay Date","cSpaydateM");
		dropDownMenu112(frm.cSpaydateY,"Second Pay Date : Please choose Year of Pay Date","cSpaydateM");
		
		IsNull112(frm.cBankname.value,"Please Enter Bank Name","cBankname");
		IsNull112(frm.cAbano.value,"Please Enter ABA Number","cAbano");
		IsNull112(frm.cAccno.value,"Please Enter Account  Number","cAccno");
		checkradio112(frm.cAcctype,"Please Choose your Account Type","cAcctype");
		
		 
		   IsNull112(frm.rFname1.value,"First Reference : Please Enter First Name","rFname1");
		IsNull112(frm.rLname1.value,"First Reference : Please Enter Last Name","rLname1");
		IsNull112(frm.rPhone1.value,"First Reference : Please Enter Phone Number","rPhone1");
		 dropDownMenu112(frm.rRelation1,"First Reference : Please choose Relation","rRelation1");
		
		   IsNull112(frm.rFname2.value,"Second Reference : Please Enter First Name","rFname2");
		IsNull112(frm.rLname2.value,"Second Reference : Please Enter Last Name","rLname2");
		IsNull112(frm.rPhone2.value,"Second Reference : Please Enter Phone Number","rPhone2");
		 dropDownMenu112(frm.rRelation2,"Second Reference : Please choose Relation","rRelation2");
		 
		   if ( !frm.checkbox.checked)
		   { 
		      emsg +="-- Please Agree  to  terms and conditions\n";
			    document.getElementById("l_checkbox").style.color="#cc0000";
				   nosubmit=true;
			   
		   }
		   else
		   {
		       document.getElementById("l_checkbox").style.color="#000000";
			
		   }
		
		
		if ( nosubmit==true )
		{

			if  (count-1==recount)
			emsg= "Please enter the follwing details :\n-----------------------------------\n"+"All  Fieleds are Mandatory" ;
			else
			{
			emsg1= "One or More Errors  are found , Please  Check the Fileds  which  are in Red Color\n-----------------------------------\n"+emsg;
			 /*document.getElementById("emms").innerHTML= "<u>Please Correct the Foloowing : </u><br> "+emsg;
			 document.getElementById("emms").style.display="block";
				document.getElementById("tdForm").style.display="none";*/
			}
			alert(emsg1);
			emsg="";
			nosubmit=false;
			return false;
		}
				
		return true;
}




function usphone(x) {
    var filter = /^[ ]*[(]{0,1}[ ]*[0-9]{3,3}[ ]*[)]{0,1}[-]{0,1}[ ]*[0-9]{3,3}[ ]*[-]{0,1}[ ]*[0-9]{4,4}[ ]*$/; 
	if (!filter.test(x)) 
	{
		return false;
	}
	else
	{ 
	 return true;
	}
}

function isValidSSN(x) {
    var filter = /^([0-6]\d{2}|7[0-6]\d|77[0-2])([ \-]?)(\d{2})\2(\d{4})$/; 
	if (!filter.test(x)) 
	{
		return false;
	}
	else
	{ 
	 return true;
	}
}

function removedefault( val)
{
document.getElementById(val).value="";
	
}

function checkdefault( val,val1)
{
var x=document.getElementById(val).value;
if (x.length==0 && x=="")
document.getElementById(val).value=val1;

	
}
function IsNull1(aTextField,mes) {
   if (aTextField=="dd"  || aTextField=="mm" || aTextField=="yyyy") 
   {
	   emsg += mes+'\n'
	   nosubmit=true;
    }
}	




function check_date(d,m,y)
{
	if  (d>31) 
	{
	   emsg += 'Date Value Can not be >31 \n'
	   nosubmit=true;
    }
	if  (m>12) 
	{
	   emsg += 'Month Value can not be >12 \n'
	   nosubmit=true;
    }
	if  (y>2008 || y <1900) 
	{
	   emsg += 'Year  should not be less than 1900 and  greater than present year  \n'
	   nosubmit=true;
    }
	
}





function IsNull112(aTextField,mes,namee) {
	 var x="l_"+namee;
   if ((aTextField.length==0) ||   (aTextField==null)) 
   {
	   recount ++;
	 //emsg += '<li>'+mes+'</li>\n';
	  	  emsg += ' --'+mes+'\n';
	   document.getElementById(x).style.color="#cc0000";
//	   emsg += mes+'\n'
	   nosubmit=true;
    }
	else
	 document.getElementById(x).style.color="#000000";
	
}	

function dropDownMenu112(menu, mes,namee) 
   {
   var myindex=menu.selectedIndex;
   var x="l_"+namee;
   if (myindex==0)
      {
		  recount++;
		   //emsg += '<li>'+mes+'</li>\n';
	  	  emsg += ' --'+mes+'\n';
       document.getElementById(x).style.color="#cc0000";
	  nosubmit=true;
       }
	else
	 document.getElementById(x).style.color="#000000";
   }


function checkradio112(fld,mes,namee)
{ 
var x="l_"+namee;
	myOption = -1;
		for (i=fld.length-1; i > -1; i--) 
		{
			if (fld[i].checked){
			myOption = i; i = -1;
			}
		}
		
		jointapp=myOption
if (myOption == -1)
	{
   document.getElementById(x).style.color="#cc0000";
	  //emsg += '<li>'+mes+'</li>\n';
		  emsg += ' --'+mes+'\n';
	nosubmit=true;
	}
	else
	  document.getElementById(x).style.color="#000000";
}

function checkMail112(fld,mes,namee)
{
	var x="l_"+namee;
	
	var x = fld;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9.]{2,5})+$/;
	if (!filter.test(x)) 
	{
		
		// document.getElementById(x).style.color="#cc0000";
	 //emsg += '<li>'+mes+'</li>\n';
	  emsg += ' --'+mes+'\n';
	nosubmit=true;
	}
	else
	{ 
	 // document.getElementById(x).style.color="#000000";
	}
	
}






//  required functions

   function getkey(e){
if (window.event)
return window.event.keyCode;
else if (e)
return e.which;
else
return null;
}
	function onlyNumbers(e){
	//alert(e.value);
var key, keychar;
var goods="0123456789";
key = getkey(e);
if (key == null) return true;
keychar = String.fromCharCode(key);
if (goods.indexOf(keychar) != -1)
	return true;
if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
	return true;
return false;
}



function toggle(str)
{
	
	if  (str=="Yes" )
	document.getElementById("sappdetails").style.display="block";
	else
	document.getElementById("sappdetails").style.display="none";
	
}