function verify_submit(){
	var isErrorFound = false;
	var isPropertyError=false;
	var isDownPaymentError=false;
	var isInterestRateError=false;
	var isPropertyOptError=false;
	var isDownPaymentOptError=false;
	var isInterestRateOptError=false;
	var isAmountError=false;
	var isAmountOptError=false;
	
	if (!calcFromAmount){
		//Validation du prix de la propriete
		if (!isValidMandatoryField('propertyCostDiv', 'mandatoryPropertyCost', document.monthlyPaymentForm.propertyCost,'propertyCostErrorMsg', false)){			
			isPropertyError=true;
			isErrorFound=true;
		}
		
		if (!isPropertyError && !isValidInput('propertyCostDiv', document.monthlyPaymentForm.propertyCost,'propertyCostErrorMsg', false)){		
			isErrorFound=true;
		}
	
		//Validation de la mise de fonds
		if ((document.monthlyPaymentForm.residenceTypeListChoice.value == 4) && (!isValidMandatoryField('downpaymentDiv', 'mandatoryDownPayment', document.monthlyPaymentForm.downpayment,'downPaymentErrorMsg', false))) {			
			isDownPaymentError=true;
			isErrorFound=true;
		}

		if (!isDownPaymentError && !isValidInput('downpaymentDiv', document.monthlyPaymentForm.downpayment,'downPaymentErrorMsg', false, true)){
			isDownPaymentError=true		
			isErrorFound=true;
		}
		
		if (!isDownPaymentError && !isValidDownPayment('downpaymentDiv', document.monthlyPaymentForm.downpayment,'downPaymentErrorMsg', false, false)){				
			isErrorFound=true;
		}
	}
	
	if (calcFromAmount){
		//Validation du montant de l'emprunt
		if (!isValidMandatoryField('loanAmountDiv', 'mandatoryLoanAmount', document.monthlyPaymentForm.loanAmount,'loanAmountErrorMsg', false)){			
			isAmountError=true;
			isErrorFound=true;
		}
		
		if (!isAmountError && !isValidInput('loanAmountDiv', document.monthlyPaymentForm.loanAmount,'loanAmountErrorMsg', false)){		
			isErrorFound=true;
		}		
	}
	//validation revenus de location
	if (document.monthlyPaymentForm.residenceTypeListChoice.selectedIndex==2 ||document.monthlyPaymentForm.residenceTypeListChoice.selectedIndex==3){
		if (!isValidInput('rentField2', document.monthlyPaymentForm.rentIncome,'rentIncomeErrorMsg', false)){	
			isErrorFound=true;
		}
	}else{
		document.monthlyPaymentForm.rentIncome.value="";
	}
	//Validation de la duree de remboursement
	if (!isValidDepreciationList('depreciationDiv', 'mandatoryDepreciation', document.monthlyPaymentForm.depreciationListChoice,'depreciationErrorMsg', false)){
		isErrorFound=true;
	}
		
	//Validation du taux d'interet
	if (!isValidMandatoryField('interestRateDiv', 'mandatoryInterestRate', document.monthlyPaymentForm.interestRate,'interestRateErrorMsg', false)){			
		isInterestRateError=true;
		isErrorFound=true;
	}
	
	if (!isInterestRateError && !isValidInputRate('interestRateDiv', document.monthlyPaymentForm.interestRate,'interestRateErrorMsg', false)){	
		isErrorFound=true;
	}

	
	//scenario de comparaison
	if (document.getElementById('compareCheckbox').checked == true){
		document.monthlyPaymentForm.bCompare.value="1";
		//Validation du type de residence
		if (!isValidMandatoryField('residenceTypeOptDiv', 'mandatoryTypeOfPropertyOpt', document.monthlyPaymentForm.residenceTypeListChoiceOpt,'residenceTypeOptErrorMsg', false)){
			isErrorFound=true;
		}
		
		if (!calcFromAmount){
			//Validation du prix de la propriete
			if (!isValidMandatoryField('propertyCostOptDiv', 'mandatoryPropertyCostOpt', document.monthlyPaymentForm.propertyCostOpt,'propertyCostOptErrorMsg', false)){			
				isPropertyOptError=true;
				isErrorFound=true;
			}
			
			if (!isPropertyOptError && !isValidInput('propertyCostOptDiv', document.monthlyPaymentForm.propertyCostOpt,'propertyCostOptErrorMsg', false)){		
				isErrorFound=true;
			}
			
			//Validation de la mise de fonds
			if ((document.monthlyPaymentForm.residenceTypeListChoiceOpt.value == 4) && (!isValidMandatoryField('downpaymentOptDiv', 'mandatoryDownpaymentOpt', document.monthlyPaymentForm.downpaymentOpt,'downpaymentOptErrorMsg', false))) {
				isDownPaymentOptError=true;
				isErrorFound=true;
			}
			
			if (!isDownPaymentOptError && !isValidInput('downpaymentOptDiv', document.monthlyPaymentForm.downpaymentOpt,'downpaymentOptErrorMsg', false, true)){
				isDownPaymentOptError=true		
				isErrorFound=true;
			}
			
			if (!isDownPaymentOptError && !isValidDownPayment('downpaymentOptDiv', document.monthlyPaymentForm.downpaymentOpt,'downpaymentOptErrorMsg', false, true)){	
				isErrorFound=true;
			}	
					
		}
		
		if (calcFromAmount){
			//validation du montant de l'emprunt
			if (!isValidMandatoryField('loanAmountOptDiv', 'mandatoryLoanAmountOpt', document.monthlyPaymentForm.loanAmountOpt,'loanAmountOptErrorMsg', false)){			
				isAmountOptError=true;
				isErrorFound=true;
			}
			
			if (!isAmountOptError && !isValidInput('loanAmountOptDiv', document.monthlyPaymentForm.loanAmountOpt,'loanAmountOptErrorMsg', false)){		
				isErrorFound=true;
			}
		}
		//validation revenus de location
		if (document.monthlyPaymentForm.residenceTypeListChoiceOpt.selectedIndex==3 ||document.monthlyPaymentForm.residenceTypeListChoiceOpt.selectedIndex==4){
			if (!isValidInput('rentFieldOpt2', document.monthlyPaymentForm.rentIncomeOpt,'rentIncomeOptErrorMsg', false)){	
				isErrorFound=true;
			}
		}else{
			document.monthlyPaymentForm.rentIncomeOpt.value="";
		}
		
		//Validation de la duree de remboursement		
		if (!validateDepreciationListOpt('depreciationOptDiv', 'mandatoryDepreciationOpt', document.monthlyPaymentForm.depreciationListChoiceOpt,'depreciationOptErrorMsg', false)){
			isErrorFound=true;
		}
		
		
		//Validation du taux d'interet
		if (!isValidMandatoryField('interestRateOptDiv', 'mandatoryInterestRateOpt', document.monthlyPaymentForm.interestRateOpt,'interestRateOptErrorMsg', false)){			
			isInterestRateOptError=true;
			isErrorFound=true;
		}
		
		if (!isInterestRateOptError && !isValidInputRate('interestRateOptDiv', document.monthlyPaymentForm.interestRateOpt,'interestRateOptErrorMsg', false)){	
			isErrorFound=true;
		}		
					
	}else{
		document.monthlyPaymentForm.bCompare.value="0";
	}
	
	if (isErrorFound) {
		if (!calcFromAmount){
			document.monthlyPaymentForm.propertyCost.value = formatCurrency(document.monthlyPaymentForm.propertyCost.value);	
			document.monthlyPaymentForm.downpayment.value = formatCurrency(document.monthlyPaymentForm.downpayment.value);	
			document.monthlyPaymentForm.rentIncome.value = formatCurrency(document.monthlyPaymentForm.rentIncome.value);
			document.monthlyPaymentForm.propertyCostOpt.value = formatCurrency(document.monthlyPaymentForm.propertyCostOpt.value);	
			document.monthlyPaymentForm.downpaymentOpt.value = formatCurrency(document.monthlyPaymentForm.downpaymentOpt.value);	
			document.monthlyPaymentForm.rentIncomeOpt.value = formatCurrency(document.monthlyPaymentForm.rentIncomeOpt.value);	
		}
		
		if (calcFromAmount){
			document.monthlyPaymentForm.loanAmount.value = formatCurrency(document.monthlyPaymentForm.loanAmount.value);	
			document.monthlyPaymentForm.loanAmountOpt.value = formatCurrency(document.monthlyPaymentForm.loanAmountOpt.value);	
		}

	}
	else {
		document.monthlyPaymentForm.loanAmount.value = removeCharacter(document.monthlyPaymentForm.loanAmount.value);
		document.monthlyPaymentForm.loanAmountOpt.value = removeCharacter(document.monthlyPaymentForm.loanAmountOpt.value);

		document.monthlyPaymentForm.propertyCost.value = removeCharacter(document.monthlyPaymentForm.propertyCost.value);	
		document.monthlyPaymentForm.downpayment.value = removeCharacter(document.monthlyPaymentForm.downpayment.value);	
		document.monthlyPaymentForm.rentIncome.value = removeCharacter(document.monthlyPaymentForm.rentIncome.value);
		document.monthlyPaymentForm.propertyCostOpt.value = removeCharacter(document.monthlyPaymentForm.propertyCostOpt.value);	
		document.monthlyPaymentForm.downpaymentOpt.value = removeCharacter(document.monthlyPaymentForm.downpaymentOpt.value);	
		document.monthlyPaymentForm.rentIncomeOpt.value = removeCharacter(document.monthlyPaymentForm.rentIncomeOpt.value);	
	}
	if (showGlobalErrorMsg(isErrorFound, true)){
		return false; 
	}else{	
		return true;
		
	}
}

function showResultSection(){
	document.getElementById("resultPage").style.display='';
	document.getElementById("resultPage").focus();
	document.getElementById("resultPage").style.display='none';	
	
}

function showResultSection2(){
	document.getElementById("resultPage2").style.display='';
	document.getElementById("resultPage2").focus();
	document.getElementById("resultPage2").style.display='none';	
	
}

function propertyCostData_Submit(){
	document.monthlyPaymentForm.residenceTypeListChoiceProperty.value=document.monthlyPaymentForm.residenceTypeListChoice[document.monthlyPaymentForm.residenceTypeListChoice.selectedIndex].value;
	document.monthlyPaymentForm.residenceTypeListChoice[document.monthlyPaymentForm.residenceTypeListChoice.selectedIndex].value=document.monthlyPaymentForm.residenceTypeListChoiceAmount.value;	
	if (document.getElementById('compareCheckbox').checked == true){
		document.monthlyPaymentForm.bCompareProperty.value="1";
	}else{
		document.monthlyPaymentForm.bCompareProperty.value="0";
	}

	document.monthlyPaymentForm.bCompare.value=document.monthlyPaymentForm.bCompareAmount.value;	
	
	if(document.monthlyPaymentForm.bCompare.value=="1"){
		document.getElementById('compareCheckbox').checked = true;
		activateDeactivateFields();
	}
	
	document.monthlyPaymentForm.residenceTypeListChoicePropertyOpt.value=document.monthlyPaymentForm.residenceTypeListChoiceOpt[document.monthlyPaymentForm.residenceTypeListChoiceOpt.selectedIndex].value;
	document.monthlyPaymentForm.residenceTypeListChoiceOpt[document.monthlyPaymentForm.residenceTypeListChoiceOpt.selectedIndex].value=document.monthlyPaymentForm.residenceTypeListChoiceAmountOpt.value;		
	document.monthlyPaymentForm.rentIncomeProperty.value=document.monthlyPaymentForm.rentIncome.value;
	document.monthlyPaymentForm.rentIncome.value=removeCharacter(document.monthlyPaymentForm.rentIncomeAmount.value);	
	document.monthlyPaymentForm.rentIncomePropertyOpt.value=removeCharacter(document.monthlyPaymentForm.rentIncomeOpt.value);
	document.monthlyPaymentForm.rentIncomeOpt.value=removeCharacter(document.monthlyPaymentForm.rentIncomeAmountOpt.value);	
	document.monthlyPaymentForm.depreciationListChoiceProperty.value=document.monthlyPaymentForm.depreciationListChoice[document.monthlyPaymentForm.depreciationListChoice.selectedIndex].value;
	document.monthlyPaymentForm.depreciationListChoice[document.monthlyPaymentForm.depreciationListChoice.selectedIndex].value=document.monthlyPaymentForm.depreciationListChoiceAmount.value;	
	document.monthlyPaymentForm.depreciationListChoicePropertyOpt.value=document.monthlyPaymentForm.depreciationListChoiceOpt[document.monthlyPaymentForm.depreciationListChoiceOpt.selectedIndex].value;
	document.monthlyPaymentForm.depreciationListChoiceOpt[document.monthlyPaymentForm.depreciationListChoiceOpt.selectedIndex].value=document.monthlyPaymentForm.depreciationListChoiceAmountOpt.value;		
	document.monthlyPaymentForm.interestRateProperty.value=document.monthlyPaymentForm.interestRate.value;
	document.monthlyPaymentForm.interestRate.value=document.monthlyPaymentForm.interestRateAmount.value;
	document.monthlyPaymentForm.interestRatePropertyOpt.value=document.monthlyPaymentForm.interestRateOpt.value;
	document.monthlyPaymentForm.interestRateOpt.value=document.monthlyPaymentForm.interestRateAmountOpt.value;		
	
	if (document.monthlyPaymentForm.loanAmount.value.length > 0) {
		document.monthlyPaymentForm.action.value = "42";
		document.monthlyPaymentForm.aliasDispatcher.value = "monthlyPaymentResult";
		document.monthlyPaymentForm.fromTab.value = "true";
	}
	else {
		document.monthlyPaymentForm.action.value = "41";
		document.monthlyPaymentForm.aliasDispatcher.value = "monthlyPayment";
		document.monthlyPaymentForm.fromTab.value = "false";
	}
	document.monthlyPaymentForm.calcFromAmount.value="1";

	document.monthlyPaymentForm.loanAmount.value = removeCharacter(document.monthlyPaymentForm.loanAmount.value);
	document.monthlyPaymentForm.loanAmountOpt.value = removeCharacter(document.monthlyPaymentForm.loanAmountOpt.value);

	document.monthlyPaymentForm.propertyCost.value = removeCharacter(document.monthlyPaymentForm.propertyCost.value);	
	document.monthlyPaymentForm.downpayment.value = removeCharacter(document.monthlyPaymentForm.downpayment.value);	
	document.monthlyPaymentForm.rentIncome.value = removeCharacter(document.monthlyPaymentForm.rentIncome.value);
	document.monthlyPaymentForm.propertyCostOpt.value = removeCharacter(document.monthlyPaymentForm.propertyCostOpt.value);	
	document.monthlyPaymentForm.downpaymentOpt.value = removeCharacter(document.monthlyPaymentForm.downpaymentOpt.value);	
	document.monthlyPaymentForm.rentIncomeOpt.value = removeCharacter(document.monthlyPaymentForm.rentIncomeOpt.value);	
	document.monthlyPaymentForm.submit();
}

function amountData_Submit(){

	document.monthlyPaymentForm.residenceTypeListChoiceAmount.value=document.monthlyPaymentForm.residenceTypeListChoice[document.monthlyPaymentForm.residenceTypeListChoice.selectedIndex].value;
	document.monthlyPaymentForm.residenceTypeListChoice[document.monthlyPaymentForm.residenceTypeListChoice.selectedIndex].value=document.monthlyPaymentForm.residenceTypeListChoiceProperty.value;	
	
	if (document.getElementById('compareCheckbox').checked == true){
		document.monthlyPaymentForm.bCompareAmount.value="1";
	}else{
		document.monthlyPaymentForm.bCompareAmount.value="0";
	}
	
	document.monthlyPaymentForm.bCompare.value=document.monthlyPaymentForm.bCompareProperty.value;
	
	if(document.monthlyPaymentForm.bCompare.value=="1"){
		document.getElementById('compareCheckbox').checked = true;
		activateDeactivateFields();
	}
		
	document.monthlyPaymentForm.residenceTypeListChoiceAmountOpt.value=document.monthlyPaymentForm.residenceTypeListChoiceOpt[document.monthlyPaymentForm.residenceTypeListChoiceOpt.selectedIndex].value;
	document.monthlyPaymentForm.residenceTypeListChoiceOpt[document.monthlyPaymentForm.residenceTypeListChoiceOpt.selectedIndex].value=document.monthlyPaymentForm.residenceTypeListChoicePropertyOpt.value;		
	
	document.monthlyPaymentForm.rentIncomeAmount.value=removeCharacter(document.monthlyPaymentForm.rentIncome.value);
	document.monthlyPaymentForm.rentIncome.value=removeCharacter(document.monthlyPaymentForm.rentIncomeProperty.value);	
	document.monthlyPaymentForm.rentIncomeAmountOpt.value=removeCharacter(document.monthlyPaymentForm.rentIncomeOpt.value);
	document.monthlyPaymentForm.rentIncomeOpt.value=removeCharacter(document.monthlyPaymentForm.rentIncomePropertyOpt.value);		
	document.monthlyPaymentForm.depreciationListChoiceAmount.value=document.monthlyPaymentForm.depreciationListChoice[document.monthlyPaymentForm.depreciationListChoice.selectedIndex].value;
	document.monthlyPaymentForm.depreciationListChoice[document.monthlyPaymentForm.depreciationListChoice.selectedIndex].value=document.monthlyPaymentForm.depreciationListChoiceProperty.value;	
	document.monthlyPaymentForm.depreciationListChoiceAmountOpt.value=document.monthlyPaymentForm.depreciationListChoiceOpt[document.monthlyPaymentForm.depreciationListChoiceOpt.selectedIndex].value;
	document.monthlyPaymentForm.depreciationListChoiceOpt[document.monthlyPaymentForm.depreciationListChoiceOpt.selectedIndex].value=document.monthlyPaymentForm.depreciationListChoicePropertyOpt.value;		
	document.monthlyPaymentForm.interestRateAmount.value=document.monthlyPaymentForm.interestRate.value;
	document.monthlyPaymentForm.interestRate.value=document.monthlyPaymentForm.interestRateProperty.value;
	document.monthlyPaymentForm.interestRateAmountOpt.value=document.monthlyPaymentForm.interestRateOpt.value;
	document.monthlyPaymentForm.interestRateOpt.value=document.monthlyPaymentForm.interestRatePropertyOpt.value;
	
	if (document.monthlyPaymentForm.propertyCost.value.length > 0) {
		document.monthlyPaymentForm.action.value = "42";
		document.monthlyPaymentForm.aliasDispatcher.value = "monthlyPaymentResult";
		document.monthlyPaymentForm.fromTab.value = "true";
	}
	else {
		document.monthlyPaymentForm.action.value = "41";
		document.monthlyPaymentForm.aliasDispatcher.value = "monthlyPayment";
		document.monthlyPaymentForm.fromTab.value = "false";
	}
	document.monthlyPaymentForm.calcFromAmount.value="0";				

	document.monthlyPaymentForm.loanAmount.value = removeCharacter(document.monthlyPaymentForm.loanAmount.value);
	document.monthlyPaymentForm.loanAmountOpt.value = removeCharacter(document.monthlyPaymentForm.loanAmountOpt.value);

	document.monthlyPaymentForm.propertyCost.value = removeCharacter(document.monthlyPaymentForm.propertyCost.value);	
	document.monthlyPaymentForm.downpayment.value = removeCharacter(document.monthlyPaymentForm.downpayment.value);	
	document.monthlyPaymentForm.rentIncome.value = removeCharacter(document.monthlyPaymentForm.rentIncome.value);
	document.monthlyPaymentForm.propertyCostOpt.value = removeCharacter(document.monthlyPaymentForm.propertyCostOpt.value);	
	document.monthlyPaymentForm.downpaymentOpt.value = removeCharacter(document.monthlyPaymentForm.downpaymentOpt.value);	
	document.monthlyPaymentForm.rentIncomeOpt.value = removeCharacter(document.monthlyPaymentForm.rentIncomeOpt.value);	
	
	document.monthlyPaymentForm.submit();
}


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 = j0181;
		document.getElementById('globalErrorMsg').style.display='block';
		return true;
	}else{
		document.getElementById('globalError').innerHTML = '&nbsp;';
		document.getElementById('globalErrorMsg').style.display='none';
		return false;
	}
}
function validateRateField(divId, starId, field, fieldErrorMsg,showErrorMsg){
	if (isValidMandatoryField(divId, starId, field, fieldErrorMsg,showErrorMsg)){
		if(isValidInputRate(divId, field, fieldErrorMsg, showErrorMsg)){
			return true;
		}
	}
	return false;
}
function validateMandatoryField(divId, starId, field, fieldErrorMsg,showErrorMsg){
	if (isValidMandatoryField(divId, starId, field, fieldErrorMsg,showErrorMsg)){
		if(isValidInput(divId, field, fieldErrorMsg, showErrorMsg)){
			field.value = formatCurrency(field.value, false);
			return true;
		}
	}
	return false;
}

function validateFieldDownPayment(divId, starId, field, fieldResidenceType, fieldErrorMsg,showErrorMsg, optionalScenario){
	if ((fieldResidenceType.value != 4) || isValidMandatoryField(divId, starId, field, fieldErrorMsg,showErrorMsg)) {
		if(isValidInput(divId, field, fieldErrorMsg, showErrorMsg, true)){
			if(isValidDownPayment(divId, field, fieldErrorMsg, showErrorMsg, optionalScenario)){
			    field.value = formatCurrency(field.value, false);
				return true;
			}
		}
	}
	else if (fieldResidenceType.value != 4) {
		alert(fieldResidenceType);
		field.value = "0.00"
	}
	return false;
}

function validateDepreciationListOpt(divId, starId, field, fieldErrorMsg,showErrorMsg){	
	if(isValidDepreciationList(divId, starId, field, fieldErrorMsg,showErrorMsg)){
		return true;
	}		
	return false;
}

function isValidDepreciationList(divId, starId, field, fieldErrorMsg,showErrorMsg){
	var isError=false;
	//field[field.selectedIndex].value
	if (field[field.selectedIndex].text == "-- --") {
		isError=true;
	}
	
	if (isError){		
		document.getElementById(fieldErrorMsg).innerHTML = j0173;
		document.getElementById(fieldErrorMsg).style.display ='block';
		document.getElementById(divId).className='invalidInput';
		document.getElementById(starId).className='textErrorRed';		
		return false;
	}
	document.getElementById(fieldErrorMsg).innerHTML = '&nbsp;';
	document.getElementById(fieldErrorMsg).style.display ='none';
	document.getElementById(divId).className='validInput';
	document.getElementById(starId).className='text';
	return true;
}

function isValidMandatoryField(divId, starId, field, fieldErrorMsg,showErrorMsg){
	var isError=false;
	if (field.tagName=='INPUT'){
		if (isWhiteSpace(field.value)){
			isError=true;
		}
	}
	if (field.tagName=='SELECT'){
		if (field.selectedIndex == 0){
			isError=true;
		}
	}
	if ((isError) && !showErrorMsg) {		
		document.getElementById(fieldErrorMsg).innerHTML = j0173;
		document.getElementById(fieldErrorMsg).style.display ='block';
		document.getElementById(divId).className='invalidInput';
		document.getElementById(starId).className='textErrorRed';		
		return false;
	}
	document.getElementById(fieldErrorMsg).innerHTML = '&nbsp;';
	document.getElementById(fieldErrorMsg).style.display ='none';
	document.getElementById(divId).className='validInput';
	document.getElementById(starId).className='text';	
	return true;
}

function isValidInput(divId, field, fieldErrorMsg, showErrorMsg, acceptZero){
	if (!isWhiteSpace(field.value)){
		if(!validateAmount(fieldErrorMsg, field, acceptZero)){
			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 isValidDownPayment(divId, field, fieldErrorMsg, showErrorMsg, optionalScenario){
	var isErrorFound=false;
	var isErrorExcess=false;
	if (!isWhiteSpace(field.value)){ 
		if (!optionalScenario){
			var propertyPrice=removeSeparator(document.monthlyPaymentForm.propertyCost);
			propertyPrice=parseFloat(propertyPrice);
			var downPaymentValue=removeSeparator(field);
			downPaymentValue=parseFloat(downPaymentValue);
						
			if(downPaymentValue>=propertyPrice){				
				isErrorExcess=true;
			}
			if(!isErrorExcess && field.value<calculateDownPayment(document.monthlyPaymentForm.propertyCost,'minimumDownPayment',false)){
				isErrorFound=true;
			}
		}
		
		if (optionalScenario){
			var propertyPriceOpt=removeSeparator(document.monthlyPaymentForm.propertyCostOpt);
			propertyPriceOpt=parseFloat(propertyPriceOpt);
			var downPaymentValueOpt=removeSeparator(field);
			downPaymentValueOpt=parseFloat(downPaymentValueOpt);
						
			if(downPaymentValueOpt>=propertyPriceOpt){				
				isErrorExcess=true;
			}
						
			if(field.value<calculateDownPayment(document.monthlyPaymentForm.propertyCostOpt,'minimumDownPaymentOpt',true)){
				isErrorFound=true;
			}
		}
		
		if(isErrorExcess){
			document.getElementById(divId).className='invalidInput';
			document.getElementById(fieldErrorMsg).innerHTML = j0187; 
			document.getElementById(fieldErrorMsg).style.display='block';			
			return false;
		}

		if(isErrorFound){
			document.getElementById(divId).className='invalidInput';
			document.getElementById(fieldErrorMsg).innerHTML = j0188; 
			document.getElementById(fieldErrorMsg).style.display='block';			
			return false;
		}
	}
	
	document.getElementById(divId).className='validInput';
	document.getElementById(fieldErrorMsg).innerHTML = '&nbsp;'; 
	document.getElementById(fieldErrorMsg).style.display='none';	

	return true;	
}

function showAdditionalPropertyField(firstPropertyCombo){	
	if (firstPropertyCombo){				
		if (document.monthlyPaymentForm.residenceTypeListChoice.selectedIndex==2 ||document.monthlyPaymentForm.residenceTypeListChoice.selectedIndex==3){		
			for (i=1; i<=3; i++){
				var field='rentField';
				field+=i;
				document.getElementById(field).style.display = 'block';
			}
			document.getElementById('rentIncomeErrorMsg').style.display='block';
		}else{
			for (i=1; i<=3; i++){
				var field='rentField';
				field+=i;
				document.getElementById(field).style.display = 'none';
			}
		}
		document.getElementById('rentField2').className='validInput';
		document.getElementById('rentIncomeErrorMsg').innerHTML = '&nbsp;'; 
		document.getElementById('rentIncomeErrorMsg').style.display='none';		
	}else{
		if (document.monthlyPaymentForm.residenceTypeListChoiceOpt.selectedIndex==3 ||document.monthlyPaymentForm.residenceTypeListChoiceOpt.selectedIndex==4){		
			for (i=1; i<=3; i++){
				var field='rentFieldOpt';
				field+=i;
				document.getElementById(field).style.display = 'block';
			}					
		}else{
			for (i=1; i<=3; i++){
				var field='rentFieldOpt';
				field+=i;
				document.getElementById(field).style.display = 'none';
			}			
		}
		document.getElementById('rentFieldOpt2').className='validInput';
		document.getElementById('rentIncomeOptErrorMsg').innerHTML = '&nbsp;'; 
		document.getElementById('rentIncomeOptErrorMsg').style.display='none';			
	}
}
function activateDeactivateFields(){

	if (document.getElementById('compareCheckbox').checked == true){
		document.getElementById('typeOfPropertyText').className='text';
		
		if(!calcFromAmount){
			document.getElementById('propertyCostText').className='text';
			document.getElementById('propertyDollarSign').className='text';
			document.getElementById('mandatoryPropertyCostOpt').className='text';
			document.getElementById('downpaymentText').className='text';
			document.getElementById('downpaymentOptDollarSign').className='text';
			document.getElementById('minimumDownPaymentOpt').className='text';
			document.getElementById('mandatoryDownpaymentOpt').className='text';
			document.getElementById('propertyCostOpt').disabled=false;
			document.getElementById('downpaymentOpt').disabled=false;
		}else if (calcFromAmount){
			document.getElementById('loanAmountText').className='text';
			document.getElementById('loanAmountOptDollarSign').className='text';
			document.getElementById('mandatoryLoanAmountOpt').className='text';
			document.getElementById('loanAmountOpt').disabled=false;
		}
		document.getElementById('mandatoryTypeOfPropertyOpt').className='text';
		document.getElementById('rentIncomeText').className='text';
		document.getElementById('rentIncomeOptDollarSign').className='text';
		document.getElementById('depreciationText').className='text';
		document.getElementById('depreciationYearLabel').className='text';
		document.getElementById('mandatoryDepreciationOpt').className='text';
		document.getElementById('interestRateText').className='text';
		document.getElementById('interestRateOptPercent').className='text';
		document.getElementById('mandatoryInterestRateOpt').className='text';
		document.getElementById('residenceTypeListChoiceOpt').disabled=false;		
		document.getElementById('depreciationListChoiceOpt').disabled=false;
		document.getElementById('interestRateOpt').disabled=false;
		document.getElementById('rentIncomeOpt').disabled=false;
				
	
	}else{		
		document.getElementById('typeOfPropertyText').className='textDisabled';
		if(!calcFromAmount){
			document.getElementById('propertyCostText').className='textDisabled';
			document.getElementById('propertyDollarSign').className='textDisabled';
			document.getElementById('mandatoryPropertyCostOpt').className='textDisabled';
			document.getElementById('downpaymentText').className='textDisabled';
			document.getElementById('downpaymentOptDollarSign').className='textDisabled';
			document.getElementById('minimumDownPaymentOpt').className='textDisabled';
			document.getElementById('mandatoryDownpaymentOpt').className='textDisabled';
			document.getElementById('propertyCostOpt').disabled=true;		
			document.getElementById('downpaymentOpt').disabled=true;
		}else  if (calcFromAmount){
			document.getElementById('loanAmountText').className='textDisabled';
			document.getElementById('loanAmountOptDollarSign').className='textDisabled';
			document.getElementById('mandatoryLoanAmountOpt').className='textDisabled';
			document.getElementById('loanAmountOpt').disabled=true;
		}
		document.getElementById('mandatoryTypeOfPropertyOpt').className='textDisabled';
		document.getElementById('rentIncomeText').className='textDisabled';
		document.getElementById('rentIncomeOptDollarSign').className='textDisabled';
		document.getElementById('depreciationText').className='textDisabled';
		document.getElementById('depreciationYearLabel').className='textDisabled';
		document.getElementById('mandatoryDepreciationOpt').className='textDisabled';
		document.getElementById('interestRateText').className='textDisabled';
		document.getElementById('interestRateOptPercent').className='textDisabled';
		document.getElementById('mandatoryInterestRateOpt').className='textDisabled';
		document.getElementById('residenceTypeListChoiceOpt').disabled=true;		
		document.getElementById('depreciationListChoiceOpt').disabled=true;
		document.getElementById('interestRateOpt').disabled=true;
		document.getElementById('rentIncomeOpt').disabled=true;	
		removeOptionalScenarioErrorMessages();		
	}	
}

function calculateDownPayment(propertyCostField, spanResult, optionalScenario){
	if(!calcFromAmount){
		if (!isWhiteSpace(propertyCostField.value) && propertyCostField.value>0){
			var propertyPrice=removeSeparator(propertyCostField); 					
			propertyPrice=parseFloat(propertyPrice);		
			var downPayment=0;
			var downPaymentPercentage=0;
			
			if(!optionalScenario){
				//unifamiliale ou condo
				if (document.monthlyPaymentForm.residenceTypeListChoice.selectedIndex==0 || document.monthlyPaymentForm.residenceTypeListChoice.selectedIndex==1){
					downPayment=propertyPrice*rateDownPaymentCondo;
					downPaymentPercentage=rateDownPaymentCondo*100;
				}
				
				//Duplex
				if (document.monthlyPaymentForm.residenceTypeListChoice.selectedIndex==2){
					downPayment=propertyPrice*rateDownPaymentDuplex;
					downPaymentPercentage=rateDownPaymentDuplex*100;
				}
				
				//Triplex
				if (document.monthlyPaymentForm.residenceTypeListChoice.selectedIndex==3){
					downPayment=propertyPrice*rateDownPaymentTriplex;
					downPaymentPercentage=rateDownPaymentTriplex*100;
				}
				
			}
			
			if(optionalScenario){
				if(document.monthlyPaymentForm.residenceTypeListChoiceOpt.selectedIndex==0){
					document.getElementById(spanResult).innerHTML = '&nbsp';
					return 0;
				}else{
					//unifamiliale ou condo
					if (document.monthlyPaymentForm.residenceTypeListChoiceOpt.selectedIndex==1 || document.monthlyPaymentForm.residenceTypeListChoiceOpt.selectedIndex==2){
						downPayment=propertyPrice*rateDownPaymentCondo;
						downPaymentPercentage=rateDownPaymentCondo*100;
					}
					
					//Duplex
					if (document.monthlyPaymentForm.residenceTypeListChoiceOpt.selectedIndex==3){
						downPayment=propertyPrice*rateDownPaymentDuplex;
						downPaymentPercentage=rateDownPaymentDuplex*100;
					}
					
					//Triplex
					if (document.monthlyPaymentForm.residenceTypeListChoiceOpt.selectedIndex==4){
						downPayment=propertyPrice*rateDownPaymentTriplex;
						downPaymentPercentage=rateDownPaymentTriplex*100;
					}	
				}	
			}
			
			//downPaymentPercentage = (downPayment/propertyPrice)*100;
			downPaymentString=formatCurrency(formatAmount(downPayment), true);	
			document.getElementById(spanResult).innerHTML = '(' + downPaymentPercentage+ '% =' + downPaymentString +')';
			
			return downPayment;
		}
	}
}

function formatCurrency(amount, dollarSign)
{
	var i = parseFloat(removeCharacter(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);
	if (dollarSign == true) {
		if (varLang=='fr'){
			return (s + ' $');
		}else{
			return ( '$ ' + s );
		}
	}
	return s;
}


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 showMinimumDownPaymentPercentage(){
	if (!calcFromAmount){
		var condoMinimumdownPaymentPercentage=0.05;
		var duplexMinimumdownPaymentPercentage=0.05;
		var triplexMinimumdownPaymentPercentage=0;

		condoMinimumdownPaymentPercentage=rateDownPaymentCondo*100;
		duplexMinimumdownPaymentPercentage=rateDownPaymentDuplex*100;
		triplexMinimumdownPaymentPercentage=rateDownPaymentTriplex*100;
		
		document.getElementById('condoMinimumPercentage').innerHTML =condoMinimumdownPaymentPercentage;	
		//document.getElementById('duplexMinimumPercentage').innerHTML =duplexMinimumdownPaymentPercentage;	
		document.getElementById('triplexMinimumPercentage').innerHTML =triplexMinimumdownPaymentPercentage;	
	}
}

function removeOptionalScenarioErrorMessages(){
    document.getElementById('residenceTypeOptDiv').className='validInput';
    if (!calcFromAmount){
    	document.getElementById('propertyCostOptDiv').className='validInput';
    	document.getElementById('downpaymentOptDiv').className='validInput';
    	document.getElementById('propertyCostOptErrorMsg').innerHTML = '&nbsp;'; 
		document.getElementById('propertyCostOptErrorMsg').style.display='none';
		document.getElementById('downpaymentOptErrorMsg').innerHTML = '&nbsp;'; 
		document.getElementById('downpaymentOptErrorMsg').style.display='none';
		
    }
    if (calcFromAmount){
    	document.getElementById('loanAmountOptDiv').className='validInput';
    	document.getElementById('loanAmountOptErrorMsg').innerHTML = '&nbsp;'; 
		document.getElementById('loanAmountOptErrorMsg').style.display='none';
    }
	
	document.getElementById('rentFieldOpt2').className='validInput';	
	document.getElementById('depreciationOptDiv').className='validInput';
	document.getElementById('interestRateOptDiv').className='validInput';	
	document.getElementById('residenceTypeOptErrorMsg').innerHTML = '&nbsp;'; 
	document.getElementById('residenceTypeOptErrorMsg').style.display='none';	
	document.getElementById('rentIncomeOptErrorMsg').innerHTML = '&nbsp;'; 
	document.getElementById('rentIncomeOptErrorMsg').style.display='none';	
	document.getElementById('depreciationOptErrorMsg').innerHTML = '&nbsp;'; 
	document.getElementById('depreciationOptErrorMsg').style.display='none';
	document.getElementById('interestRateOptErrorMsg').innerHTML = '&nbsp;'; 
	document.getElementById('interestRateOptErrorMsg').style.display='none';
}

function removeErrorMessages(firstCombo){
	if(firstCombo){
		if (!calcFromAmount){
			document.getElementById('propertyCostDiv').className='validInput';
			document.getElementById('propertyCostErrorMsg').innerHTML = '&nbsp;'; 
			document.getElementById('propertyCostErrorMsg').style.display='none';			
			document.getElementById('mandatoryPropertyCost').className='text';
			document.getElementById('mandatoryDownPayment').className='text';
			document.getElementById('downPaymentErrorMsg').innerHTML = '&nbsp;'; 
			document.getElementById('downPaymentErrorMsg').style.display='none';	
			document.getElementById('downpaymentDiv').className='validInput';			
		}
		document.getElementById('rentField2').className='validInput';
		document.getElementById('rentIncomeErrorMsg').innerHTML = '&nbsp;'; 
		document.getElementById('rentIncomeErrorMsg').style.display='none';
	}else{
		if (!calcFromAmount){
			document.getElementById('propertyCostOptDiv').className='validInput';
			document.getElementById('mandatoryPropertyCostOpt').className='text';
			document.getElementById('propertyCostErrorMsg').innerHTML = '&nbsp;'; 
			document.getElementById('propertyCostErrorMsg').style.display='none';
			document.getElementById('mandatoryDownpaymentOpt').className='text';
			document.getElementById('downpaymentOptErrorMsg').innerHTML = '&nbsp;'; 
			document.getElementById('downpaymentOptErrorMsg').style.display='none';
			document.getElementById('downpaymentOptDiv').className='validInput';			
		}
		document.getElementById('rentFieldOpt2').className='validInput';
		document.getElementById('rentIncomeOptErrorMsg').innerHTML = '&nbsp;'; 
		document.getElementById('rentIncomeOptErrorMsg').style.display='none';
	}
	
}

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, tableToHide, windowFirstSectionLink, windowResultSecondSection1, windowResultSecondSection2){
	if (document.getElementById(tableToShow).style.display == 'none'){
		document.getElementById(windowFirstSectionLink).style.display = 'none';
		document.getElementById(tableToHide).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 isValidInputRate(divId, field, fieldErrorMsg, showErrorMsg){
	if (!isWhiteSpace(field.value)){
		
		if(!validateRate(fieldErrorMsg, field)||!IsNumeric(field.value)){
			document.getElementById(divId).className='invalidInput';
			document.getElementById(fieldErrorMsg).innerHTML = j0174;  
			document.getElementById(fieldErrorMsg).style.display='block';									
			return false;
		}
	}
	document.getElementById(divId).className='validInput';
	document.getElementById(fieldErrorMsg).innerHTML = '&nbsp;';	
	document.getElementById(fieldErrorMsg).style.display='none';		
	return true;	
}

function validateRate(fieldErrorMsg,objVal)
{

	objValue=trimAll(objVal.value); 
	var strValidDecimalPart = "0123456789";	
	var decimalPos = objValue.indexOf('.');
	
	if (objValue.value != ""){ 
		if (decimalPos==-1){
			
			if (objValue.length > 2) {
				document.getElementById(fieldErrorMsg).innerHTML = j0174;  
				return false;
			} else{
				
				for (j=0;j<objValue.length;j++) {
					if (objValue.indexOf(objValue.charAt(j))==-1) {
						document.getElementById(fieldErrorMsg).innerHTML = j0174;  
						return false;
					}
				}
			}
				
		} else {
		
			var tempVal = objValue.substring(decimalPos + 1)
		
			if (tempVal.length > 2){
				document.getElementById(fieldErrorMsg).innerHTML = j0174;  
				return false;
				
			} else{
				
				for (j=0;j<tempVal.length;j++) {
					if (tempVal.indexOf(tempVal.charAt(j))==-1) {
						document.getElementById(fieldErrorMsg).innerHTML = j0174;  
						return false;
					}
				}
				
				tempVal = objValue.substring(0, decimalPos)
				
				if (tempVal.length > 2) {
					document.getElementById(fieldErrorMsg).innerHTML = j0174;  
					return false;
				} else{
					
					for (j=0;j<tempVal.length;j++) {
						if (tempVal.indexOf(tempVal.charAt(j))==-1) {
							document.getElementById(fieldErrorMsg).innerHTML = j0174;  
							return false;
						}
					}
				}
			}
		}
	}
	document.getElementById(fieldErrorMsg).innerHTML = '&nbsp;';  			
	return true;	
		
}
function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   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 removeSeparator(objVal){
	var amount = objVal.value;
	var amount2 = removeCharacter(amount); 	
			
	amount2=trimAll(amount2); 
	return amount2;
} 
 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;
}
