function verify_submit(){
	var isErrorFound = false;
	var isIncomeError = false;
	var isCoIncomeError = false;
	var isCoApplicantVisible = false;
	var isTxMunError = false;
	var isChfError = false;
	var isComparaisonOptionActivated = false;
	var isErrorMunicipalFees = false;
	var isErrorHeating = false;
	var isErrorResTypOpt=false;
	
	if (document.getElementById('coAppCheckbox').checked == true){
		isCoApplicantVisible =true;
	}
	 
	//> DEMANDEUR 
	//Validation Revenu demandeur
	if (!isValidMandatoryField('income', document.borrowCapacity.income,'incomeErrorMsg', false)){
		document.getElementById('mandatoryIncomeField').className='textErrorRed';
		isErrorFound=true;
		isIncomeError =true;
	}

	if (!isIncomeError){
		document.getElementById('mandatoryIncomeField').className='text';
	}
	
	if (!isIncomeError && !isValidInput('income', document.borrowCapacity.income,'incomeErrorMsg', false)){		
		isErrorFound=true;
	}	
			

	//Validation de l'engagement financier	du demandeur
	if (!isValidInput('carLoan', document.borrowCapacity.carLoan,'carLoanErrorMsg', false)){
		isErrorFound=true;
	}

	if (!isValidInput('personalLoan', document.borrowCapacity.personalLoan,'personalLoanErrorMsg', false)){
		isErrorFound=true;
	}

	if (!isValidInput('pension', document.borrowCapacity.pension,'pensionErrorMsg', false)){
		isErrorFound=true;
	}		

	if (!isValidInput('creditCard', document.borrowCapacity.creditCard,'creditCardErrorMsg', false)){
		isErrorFound=true;
	}
	
	if (!isValidInput('lineOfCredit', document.borrowCapacity.lineOfCredit,'lineOfCreditErrorMsg', false)){
		isErrorFound=true;
	}
	
	if (!isValidInput('lineOfCreditMortageGuarantee', document.borrowCapacity.lineOfCreditMortageGuarantee,'lineOfCreditMortageGuaranteeErrorMsg', false)){
		isErrorFound=true;
	}
	
	if (!isErrorFound){
		document.borrowCapacity.income.value=formatFormValues(document.borrowCapacity.income);
		document.borrowCapacity.carLoan.value=formatFormValues(document.borrowCapacity.carLoan);
		document.borrowCapacity.personalLoan.value=formatFormValues(document.borrowCapacity.personalLoan);
		document.borrowCapacity.pension.value=formatFormValues(document.borrowCapacity.pension);
		document.borrowCapacity.creditCard.value=formatFormValues(document.borrowCapacity.creditCard);
		document.borrowCapacity.lineOfCredit.value=formatFormValues(document.borrowCapacity.lineOfCredit);
		document.borrowCapacity.lineOfCreditMortageGuarantee.value=formatFormValues(document.borrowCapacity.lineOfCreditMortageGuarantee);
	}
	
	//CO-DEMANDEUR
	if (isCoApplicantVisible){
		//Validation Revenu du co-demandeur
		if (!isValidInput('coField3', document.borrowCapacity.coIncome,'coField3ErrorMsg', false)){		
			isErrorFound=true;
		}
		
		/*
		if (!isValidMandatoryField('coField5', document.borrowCapacity.coIncomeFrequencyListChoice,'coIncomeFrequencyListChoiceErrorMsg', false)){
			isErrorFound=true;
		}	*/	
		
		////Validation de l'engagement financier du co-demandeur
		if (!isValidInput('coField9', document.borrowCapacity.coCarLoan,'coCarLoanErrorMsg', false)){
			isErrorFound=true;
		}
		
		if (!isValidInput('coField12', document.borrowCapacity.coPersonalLoan,'coPersonalLoanErrorMsg', false)){
			isErrorFound=true;
		}
		
		if (!isValidInput('coField15', document.borrowCapacity.coPension,'coPensionErrorMsg', false)){
			isErrorFound=true;
		}		
			
		if (!isValidInput('coField18', document.borrowCapacity.coCreditCard,'coCreditCardErrorMsg', false)){
			isErrorFound=true;
		}
		
		if (!isValidInput('coField21', document.borrowCapacity.coLineOfCredit,'coLineOfCreditErrorMsg', false)){
			isErrorFound=true;
		}

		if (!isValidInput('coField24', document.borrowCapacity.coLineOfCreditMortageGuarantee,'coLineOfCreditMortageGuaranteeErrorMsg', false)){
			isErrorFound=true;
		}
		
		if(!isErrorFound){
			document.borrowCapacity.coIncome.value=formatFormValues(document.borrowCapacity.coIncome);
			document.borrowCapacity.coCarLoan.value=formatFormValues(document.borrowCapacity.coCarLoan);
			document.borrowCapacity.coPersonalLoan.value=formatFormValues(document.borrowCapacity.coPersonalLoan);
			document.borrowCapacity.coPension.value=formatFormValues(document.borrowCapacity.coPension);
			document.borrowCapacity.coCreditCard.value=formatFormValues(document.borrowCapacity.coCreditCard);
			document.borrowCapacity.coLineOfCredit.value=formatFormValues(document.borrowCapacity.coLineOfCredit);
			document.borrowCapacity.coLineOfCreditMortageGuarantee.value=formatFormValues(document.borrowCapacity.coLineOfCreditMortageGuarantee);
		}
		
	}else{
		document.borrowCapacity.coIncome.value="";
		document.borrowCapacity.coCarLoan.value="";
		document.borrowCapacity.coPersonalLoan.value="";
		document.borrowCapacity.coPension.value="";
		document.borrowCapacity.coCreditCard.value="";
		document.borrowCapacity.coLineOfCredit.value="";
		document.borrowCapacity.coLineOfCreditMortageGuarantee.value="";
	}
	
	//type de proprietes
	if (!isValidMandatoryField('municipalTax', document.borrowCapacity.municipalTax,'municipalTaxErrorMsg', false)){
		document.getElementById('municipalTaxMandatoryField').className='textErrorRed';
		isErrorFound=true;
		isTxMunError =true;
	}
	
	if (!isTxMunError){
		document.getElementById('municipalTaxMandatoryField').className='text';
	}
	
	if (!isTxMunError && !isValidInput('municipalTax', document.borrowCapacity.municipalTax,'municipalTaxErrorMsg', false)){	
		isTxMunError =true;	
		isErrorFound=true;
	}
	
	if (!isTxMunError){
		document.borrowCapacity.municipalTax.value=removeSeparator(document.borrowCapacity.municipalTax);
	}

	if (!isValidInput('schoolTax', document.borrowCapacity.schoolTax,'schoolTaxErrorMsg', false)){
		isErrorFound=true;
	}else{
		document.borrowCapacity.schoolTax.value=removeSeparator(document.borrowCapacity.schoolTax);
	}
	
	if (!isValidMandatoryField('heatingCosts', document.borrowCapacity.heatingCosts,'heatingCostsErrorMsg', false)){		
		document.getElementById('heatingCostsMandatoryField').className='textErrorRed';
		isErrorFound=true;
		isChfError =true;
	}
	
	if (!isChfError){
		document.getElementById('heatingCostsMandatoryField').className='text';
	}
	
	if (!isChfError && !isValidInput('heatingCosts', document.borrowCapacity.heatingCosts,'heatingCostsErrorMsg', false)){
		isChfError =true;		
		isErrorFound=true;
	}
	
	if (!isChfError){
		document.borrowCapacity.heatingCosts.value=removeSeparator(document.borrowCapacity.heatingCosts);
	}
	
	if (document.getElementById('compareCheckbox').checked == true){
		isComparaisonOptionActivated=true;
		document.borrowCapacity.bCompare.value="1";
	}else{
		document.borrowCapacity.bCompare.value="0";
	}
	
	if (document.borrowCapacity.resTyp.selectedIndex==1){
		if (!isValidInput('condoFeeField3', document.borrowCapacity.condoFees,'condoFeeField3ErrorMsg', false)){
			isErrorFound=true;
		}
		else{
			document.borrowCapacity.condoFees.value=removeSeparator(document.borrowCapacity.condoFees);
		}
	}else{
		document.borrowCapacity.condoFees.value="";
	}
	
	if (document.borrowCapacity.resTyp.selectedIndex==2 ||document.borrowCapacity.resTyp.selectedIndex==3){
		if (!isValidInput('rentField3', document.borrowCapacity.rentIncome,'rentField3ErrorMsg', false)){
			isErrorFound=true;
		}
	}else{
		document.borrowCapacity.rentIncome.value="";
	}
	
	if(!isErrorFound){
		document.borrowCapacity.municipalTax.value=formatFormValues(document.borrowCapacity.municipalTax);
		document.borrowCapacity.schoolTax.value=formatFormValues(document.borrowCapacity.schoolTax);
		document.borrowCapacity.heatingCosts.value=formatFormValues(document.borrowCapacity.heatingCosts);
		document.borrowCapacity.condoFees.value=formatFormValues(document.borrowCapacity.condoFees);
		document.borrowCapacity.rentIncome.value=formatFormValues(document.borrowCapacity.rentIncome);
	}
	//Validation des options de comparaison
	if (isComparaisonOptionActivated){
		if (!isValidMandatoryField('resOptTyp', document.borrowCapacity.resTypOpt,'resTypOptErrorMsg', false)){
			document.getElementById('resTypMandatoryOpt').className='textErrorRed';
			isErrorFound=true;
			isErrorResTypOpt=true;
		}
		
		if (!isErrorResTypOpt){
			document.getElementById('resTypMandatoryOpt').className='text';
		}

		if (!isValidMandatoryField('fieldOpt3', document.borrowCapacity.municipalTaxOpt,'fieldOpt3ErrorMsg', false)){
			document.getElementById('txMuniMandatoryFieldOpt').className='textErrorRed';
			isErrorFound=true;
			isErrorMunicipalFees=true;
		}
		
		if (!isErrorMunicipalFees){
			document.getElementById('txMuniMandatoryFieldOpt').className='text';
		}
				
		if (!isErrorMunicipalFees && !isValidInput('fieldOpt3', document.borrowCapacity.municipalTaxOpt,'fieldOpt3ErrorMsg', false)){		
			isErrorFound=true;
			isErrorMunicipalFees=true;
		}
		
		if (!isErrorMunicipalFees){
			document.borrowCapacity.municipalTaxOpt.value=removeSeparator(document.borrowCapacity.municipalTaxOpt);
		}
		
		if (!isValidInput('fieldOpt6', document.borrowCapacity.schoolTaxOpt,'fieldOpt6ErrorMsg', false)){
			isErrorFound=true;
		}else{
			document.borrowCapacity.schoolTaxOpt.value=removeSeparator(document.borrowCapacity.schoolTaxOpt);
		}
		
		if (!isValidMandatoryField('fieldOpt9', document.borrowCapacity.heatingCostsOpt,'fieldOpt9ErrorMsg', false)){
			document.getElementById('chfMandatoryFieldOpt').className='textErrorRed';		
			isErrorFound=true;
			isErrorHeating=true;
		}
		
		if (!isErrorHeating){
			document.getElementById('chfMandatoryFieldOpt').className='text';
		}
		
		if (!isErrorHeating && !isValidInput('fieldOpt9', document.borrowCapacity.heatingCostsOpt,'fieldOpt9ErrorMsg', false)){		
			isErrorFound=true;
		}
		
		if(!isErrorHeating){
			document.borrowCapacity.heatingCostsOpt.value=removeSeparator(document.borrowCapacity.heatingCostsOpt);
		}
		
		if (document.borrowCapacity.resTypOpt.selectedIndex==2){
			if (!isValidInput('condoFeeFieldOpt3', document.borrowCapacity.condoFeesOpt,'condoFeeFieldOpt3ErrorMsg', false)){
				isErrorFound=true;
			}else{
				document.borrowCapacity.condoFeesOpt.value=removeSeparator(document.borrowCapacity.condoFeesOpt);
			}
		}else{
			document.borrowCapacity.condoFeesOpt.value="";
		} 
		
		if (document.borrowCapacity.resTypOpt.selectedIndex==3||document.borrowCapacity.resTypOpt.selectedIndex==4){
			if (!isValidInput('rentFieldOpt3', document.borrowCapacity.rentIncomeOpt,'rentFieldOpt3ErrorMsg',false)){
				isErrorFound=true;
			}
		}else{
			document.borrowCapacity.rentIncomeOpt.value="";
		}
		
		if (!isErrorFound){
			document.borrowCapacity.municipalTaxOpt.value=formatFormValues(document.borrowCapacity.municipalTaxOpt);
			document.borrowCapacity.schoolTaxOpt.value=formatFormValues(document.borrowCapacity.schoolTaxOpt);
			document.borrowCapacity.heatingCostsOpt.value=formatFormValues(document.borrowCapacity.heatingCostsOpt);
			document.borrowCapacity.condoFeesOpt.value=formatFormValues(document.borrowCapacity.condoFeesOpt);
			document.borrowCapacity.rentIncomeOpt.value=formatFormValues(document.borrowCapacity.rentIncomeOpt);
		}		
	}else{
		document.borrowCapacity.municipalTaxOpt.value="";
		document.borrowCapacity.schoolTaxOpt.value="";
		document.borrowCapacity.heatingCostsOpt.value="";
		document.borrowCapacity.condoFeesOpt.value="";
		document.borrowCapacity.rentIncomeOpt.value="";
	}
	
	//Remplir les champs hidden avant d'envoyer au bean
	if (!isErrorFound){
		//>Revenus du demandeur
			document.borrowCapacity.hiddenIncome.value=document.borrowCapacity.income.value;
		//annuel
		if (document.borrowCapacity.incomeFrequencyListChoice.selectedIndex==0){
			document.borrowCapacity.annualIncome.value=document.borrowCapacity.income.value;			
		}
		//mois
		if (document.borrowCapacity.incomeFrequencyListChoice.selectedIndex==1){
			document.borrowCapacity.monthlyIncome.value=document.borrowCapacity.income.value;			
		}
		//semaine
		if (document.borrowCapacity.incomeFrequencyListChoice.selectedIndex==2){
			document.borrowCapacity.weeklyIncome.value=document.borrowCapacity.income.value;			
		}
		//deux semaines
		if (document.borrowCapacity.incomeFrequencyListChoice.selectedIndex==3){
			document.borrowCapacity.biWeeklyIncome.value=document.borrowCapacity.income.value;			
		}
		//deux fois par mois
		if (document.borrowCapacity.incomeFrequencyListChoice.selectedIndex==4){
			document.borrowCapacity.semiMonthlyIncome.value=document.borrowCapacity.income.value;			
		}
		
		//>Revenus du co-demandeur
		if (isCoApplicantVisible){
			document.borrowCapacity.isCoApplicant.value="1";
			document.borrowCapacity.coHiddenIncome.value=document.borrowCapacity.coIncome.value;
			//annuel
			if (document.borrowCapacity.coIncomeFrequencyListChoice.selectedIndex==0){
				document.borrowCapacity.coAnnualIncome.value=document.borrowCapacity.coIncome.value;			
			}
			//mois
			if (document.borrowCapacity.coIncomeFrequencyListChoice.selectedIndex==1){
				document.borrowCapacity.coMonthlyIncome.value=document.borrowCapacity.coIncome.value;			
			}
			//semaine
			if (document.borrowCapacity.coIncomeFrequencyListChoice.selectedIndex==2){
				document.borrowCapacity.coWeeklyIncome.value=document.borrowCapacity.coIncome.value;			
			}
			//deux semaines
			if (document.borrowCapacity.coIncomeFrequencyListChoice.selectedIndex==3){
				document.borrowCapacity.coBiWeeklyIncome.value=document.borrowCapacity.coIncome.value;			
			}
			//deux fois par mois
			if (document.borrowCapacity.coIncomeFrequencyListChoice.selectedIndex==4){
				document.borrowCapacity.coSemiMonthlyIncome.value=document.borrowCapacity.coIncome.value;			
			}			
		}
		
		//Type de residence
		document.borrowCapacity.residenceType.value=document.borrowCapacity.resTyp.selectedIndex;	
		
		//frequence des revenus de location
		document.borrowCapacity.rentFrequencyChoice.value=document.borrowCapacity.rentListChoice.selectedIndex;
		document.borrowCapacity.municipalTaxFrequencyChoice.value=document.borrowCapacity.municipalTaxListChoice.selectedIndex;
		document.borrowCapacity.schoolTaxFrequencyChoice.value=document.borrowCapacity.txscoListChoice.selectedIndex;
		document.borrowCapacity.heatingCostsFrequencyChoice.value=document.borrowCapacity.heatListChoice.selectedIndex;		
		document.borrowCapacity.condoFeesFrequencyChoice.value=document.borrowCapacity.condoFeeListChoice.selectedIndex;				
				
		
		//Scenario de comparaion
		if (isComparaisonOptionActivated){
			document.borrowCapacity.residenceTypeOpt.value=document.borrowCapacity.resTypOpt.selectedIndex;
			document.borrowCapacity.rentFrequencyChoiceOpt.value=document.borrowCapacity.rentListChoiceOpt.selectedIndex;
			document.borrowCapacity.municipalTaxFrequencyChoiceOpt.value=document.borrowCapacity.txMuniListChoiceOpt.selectedIndex;
			document.borrowCapacity.schoolTaxFrequencyChoiceOpt.value=document.borrowCapacity.txscoListChoiceOpt.selectedIndex;
			document.borrowCapacity.heatingCostsFrequencyChoiceOpt.value=document.borrowCapacity.heatListChoiceOpt.selectedIndex;		
			document.borrowCapacity.condoFeesFrequencyChoiceOpt.value=document.borrowCapacity.condoFeeListChoiceOpt.selectedIndex;
		}
			
	}
	
	if(isResult && !eligibiltyError){
		if (!isWhiteSpace(document.borrowCapacity.resultInput.value)){
			if(!isValidResultInput('resultInputField', document.borrowCapacity.resultInput,'resultInputFieldErrorMsg', true)){
				return false;
			}
		}
	}
	
	if(isResult && !eligibiltyOptError){
		if (isCompareResult){			
			if (!isWhiteSpace(document.borrowCapacity.resultInputOpt.value)){
				if (!isValidResultInput('resultInputFieldOpt', document.borrowCapacity.resultInputOpt,'resultInputFieldOptErrorMsg', true)){
					return false;
				}
			}
		}		
	}

	if (showGlobalErrorMsg(isErrorFound, true)){
		return false; 
	}
	else{
		if (document.borrowCapacity.resultInput != undefined)
			document.borrowCapacity.resultInput.value = "";
		if (document.borrowCapacity.resultInputOpt != undefined)
			document.borrowCapacity.resultInputOpt.value = "";
		return true;
	}
}
function showGlobalErrorMsg(isErrorFound, showError) {
	if (isErrorFound && showError) {
		document.getElementById("topOfPageId").style.display='';
		document.getElementById("topOfPageId").focus();
		document.getElementById("topOfPageId").style.display='none';
		document.getElementById('globalError').innerHTML = j0184;
		document.getElementById('globalErrorMsg').style.display='block';		
		return true;
	}else{
		document.getElementById('globalError').innerHTML = '&nbsp;';
		document.getElementById('globalErrorMsg').style.display='none';
		//showEligibilityErrorMsg(eligibiltyError);
		return false;
	}
}

function showEligibilityErrorMsg(showError) {
	if(showError){
		document.getElementById("topOfPageId").style.display='';
		document.getElementById("topOfPageId").focus();
		document.getElementById("topOfPageId").style.display='none';
		document.getElementById('globalError').innerHTML = j0185;
		document.getElementById('globalErrorMsg').style.display='block';
		return true;
	}else{
		document.getElementById('globalError').innerHTML = '&nbsp;';
		document.getElementById('globalErrorMsg').style.display='none';		
		return false;
	}
}

function showResultEligibilityErrorMsg(showError) {
	if (showError) {
		document.getElementById('globalResultError').innerHTML = j0185;
		document.getElementById('globalResultErrorMsg').style.display='block';
		return true;
	}else{
		document.getElementById('globalResultError').innerHTML = '&nbsp;';
		document.getElementById('globalResultErrorMsg').style.display='none';
		return false;
	}
}

function showResultEligibilityOptErrorMsg(showError) {
	if (showError) {
		document.getElementById('globalResultOptError').innerHTML = j0185;
		document.getElementById('globalResultOptErrorMsg').style.display='block';
		return true;
	}else{
		document.getElementById('globalResultOptError').innerHTML = '&nbsp;';
		document.getElementById('globalResultOptErrorMsg').style.display='none';
		return false;
	}
}

function showGlobalResultErrorMsg(isErrorFound, showError) {
	if (isErrorFound && showError) {
		document.getElementById('globalResultError').innerHTML = j0184;
		document.getElementById('globalResultErrorMsg').style.display='block';
		return true;
	}else{
		document.getElementById('globalResultError').innerHTML = '&nbsp;';
		document.getElementById('globalResultErrorMsg').style.display='none';
		return false;
	}
}

function isValidInput(divId, field, fieldErrorMsg, showErrorMsg){
	if (!isWhiteSpace(field.value)){
		if(!validateAmount(fieldErrorMsg, field, true)){
			document.getElementById(divId).className='invalidInput';			
			return false;
		}
	}
	
	document.getElementById(divId).className='validInput';
	document.getElementById(fieldErrorMsg).innerHTML = '&nbsp;'; 
	document.getElementById(fieldErrorMsg).style.display='none';	

	return true;	
}

function isValidResultInput(divId, field, fieldErrorMsg, showErrorMsg){

	if (!isWhiteSpace(field.value)){
		if(!validateAmount(fieldErrorMsg, field, true)){
			document.getElementById(divId).className='invalidInput';
			showGlobalResultErrorMsg(true, showErrorMsg);
			return false;
		}
	}
	
	document.getElementById(divId).className='validInput';
	document.getElementById(fieldErrorMsg).innerHTML = '&nbsp;'; 
	document.getElementById(fieldErrorMsg).style.display='none';
	showGlobalResultErrorMsg(true, !showErrorMsg);
	
	return true;	
}
function validateMandatoryField(divId, divStarId, field, fieldErrorMsg,showErrorMsg){
	if (isValidMandatoryField(divId, field, fieldErrorMsg,showErrorMsg)){
		document.getElementById(divStarId).className='text';
		if (isValidInput(divId, field, fieldErrorMsg, showErrorMsg)){
			field.value = formatCurrency(field.value);
			return true;
		}
	}else{
		document.getElementById(divStarId).className='textErrorRed';
	}
	return false;
}
function isValidMandatoryField(divId, field, fieldErrorMsg,showErrorMsg){
	var isError=false;
	if (field.tagName=='INPUT'){
		if (isWhiteSpace(field.value) || (field.value<=0)){
			isError=true;
		}
	}
	if (field.tagName=='SELECT'){
		if (field.selectedIndex == 0){
			isError=true;
		}
	}
	if (isError){		
		document.getElementById(fieldErrorMsg).innerHTML = j0173;
		document.getElementById(fieldErrorMsg).style.display ='block';
		document.getElementById(divId).className='invalidInput';		
		return false;
	}
	document.getElementById(fieldErrorMsg).innerHTML = '&nbsp;';
	document.getElementById(fieldErrorMsg).style.display ='none';
	document.getElementById(divId).className='validInput';	
	return true;
}

function validateAmount(divId,objVal, changeValue)
{
	var amount = objVal.value;
	var amount2 = removeCharacter(amount); 
	newVal=""; 
	
	amount=newVal;	
	newVal=trimAll(amount2); 

	if (objVal.value != "")
	{ 	
		if(!IsAmountFieldFormatValid(objVal))
		{ 
			document.getElementById(divId).innerHTML = j0174;  
			document.getElementById(divId).style.display='block';
			return false;
		} else{
			/*if (changeValue){
				objVal.value = newVal;
			}*/
			document.getElementById(divId).innerHTML = '&nbsp;';  
			document.getElementById(divId).style.display='none';
			return true;
		}
	}
	else { 
		document.getElementById(divId).innerHTML = '&nbsp;';  
	}
	return true;
}

function trimAll( strValue ) { 
 var objRegExp = /^(\s*)$/; 
 
    //check for all spaces 
    if(objRegExp.test(strValue)) { 
       strValue = strValue.replace(objRegExp, ''); 
       if( strValue.length == 0)
          return strValue; 
    } 
     
   //check for leading & trailing spaces 
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/; 
   if(objRegExp.test(strValue)) { 
       //remove leading and trailing whitespace characters 
       strValue = strValue.replace(objRegExp, '$2'); 
    } 
  return strValue; 
}

function removeCharacter (strValue) 
{ 
 var objRegExp = / /g;  
 var objRegExpVirgule=/,/g;
   
   //replace all matches with empty strings 
   if(objRegExp.test(strValue)) 
   {  
		return strValue.replace(objRegExp,''); 
   } 
   else if (objRegExpVirgule.test(strValue))
   {
   		return strValue.replace(objRegExpVirgule,''); 
   }
   	else return strValue; 
}

// **********************************************************************************
// DEBUT DE LA LIBRAY DE FORMATAGE ET VALIDATION DE MONTANT MONETAIRE
// AUTEUR           : Martin Rajotte
// POUR             : Banque Nationale du Canada
// DATE D'ECRITURE  : 16 JAN 2004
//
//  DESCRIPTION DU PROGRAMME: Fct. divers pour le traitement des valeurs monetaire en JavaScript.
//  
//  boolean IsAmountFieldFormatValid(TextBox txtField): Valide le contenue d'un TextBox pour savoir si c'est une valeur monetaire valide. 
//                                                      Si valide corrige les leading et taling zero.
//
//  String formatAmountLeadingZeroes(String str):       Eneve les zero non sigificatif avant le point d'une string contenant une valeur monetaire valide.
//
//  String formatAmountTailingZeroes(String str):       Formate une valeur monetaire valide avec 2 digit apres le point.
//
//  boolean IsAmountFormatValid(String strValue):       Valide le contenue d'une String pour savoir si c'est une valeur monetaire valide. 
//
//  String AmountValidToNumericFormat(String strValue)  Converti une valeur monetaire valide et retourne un 
//                                                      String contenant la valeur recu SANS les SPACE et les VIRGULE ex: 5000.55
//
//  Integer AmountValidToRawInt(String strValue)        Converti une valeur monetaire valide et retourne un 
//                                                      String contenant la valeur recu SANS les SPACE , les VIRGULE , le POINT et
//                                                      Multiplie par 100
//
//  String rawIntToStrAmount(Integer iValue)            Divise le rawInt par 100 et le convertit en String ex: 500 ==> 5.00
//
// **********************************************************************************


// **********************************************************************************
// *	function IsAmountFieldFormatValid(txtField)
// *	Entre: champ contenant une valeur monetaire
// *	Sortie: True: Si le format est valide False si invalide
// *         Si Format Valide applique le formatAmountLeadingZeroes et formatAmountTailingZeroes
// *         Sur la VALEUR du CHAMP
// **********************************************************************************

function IsAmountFieldFormatValid(txtField) {
	var strFieldValue = txtField.value;

	if(IsAmountFormatValid(strFieldValue)){

		
		strFieldValue = formatAmountLeadingZeroes(strFieldValue);
		
		// Desactive pour ne pas ajouter le .00 a la fin		
		// strFieldValue = formatAmountTailingZeroes(strFieldValue) 
		
		
		txtField.value = strFieldValue;
		return true;
	}
	
	return false;
}

function AmountValidToNumericFormat(strValue) {
	var strDecimal  = ".";
	var strAmountNumeric = "";
	var iDecimalPos = strValue.indexOf(strDecimal);	

	for (j=0;j<strValue.length;j++) {
		if ( (strValue.charAt(j) != ",") && (strValue.charAt(j) != " ") ) {
			strAmountNumeric = strAmountNumeric + strValue.charAt(j);
		}
	}

	strAmountNumeric = formatAmountLeadingZeroes(strAmountNumeric);
	strAmountNumeric = formatAmountTailingZeroes(strAmountNumeric);

	return strAmountNumeric;
}

function formatAmountTailingZeroes(str) {
	var strDecimal  = ".";
	var iDecimalPos = str.indexOf(strDecimal);

	// ***** On s assure que le chiffre a 2 digit apres le point
			
			
			if (iDecimalPos == -1){
				str = str + strDecimal + "00";
			}else{
			
				
				if ((str.length - (iDecimalPos + 1)) == 1){
					str = str + "0";
				}
			}
	return str;

}
// **********************************************************************************
// *	function formatAmountLeadingZeroes(str)
// *	Entre: string contenant une valeur monetaire VALIDE
// *	Sortie: string contenant la valeur monetaire  sans les zero non sigificatif avant le point.
// **********************************************************************************

function formatAmountLeadingZeroes(str) {
	if (str == "") {
		return str;
	}
	else {
		while (str.charAt(0) == '0' || str.charAt(0) == ',') {
			str = str.substring(1,str.length);
		}
		//si on a un nombre comme 0.50 on laisse le 0 devant
		if (str.charAt(0) == '.') {
			str = '0' + str;
		}
		if (str == "") {
			return "0";
		}
		else {	
			return str;
		}
	}
}

// **********************************************************************************
// *	function IsAmountFormatValid(strValue)
// *	Entre: String contenant une valeur monetaire
// *	Sortie: True: Si le format est valide
// *	Sortie: False: Si le format est invalide
// *	Dans les champs de saisies monetaire, les formats acceptes sont :
// *
// *		999 999 999
// *		999 999 999.9
// *		999 999 999.99
// *
// *		999,999,999
// *		999,999,999.9
// *		999,999,999.99
// *
// *		999999999
// *		999999999.9
// *		999999999.99
// *
// *		         .9
// * - Les leading zero non significatif doivent etre enleve meme si il sont considere comme valide.
// * - Il doit y avoir 2 decimal apres le point meme si des decimal manquant sont considere comme valide.
// **********************************************************************************

function IsAmountFormatValid(strValue) {
	var strDecimal = ".";
	var strMillieme = ",";
	var strMilliemeSpace = " ";
	var iDecimalPos = strValue.indexOf(strDecimal);
	var iDecimalDigit = 0;

	var strValid    = " ,.0123456789";
	var iStrDecimalCount = 0;
	var iStrMilliemeCount = 0;
	var iStrMilliemeSpaceCount = 0;
	
	var strIntegerPart = "";
	var strDecimalPart = "";		
	
	// Valider si string vide
	if (strValue == "") {
		return false;
	}

	// valider les caracteres entre (0-9 . , )
	for (j=0;j<strValue.length;j++)	{
		if (strValid.indexOf(strValue.charAt(j))==-1) {
			return false;
		}

		if (strValue.charAt(j) == strDecimal) {
			iStrDecimalCount = iStrDecimalCount + 1;
		}

		if (strValue.charAt(j) == strMillieme) {
			iStrMilliemeCount = iStrMilliemeCount + 1;
		}

		if (strValue.charAt(j) == strMilliemeSpace){
			iStrMilliemeSpaceCount = iStrMilliemeSpaceCount + 1;
		}

	}

	// Valider si la string contient plus d'un point
	if (iStrDecimalCount > 1) {
		return false;
	}

	// Valider si la string contient des Spaces et des virgules
	if ( (iStrMilliemeCount > 0) && (iStrMilliemeSpaceCount > 0)) {
		return false;
	}

	// ***** Si il y a un point, on verifie le format de la partie decimal ***** 
	if (iStrDecimalCount == 1) {
		var strValidDecimalPart = "0123456789";

		strDecimalPart = strValue.substring(iDecimalPos + 1);  // on prend ce qu'il y a apres le point
		strIntegerPart = strValue.substring(0,iDecimalPos);  // on prend ce qu'il y a avant le point (assignation de la partie entiere incluant les spaces et separteur de milier)

		// valider les caracteres entre (0-9) pour la partie decimal
		for (j=0;j<strDecimalPart.length;j++) {
			if (strValidDecimalPart.indexOf(strDecimalPart.charAt(j))==-1) {
				return false;
			}
		}
				
		// Un ValidAmount contient 0 ou 1 ou 2 chiffre dans la partie decimal
		iDecimalDigit = strDecimalPart.length;
		if ((iDecimalDigit == 0) || (iDecimalDigit > 2)){
			return false;
		}
				
	}
	else {  // Si il n'y a pas de point
		strIntegerPart = strValue  // assignation de la partie entiere incluant les spaces et separteur de milier
	}

	// ***** Verification de la partie entiere

	if ( (iStrMilliemeCount > 0) || (iStrMilliemeSpaceCount > 0)) {  // Si la partie entiere contient des strMillieme ou des strMilliemeSpace
		var strMilliemChar = "";
			
		if (iStrMilliemeCount > 0) {
			strMilliemChar = strMillieme;
		}
		if (iStrMilliemeSpaceCount > 0) {
			strMilliemChar = strMilliemeSpace;
		}

		// Valider si il y a une leading virgule ou space invalid
		if (strIntegerPart.charAt(0) == strMilliemChar){
			return false;
		}

		var iPosIndex = 0;
		var iPosInStrIntegerPart = strIntegerPart.length -1;
			
		// On teste la position des strMilliemChar
			
		while (iPosInStrIntegerPart > -1) {
			if ((iPosIndex == 3) && (strMilliemChar != strIntegerPart.charAt(iPosInStrIntegerPart))) {
				return false;
			}
			iPosInStrIntegerPart = iPosInStrIntegerPart -1;
			iPosIndex = iPosIndex + 1
			if (iPosIndex > 3) { // on reset le count 
				iPosIndex = 0;
			}
		}
	}
	return true;
}

function hidediv() { 
	if (document.getElementById) { // DOM3 = IE5, NS6 
		document.getElementById('hideShow').style.display='none';
	} 
	else { 
			if (document.layers) { // Netscape 4 
				document.hideShow.display = 'none'; 
			} 
			else { // IE 4 
				document.all.hideShow.style.display = 'none'; 
			} 
	} 
} 

	
function showHideFields() {

		if (document.getElementById('coAppCheckbox').checked == true){	
			showAdditionalPropertyField(false);populateSelectField(false);
			showCoApplicantErrorFields(true);		
			for (i=1; i<=25; i++){
				var field='coField';
				field+=i;
				document.getElementById([field]).style.display = 'block';
			}
			document.borrowCapacity.coIncome.value=coIncome;						
			document.borrowCapacity.coCarLoan.value=coCarLoan;
			document.borrowCapacity.coPersonalLoan.value=coPersonalLoan;
			document.borrowCapacity.coPension.value=coPension;
			document.borrowCapacity.coCreditCard.value=coCreditCard;
			document.borrowCapacity.coLineOfCredit.value=coLineOfCredit;
			document.borrowCapacity.coLineOfCreditMortageGuarantee.value=coLineOfCreditMortageGuarantee;
		}else{
			showAdditionalPropertyField(false);populateSelectField(false);
			showCoApplicantErrorFields(false);	
			for (i=1; i<=25; i++){
				var field='coField';
				field+=i;
				document.getElementById([field]).style.display = 'none';
			}			
										
		} 			
} 
function isValidHiddenInput(divId, field, fieldErrorMsg, showErrorMsg, validateHidden){
	if (validateHidden){
		if (!isWhiteSpace(field.value)){
			if(!validateAmount(fieldErrorMsg, field, false)){
				document.getElementById(divId).className='invalidInput';				
				return false;
			}else{
				document.getElementById(divId).className='validInput';				
				return true;
			}
		}
	}else{
		document.getElementById(fieldErrorMsg).innerHTML = '&nbsp;'; 
		document.getElementById(fieldErrorMsg).style.display='none';
		document.getElementById(divId).className='validInput';
	}
	
	return true;
}

function showCoApplicantErrorFields(validateHidden){
	var isCoIncomeError=false;
	var isError=false;

		
	if (!isValidHiddenInput('coField3', document.borrowCapacity.coIncome,'coField3ErrorMsg', true, validateHidden)){
		isError=true;
		isCoIncomeError=true;
	}
	
	
	if (!validateHidden){
		document.getElementById('coIncomeFrequencyListChoiceErrorMsg').innerHTML = '&nbsp;';
		document.getElementById('coIncomeFrequencyListChoiceErrorMsg').style.display ='none';
		document.getElementById('coField5').className='validInput';
	}
				
	if (!isValidHiddenInput('coField9', document.borrowCapacity.coCarLoan,'coCarLoanErrorMsg', true, validateHidden)){
		isError=true;
	}				
		
	if (!isValidHiddenInput('coField12', document.borrowCapacity.coPersonalLoan,'coPersonalLoanErrorMsg', true, validateHidden)){
		isError=true;
	}
	
	if (!isValidHiddenInput('coField15', document.borrowCapacity.coPension,'coPensionErrorMsg', true, validateHidden )){
		isError=true;
	}
	
	if (!isValidHiddenInput('coField18', document.borrowCapacity.coCreditCard,'coCreditCardErrorMsg', true, validateHidden)){
		isError=true;
	}
	
	if (!isValidHiddenInput('coField21', document.borrowCapacity.coLineOfCredit,'coLineOfCreditErrorMsg', true, validateHidden)){
		isError=true;
	}
	
	if (!isValidHiddenInput('coField24', document.borrowCapacity.coLineOfCreditMortageGuarantee,'coLineOfCreditMortageGuaranteeErrorMsg', true, validateHidden)){
		isError=true;
	}
		
	

}
function populateSelectField(firstPropertyCombo){

	if (firstPropertyCombo){		
		if(document.borrowCapacity.resTyp.selectedIndex==0){
			//Unifamiliale
			if(!isUnifamiliale ){document.borrowCapacity.municipalTax.value=formatDbAmount(municipalTaxUnifamiliale);}
			if(!isUnifamiliale){document.borrowCapacity.schoolTax.value=formatDbAmount(schoolTaxUnifamiliale);}
			if(!isUnifamiliale ){document.borrowCapacity.heatingCosts.value=formatDbAmount(heatingCostsUnifamiliale);}
			isCondo=false;			
			isDuplex=false;
			isTriplex=false;
			
		}else if(document.borrowCapacity.resTyp.selectedIndex==1){
			//condo
			if(!isCondo ){document.borrowCapacity.municipalTax.value=formatDbAmount(municipalTaxCondo);}
			if(!isCondo ){document.borrowCapacity.schoolTax.value=formatDbAmount(schoolTaxCondo);}
			if(!isCondo ){document.borrowCapacity.heatingCosts.value=formatDbAmount(heatingCostsCondo);}
			if(!isCondo ){document.borrowCapacity.condoFees.value=formatDbAmount(condoFees);}
			isUnifamiliale=false;			
			isDuplex=false;
			isTriplex=false;
		}else if(document.borrowCapacity.resTyp.selectedIndex==2){
			//duplex
			if(!isDuplex ){document.borrowCapacity.municipalTax.value=formatDbAmount(municipalTaxDuplex);}
			if(!isDuplex ){document.borrowCapacity.schoolTax.value=formatDbAmount(schoolTaxDuplex);}
			if(!isDuplex ){document.borrowCapacity.heatingCosts.value=formatDbAmount(heatingCostsDuplex);}
			isUnifamiliale=false;			
			isCondo=false;
			isTriplex=false;
			
		}else if(document.borrowCapacity.resTyp.selectedIndex==3){
			//3-4 Plex
			if(!isTriplex ){document.borrowCapacity.municipalTax.value=formatDbAmount(municipalTax34Plex);}
			if(!isTriplex ){document.borrowCapacity.schoolTax.value=formatDbAmount(schoolTax34Plex);}
			if(!isTriplex ){document.borrowCapacity.heatingCosts.value=formatDbAmount(heatingCosts34Plex);}	
			isUnifamiliale=false;			
			isDuplex=false;
			isCondo=false;		
		}
	}else{
		if(document.borrowCapacity.resTypOpt.selectedIndex==0){
			//choisir
			document.borrowCapacity.municipalTaxOpt.value="";
			document.borrowCapacity.schoolTaxOpt.value="";
			document.borrowCapacity.heatingCostsOpt.value="";
			
		}else if(document.borrowCapacity.resTypOpt.selectedIndex==1){
			//Unifamiliale (optionel)
			if(!isUnifamilialeOpt ){document.borrowCapacity.municipalTaxOpt.value=formatDbAmount(municipalTaxUnifamiliale);}
			if(!isUnifamilialeOpt ){document.borrowCapacity.schoolTaxOpt.value=formatDbAmount(schoolTaxUnifamiliale);}
			if(!isUnifamilialeOpt ){document.borrowCapacity.heatingCostsOpt.value=formatDbAmount(heatingCostsUnifamiliale);}
			isCondoOpt=false;			
			isDuplexOpt=false;
			isTriplexOpt=false;
			
		}else if(document.borrowCapacity.resTypOpt.selectedIndex==2){
			//condo (optionel)
			if(!isCondoOpt ){document.borrowCapacity.municipalTaxOpt.value=formatDbAmount(municipalTaxCondo);}
			if(!isCondoOpt ){document.borrowCapacity.schoolTaxOpt.value=formatDbAmount(schoolTaxCondo);}
			if(!isCondoOpt ){document.borrowCapacity.heatingCostsOpt.value=formatDbAmount(heatingCostsCondo);}
			if(!isCondoOpt ){document.borrowCapacity.condoFeesOpt.value=formatDbAmount(condoFees);}	
			isUnifamilialeOpt=false;			
			isDuplexOpt=false;
			isTriplexOpt=false;		
			
		}else if(document.borrowCapacity.resTypOpt.selectedIndex==3){
			//duplex (optionel)
			if(!isDuplexOpt ){document.borrowCapacity.municipalTaxOpt.value=formatDbAmount(municipalTaxDuplex);}
			if(!isDuplexOpt ){document.borrowCapacity.schoolTaxOpt.value=formatDbAmount(schoolTaxDuplex);}
			if(!isDuplexOpt ){document.borrowCapacity.heatingCostsOpt.value=formatDbAmount(heatingCostsDuplex);}
			isUnifamilialeOpt=false;			
			isCondoOpt=false;
			isTriplexOpt=false;
			
		}else if(document.borrowCapacity.resTypOpt.selectedIndex==4){
			//3-4 Plex (optionel)
			if(!isTriplexOpt ){document.borrowCapacity.municipalTaxOpt.value=formatDbAmount(municipalTax34Plex);}
			if(!isTriplexOpt ){document.borrowCapacity.schoolTaxOpt.value=formatDbAmount(schoolTax34Plex);}
			if(!isTriplexOpt ){document.borrowCapacity.heatingCostsOpt.value=formatDbAmount(heatingCosts34Plex);}
			isUnifamilialeOpt=false;			
			isCondoOpt=false;
			isDuplexOpt=false;
		}		
	}
	initFormvalues();
}
function showAdditionalPropertyField(firstPropertyCombo){
	
	if (firstPropertyCombo){			
		//enleve les messages d'erreurs, si necessaire
		showAdditionalPropertyFieldErrorFields('municipalTax', document.borrowCapacity.municipalTax,'municipalTaxErrorMsg', true, false);	
		showAdditionalPropertyFieldErrorFields('schoolTax', document.borrowCapacity.schoolTax,'schoolTaxErrorMsg', true, false);	
		showAdditionalPropertyFieldErrorFields('heatingCosts', document.borrowCapacity.heatingCosts,'heatingCostsErrorMsg', true, false);
				
		document.getElementById('municipalTaxMandatoryField').className='text';
		document.getElementById('heatingCostsMandatoryField').className='text';
		
		if (document.borrowCapacity.resTyp.selectedIndex==1){	
			//enleve les messages d'erreurs, si necessaire
			showAdditionalPropertyFieldErrorFields('condoFeeField3', document.borrowCapacity.condoFees,'condoFeeField3ErrorMsg', true, false);	
			for (i=1; i<=7; i++){
				var field='condoFeeField';
				field+=i;
				document.getElementById(field).style.display = 'block';			
			}			
						
		}else{
			//enleve les messages d'erreurs, si necessaire
			showAdditionalPropertyFieldErrorFields('condoFeeField3', document.borrowCapacity.condoFees,'condoFeeField3ErrorMsg', true, false);	
			for (i=1; i<=7; i++){
				var field='condoFeeField';
				field+=i;
				document.getElementById(field).style.display = 'none';
			}			
		}
		if (document.borrowCapacity.resTyp.selectedIndex==2 ||document.borrowCapacity.resTyp.selectedIndex==3){	
			//enleve les messages d'erreurs, si necessaire
			showAdditionalPropertyFieldErrorFields('rentField3', document.borrowCapacity.rentIncome,'rentField3ErrorMsg', true, false);		
			for (i=1; i<=7; i++){
				var field='rentField';
				field+=i;
				document.getElementById(field).style.display = 'block';
			}						
		}else{
			//enleve les messages d'erreurs, si necessaire
			showAdditionalPropertyFieldErrorFields('rentField3', document.borrowCapacity.rentIncome,'rentField3ErrorMsg', true, false);	
			for (i=1; i<=7; i++){
				var field='rentField';
				field+=i;
				document.getElementById(field).style.display = 'none';
			}			
		}		
	}else{
		//document.getElementById('txMuniMandatoryFieldOpt').className='text';
		//document.getElementById('chfMandatoryFieldOpt').className='text';
	
		if (document.borrowCapacity.resTypOpt.selectedIndex!=0){
			document.getElementById('resTypOptErrorMsg').innerHTML = '&nbsp;';
			document.getElementById('resTypOptErrorMsg').style.display ='none';
			document.getElementById('resOptTyp').className='validInput';
			document.getElementById('resTypMandatoryOpt').className='text';
			
			showAdditionalPropertyFieldErrorFields('fieldOpt3', document.borrowCapacity.municipalTaxOpt,'fieldOpt3ErrorMsg', true, true);	
			showAdditionalPropertyFieldErrorFields('fieldOpt6', document.borrowCapacity.schoolTaxOpt,'fieldOpt6ErrorMsg', true, true);	
			showAdditionalPropertyFieldErrorFields('fieldOpt9', document.borrowCapacity.heatingCostsOpt,'fieldOpt9ErrorMsg', true, true);
				
		}
		if (document.borrowCapacity.resTypOpt.selectedIndex==2){
			//enleve les messages d'erreurs, si necessaire
			showAdditionalPropertyFieldErrorFields('condoFeeFieldOpt3', document.borrowCapacity.condoFeesOpt,'condoFeeFieldOpt3ErrorMsg', true, false);					
			for (i=1; i<=7; i++){
				var field='condoFeeFieldOpt';
				field+=i;
				document.getElementById(field).style.display = 'block';
			}			
		}else{
			//enleve les messages d'erreurs, si necessaire
			showAdditionalPropertyFieldErrorFields('condoFeeFieldOpt3', document.borrowCapacity.condoFeesOpt,'condoFeeFieldOpt3ErrorMsg', true, false);	
			for (i=1; i<=7; i++){
				var field='condoFeeFieldOpt';
				field+=i;
				document.getElementById(field).style.display = 'none';
			}			
		}
		if (document.borrowCapacity.resTypOpt.selectedIndex==3 ||document.borrowCapacity.resTypOpt.selectedIndex==4){	
			//enleve les messages d'erreurs, si necessaire
			showAdditionalPropertyFieldErrorFields('rentFieldOpt3', document.borrowCapacity.rentIncomeOpt,'rentFieldOpt3ErrorMsg', true, false);					
			for (i=1; i<=7; i++){
				var field='rentFieldOpt';
				field+=i;
				document.getElementById(field).style.display = 'block';
			}
			
		}else{
			//enleve les messages d'erreurs, si necessaire
			showAdditionalPropertyFieldErrorFields('rentFieldOpt3', document.borrowCapacity.rentIncomeOpt,'rentFieldOpt3ErrorMsg', true, false);	
			for (i=1; i<=7; i++){
				var field='rentFieldOpt';
				field+=i;
				document.getElementById(field).style.display = 'none';
			}
			
		}					
	}

}

function showAdditionalPropertyFieldErrorFields(divId, field, fieldErrorMsg, showErrorMsg, validateHidden){
	var isError=false;
	
	if (!isValidHiddenInput(divId, field, fieldErrorMsg, showErrorMsg, validateHidden)){
			isError=true;
	}

}

function togglediv(windowId) {
	if (document.getElementById) { // DOM3 = IE5, NS6 
		if (document.getElementById(windowId).style.display == 'block'){
			document.getElementById(windowId).style.display = 'none';				
		}else{
			document.getElementById(windowId).style.display = 'block';				
		}
	} 
}	

function toggleLink(windowId1,windowId2) {
	if (document.getElementById) { // DOM3 = IE5, NS6 
		if (document.getElementById(windowId1).style.display == 'block'){
			document.getElementById(windowId1).style.display = 'none';	
			document.getElementById(windowId2).style.display = 'block';			
		}else{
			document.getElementById(windowId1).style.display = 'block';	
			document.getElementById(windowId2).style.display = 'none';			
		}
	} 
}

function showBreakdownMonthlyPayment(tableToShow,tableToHide1,tableToHide2,tableToHide3, windowFirstSectionLink, windowResultSecondSection1, windowResultSecondSection2){
	if (document.getElementById(tableToShow).style.display == 'none'){
		document.getElementById(windowFirstSectionLink).style.display = 'none';
		document.getElementById(tableToHide1).style.display = 'none';
		document.getElementById(tableToHide2).style.display = 'none';	
		document.getElementById(tableToHide3).style.display = 'none';		
		document.getElementById(tableToShow).style.display = 'block';
		document.getElementById(windowResultSecondSection1).style.display = 'block';
		document.getElementById(windowResultSecondSection2).style.display = 'block';	
	}else{
		document.getElementById(windowFirstSectionLink).style.display = 'block';
		document.getElementById(tableToShow).style.display = 'none';
		document.getElementById(windowResultSecondSection1).style.display = 'none';
		document.getElementById(windowResultSecondSection2).style.display = 'none';
	}
}

function showComparaisonOptionErrorFields(validateActiveFields){
	var isError=false;
	
	if (!isValidHiddenInput('fieldOpt3', document.borrowCapacity.municipalTaxOpt,'fieldOpt3ErrorMsg', true, validateActiveFields)){
		isError=true;
		isTxMunError=true;
	}
	
	if (!isValidHiddenInput('fieldOpt6', document.borrowCapacity.schoolTaxOpt,'fieldOpt6ErrorMsg', true, validateActiveFields )){
		isError=true;
	}
		
	if ( !isValidHiddenInput('fieldOpt9', document.borrowCapacity.heatingCostsOpt,'fieldOpt9ErrorMsg', true, validateActiveFields)){		
		isError=true;
	}
	
	if (document.borrowCapacity.resTypOpt.selectedIndex==2){
		if (!isValidHiddenInput('condoFeeFieldOpt3', document.borrowCapacity.condoFeesOpt,'condoFeeFieldOpt3ErrorMsg', true, validateActiveFields)){
			isErrorFound=true;
		}
	} 
	
	if (document.borrowCapacity.resTypOpt.selectedIndex==3||document.borrowCapacity.resTypOpt.selectedIndex==4){
		if (!isValidHiddenInput('rentFieldOpt3', document.borrowCapacity.rentIncomeOpt,'rentFieldOpt3ErrorMsg', true, validateActiveFields)){
			isErrorFound=true;
		}
	}	

	
}
function activateDeactivateFields(){
	if (document.getElementById('compareCheckbox').checked == true){
		document.getElementById('fieldOpt1').className='text';
		document.getElementById('resTypMandatoryOpt').className='text';
		document.getElementById('resTypOpt').disabled=false;
		document.getElementById('fieldOpt2').className='text';
		document.getElementById('txMuniMandatoryFieldOpt').className='text';
		document.getElementById('municipalTaxOpt').disabled=false;
		document.getElementById('fieldOpt4').className='text';
		document.getElementById('txMuniListChoiceOpt').disabled=false;
		document.getElementById('fieldOpt5').className='text';
		document.getElementById('schoolTaxOpt').disabled=false;
		document.getElementById('fieldOpt7').className='text';
		document.getElementById('txscoListChoiceOpt').disabled=false;
		document.getElementById('fieldOpt8').className='text';
		document.getElementById('chfMandatoryFieldOpt').className='text';
		document.getElementById('heatingCostsOpt').disabled=false;
		document.getElementById('fieldOpt10').className='text';
		document.getElementById('heatListChoiceOpt').disabled=false;
		
		if (document.borrowCapacity.resTypOpt.selectedIndex==2){			
			for (i=1; i<=7; i++){
				var field='condoFeeFieldOpt';
				field+=i;
				document.getElementById(field).className='text';
				document.getElementById(field).style.display = 'block';
			}				
			document.getElementById('condoFeesOpt').disabled=false;		
			document.getElementById('condoFeeListChoiceOpt').disabled=false;		
		}
		
		if (document.borrowCapacity.resTypOpt.selectedIndex==3 ||document.borrowCapacity.resTypOpt.selectedIndex==4){	
			for (i=1; i<=7; i++){
				var field='rentFieldOpt';
				field+=i;
				document.getElementById(field).className='text';
				document.getElementById(field).style.display = 'block';
			}
			document.getElementById('rentIncomeOpt').disabled=false;		
			document.getElementById('rentListChoiceOpt').disabled=false;
		}
		showComparaisonOptionErrorFields(true);						
	
	}else{
		
		document.getElementById('fieldOpt1').className='textDisabled';
		document.getElementById('resTypMandatoryOpt').className='textDisabled';		
		document.getElementById('resTypOpt').disabled=true;
		document.getElementById('fieldOpt2').className='textDisabled';
		document.getElementById('txMuniMandatoryFieldOpt').className='textDisabled';
		document.getElementById('municipalTaxOpt').disabled=true;
		document.getElementById('fieldOpt4').className='textDisabled';
		document.getElementById('txMuniListChoiceOpt').disabled=true;
		document.getElementById('fieldOpt5').className='textDisabled';
		document.getElementById('schoolTaxOpt').disabled=true;
		document.getElementById('fieldOpt7').className='textDisabled';
		document.getElementById('txscoListChoiceOpt').disabled=true;
		document.getElementById('fieldOpt8').className='textDisabled';
		document.getElementById('chfMandatoryFieldOpt').className='textDisabled';
		document.getElementById('heatingCostsOpt').disabled=true;
		document.getElementById('fieldOpt10').className='textDisabled';
		document.getElementById('heatListChoiceOpt').disabled=true;
		
		if (document.borrowCapacity.resTypOpt.selectedIndex==2){				
			for (i=1; i<=7; i++){
				var field='condoFeeFieldOpt';
				field+=i;
				document.getElementById(field).className='textDisabled';
				document.getElementById(field).style.display = 'block';
			}			
			document.getElementById('condoFeesOpt').disabled=true;	
			document.getElementById('condoFeeListChoiceOpt').disabled=true;		
		}
		
		if (document.borrowCapacity.resTypOpt.selectedIndex==3 ||document.borrowCapacity.resTypOpt.selectedIndex==4){	
			for (i=1; i<=7; i++){
				var field='rentFieldOpt';
				field+=i;
				document.getElementById(field).className='textDisabled';
				document.getElementById(field).style.display = 'block';
			}
			document.getElementById('rentIncomeOpt').disabled=true;		
			document.getElementById('rentListChoiceOpt').disabled=true;
		}
		
		document.getElementById('resTypOptErrorMsg').innerHTML = '&nbsp;';
		document.getElementById('resTypOptErrorMsg').style.display ='none';
		document.getElementById('resOptTyp').className='validInput';
		
		showComparaisonOptionErrorFields(false);				
	}	
}		

function calculateMortgageAmount() {
	calculateMortgageAmountCore(false, false);
}

function calculateMortgageAmountOnKeyDown() {
	calculateMortgageAmountCore(true, false);
}

function calculateMortgageAmountCore(keyPress, print) {
	if(isResult&&!eligibiltyError){
		if (isWhiteSpace(document.borrowCapacity.resultInput.value)){
			document.getElementById('mortgageAmount').innerHTML = simpleFormatCurrency(0);		
			document.getElementById('downPaymentPercentage').innerHTML ='<nobr> (0.0 %) </nobr>';
			document.getElementById('insurancePremiumResult').innerHTML = simpleFormatCurrency(0);
			document.getElementById('monthlyPaymentResultLink').style.display='none';
			document.getElementById('zeroMonthlyPaymentResult').style.display='block';					
			document.getElementById('zeroMonthlyPaymentResult').innerHTML = simpleFormatCurrency(0);
			document.getElementById('totalPropertyCost').innerHTML = simpleFormatCurrency(0);
			if (!print) {
				document.borrowCapacityPrint.resultInput.value=0;
			}
		}
		else if (((keyPress) || (print)) || (isValidResultInput('resultInputField', document.borrowCapacity.resultInput,'resultInputFieldErrorMsg', true))){
		
			var downPaymentRatePercentage = downPaymentRate/100;
			var downPayment=parseFloat(removeSeparator(document.borrowCapacity.resultInput));
			var mortgageAmount=0;
			var propertyCost=0;
			var varRate=parseFloat(rate);
			var rateFactor=0;	
			var insurance=0;
			var monthlyPayment=0;
			var monthlyInsurance=0;
			var totalMonthlyPayment=0;
			var downPaymentPercentage=0;
			var varMaximumMortageAmount=parseFloat(maximumMortageAmount);
				
			mortgageAmount=(downPayment*(1-downPaymentRatePercentage))/downPaymentRatePercentage;
				
			if (mortgageAmount>varMaximumMortageAmount){
				mortgageAmount=varMaximumMortageAmount;
			}
			propertyCost = mortgageAmount + downPayment;
			downPaymentPercentage = (parseFloat(formatAmount(downPayment))/parseFloat(formatAmount(propertyCost)))*100;
			
			insurance = getInsurance(mortgageAmount, downPaymentPercentage);

			rateFactor=Math.pow((1 + varRate / 200), 1/6)-1;
			monthlyPayment = (mortgageAmount * rateFactor) / (1 - (Math.pow((1 + rateFactor), -360)));
			monthlyInsurance = (insurance * rateFactor) / (1 - (Math.pow((1 + rateFactor), -360)));
			totalMonthlyPayment= monthlyPayment+monthlyInsurance;	
			
			var varTotalMonthlyPayment =parseFloat(formatAmount(totalMonthlyPayment));
			var varMonthlyPayment	  =parseFloat(formatAmount(monthlyPayment));
			var varMonthlyInsurance   =varTotalMonthlyPayment-varMonthlyPayment;	
						
			if (totalMonthlyPayment>0){
				document.getElementById('zeroMonthlyPaymentResult').style.display='none';
				document.getElementById('monthlyPaymentResultLink').style.display='block';
				if (varLang=='fr') {
					document.getElementById('monthlyPaymentResult').innerHTML = formatCurrency(formatAmount(totalMonthlyPayment)) + ' $';
				}
				else {
					document.getElementById('monthlyPaymentResult').innerHTML = '$ ' + formatCurrency(formatAmount(totalMonthlyPayment));
				}
			
			}
			else{
				document.getElementById('zeroMonthlyPaymentResult').style.display='block';
				document.getElementById('monthlyPaymentResultLink').style.display='none';
				if (varLang=='fr') {
					document.getElementById('zeroMonthlyPaymentResult').innerHTML = formatCurrency(formatAmount(totalMonthlyPayment)) + ' $';
				}
				else {
					document.getElementById('zeroMonthlyPaymentResult').innerHTML = '$ ' + formatCurrency(formatAmount(totalMonthlyPayment));
				}
		
			}
			var varMonthlyMunicipalTax=parseFloat(formatViewAmount(monthlyMunicipalTax));
			var varMonthlySchoolTax=parseFloat(formatViewAmount(monthlySchoolTax));
			var varMonthlyCondoFees=parseFloat(formatViewAmount(monthlyCondoFees));
			var varMonthlyRentIncome=parseFloat(formatViewAmount(monthlyRentIncome));
			
			var totalMonthlyFee=totalMonthlyPayment+varMonthlyMunicipalTax+varMonthlySchoolTax +varMonthlyCondoFees-varMonthlyRentIncome;
			
			if(!print){
				document.getElementById('totalMonthlyFee2').innerHTML = formatCurrency(formatAmount(totalMonthlyFee));
				document.getElementById('monthlyPayment2').innerHTML = formatCurrency(formatAmount(monthlyPayment));
				document.getElementById('monthlyInsurancePremium2').innerHTML = formatCurrency(varMonthlyInsurance);
				document.getElementById('totalMonthlyPayment2').innerHTML = formatCurrency(formatAmount(totalMonthlyPayment));
			}
			
			document.getElementById('downPaymentPercentage').innerHTML ='<nobr>(' + formatPercentage(downPaymentPercentage)+ ' %)</nobr>';
			
			if (varLang=='fr') {
				document.getElementById('mortgageAmount').innerHTML = formatCurrency(formatAmount(mortgageAmount)) + ' $';
				document.getElementById('insurancePremiumResult').innerHTML = formatCurrency(formatAmount(insurance)) + ' $';
				document.getElementById('totalPropertyCost').innerHTML = formatCurrency(formatAmount(propertyCost)) + ' $';
			}
			else {
				document.getElementById('mortgageAmount').innerHTML = '$ ' + formatCurrency(formatAmount(mortgageAmount));
				document.getElementById('insurancePremiumResult').innerHTML = '$ ' + formatCurrency(formatAmount(insurance));
				document.getElementById('totalPropertyCost').innerHTML = '$ ' + formatCurrency(formatAmount(propertyCost));
			}
			if ((!print) && (!keyPress)) {
				document.getElementById('resultInput').value=formatCurrency(document.getElementById('resultInput').value);
			} 
			else if (!print) {
				document.borrowCapacityPrint.resultInput.value = AmountValidToNumericFormat(document.borrowCapacity.resultInput.value);
			}
			else if (print) {
				if (varLang=='fr') {
					document.getElementById('downPaymentResult').innerHTML = formatCurrency(formatAmount(document.borrowCapacity.resultInput.value)) + ' $';
				}
				else {
					document.getElementById('downPaymentResult').innerHTML = '$ ' + formatCurrency(formatAmount(document.borrowCapacity.resultInput.value));
				}
			}
		}
	}
}

function openMonthlyPayment(lang, residenceType, propertyCost, interestRate) {
	if (IsAmountFieldFormatValid(document.borrowCapacityPrint.resultInput)) {
		window.open("/WebInfoWeb/DispatchRequest?aliasDispatcher=monthlyPayment&action=41&lang=" + lang + "&residenceType=" + residenceType + "&propertyCost=" + propertyCost + "&interestRate=" + interestRate + "&downpayment=" + document.borrowCapacityPrint.resultInput.value);
	}
}

function openMonthlyPaymentOpt(lang, residenceType, propertyCost, interestRate) {
	if (IsAmountFieldFormatValid(document.borrowCapacityPrint.resultInputOpt)) {
		window.open("/WebInfoWeb/DispatchRequest?aliasDispatcher=monthlyPayment&action=41&lang=" + lang + "&residenceType=" + residenceType + "&propertyCost=" + propertyCost + "&interestRate=" + interestRate + "&downpayment=" + document.borrowCapacityPrint.resultInputOpt.value);
	}
}

function open34MonthlyPayment(lang, residenceType, propertyCost, interestRate, downpayment) {
	var rentIncome =  0;
	
	if (IsAmountFieldFormatValid(document.borrowCapacity.rentIncome)) {
		rentIncome = AmountValidToNumericFormat(document.borrowCapacity.rentIncome.value);
	}
	
	if (IsAmountFieldFormatValid(document.borrowCapacityPrint.resultInput)) {
		if (parseFloat(downpayment) >= parseFloat(document.borrowCapacityPrint.resultInput.value)) {
			window.open("/WebInfoWeb/DispatchRequest?aliasDispatcher=monthlyPayment&action=41&lang=" + lang + "&residenceType=" + residenceType + "&propertyCost=" + propertyCost + "&interestRate=" + interestRate + "&rentIncome=" + rentIncome + "&downpayment=" + downpayment);
		}
		else {
			window.open("/WebInfoWeb/DispatchRequest?aliasDispatcher=monthlyPayment&action=41&lang=" + lang + "&residenceType=" + residenceType + "&propertyCost=" + propertyCost + "&interestRate=" + interestRate + "&rentIncome=" + rentIncome + "&downpayment=" + document.borrowCapacityPrint.resultInput.value);
		}
	}
}

function open34MonthlyPaymentOpt(lang, residenceType, propertyCost, interestRate, downpayment) {
	var rentIncome =  0;
	
	if (IsAmountFieldFormatValid(document.borrowCapacity.rentIncomeOpt)) {
		rentIncome = AmountValidToNumericFormat(document.borrowCapacity.rentIncomeOpt.value);
	}
	
	if (IsAmountFieldFormatValid(document.borrowCapacityPrint.resultInputOpt)) {
		if (parseFloat(downpayment) >= parseFloat(document.borrowCapacityPrint.resultInputOpt.value)) {
			window.open("/WebInfoWeb/DispatchRequest?aliasDispatcher=monthlyPayment&action=41&lang=" + lang + "&residenceType=" + residenceType + "&propertyCost=" + propertyCost + "&interestRate=" + interestRate + "&rentIncome=" + rentIncome + "&downpayment=" + downpayment);		
		}
		else {
			window.open("/WebInfoWeb/DispatchRequest?aliasDispatcher=monthlyPayment&action=41&lang=" + lang + "&residenceType=" + residenceType + "&propertyCost=" + propertyCost + "&interestRate=" + interestRate + "&rentIncome=" + rentIncome + "&downpayment=" + document.borrowCapacityPrint.resultInputOpt.value);
		}
	}
}


function calculateMortgageAmountOpt(){
	calculateMortgageAmountOptCore(false, false);
}
function calculateMortgageAmountOptOnKeyDown(){
	calculateMortgageAmountOptCore(true, false);
}

function calculateMortgageAmountOptCore(keyPress, print) {
	if(isResult && isCompareResult && !eligibiltyOptError){
		if (isWhiteSpace(document.borrowCapacity.resultInputOpt.value)){
			document.getElementById('mortgageAmountOpt').innerHTML = simpleFormatCurrency(0);		
			document.getElementById('downPaymentPercentageOpt').innerHTML ='<nobr>(0.0' + ' %)</nobr>';
			document.getElementById('insurancePremiumResultOpt').innerHTML = simpleFormatCurrency(0);
			document.getElementById('monthlyPaymentResultLinkOpt').style.display='none';
			document.getElementById('zeroMonthlyPaymentResultOpt').style.display='block';
			document.getElementById('zeroMonthlyPaymentResultOpt').innerHTML = simpleFormatCurrency(0);
			document.getElementById('totalPropertyCostOpt').innerHTML = simpleFormatCurrency(0);
			if (!print) {
				document.borrowCapacityPrint.resultInputOpt.value=0;
			}
		}
		else{
			var downPaymentRatePercentageOpt = downPaymentRateOpt/100;
			var downPaymentOpt=parseFloat(removeSeparator(document.borrowCapacity.resultInputOpt));
			var mortgageAmountOpt=0;
			var propertyCostOpt=0;
			var varRateOpt=parseFloat(rateOpt);
			var rateFactorOpt=0;	
			var insuranceOpt=0;
			var monthlyPaymentOpt=0;
			var monthlyInsuranceOpt=0;
			var totalMonthlyPaymentOpt=0;
			var downPaymentPercentageOpt=0;
			var varMaximumMortageAmountOpt=parseFloat(maximumMortageAmountOpt);
			
			if (((keyPress) || (print)) || (isValidResultInput('resultInputFieldOpt', document.borrowCapacity.resultInputOpt,'resultInputFieldOptErrorMsg', true))) {
				mortgageAmountOpt=(downPaymentOpt*(1-downPaymentRatePercentageOpt))/downPaymentRatePercentageOpt;
				if (mortgageAmountOpt>varMaximumMortageAmountOpt){
					mortgageAmountOpt=varMaximumMortageAmountOpt;
				}
				propertyCostOpt = mortgageAmountOpt + downPaymentOpt;
				downPaymentPercentageOpt = (parseFloat(formatAmount(downPaymentOpt))/parseFloat(formatAmount(propertyCostOpt)))*100;
			
				insuranceOpt = getInsurance(mortgageAmountOpt, downPaymentPercentageOpt);
				
				rateFactorOpt=Math.pow((1 + varRateOpt / 200), 1/6)-1;
				monthlyPaymentOpt = (mortgageAmountOpt * rateFactorOpt) / (1 - (Math.pow((1 + rateFactorOpt), -360)));
				monthlyInsuranceOpt = (insuranceOpt * rateFactorOpt) / (1 - (Math.pow((1 + rateFactorOpt), -360)));
				totalMonthlyPaymentOpt= monthlyPaymentOpt+monthlyInsuranceOpt;	
				
				var varTotalMonthlyPaymentOpt =parseFloat(formatAmount(totalMonthlyPaymentOpt));
				var varMonthlyPaymentOpt	  =parseFloat(formatAmount(monthlyPaymentOpt));
				var varMonthlyInsuranceOpt=varTotalMonthlyPaymentOpt-varMonthlyPaymentOpt;		
				
				
				if (totalMonthlyPaymentOpt>0){
					document.getElementById('zeroMonthlyPaymentResultOpt').style.display='none';
					document.getElementById('monthlyPaymentResultLinkOpt').style.display='block';
					if (varLang=='fr') {
						document.getElementById('monthlyPaymentResultOpt').innerHTML = formatCurrency(formatAmount(totalMonthlyPaymentOpt)) + ' $';
					} else {
						document.getElementById('monthlyPaymentResultOpt').innerHTML = '$ ' + formatCurrency(formatAmount(totalMonthlyPaymentOpt));
					}
					
				}else{
					document.getElementById('zeroMonthlyPaymentResultOpt').style.display='block';
					document.getElementById('monthlyPaymentResultLinkOpt').style.display='none';
					if (varLang=='fr') {
						document.getElementById('zeroMonthlyPaymentResultOpt').innerHTML = formatCurrency(formatAmount(totalMonthlyPaymentOpt)) + ' $';
					} else {
						document.getElementById('zeroMonthlyPaymentResultOpt').innerHTML = '$ ' + formatCurrency(formatAmount(totalMonthlyPaymentOpt));
					}
				}
				var varMonthlyMunicipalTaxOpt=parseFloat(formatViewAmount(monthlyMunicipalTaxOpt));
				var varMonthlySchoolTaxOpt=parseFloat(formatViewAmount(monthlySchoolTaxOpt));
				var varMonthlyCondoFeesOpt=parseFloat(formatViewAmount(monthlyCondoFeesOpt));
				var varMonthlyRentIncomeOpt=parseFloat(formatViewAmount(monthlyRentIncomeOpt));
				
				var totalMonthlyFeeOpt=totalMonthlyPaymentOpt+varMonthlyMunicipalTaxOpt+varMonthlySchoolTaxOpt +varMonthlyCondoFeesOpt-varMonthlyRentIncomeOpt;
	
				if (!print) {			
					document.getElementById('totalMonthlyFeeOpt2').innerHTML = formatCurrency(formatAmount(totalMonthlyFeeOpt));
					document.getElementById('monthlyPaymentOpt2').innerHTML = formatCurrency(formatAmount(monthlyPaymentOpt));
					document.getElementById('monthlyInsurancePremiumOpt2').innerHTML = formatCurrency(varMonthlyInsuranceOpt);
					document.getElementById('totalMonthlyPaymentOpt2').innerHTML = formatCurrency(formatAmount(totalMonthlyPaymentOpt));
				}
				
				document.getElementById('downPaymentPercentageOpt').innerHTML ='<nobr>(' +formatPercentage(downPaymentPercentageOpt)+ ' %)</nobr>';

				if (varLang=='fr') {
					document.getElementById('mortgageAmountOpt').innerHTML = formatCurrency(formatAmount(mortgageAmountOpt)) + ' $';
					document.getElementById('insurancePremiumResultOpt').innerHTML = formatCurrency(formatAmount(insuranceOpt)) + ' $';
					document.getElementById('totalPropertyCostOpt').innerHTML = formatCurrency(formatAmount(propertyCostOpt)) + ' $';
				}
				else {
					document.getElementById('mortgageAmountOpt').innerHTML = '$ ' + formatCurrency(formatAmount(mortgageAmountOpt));
					document.getElementById('insurancePremiumResultOpt').innerHTML = '$ ' + formatCurrency(formatAmount(insuranceOpt));
					document.getElementById('totalPropertyCostOpt').innerHTML = '$ ' + formatCurrency(formatAmount(propertyCostOpt));
				}
				
				if ((!print) && (!keyPress)) {
					document.getElementById('resultInputOpt').value=formatCurrency(document.getElementById('resultInputOpt').value);
				}
				else if (!print) {
					document.borrowCapacityPrint.resultInputOpt.value = AmountValidToNumericFormat(document.borrowCapacity.resultInputOpt.value);
				}
				else if (print) {
					if (varLang=='fr') {
						document.getElementById('downPaymentResultOpt').innerHTML = formatCurrency(formatAmount(document.borrowCapacity.resultInputOpt.value)) + ' $';
					}
					else {
						document.getElementById('downPaymentResultOpt').innerHTML = '$ ' + formatCurrency(formatAmount(document.borrowCapacity.resultInputOpt.value));
					}
				}
			}
		}
	}	
}

function getInsurance (mortgageAmount, downPaymentPercentage) {
	var insurancePremiumPercentage = parseFloat(insurancePremium) / 100;
	
	if (downPaymentPercentage >= 20) {
		insurancePremiumPercentage = 0;
	} 
	else if(downPaymentPercentage >= 15 && downPaymentPercentage < 20) {
		insurancePremiumPercentage = parseFloat(insurancePremiumPercentageInterval15) / 100;
	}
	else if(downPaymentPercentage >= 10 && downPaymentPercentage < 15){
		insurancePremiumPercentage = parseFloat(insurancePremiumPercentageInterval10) / 100;
	}
	else if(downPaymentPercentage >= 5 && downPaymentPercentage < 10){
		insurancePremiumPercentage = parseFloat(insurancePremiumPercentageInterval5) / 100;
	}
	else if(downPaymentPercentage >= 0 && downPaymentPercentage < 5){
		insurancePremiumPercentage = parseFloat(insurancePremiumPercentageInterval0) / 100;
	}
	insurance = (mortgageAmount * insurancePremiumPercentage);
	
	return insurance;
}


function formatViewAmount(num) {
	num = num.toString().replace(/\$|\,/g,'');
	num= num.replace ("&nbsp;" ," ");
	return num;
}

function showMonthlyInsurancePremium(){
	if(isResult && !eligibiltyError ||eligibiltyError&&isComparaison ){		
		var varTotalMonthlyPayment = parseFloat(formatViewAmount(totalMonthlyPayment));
		var varMonthlyPayment	   = parseFloat(formatViewAmount(monthlyPayment));
		var varMonthlyInsurance    = varTotalMonthlyPayment-varMonthlyPayment;
		document.getElementById('monthlyInsurancePremium25').innerHTML = formatCurrency(varMonthlyInsurance);	
	}	
	
}

function showMonthlyInsurancePremiumOpt(){
	if(isComparaison && isResult && !eligibiltyOptError){		
		var varTotalMonthlyPaymentOpt =parseFloat(formatViewAmount(totalMonthlyPaymentOpt));
		var varMonthlyPaymentOpt	  =parseFloat(formatViewAmount(monthlyPaymentOpt));
		var varMonthlyInsuranceOpt   =varTotalMonthlyPaymentOpt-varMonthlyPaymentOpt;
		document.getElementById('monthlyInsurancePremiumOpt25').innerHTML = formatCurrency(varMonthlyInsuranceOpt);	
	}	
	
}

function formatCurrency(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	var s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	s=CommaFormatted(s);
	if (varLang=='fr'){
		return (s + ' $');
	}else{
		return ( '$ ' + s );
	}
	return s;
}

function simpleFormatCurrency(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	var s = new String(i);

	if (varLang=='fr'){
		return (s + ' $');
	}else{
		return ( '$ ' + s );
	}
	return s;
}

function formatFormValues(amount){
	if(!isWhiteSpace(amount.value)){
		amount.value=removeSeparator(amount);
		var i = parseFloat(amount.value);
		if(isNaN(i)) { i = 0.00; }
		var minus = '';
		if(i < 0) { minus = '-'; }
		i = Math.abs(i);
		i = parseInt((i + .005) * 100);
		i = i / 100;
		var s = new String(i);
		if(s.indexOf('.') < 0) { s += '.00'; }
		if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
		s = minus + s;
		return s; 
	}else{
		return amount.value;
	}
}
function initFormvalues(){
	document.borrowCapacity.income.value=formatDbAmount(document.borrowCapacity.income.value);
	document.borrowCapacity.coIncome.value=formatDbAmount(document.borrowCapacity.coIncome.value);
	document.borrowCapacity.carLoan.value=formatDbAmount(document.borrowCapacity.carLoan.value);
	document.borrowCapacity.coCarLoan.value=formatDbAmount(document.borrowCapacity.coCarLoan.value);
	document.borrowCapacity.personalLoan.value=formatDbAmount(document.borrowCapacity.personalLoan.value);
	document.borrowCapacity.coPersonalLoan.value=formatDbAmount(document.borrowCapacity.coPersonalLoan.value);
	document.borrowCapacity.pension.value=formatDbAmount(document.borrowCapacity.pension.value);
	document.borrowCapacity.coPension.value=formatDbAmount(document.borrowCapacity.coPension.value);
	document.borrowCapacity.creditCard.value=formatDbAmount(document.borrowCapacity.creditCard.value);
	document.borrowCapacity.coCreditCard.value=formatDbAmount(document.borrowCapacity.coCreditCard.value);
	document.borrowCapacity.lineOfCredit.value=formatDbAmount(document.borrowCapacity.lineOfCredit.value);
	document.borrowCapacity.coLineOfCredit.value=formatDbAmount(document.borrowCapacity.coLineOfCredit.value);
	document.borrowCapacity.lineOfCreditMortageGuarantee.value=formatDbAmount(document.borrowCapacity.lineOfCreditMortageGuarantee.value);
	document.borrowCapacity.coLineOfCreditMortageGuarantee.value=formatDbAmount(document.borrowCapacity.coLineOfCreditMortageGuarantee.value);
	document.borrowCapacity.municipalTax.value=formatDbAmount(document.borrowCapacity.municipalTax.value);
	document.borrowCapacity.schoolTax.value=formatDbAmount(document.borrowCapacity.schoolTax.value);
	document.borrowCapacity.heatingCosts.value=formatDbAmount(document.borrowCapacity.heatingCosts.value);
	document.borrowCapacity.condoFees.value=formatDbAmount(document.borrowCapacity.condoFees.value);
	document.borrowCapacity.rentIncome.value=formatDbAmount(document.borrowCapacity.rentIncome.value);
	document.borrowCapacity.municipalTaxOpt.value=formatDbAmount(document.borrowCapacity.municipalTaxOpt.value);
	document.borrowCapacity.schoolTaxOpt.value=formatDbAmount(document.borrowCapacity.schoolTaxOpt.value);
	document.borrowCapacity.heatingCostsOpt.value=formatDbAmount(document.borrowCapacity.heatingCostsOpt.value);
	document.borrowCapacity.condoFeesOpt.value=formatDbAmount(document.borrowCapacity.condoFeesOpt.value);
	document.borrowCapacity.rentIncomeOpt.value=formatDbAmount(document.borrowCapacity.rentIncomeOpt.value);
}
function formatDbAmount(amount)
{
	if(!isWhiteSpace(amount)){
		amount = amount.toString().replace(/\$|\,/g,'');
		if(isNaN(amount)){
			amount = "0";
		}
		
		var i = parseFloat(amount);
		if(isNaN(i)) { i = 0.00; }
		var minus = '';
		if(i < 0) { minus = '-'; }
		i = Math.abs(i);
		i = parseInt((i + .005) * 100);
		i = i / 100;
		var s = new String(i);
		if(s.indexOf('.') < 0) { s += '.00'; }
		//if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
		s = minus + s;
		s=CommaFormatted(s);
		return s;
	}else{
		return amount;
	}
}

function CommaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}


function formatPercentage(amount)
{
	amount = amount.toString().replace(/\$|\,/g,'');
	if(isNaN(amount)){
		amount = "0";
	}
	
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	var s = new String(i);
	if(s.indexOf('.') < 0) { s += '.0'; }
	//if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

function openPrintWindow(){
  print_window = window.open('','print_window','width=760,height=480,toolbar=0,menubar=0,status=0,scrollbars=1,resizable=1');
  return true;
}

function trackPage(imageName) {
	var trackImage = new Image(1,1);
	var trackNumber  = Math.round(Math.random() * 2147483647);
	trackImage.src = imageName+"?tr="+trackNumber;
	return 0;
}

function removeSeparator(objVal){
	var amount = objVal.value;
	var amount2 = removeCharacter(amount); 	
			
	amount2=trimAll(amount2); 
	return amount2;
}

function formatCurrency(amount)
{
    amount = removeCharacter(amount);
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	s=CommaFormatted(s);
	return s;
}

