//Calculateur Hypotheque
function checkForZero(field) {
	if (field.value == 0 || field.value.length == 0) {
		alert ("La valeur ne peut être 0!");
		field.focus(); }
	else
	calculatePayment(field.form);
}

function cmdCalc_Click(form) {
	if (form.price.value == 0 || form.price.value.length == 0) {
		alert ("Le prix ne peut être égale ou inférieur à 0!");
		form.price.focus(); }
	else if (form.ir.value == 0 || form.ir.value.length == 0) {
		alert ("Le taux d'intérêt ne peut être égale ou inférieur à 0!");
		form.ir.focus(); }
	else
		calculatePayment(form);
		return false;
}

function calculatePayment(form) {
	princ = form.price.value - form.dp.value;
	intRate = (form.ir.value/100) / 12;
	months = form.amortissement.value * 12;
	form.pmt.value = Math.floor((princ*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100;
	form.principle.value = princ;
	form.payments.value = months;
	}
	
/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

// starting the script on page load
$(document).ready(function(){
	tooltip();

	//LightBox
	$(function() {
		$('a#plan').lightBox();	
		$('a.light').lightBox();	
	});
});

