/**
 **************************************************************
 *  SECTION POUR LA CALCULETTE
 **************************************************************
 */
function checkAndSubmit(lang) {  
    
    var downpayment = document.hypoForm.downPayment.value;
    var mortgage = document.hypoForm.mortgage.value;
    var price = document.hypoForm.price.value;
    var amortization = document.hypoForm.amortization.value;
    var frequency = document.hypoForm.frequency.value;
    var interest = document.hypoForm.interest.value;
    
    if (document.hypoForm.downPayment.value == '') {
        downpayment = 0;
    }
    
    
    
    /*
     *  VALIDATION EFFECTUÉE ET CALCUL DE L'HYPOTHEQUE
     */
    var parameter = '/calculette/' + price + '/' + downpayment + '/' + mortgage + '/' + interest + '/' + amortization + '/' + frequency;
    var path = contextPath + parameter + '/' + 'calculateMortgage.rmx';
    http('GET', path, getMortgageTotal);
    
    /*
     *  AJOUT DE LA VALIDATION ICI!
     */
    if ((document.hypoForm.price.value < document.hypoForm.downPayment.value) && (lang == 'fr')) {
        //alert('La mise de fond ne peut pas &ecirc;tre plus grande ou &eacute;gal au prix de la propri&eacute;t&eacute;');
    }   
    else if ((document.hypoForm.price.value < document.hypoForm.downPayment.value) && (lang == 'en')) {
        //alert('Downpayment cannot be higher or equal to the property price');    
    }
    else {
        
        
    }
    
}

function calculateTotalMortgage() {
    
    var mortgage = document.hypoForm.price.value - document.hypoForm.downPayment.value;
    
    if (mortgage > 0) {
        document.hypoForm.mortgage.value = mortgage;
    }
    else {
        document.hypoForm.mortgage.value = document.hypoForm.price.value;
        document.hypoForm.downPayment.value = 0;
    }
}

function validateCalculetteData(lang) {
    
}

function numbersonly(myfield, e, dec)
{

var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return true;
   }
else
   return false;
}



function getMortgageTotal(obj) {
    try {
        document.getElementById('mortgageTotal').innerHTML = obj;
    }
    catch (e) {}
    
    document.getElementById('paymentByMonth').value = obj;
}
