function bookmark() {
 if (navigator.appName == 'Microsoft Internet Explorer') {
	 window.external.AddFavorite(document.location.href, document.title);
 }
 else {
	 window.sidebar.addPanel(document.title, document.location.href, '');
 }
} 

var lastslidenb = -1;
function slideOnBlock(nb){
	if (lastslidenb == nb) {
		$('.graybox').slideUp();
		$('.graybox_top').slideUp();
		lastslidenb = -1;
		return false;
	}
	$('.graybox_top').slideDown();
	$('.graybox').slideUp();
	$('.graybox:eq('+ nb +')').slideDown();
	lastslidenb = nb;
	return false;
}

function toggleTime( x ) {
	$("#heure_" + x.value).toggle();
}

function Estim(){
	var price = 15.64;
	var majored_price = 16.69;
	var total = 0 ;
	var reduc = 0;
	$("#estim input").each(function (index){
		var base = $(this).parent().parent();
		$(this).val($(this).val().replace(",", "."))
		$(this).val($(this).val().replace("h", "."))
		if( IsNumeric($(this).val())) {
			if($(this).hasClass('deductible')) {
				var cur = $(this).val() * price;
				cur = Math.round(cur*100)/100;
				var cur_reduc = $(this).val() * price / 2;
				cur_reduc = Math.round(cur_reduc*100)/100;
				total += cur ;
				reduc += cur_reduc ;
				
				$( 'td:eq(2)' , base).html( cur + "€" );
				$( 'td:eq(3)' , base).html( cur_reduc + "€" );
			}
			else if ($(this).hasClass('tarif_majore')) {
				var cur = Math.round( $(this).val() * majored_price * 100)/100;
				total += cur  ;
				$( 'td:eq(2)' , base).html( cur+ "€" );
			}
			else {
				var cur = $(this).val() * price;
				total += Math.round(cur*100)/100 ;
				$( 'td:eq(2)' , base).html( cur + "€" );
			}
		}
		else {
			$( 'td:eq(2)' , base).html( "" );
			$( 'td:eq(3)' , base).html( "" );
		}
	});
	
	$("#estim_cout").html(Math.round(total*100)/100 + "€");
	$("#estim_reduc").html(Math.round(reduc *100 ) /100 + "€");
}

function reinit() {
	$("#estim input").each(function (){
		$(this).val('');
	});
	Estim();
}

function convertb60tob100( x ) {
	var min = x % 1;
	var heure = Math.floor(x);
    min = Math.round(min*10000 ) /100;
    min100 = min*100/60;
	return (heure+"."+min100);
}

function IsNumeric(input) {
   return (input - 0) == input && input.length > 0;
}

$(document).ready(function(){
	$("form#info").validate({
		rules : {
			mail : {
				required : function() {
					if ($('#tel').val()== "")
						return true;
					else
						return false;
				}
			},
			tel : {
				required : function() {
					if ($('#mail').val()== "")
						return true;
					else
						return false;
				}
			}
		},
		errorPlacement: function(error, element) { 
	    	error.appendTo( $("label" , element.parent()).after() );        
	  	},
	  	highlight: function(element, errorClass) {
	  		if ( ! $(element).hasClass("error")) $(element).fadeOut(function() {
	  	    	$(element).fadeIn();
	  		});
	  		$(element).removeClass("error").addClass("error");
	  	},
	  	errorElement: "span"
	});
});

