function MM_validateForm3() { //v4.0
  //Color
  var varRedColor="#F4CECE";
  var varWhiteColor="#FFFFFF";
  var blnAgreementError=false;

  //Email address
  txtEmail=document.getElementById("txtEmail").value;
  txtCEmail=document.getElementById("txtCEmail").value;

  //Password
  txtPassword=document.getElementById("txtPassword").value;
  txtCPassword=document.getElementById("txtCPassword").value;

  //SSN number
  txtSSN1=document.getElementById("txtSSN1").value;
  txtSSN2=document.getElementById("txtSSN2").value; document.getElementById("txtSSN2").style.background=varWhiteColor; 
  txtSSN3=document.getElementById("txtSSN3").value; document.getElementById("txtSSN3").style.background=varWhiteColor; 

  //Cell number
  txtCell1=document.getElementById("txtCell1").value;
  txtCell2=document.getElementById("txtCell2").value; document.getElementById("txtCell2").style.background=varWhiteColor; 
  txtCell3=document.getElementById("txtCell3").value; document.getElementById("txtCell3").style.background=varWhiteColor; 

 //Lender
  blnUsingLender=document.frmApplyNow.intUsingLender(0).checked;

  //Agreement
  txtQuestion1=document.getElementById("txtQuestion1").value; document.getElementById("txtQuestion1").style.background=varWhiteColor; 
  txtQuestion2=document.getElementById("txtQuestion2").value; document.getElementById("txtQuestion2").style.background=varWhiteColor; 
  txtQuestion3=document.getElementById("txtQuestion3").value; document.getElementById("txtQuestion3").style.background=varWhiteColor; 
  txtQuestion4=document.getElementById("txtQuestion4").value; document.getElementById("txtQuestion4").style.background=varWhiteColor; 
  txtQuestion5=document.getElementById("txtQuestion5").value; document.getElementById("txtQuestion5").style.background=varWhiteColor; 
  txtQuestion6=document.getElementById("txtQuestion6").value; document.getElementById("txtQuestion6").style.background=varWhiteColor; 

  blnAgree1=document.frmApplyNow.optAgree1.checked; document.getElementById("optAgree1").style.background=varWhiteColor; 
  blnAgree2=document.frmApplyNow.optAgree2.checked; document.getElementById("optAgree2").style.background=varWhiteColor; 

  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm3.arguments;
  
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObjValidate(args[i]); 
  		//alert(args[i]);
		document.getElementById(args[i]).style.background=varWhiteColor;
    if (val) { nm=val.name; if ((val=val.value)!="") {

      if (test.indexOf('isEmail')!=-1) 
	  	{ p=val.indexOf('@');
			if (p<1 || p==(val.length-1)) {
					errors+='- '+args[i+1]+' field must contain an e-mail address.\n'; 
					document.getElementById(args[i]).style.background=varRedColor;
				}
      } else if (test!='R' && test!='L' && test!='Q') { num = parseFloat(val);
			if (isNaN(val)) {
					errors+='- '+args[i+1]+' must contain a number.\n'; 
					document.getElementById(args[i]).style.background=varbgcolor;
				}
			if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
			  min=test.substring(8,p); max=test.substring(p+1);
			  if (num<min || max<num)  {
				  errors+='- '+args[i+1]+' must contain a number between '+min+' and '+max+'.\n'; 
				  document.getElementById(args[i]).style.background=varRedColor;
			   } //if (num<min || max<num)
    		}  //if (test.indexOf('inRange') != -1)
		} //else if (test!='R')
	} //if (test.indexOf('isEmail')!=-1) 

		else if (test.charAt(0) == 'R') {
			errors += '- '+args[i+1]+' is required.\n'; 
			document.getElementById(args[i]).style.background=varRedColor; 
			} 
		//Lender	
		else if (test.charAt(0) == 'L' && blnUsingLender) {
			errors += '- '+args[i+1]+' is required.\n'; 
			document.getElementById(args[i]).style.background=varRedColor; 
		  }

		  
	} //if (val)
		
		//SSN Number
		 if (args[i] == "txtSSN1" && (txtSSN1=="" || txtSSN2=="" || txtSSN3=="")) {
			errors += '- '+args[i+1]+' number is required.\n'; 
			document.getElementById("txtSSN1").style.background=varRedColor; 
			document.getElementById("txtSSN2").style.background=varRedColor; 
			document.getElementById("txtSSN3").style.background=varRedColor; 
		  }else{}

		//Cell Number
		 if (args[i] == "txtCell1" && (txtCell1=="" || txtCell2=="" || txtCell3=="")) {
			errors += '- '+args[i+1]+' number is required.\n'; 
			document.getElementById("txtCell1").style.background=varRedColor; 
			document.getElementById("txtCell2").style.background=varRedColor; 
			document.getElementById("txtCell3").style.background=varRedColor; 
		  }else{}
		  
		//Agreement - This is only to insert the value in error variable
		if ((args[i+1] == "Question") && !blnAgreementError && (txtQuestion1=="" || txtQuestion2=="" || txtQuestion3=="" || txtQuestion4=="" || txtQuestion5=="" || txtQuestion6=="" || !blnAgree1 || !blnAgree2)) {
				blnAgreementError=true; //prevent iteration of same error.
				errors += '- Please answer all questions and check boxes in agreement.\n'; 
		 }else{}
		 	
			//Below will mark the agreement fields to red
		 	if (txtQuestion1=="")  document.getElementById("txtQuestion1").style.background=varRedColor; 
			if (txtQuestion2=="")  document.getElementById("txtQuestion2").style.background=varRedColor; 
			if (txtQuestion3=="")  document.getElementById("txtQuestion3").style.background=varRedColor; 
		 	if (txtQuestion4=="")  document.getElementById("txtQuestion4").style.background=varRedColor; 
			if (txtQuestion5=="")  document.getElementById("txtQuestion5").style.background=varRedColor; 
			if (txtQuestion6=="")  document.getElementById("txtQuestion6").style.background=varRedColor; 
			
			if (!blnAgree1) document.getElementById("optAgree1").style.background=varRedColor; 
			if (!blnAgree2) document.getElementById("optAgree2").style.background=varRedColor; 

  } //for (i=0; i<(args.length-2); i+=3)
  
  if(txtEmail!=txtCEmail){
	  	errors=errors+"- Email address and Confirm email address mismatch.\n"; 
		document.getElementById("txtEmail").style.background=varRedColor; 
		document.getElementById("txtCEmail").style.background=varRedColor; 		
	}else{}
	
  if(txtPassword!=txtCPassword){
	  	errors=errors+"- Password and Confirm password mismatch.\n"; 
		document.getElementById("txtPassword").style.background=varRedColor; 
		document.getElementById("txtCPassword").style.background=varRedColor; 		
	}else{}
	
  if (errors) alert("Error Occured!\n One or more required feilds are left blank or invalid data provided.\n Please check feilds marked with red color.");//alert('There are error(s) in the form. The fields are highlighted in red color.');//alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}//function MM_validateForm3()

