// JavaScript Document

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}


function toDollarsAndCents(n) {
  var s = "" + Math.round(n * 100) / 100;
  var i = s.indexOf('.');
  if (i < 0) return s + ".00";
  var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3);
  if (i + 2 == s.length) t += "0";
  return t;
}


function IsNumeric(sText, required)

{
   var IsNumber=true;
   
   if (required && sText.length <= 0) 
   	{
		IsNumber = false;
	}
   else
   	{
	   var ValidChars = "0123456789.";
	   var Char;
	
	 
	   for (i = 0; i < sText.length && IsNumber == true; i++) 
		  { 
		  Char = sText.charAt(i); 
		  if (ValidChars.indexOf(Char) == -1) 
			 {
			 IsNumber = false;
			 }
		  }
	  
	  }
   return IsNumber;
   
   }
   
   

function calculateAssets(myForm)
	{
        var total = 0;
        
        total += parseFloat(IsNumeric(myForm.financialInfoAssetsCashAmount.value, true) ? myForm.financialInfoAssetsCashAmount.value : 0);
        
        total += parseFloat(IsNumeric(myForm.financialInfoAssetsPropertyDepositAmount.value, true) ? myForm.financialInfoAssetsPropertyDepositAmount.value : 0);
        total += parseFloat(IsNumeric(myForm.financialInfoAssetsAutomobileValue.value, true) ? myForm.financialInfoAssetsAutomobileValue.value : 0);
        total += parseFloat(IsNumeric(myForm.financialInfoAssetsHomeValue.value, true) ? myForm.financialInfoAssetsHomeValue.value : 0);
        total += parseFloat(IsNumeric(myForm.financialInfoAssetsInvestmentPropertiesValue.value, true) ? myForm.financialInfoAssetsInvestmentPropertiesValue.value : 0);
        total += parseFloat(IsNumeric(myForm.financialInfoAssetsStocksEtcAmount.value, true) ? myForm.financialInfoAssetsStocksEtcAmount.value : 0);
        total += parseFloat(IsNumeric(myForm.financialInfoAssetsRRSPAmount.value, true) ? myForm.financialInfoAssetsRRSPAmount.value : 0);
        total += parseFloat(IsNumeric(myForm.financialInfoAssetsOtherAmount.value, true) ? myForm.financialInfoAssetsOtherAmount.value : 0);
        
        myForm.totalAssets.value = toDollarsAndCents(total);
        
        calcNetWorth(myForm);
	}
	
function calculateLiabilities(myForm)
	{
        var totalOwing = 0;
        var totalMonthly = 0;
                
        totalOwing += parseFloat(IsNumeric(myForm.financialInfoLiabilitiesBankLoansOwing.value, true) ? myForm.financialInfoLiabilitiesBankLoansOwing.value : 0);
        totalOwing += parseFloat(IsNumeric(myForm.financialInfoLiabilitiesCreditCardOwing.value, true) ? myForm.financialInfoLiabilitiesCreditCardOwing.value : 0);
        totalOwing += parseFloat(IsNumeric(myForm.financialInfoLiabilitiesVehicleOwing.value, true) ? myForm.financialInfoLiabilitiesVehicleOwing.value :0);
        totalOwing += parseFloat(IsNumeric(myForm.financialInfoLiabilitiesFirstMortgageOwing.value, true) ? myForm.financialInfoLiabilitiesFirstMortgageOwing.value : 0);
        totalOwing += parseFloat(IsNumeric(myForm.financialInfoLiabilitiesSecondMortgageOwing.value, true) ? myForm.financialInfoLiabilitiesSecondMortgageOwing.value : 0);
        totalOwing += parseFloat(IsNumeric(myForm.financialInfoLiabilitiesFinanceCompanyLoansOwing.value, true) ? myForm.financialInfoLiabilitiesFinanceCompanyLoansOwing.value : 0);

        totalMonthly += parseFloat(IsNumeric(myForm.financialInfoLiabilitiesBankLoansMonthly.value, true) ? myForm.financialInfoLiabilitiesBankLoansMonthly.value : 0 );
        totalMonthly += parseFloat(IsNumeric(myForm.financialInfoLiabilitiesCreditCardMonthly.value, true) ? myForm.financialInfoLiabilitiesCreditCardMonthly.value : 0);
        totalMonthly += parseFloat(IsNumeric(myForm.financialInfoLiabilitiesVehicleMonthly.value, true) ? myForm.financialInfoLiabilitiesVehicleMonthly.value : 0);
        totalMonthly += parseFloat(IsNumeric(myForm.financialInfoLiabilitiesFirstMortgageMonthly.value, true) ? myForm.financialInfoLiabilitiesFirstMortgageMonthly.value : 0);
        totalMonthly += parseFloat(IsNumeric(myForm.financialInfoLiabilitiesSecondMortgageMonthly.value, true) ? myForm.financialInfoLiabilitiesSecondMortgageMonthly.value : 0);
        totalMonthly += parseFloat(IsNumeric(myForm.financialInfoLiabilitiesFinanceCompanyLoansMonthly.value, true) ? myForm.financialInfoLiabilitiesFinanceCompanyLoansMonthly.value : 0);
        totalMonthly += parseFloat(IsNumeric(myForm.financialInfoLiabilitiesAlimonyChildSupportMonthly.value, true) ? myForm.financialInfoLiabilitiesAlimonyChildSupportMonthly.value : 0);

        myForm.totalOwing.value = toDollarsAndCents(totalOwing);
        myForm.totalMonthly.value = toDollarsAndCents(totalMonthly);
        
        calcNetWorth(myForm);        
	}
    
    
function calcNetWorth(myForm)
    {
        myForm.netWorth.value = ( (parseFloat( IsNumeric(myForm.totalAssets.value, true) ? myForm.totalAssets.value : 0) - parseFloat(IsNumeric(myForm.totalOwing.value, true) ? myForm.totalOwing.value : 0)));
		myForm.netWorth.value = toDollarsAndCents(parseFloat(myForm.netWorth.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){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}


function postalCheck(value)
{
    var result = true;
    var postalPattern = /^[A-Z][0-9][A-Z](|-)[0-9][A-Z][0-9]$/;
    var postalRegExp = new RegExp(postalPattern);
    if (value =="")
        {
            result = false;
        }
    if (postalRegExp.test(value) == false )
        {
            result = false;
        }
    return result;
}


function dateFormatCheck(value)
{
	var result = true;
    /*var datePattern = /^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/;*/
	var datePattern = /^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/;
    var dateRegExp = new RegExp(datePattern);
    if (value =="")
        {
            result = false;
        }
    if (dateRegExp.test(value) == false )
        {
            result = false;
        }
		
    return result;
}

function checkdate(input)
{
	/*var validformat=/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/ //Basic check for format validity*/
	var validformat = /^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/;
	var returnval=false
	if (!validformat.test(input))
		{
			//Bad Format	
		}
	else
		{ //Detailed check for valid date ranges
		    /*
			var monthfield=input.split("-")[1]
			var dayfield=input.split("-")[2]
			var yearfield=input.split("-")[0]
			*/
			
			/* mmddyyyy */
			var monthfield=input.substr(0,2);
			var dayfield=input.substr(2,2);
			var yearfield=input.substr(4);
			
			var dayobj = new Date(yearfield, monthfield-1, dayfield)
			if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
				{
					//Date is not valid.	
				}
			else
				{
				returnval=true
				}
		}
		
	return returnval
}


function mortgageAppValidate(theForm)
	{
		var result = true;
		var msg = "";
		
		/* Loan Information */
		if (theForm.mortgageDetailsPurposeOfLoan.selectedIndex == 0) 
			{
				result = false;
				msg += "'Purpose of Loan' is a required field.\n";
			}
		
		if (!IsNumeric(theForm.mortgageDetailsValueOfHome.value, false)) 
			{
				result = false;
				msg += "'Value of Home' must be a numerical value.\n";
			}
		
		if (!IsNumeric(theForm.mortgageDetailsMortgageAmountRequired.value, true)) 
			{
				result = false;
				msg += "'Requested Amount' is required and must be a numerical value.\n";
			}
		
		if (!dateFormatCheck(theForm.mortgageDetailsFundsRequiredDate.value))
			{
				//Date is not in the correct format.
				result = false;
				msg += "'Date Required' must be of the form MMDDYYYY\n";	
			}
		else if (!checkdate(theForm.mortgageDetailsFundsRequiredDate.value))
			{
				result = false;
				msg += "'Date Required' contains an invalid date.\n";	
			}	
            
        /* Loan Information End*/
		
		


       /* Main Applicant Personal Information */
		if (theForm.personalInformationApplicant1Title.selectedIndex == 0) 
			{
				result = false;
				msg += "Main Applicant 'Title' is a required field.\n";
			}
			
		if (theForm.personalInformationApplicant1FirstName.value.length <= 0)
			{
				result = false;
				msg += "Main Applicant 'First Name' is a required field.\n";
			}
			
		if (theForm.personalInformationApplicant1LastName.value.length <= 0)
			{
				result = false;
				msg += "Main Applicant 'Last Name' is a required field.\n";
			}
			
		if (!dateFormatCheck(theForm.personalInformationApplicant1DateOfBirth.value))
			{
				//Date is not in the correct format.
				result = false;
				msg += "Main Applicant 'Date of Birth Required must be of the form MMDDYYYY\n";	
			}
		else if (!checkdate(theForm.personalInformationApplicant1DateOfBirth.value))
			{
				result = false;
				msg += "Main Applicant 'Date of Birth' contains an invalid date.\n";	
			}	
         
		 
		
		if (theForm.personalInformationApplicant1SIN.value.length != 9 || !IsNumeric(theForm.personalInformationApplicant1SIN.value, true))
		{
			result = false;
			msg += "Main Applicant 'SIN#' is rquired.  Please check the format.  Please enter your 9 digit Canadian SIN number\n";	
		}
			
		
		 
        if (theForm.personalInformationApplicant1HomePhoneNo.value.length < 10 || !IsNumeric(theForm.personalInformationApplicant1HomePhoneNo.value, false))
			{
				result = false;
				msg += "Main Applicant 'Home Phone#' is a required field.  Please enter your 10 digit Canadian phone number\n";
			}
            
       if (theForm.personalInformationApplicant1WorkPhoneNo.value.length > 0)
       {
           if (theForm.personalInformationApplicant1WorkPhoneNo.value.length < 10 || !IsNumeric(theForm.personalInformationApplicant1WorkPhoneNo.value, false))
                {
                    result = false;
                    msg += "Main Applicant 'Work Phone#' is invalid. Please enter your 10 digit Canadian rork phone number\n";
                }
        }
        
        if (theForm.personalInformationApplicant1EmailAddress.value.length > 0)
        {
            if (!echeck(theForm.personalInformationApplicant1EmailAddress.value))
                {
                    result = false;
                    msg += "Main Applicant 'Email Address' is invalid.\n";
                }
            
        }
        
        /* Main Applicant Personal Information End*/
        
        
        /* Main Applicant Current Address */
       if (theForm.personalInformationApplicant1CurrentAddressStreetAddress.value.length <= 0)
			{
				result = false;
				msg += "Main Applicant 'Street Address' is a required field.\n";
			}

        if (theForm.personalInformationApplicant1CurrentAddressCity.value.length <= 0)
			{
				result = false;
				msg += "Main Applicant 'City/Town' is a required field.\n";
			}
            
        if (theForm.personalInformationApplicant1CurrentAddressProvince.selectedIndex == 0) 
			{
				result = false;
				msg += "Main Applicant 'Province' is a required field.\n";
			}
        
        
        theForm.personalInformationApplicant1CurrentAddressPostalCode.value = theForm.personalInformationApplicant1CurrentAddressPostalCode.value.toUpperCase();
        
        if (!postalCheck(theForm.personalInformationApplicant1CurrentAddressPostalCode.value))
            {
                result = false;
				  msg += "Main Applicant 'Postal Code' is a required field and must be of the form T0H0H0\n";
            }
            
          if (theForm.personalInformationApplicant1CurrentAddressResidentialStatus.selectedIndex == 0) 
			{
				result = false;
				msg += "Main Applicant 'Residential Status' is a required field.\n";
			}
            
          if (theForm.personalInformationApplicant1CurrentAddressMonthlyRentPayments.value.length > 0)
          {
            if (!IsNumeric(theForm.personalInformationApplicant1CurrentAddressMonthlyRentPayments.value, false))
                {
                    result = false;
                    msg += "Main Applicant 'Monthly Rent Payments' must be a numerical value.\n";
                }
          }
          
          
          if (!IsNumeric(theForm.personalInformationApplicant1CurrentAddressTimeAtRes.value, true)) 
			{
				result = false;
				msg += "Main Applicant 'Time at Residence' is required and must be a numerical value.\n";
			}
            
            
          
          /* End Main Applicant Current Address */
          
          
          /* Applicant 1 Previous Address */
          
          if (theForm.personalInformationApplicant1CurrentAddressTimeAtRes.value < 3)
          {
          
               if (theForm.personalInformationApplicant1PrevAddressStreetAddress.value.length <= 0)
                {
                    result = false;
                    msg += "Main Applicant Previous Address 'Street Address' is a required field.\n";
                }

            if (theForm.personalInformationApplicant1PrevAddressCity.value.length <= 0)
                {
                    result = false;
                    msg += "Main Applicant Previous Address 'City/Town' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant1PrevAddressProvince.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Main Applicant Previous Address 'Province' is a required field.\n";
                }
            
            
            theForm.personalInformationApplicant1PrevAddressPostalCode.value = theForm.personalInformationApplicant1PrevAddressPostalCode.value.toUpperCase();
            
            if (!postalCheck(theForm.personalInformationApplicant1PrevAddressPostalCode.value))
                {
                    result = false;
                      msg += "Main Applicant Previous Address 'Postal Code' is a required field and must be of the form T0H0H0\n";
                }
                
              if (theForm.personalInformationApplicant1PrevAddressResidentialStatus.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Main Applicant Previous Address 'Residential Status' is a required field.\n";
                }
                
              if (theForm.personalInformationApplicant1PrevAddressMonthlyRentPayments.value.length > 0)
              {
                if (!IsNumeric(theForm.personalInformationApplicant1PrevAddressMonthlyRentPayments.value, false))
                    {
                        result = false;
                        msg += "Main Applicant Previous Address 'Monthly Rent Payments' must be a numerical value.\n";
                    }
              }
              
              if (!IsNumeric(theForm.personalInformationApplicant1PrevAddressTimeAtRes.value, true)) 
                {
                    result = false;
                    msg += "Main Applicant Previous Address 'Time at Residence' is required and must be a numerical value.\n";
                }
            
            }
          /* End Applicant 1 Previous Address*/
        
        
        /* Applicant 1 Present Employer */
            if (theForm.personalInformationApplicant1PresentEmployerName.value.length <= 0)
                {
                    result = false;
                    msg += "Main Applicant 'Employer Name' is a required field.\n";
                }
        
            if (theForm.personalInformationApplicant1PresentEmployerOccupationType.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Main Applicant 'Occupation Type' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant1PresentEmployerIndustrySector.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Main Applicant 'Industry Sector' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant1PresentEmployerAddressProvince.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Main Applicant 'Employer Province' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant1PresentEmployerIncomeType.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Main Applicant 'Type of Income' is a required field.\n";
                }
                
                
            if (theForm.personalInformationApplicant1PresentEmployerAddressStreetAddress.value.length <= 0)
                {
                    result = false;
                    msg += "Main Applicant 'Employer Address' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant1PresentEmployerAddressCity.value.length <= 0)
                {
                    result = false;
                    msg += "Main Applicant 'Employer City' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant1PresentEmployerAddressPostalCode.value.length > 0)
                {
                    theForm.personalInformationApplicant1PresentEmployerAddressPostalCode.value = theForm.personalInformationApplicant1PresentEmployerAddressPostalCode.value.toUpperCase();
                    if (!postalCheck(theForm.personalInformationApplicant1PresentEmployerAddressPostalCode.value))
                        {
                            result = false;
                            msg += "Main Applicant 'Employer Postal Code' must be of the form T0H0H0.\n";
                        }
                }
                
            if (!IsNumeric(theForm.personalInformationApplicant1PresentEmployerEmploymentLengthYear.value.length, true))
                {
                    result = false;
                    msg += "Main Applicant 'Length of Employment Years' is required and must be a number.\n";
                }
                
            if (!IsNumeric(theForm.personalInformationApplicant1PresentEmployerEmploymentLengthMon.value.length, true))
                {
                    result = false;
                    msg += "Main Applicant 'Length of Employment months' is required and must be a number.\n";
                }
                
            if (!IsNumeric(theForm.personalInformationApplicant1PresentEmployerYearsInBusinessYears.value.length, false))
                {
                    result = false;
                    msg += "Main Applicant 'Years in Business Years' must be a number.\n";
                }
                
            if (!IsNumeric(theForm.personalInformationApplicant1PresentEmployerYearsInBusinessMon.value.length, false))
                {
                    result = false;
                    msg += "Main Applicant 'Years in Business Months' must be a number.\n";
                }
                
            if (!IsNumeric(theForm.personalInformationApplicant1PresentEmployerAnnualIncome.value.length, true))
                {
                    result = false;
                    msg += "Main Applicant 'Annual Income' is required and must be a number.\n";
                }
            
        
        
        /* End Main Applicant Present Employer*/
        
        
        
        
        /* Applicant 1 Previous Employer */
        
        if (theForm.personalInformationApplicant1PresentEmployerEmploymentLengthYear.value < 3 )
        {
        
            if (theForm.personalInformationApplicant1PrevEmployerName.value.length <= 0)
                {
                    result = false;
                    msg += "Main Applicant Previous Employer 'Name' is a required field.\n";
                }
        
            if (theForm.personalInformationApplicant1PrevEmployerOccupationType.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Main Applicant Previous Employer 'Occupation Type' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant1PrevEmployerIndustrySector.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Main Applicant Previous Employer 'Industry Sector' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant1PrevEmployerAddressProvince.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Main Applicant Previous Employer 'Employer Province' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant1PrevEmployerIncomeType.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Main Applicant Previous Employer 'Type of Income' is a required field.\n";
                }
                
                
            if (theForm.personalInformationApplicant1PrevEmployerAddressStreetAddress.value.length <= 0)
                {
                    result = false;
                    msg += "Main Applicant Previous Employer 'Employer Address' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant1PrevEmployerAddressCity.value.length <= 0)
                {
                    result = false;
                    msg += "Main Applicant Previous Employer 'Employer City' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant1PrevEmployerAddressPostalCode.value.length > 0)
                {
                    theForm.personalInformationApplicant1PrevEmployerAddressPostalCode.value = theForm.personalInformationApplicant1PrevEmployerAddressPostalCode.value.toUpperCase();
                    if (!postalCheck(theForm.personalInformationApplicant1PrevEmployerAddressPostalCode.value))
                        {
                            result = false;
                            msg += "Main Applicant Previous Employer 'Employer Postal Code' must be of the form T0H0H0.\n";
                        }
                }
                
            if (!IsNumeric(theForm.personalInformationApplicant1PrevEmployerEmploymentLengthYear.value.length, true))
                {
                    result = false;
                    msg += "Main Applicant Previous Employer 'Length of Employment Years' is required and must be a number.\n";
                }
                
            if (!IsNumeric(theForm.personalInformationApplicant1PrevEmployerEmploymentLengthMon.value.length, true))
                {
                    result = false;
                    msg += "Main Applicant Previous Employer 'Length of Employment months' is required and must be a number.\n";
                }
                
            if (!IsNumeric(theForm.personalInformationApplicant1PrevEmployerYearsInBusinessYears.value.length, false))
                {
                    result = false;
                    msg += "Main Applicant Previous Employer 'Years in Business Years' must be a number.\n";
                }
                
            if (!IsNumeric(theForm.personalInformationApplicant1PrevEmployerYearsInBusinessMon.value.length, false))
                {
                    result = false;
                    msg += "Main Applicant Previous Employer 'Years in Business Months' must be a number.\n";
                }
                
            if (!IsNumeric(theForm.personalInformationApplicant1PrevEmployerAnnualIncome.value.length, true))
                {
                    result = false;
                    msg += "Main Applicant Previous Employer 'Annual Income' is required and must be a number.\n";
                }
            
        }
        
        /* Applicant 1 Previous Employer End */
        
        
        
        if (theForm.personalInformationApplicant1OtherIncomeSource.value.length > 0)
                {
                    if (!IsNumeric(theForm.personalInformationApplicant1OtherIncomeAmount.value, true))
                        {
                            result = false;
                            msg += "Main Applicant 'Other Income Amount' is required and must be a number.\n";
                        }
                }
        
        
        
        /* End Main Applicant Personal Information */
        
        
       if (theForm.personalInformationApplicant2Title.selectedIndex > 0 || theForm.personalInformationApplicant2FirstName.value.length > 0 || theForm.personalInformationApplicant2LastName.value.length > 0)
       {
            /* Second Applicant Personal Information */
            if (theForm.personalInformationApplicant2Title.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Second Applicant 'Title' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant2FirstName.value.length <= 0)
                {
                    result = false;
                    msg += "Second Applicant 'First Name' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant2LastName.value.length <= 0)
                {
                    result = false;
                    msg += "Second Applicant 'Last Name' is a required field.\n";
                }
                
    
			
			if (!dateFormatCheck(theForm.personalInformationApplicant2DateOfBirth.value))
                {
                    //Date is not in the correct format.
                    result = false;
                    msg += "Second Applicant 'Date of Birth Required must be of the form MMDDYYYY\n";	
                }
		    else if (!checkdate(theForm.personalInformationApplicant2DateOfBirth.value))
                {
                    result = false;
                    msg += "Second Applicant 'Date of Birth' contains an invalid date.\n";	
                }	
			
			
			if (theForm.personalInformationApplicant2SIN.value.length > 0)
			{
				if (theForm.personalInformationApplicant2SIN.value.length != 9 || !IsNumeric(theForm.personalInformationApplicant2SIN.value, false))
				{
					result = false;
					msg += "Second Applicant 'SIN#' is not in the correct format.  Please enter your 9 digit Canadian SIN number\n";	
				}
			}
			
			   
            if (theForm.personalInformationApplicant2HomePhoneNo.value.length < 10 || !IsNumeric(theForm.personalInformationApplicant2HomePhoneNo.value, false))
                {
                    result = false;
                    msg += "Second Applicant 'Home Phone#' is a required field. Please enter your 10 digit Canadian phone number\n";
                }
                
           if (theForm.personalInformationApplicant2WorkPhoneNo.value.length > 0)
           {
               if (theForm.personalInformationApplicant2WorkPhoneNo.value.length < 10 || !IsNumeric(theForm.personalInformationApplicant2WorkPhoneNo.value, false))
                    {
                        result = false;
                        msg += "Second Applicant  'Work Phone#' is invalid. Please enter your 10 digit Canadian work phone number\n";
                    }
            }
            
            if (theForm.personalInformationApplicant2EmailAddress.value.length > 0)
            {
                if (!echeck(theForm.personalInformationApplicant2EmailAddress.value))
                    {
                        result = false;
                        msg += "Second Applicant  'Email Address' is invalid.\n";
                    }
                
            }
            
            
            /* Applicant 2 Personal Information End*/
            
            
            /* Applicant 2 Current Address */
           if (theForm.personalInformationApplicant2CurrentAddressStreetAddress.value.length <= 0)
                {
                    result = false;
                    msg += "Second Applicant 'Street Address' is a required field.\n";
                }

            if (theForm.personalInformationApplicant2CurrentAddressCity.value.length <= 0)
                {
                    result = false;
                    msg += "Second Applicant  'City/Town' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant2CurrentAddressProvince.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Second Applicant 'Province' is a required field.\n";
                }
            
           theForm.personalInformationApplicant2CurrentAddressPostalCode.value = theForm.personalInformationApplicant2CurrentAddressPostalCode.value.toUpperCase(); 
            
            if (!postalCheck(theForm.personalInformationApplicant2CurrentAddressPostalCode.value))
                {
                    result = false;
                      msg += "Second Applicant 'Postal Code' is a required field and must be of the form T0H0H0\n";
                }
                
              if (theForm.personalInformationApplicant2CurrentAddressResidentialStatus.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Second Applicant 'Residential Status' is a required field.\n";
                }
                
              if (theForm.personalInformationApplicant2CurrentAddressMonthlyRentPayments.value.length > 0)
              {
                if (!IsNumeric(theForm.personalInformationApplicant2CurrentAddressMonthlyRentPayments.value, false))
                    {
                        result = false;
                        msg += "Second Applicant 'Monthly Rent Payments' must be a numerical value.\n";
                    }
              }
              
            if (!IsNumeric(theForm.personalInformationApplicant2CurrentAddressTimeAtRes.value, true)) 
                {
                    result = false;
                    msg += "Second Applicant 'Time at Residence' is required and must be a numerical value.\n";
                }
            
            
            /* End Applicant 2 Current Address */
            
            
            /* Applicant 2 Previous Address */
            
            if (theForm.personalInformationApplicant2CurrentAddressTimeAtRes.value < 3)
          {
          
               if (theForm.personalInformationApplicant2PrevAddressStreetAddress.value.length <= 0)
                {
                    result = false;
                    msg += "Second Applicant Previous Address 'Street Address' is a required field.\n";
                }

            if (theForm.personalInformationApplicant2PrevAddressCity.value.length <= 0)
                {
                    result = false;
                    msg += "Second Applicant Previous Address 'City/Town' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant2PrevAddressProvince.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Second Applicant Previous Address 'Province' is a required field.\n";
                }
            
            
            theForm.personalInformationApplicant2PrevAddressPostalCode.value = theForm.personalInformationApplicant2PrevAddressPostalCode.value.toUpperCase();
            
            if (!postalCheck(theForm.personalInformationApplicant2PrevAddressPostalCode.value))
                {
                    result = false;
                      msg += "Second Applicant Previous Address 'Postal Code' is a required field and must be of the form T0H0H0\n";
                }
                
              if (theForm.personalInformationApplicant2PrevAddressResidentialStatus.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Second Applicant Previous Address 'Residential Status' is a required field.\n";
                }
                
              if (theForm.personalInformationApplicant2PrevAddressMonthlyRentPayments.value.length > 0)
              {
                if (!IsNumeric(theForm.personalInformationApplicant2PrevAddressMonthlyRentPayments.value, false))
                    {
                        result = false;
                        msg += "Second Applicant Previous Address 'Monthly Rent Payments' must be a numerical value.\n";
                    }
              }
              
              if (!IsNumeric(theForm.personalInformationApplicant2PrevAddressTimeAtRes.value, true)) 
                {
                    result = false;
                    msg += "Second Applicant Previous Address 'Time at Residence' is required and must be a numerical value.\n";
                }
            
            }
            
            /* End Applicant 2 Previous Address*/
            
            
            /* Applicant 2 Present Employer */
            
            if (theForm.personalInformationApplicant2PresentEmployerName.value.length <= 0)
                {
                    result = false;
                    msg += "Second Applicant 'Employer Name' is a required field.\n";
                }
                
                
            if (theForm.personalInformationApplicant2PresentEmployerOccupationType.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Second Applicant 'Occupation Type' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant2PresentEmployerIndustrySector.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Second Applicant 'Industry Sector' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant2PresentEmployerAddressProvince.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Second Applicant 'Employer Province' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant2PresentEmployerIncomeType.selectedIndex == 0) 
                {
                    result = false;
                    msg += "Second Applicant 'Type of Income' is a required field.\n";
                }
                
                
            if (theForm.personalInformationApplicant2PresentEmployerAddressStreetAddress.value.length <= 0)
                {
                    result = false;
                    msg += "Second Applicant 'Employer Address' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant2PresentEmployerAddressCity.value.length <= 0)
                {
                    result = false;
                    msg += "Second Applicant 'Employer City' is a required field.\n";
                }
                
            if (theForm.personalInformationApplicant2PresentEmployerAddressPostalCode.value.length > 0)
                {
                    theForm.personalInformationApplicant2PresentEmployerAddressPostalCode.value = theForm.personalInformationApplicant2PresentEmployerAddressPostalCode.value.toUpperCase();
                    if (!postalCheck(theForm.personalInformationApplicant2PresentEmployerAddressPostalCode.value))
                        {
                            result = false;
                            msg += "Second Applicant 'Employer Postal Code' must be of the form T0H0H0.\n";
                        }
                }
                
            if (!IsNumeric(theForm.personalInformationApplicant2PresentEmployerEmploymentLengthYear.value.length, true))
                {
                    result = false;
                    msg += "Second Applicant 'Length of Employment Years' is required and must be a number.\n";
                }
                
            if (!IsNumeric(theForm.personalInformationApplicant2PresentEmployerEmploymentLengthMon.value.length, true))
                {
                    result = false;
                    msg += "Second Applicant 'Length of Employment months' is required and must be a number.\n";
                }
                
            if (!IsNumeric(theForm.personalInformationApplicant2PresentEmployerYearsInBusinessYears.value.length, false))
                {
                    result = false;
                    msg += "Second Applicant 'Years in Business Years' must be a number.\n";
                }
                
            if (!IsNumeric(theForm.personalInformationApplicant2PresentEmployerYearsInBusinessMon.value.length, false))
                {
                    result = false;
                    msg += "Second Applicant 'Years in Business Months' must be a number.\n";
                }
                
            if (!IsNumeric(theForm.personalInformationApplicant2PresentEmployerAnnualIncome.value.length, true))
                {
                    result = false;
                    msg += "Second Applicant 'Annual Income' is required and must be a number.\n";
                }
            
            /* Applicant 2 Applicant Present Employer */


           /* Applicant 2 Previous Employer */
           
           if (theForm.personalInformationApplicant2PresentEmployerEmploymentLengthYear.value < 3 )
                {
                
                    if (theForm.personalInformationApplicant2PrevEmployerName.value.length <= 0)
                        {
                            result = false;
                            msg += "Second Applicant Previous Employer 'Name' is a required field.\n";
                        }
                
                    if (theForm.personalInformationApplicant2PrevEmployerOccupationType.selectedIndex == 0) 
                        {
                            result = false;
                            msg += "Second Applicant Previous Employer 'Occupation Type' is a required field.\n";
                        }
                        
                    if (theForm.personalInformationApplicant2PrevEmployerIndustrySector.selectedIndex == 0) 
                        {
                            result = false;
                            msg += "Second Applicant Previous Employer 'Industry Sector' is a required field.\n";
                        }
                        
                    if (theForm.personalInformationApplicant2PrevEmployerAddressProvince.selectedIndex == 0) 
                        {
                            result = false;
                            msg += "Second Applicant Previous Employer 'Employer Province' is a required field.\n";
                        }
                        
                    if (theForm.personalInformationApplicant2PrevEmployerIncomeType.selectedIndex == 0) 
                        {
                            result = false;
                            msg += "Second Applicant Previous Employer 'Type of Income' is a required field.\n";
                        }
                        
                        
                    if (theForm.personalInformationApplicant2PrevEmployerAddressStreetAddress.value.length <= 0)
                        {
                            result = false;
                            msg += "Second Applicant Previous Employer 'Employer Address' is a required field.\n";
                        }
                        
                    if (theForm.personalInformationApplicant2PrevEmployerAddressCity.value.length <= 0)
                        {
                            result = false;
                            msg += "Second Applicant Previous Employer 'Employer City' is a required field.\n";
                        }
                        
                    if (theForm.personalInformationApplicant2PrevEmployerAddressPostalCode.value.length > 0)
                        {
                            theForm.personalInformationApplicant2PrevEmployerAddressPostalCode.value = theForm.personalInformationApplicant2PrevEmployerAddressPostalCode.value.toUpperCase();
                            if (!postalCheck(theForm.personalInformationApplicant2PrevEmployerAddressPostalCode.value))
                                {
                                    result = false;
                                    msg += "Second Applicant Previous Employer 'Employer Postal Code' must be of the form T0H0H0.\n";
                                }
                        }
                        
                    if (!IsNumeric(theForm.personalInformationApplicant2PrevEmployerEmploymentLengthYear.value.length, true))
                        {
                            result = false;
                            msg += "Second Applicant Previous Employer 'Length of Employment Years' is required and must be a number.\n";
                        }
                        
                    if (!IsNumeric(theForm.personalInformationApplicant2PrevEmployerEmploymentLengthMon.value.length, true))
                        {
                            result = false;
                            msg += "Second Applicant Previous Employer 'Length of Employment months' is required and must be a number.\n";
                        }
                        
                    if (!IsNumeric(theForm.personalInformationApplicant2PrevEmployerYearsInBusinessYears.value.length, false))
                        {
                            result = false;
                            msg += "Second Applicant Previous Employer 'Years in Business Years' must be a number.\n";
                        }
                        
                    if (!IsNumeric(theForm.personalInformationApplicant2PrevEmployerYearsInBusinessMon.value.length, false))
                        {
                            result = false;
                            msg += "Second Applicant Previous Employer 'Years in Business Months' must be a number.\n";
                        }
                        
                    if (!IsNumeric(theForm.personalInformationApplicant2PrevEmployerAnnualIncome.value.length, true))
                        {
                            result = false;
                            msg += "Second Applicant Previous Employer 'Annual Income' is required and must be a number.\n";
                        }
                    
                }
           
           /* End Applicant 2 Previous Employer */


                
            if (theForm.personalInformationApplicant2OtherIncomeSource.value.length > 0)
                {
                    if (!IsNumeric(theForm.personalInformationApplicant2OtherIncomeAmount.value, true))
                        {
                            result = false;
                            msg += "Second Applicant 'Other Income Amount' is required and must be a number.\n";
                        }
                }
                
            
            
        }
        
            /* Validate Financial Assets*/
           if (theForm.financialInfoAssetsCashAmount.value.length > 0 && parseFloat(theForm.financialInfoAssetsCashAmount.value) > 0){
           
             if (theForm.financialInfoAssetsCashWhere.value.length <= 0)
                 {
                    result = false;
                    msg += "Financial Assets, Please specify name of the bank that your cash is located.\n";
                 }
           
             if (!IsNumeric(theForm.financialInfoAssetsCashAmount.value, false))
                {
                    result = false;
                    msg += "Financial Assets 'Cash in the Bank' must be a number.\n";
                }
                            
            } else {
                theForm.financialInfoAssetsCashAmount.value = 0;
            }
            
            
            
            
            
            
            if (theForm.financialInfoAssetsPropertyDepositAmount.value.length > 0 && parseFloat(theForm.financialInfoAssetsPropertyDepositAmount.value) > 0){
           
           
             if (!IsNumeric(theForm.financialInfoAssetsPropertyDepositAmount.value, false))
                {
                    result = false;
                    msg += "Financial Assets 'Deposit on property being purchased' must be a number.\n";
                }
                            
            } else {
                theForm.financialInfoAssetsPropertyDepositAmount.value = 0;
            }
            
            
            
            
            
            
            if (theForm.financialInfoAssetsAutomobileValue.value.length > 0 && parseFloat(theForm.financialInfoAssetsAutomobileValue.value) > 0){
           
           
             if (!IsNumeric(theForm.financialInfoAssetsAutomobileValue.value, false))
                {
                    result = false;
                    msg += "Financial Assets 'Present Value of Automobile' must be a number.\n";
                }
                            
            } else {
                theForm.financialInfoAssetsAutomobileValue.value = 0;
            }
            
            
            
            
            
            
            if (theForm.financialInfoAssetsHomeValue.value.length > 0 && parseFloat(theForm.financialInfoAssetsHomeValue.value) > 0){
           
           
             if (!IsNumeric(theForm.financialInfoAssetsHomeValue.value, false))
                {
                    result = false;
                    msg += "Financial Assets 'Value of Present Home' must be a number.\n";
                }
                            
            } else {
                theForm.financialInfoAssetsHomeValue.value = 0;
            }
            
            
            
            
            
            
            if (theForm.financialInfoAssetsInvestmentPropertiesValue.value.length > 0 && parseFloat(theForm.financialInfoAssetsInvestmentPropertiesValue.value) > 0){
           
           
             if (!IsNumeric(theForm.financialInfoAssetsInvestmentPropertiesValue.value, false))
                {
                    result = false;
                    msg += "Financial Assets 'Investment Properties' must be a number.\n";
                }
                            
            } else {
                theForm.financialInfoAssetsInvestmentPropertiesValue.value = 0;
            }
            
            
            
            
            
            
            if (theForm.financialInfoAssetsStocksEtcAmount.value.length > 0 && parseFloat(theForm.financialInfoAssetsStocksEtcAmount.value) > 0){
           
           
             if (!IsNumeric(theForm.financialInfoAssetsStocksEtcAmount.value, false))
                {
                    result = false;
                    msg += "Financial Assets 'Stocks, Bonds, mutual funds ets' must be a number.\n";
                }
                            
            } else {
                theForm.financialInfoAssetsStocksEtcAmount.value = 0;
            }
            
            
            
            
            
            
            if (theForm.financialInfoAssetsRRSPAmount.value.length > 0 && parseFloat(theForm.financialInfoAssetsRRSPAmount.value) > 0){
           
           
             if (!IsNumeric(theForm.financialInfoAssetsRRSPAmount.value, false))
                {
                    result = false;
                    msg += "Financial Assets 'RRSPs' must be a number.\n";
                }
                            
            } else {
                theForm.financialInfoAssetsRRSPAmount.value = 0;
            }
            
            
            
            
            
            
            if (theForm.financialInfoAssetsOtherAmount.value.length > 0 && parseFloat(theForm.financialInfoAssetsOtherAmount.value) > 0){
           
           
             if (!IsNumeric(theForm.financialInfoAssetsOtherAmount.value, false))
                {
                    result = false;
                    msg += "Financial Assets 'Other Assets' must be a number.\n";
                }
                            
            } else {
                theForm.financialInfoAssetsOtherAmount.value = 0;
            }
            
            
            
            if (theForm.totalAssets.value.length <= 0)
                {
                    theForm.totalAssets.value = 0;
                }
            
                       
            /* End Validate Financial Assets */
            
            
            
            
            
            /* Validate Liabilities */
            
            //Bank Loans
            if (theForm.financialInfoLiabilitiesBankLoansOwing.value.length > 0 && parseFloat(theForm.financialInfoLiabilitiesBankLoansOwing.value) > 0)
                {
                    //The Where Field must be Populated
                    if (theForm.financialInfoLiabilitiesBankLoansWhere.value.length <= 0)
                        {
                            result = false;
                            msg += "Financial Liabilities Bank Loans 'Which Bank' is required.\n";
                        }
                    
                    if (!IsNumeric(theForm.financialInfoLiabilitiesBankLoansOwing.value, false))
                        {
                            result = false;
                            msg += "Financial Liabilities Bank Loans 'Total Owing' must be a number.\n";
                        }
                }
            else
                {
                    theForm.financialInfoLiabilitiesBankLoansOwing.value = 0;
                }
                
                
                
                
            if (theForm.financialInfoLiabilitiesBankLoansMonthly.value.length > 0 && parseFloat(theForm.financialInfoLiabilitiesBankLoansMonthly.value) > 0)
                {
                    //The Where Field must be Populated
                    if (theForm.financialInfoLiabilitiesBankLoansWhere.value.length <= 0)
                    {
                        result = false;
                        msg += "Financial Liabilities Bank Loans 'Which Bank' is required.\n";
                    }
                    
                    if (!IsNumeric(theForm.financialInfoLiabilitiesBankLoansMonthly.value, false))
                        {
                            result = false;
                            msg += "Financial Liabilities Bank Loans 'Monthly Payment' must be a number.\n";
                        }
                }
            else
                {
                    theForm.financialInfoLiabilitiesBankLoansMonthly.value = 0;
                }
                
            //Credit Cards
            if (theForm.financialInfoLiabilitiesCreditCardOwing.value.length > 0 && parseFloat(theForm.financialInfoLiabilitiesCreditCardOwing.value) > 0)
                {
                    //The Where Field must be Populated
                    if (theForm.financialInfoLiabilitiesCreditCardNames.value.length <= 0)
                        {
                            result = false;
                            msg += "Financial Liabilities Credit Cards 'Which Card(s)' is required.\n";
                        }
                    
                    if (!IsNumeric(theForm.financialInfoLiabilitiesCreditCardOwing.value, false))
                        {
                            result = false;
                            msg += "Financial Liabilities Credit Cards 'Total Owing' must be a number.\n";
                        }
                }
            else
                {
                    theForm.financialInfoLiabilitiesCreditCardOwing.value = 0;
                }
                
                
                
                
            if (theForm.financialInfoLiabilitiesCreditCardMonthly.value.length > 0 && parseFloat(theForm.financialInfoLiabilitiesCreditCardMonthly.value) > 0)
                {
                    //The Where Field must be Populated
                    if (theForm.financialInfoLiabilitiesCreditCardNames.value.length <= 0)
                    {
                        result = false;
                        msg += "Financial Liabilities Credit Cards 'Which Cards' is required.\n";
                    }
                    
                    if (!IsNumeric(theForm.financialInfoLiabilitiesCreditCardMonthly.value, false))
                        {
                            result = false;
                            msg += "Financial Liabilities Credit Cards 'Monthly Payment' must be a number.\n";
                        }
                }
            else
                {
                    theForm.financialInfoLiabilitiesCreditCardMonthly.value = 0;
                }
                
            
            //Automobile
            if (theForm.financialInfoLiabilitiesVehicleOwing.value.length > 0 && parseFloat(theForm.financialInfoLiabilitiesVehicleOwing.value) > 0)
                {
                    //The Where Field must be Populated
                    if (theForm.financialInfoLiabilitiesVehicleWhere.value.length <= 0)
                        {
                            result = false;
                            msg += "Financial Liabilities Automobile 'Which Lender' is required.\n";
                        }
                    
                    if (!IsNumeric(theForm.financialInfoLiabilitiesVehicleOwing.value, false))
                        {
                            result = false;
                            msg += "Financial Liabilities Vehicle 'Total Owing' must be a number.\n";
                        }
                }
            else
                {
                    theForm.financialInfoLiabilitiesVehicleOwing.value = 0;
                }
                
                
                
                
            if (theForm.financialInfoLiabilitiesVehicleMonthly.value.length > 0 && parseFloat(theForm.financialInfoLiabilitiesVehicleMonthly.value) > 0)
                {
                    //The Where Field must be Populated
                    if (theForm.financialInfoLiabilitiesVehicleWhere.value.length <= 0)
                    {
                        result = false;
                        msg += "Financial Liabilities Automobile 'Which Lender' is required.\n";
                    }
                    
                    if (!IsNumeric(theForm.financialInfoLiabilitiesVehicleMonthly.value, false))
                        {
                            result = false;
                            msg += "Financial Liabilities Automobile 'Monthly Payment' must be a number.\n";
                        }
                }
            else
                {
                    theForm.financialInfoLiabilitiesVehicleOwing.value = 0;
                }
            
            
            
            //First Mortgage
            if (theForm.financialInfoLiabilitiesFirstMortgageOwing.value.length > 0 && parseFloat(theForm.financialInfoLiabilitiesFirstMortgageOwing.value) > 0)
                {
                    //The Where Field must be Populated
                    if (theForm.financialInfoLiabilitiesFirstMortgageWhere.value.length <= 0)
                        {
                            result = false;
                            msg += "Financial Liabilities First Mortgage 'Which Lender' is required.\n";
                        }
                        
                    if (theForm.financialInfoLiabilitiesFirstMortgageNumber.value.length <= 0)
                        {
                            result = false;
                            msg += "Financial Liabilities First Mortgage 'Mortgage Number' is required.\n";
                        }
                    
                    if (!IsNumeric(theForm.financialInfoLiabilitiesFirstMortgageOwing.value, false))
                        {
                            result = false;
                            msg += "Financial Liabilities First Mortgage 'Total Owing' must be a number.\n";
                        }
                }
            else
                {
                    theForm.financialInfoLiabilitiesFirstMortgageOwing.value = 0;
                }
                
                
                
                
            if (theForm.financialInfoLiabilitiesFirstMortgageMonthly.value.length > 0 && parseFloat(theForm.financialInfoLiabilitiesFirstMortgageMonthly.value) > 0)
                {
                    //The Where Field must be Populated
                    if (theForm.financialInfoLiabilitiesFirstMortgageWhere.value.length <= 0)
                        {
                            result = false;
                            msg += "Financial Liabilities First Mortgage 'Which Lender' is required.\n";
                        }
                        
                    if (theForm.financialInfoLiabilitiesFirstMortgageNumber.value.length <= 0)
                        {
                            result = false;
                            msg += "Financial Liabilities First Mortgage 'Mortgage Number' is required.\n";
                        }
                    
                    if (!IsNumeric(theForm.financialInfoLiabilitiesFirstMortgageMonthly.value, false))
                        {
                            result = false;
                            msg += "Financial Liabilities First Mortgage 'Monthly Payment' must be a number.\n";
                        }
                }
            else
                {
                    theForm.financialInfoLiabilitiesFirstMortgageMonthly.value = 0;
                }
                
                
            
            
            //Second Mortgage
            if (theForm.financialInfoLiabilitiesSecondMortgageOwing.value.length > 0 && parseFloat(theForm.financialInfoLiabilitiesSecondMortgageOwing.value) > 0)
                {
                    //The Where Field must be Populated
                    if (theForm.financialInfoLiabilitiesSecondMortgageWhere.value.length <= 0)
                        {
                            result = false;
                            msg += "Financial Liabilities Second Mortgage 'Which Lender' is required.\n";
                        }
                        
                    if (theForm.financialInfoLiabilitiesSecondMortgageNumber.value.length <= 0)
                        {
                            result = false;
                            msg += "Financial Liabilities Second Mortgage 'Mortgage Number' is required.\n";
                        }
                    
                    if (!IsNumeric(theForm.financialInfoLiabilitiesSecondMortgageOwing.value, false))
                        {
                            result = false;
                            msg += "Financial Liabilities Second Mortgage 'Total Owing' must be a number.\n";
                        }
                }
            else
                {
                    theForm.financialInfoLiabilitiesSecondMortgageOwing.value = 0;
                }
                
                
                
                
            if (theForm.financialInfoLiabilitiesSecondMortgageMonthly.value.length > 0 && parseFloat(theForm.financialInfoLiabilitiesSecondMortgageMonthly.value) > 0)
                {
                    //The Where Field must be Populated
                    if (theForm.financialInfoLiabilitiesSecondMortgageWhere.value.length <= 0)
                        {
                            result = false;
                            msg += "Financial Liabilities Second Mortgage 'Which Lender' is required.\n";
                        }
                        
                    if (theForm.financialInfoLiabilitiesSecondMortgageNumber.value.length <= 0)
                        {
                            result = false;
                            msg += "Financial Liabilities Second Mortgage 'Mortgage Number' is required.\n";
                        }
                    
                    if (!IsNumeric(theForm.financialInfoLiabilitiesSecondMortgageMonthly.value, false))
                        {
                            result = false;
                            msg += "Financial Liabilities Second Mortgage 'Monthly Payment' must be a number.\n";
                        }
                }
            else
                {
                    theForm.financialInfoLiabilitiesSecondMortgageMonthly.value = 0;
                }
                
                
                
            
            //Other Debts
            if (theForm.financialInfoLiabilitiesFinanceCompanyLoansOwing.value.length > 0 && parseFloat(theForm.financialInfoLiabilitiesFinanceCompanyLoansOwing.value) > 0)
                {
                    //The Where Field must be Populated
                    if (theForm.financialInfoLiabilitiesFinanceCompanyLoansWhere.value.length <= 0)
                        {
                            result = false;
                            msg += "Financial Liabilities Other Debts 'With Who' is required.\n";
                        }
                    
                    if (!IsNumeric(theForm.financialInfoLiabilitiesFinanceCompanyLoansOwing.value, false))
                        {
                            result = false;
                            msg += "Financial Liabilities Other Debts 'Total Owing' must be a number.\n";
                        }
                }
            else
                {
                    theForm.financialInfoLiabilitiesFinanceCompanyLoansOwing.value = 0;
                }
                
                
                
                
            if (theForm.financialInfoLiabilitiesFinanceCompanyLoansMonthly.value.length > 0 && parseFloat(theForm.financialInfoLiabilitiesFinanceCompanyLoansMonthly.value))
                {
                    //The Where Field must be Populated
                    if (theForm.financialInfoLiabilitiesFinanceCompanyLoansWhere.value.length <= 0)
                        {
                            result = false;
                            msg += "Financial Liabilities Other Debts 'With Who' is required.\n";
                        }
                    
                    if (!IsNumeric(theForm.financialInfoLiabilitiesFinanceCompanyLoansMonthly.value, false))
                        {
                            result = false;
                            msg += "Financial Liabilities Other Debts 'Monthly Payment' must be a number.\n";
                        }
                }
            else
                {
                    theForm.financialInfoLiabilitiesFinanceCompanyLoansMonthly.value = 0;
                }
                
                
                
            //Alimony and Child Support
            if (theForm.financialInfoLiabilitiesAlimonyChildSupportMonthly.value.length > 0 && parseFloat(theForm.financialInfoLiabilitiesAlimonyChildSupportMonthly.value) > 0)
                {
                    
                    if (!IsNumeric(theForm.financialInfoLiabilitiesAlimonyChildSupportMonthly.value, false))
                        {
                            result = false;
                            msg += "Financial Liabilities Alimony Child Support 'Monthly Payment' must be a number.\n";
                        }
                }
            else
                {
                    theForm.financialInfoLiabilitiesAlimonyChildSupportMonthly.value = 0;
                }
            
            /* End Validate Liabilities*/
        
        
        if (theForm.noteToBroker.value.length > 200) 
            {
                result = false;
                msg += "Notes for the broker may only be 200 Chars Max.  Your Notes are " + theForm.noteToBroker.value.length + "chars.\n";
            }
            
        //Where did you hear about us does not need any special validation.
       
        
		/* End Validation*/
		
		if (result) {result = confirm("Your application is about to be submitted, if your sure everything is in order press OK to continue."); }
		else {alert("We found a few errors in your application.  Please make the necessary changes and try sending again.\n\n" + msg);}
		
		if (result) { 
		
			/* The form is about to be submitted.  Before we finish the submit, convert the dates into a mysql friendly format.*/
			setSubmit(theForm); 
			
		}
		
		return result;
        
	}
	
	function convertDate(value)
	{
		/* Converts Dates of the Format mmddyyyy to YYYY-MM-DD */
		var month = value.substr(0,2);
		var day   = value.substr(2,2);
		var year  = value.substr(4);
		
		return year + "-" + month + "-" + day;
	}
	
	
	function setSubmit(theForm)
	{
		theForm.action.value="processApplication";
	}
	
	function changeInputs() 
	{
	  var els = document.getElementsByTagName('input');
	  for (var i=0; i <  els.length ;i++ )
		  {
			els[i].readOnly = true;
		   } 
		   
	  var els = document.getElementsByTagName('select');
	  for (var i=0; i <  els.length ;i++ )
		  {
			els[i].disabled = true;
		   } 
	} 