function ajax()
{ 
    var xhr; 
    if(window.XMLHttpRequest)
	{ // Mozilla, Safari, ...
		xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{ // Internet Explorer
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xhr;
}

function service(hotel, number) {
	
	$.ajax({
		type:	"POST",
		url:	"service.php",
		data:	"number="+number+"&hotel="+hotel,
		beforeSend: function() { $('#service').animate({ width:"0px" }, 1); },
		success: function(msg) { $('#service').html(msg).animate({ width:"280px" }, 300); }
	});
} 

function diaporama() {
	$(function() {
		var dimension = 0;
		$(".wrapper").each(function() {
			dimension += $(this).width();
		});
		
		$("<div>").attr("id", "container").css({ backgroundColor:"black"}).width(dimension+24).height(127).appendTo("div#viewer");
		
		$(".wrapper").each(function() {
			$(this).appendTo("div#container");
		});
		
		var duration = $(".wrapper").length * 2000;
		var speed = (parseInt($("div#container").width()) - parseInt($("div#viewer").width())) / duration;
		var margin = (parseInt($("div#viewer").width()) - parseInt($("div#container").width()));
		var animation = function(el, time, dir) {
		
			if(dir == "rtl") {
				el.removeClass("ltr").addClass("rtl");
				el.animate({
					marginLeft: margin+"px"},
					time,
					"linear",
					function() {
						animation($(this), duration, "ltr");
				});
			} else {
				el.removeClass("rtl").addClass("ltr");
				el.animate({
					marginLeft:"0px"},
					time,
					"linear",
					function() {
						animation($(this), duration, "rtl");
				});
			}
		}
		animation($("div#container"), duration, "rtl");
		
	});
}

function checkForm() {
	var tab = new Array();
	var wrong= new Array();
	for(i=0; i<14; i++) {
		tab[i] = document.forms['reservation'].elements[i].value;
	}
	
	for(i=0; i<13; i++)
	{
		if(tab[i] == "")
		{
			if(i == 5)
			{
				document.getElementById("l5").style.color = "#474747";
				wrong[5] = true;
			}
			else
			{
				document.getElementById("l"+i).style.color = "red";
				wrong[i] = false;
			}
		}
		else
		{
			document.getElementById("l"+i).style.color = "#474747";
			wrong[i] = true;
		}
	}
	
	if(wrong[9] == false) {
		document.getElementById("l8").style.color = "red";
	}
	
	for(i=0; i<13; i++) {
		if(wrong[i] == false)
			return false;
	}
	
}

function imprimer() {
	var tab = new Array();
	var tab2 = new Array();
	for(i=0; i<13; i++) {
		tab[i] = document.getElementById("l"+i).innerHTML;
		if(i != 3 || i != 12) {
			tab2[i] = '<label class="text">'+document.forms['reservation'].elements[i].value+'</label><br />'; }
		else {
			tab2[i] = '<label class="text2">'+document.forms['reservation'].elements[i].value+'</label><br />'; }
	}
	
	document.getElementById('print').innerHTML = "<div class='img'><img src='images/coala-dauphin_04.jpg' /></div>";
	document.getElementById('print').innerHTML += "<p><i>82, rue du Palais Gallien<br />33000 Bordeaux</i></p><br /><br /><br />";
	document.getElementById('print').innerHTML += "<h3>Demande de réservation : </h3><br />";
	for(i=0; i<13; i++) {
		document.getElementById('print').innerHTML += tab[i];
		document.getElementById('print').innerHTML += tab2[i];
	}
	
	window.print();
}


function dateP() {
	$(function() {
		$("#datepicker").datepicker({dateFormat:'d/mm/yy'});
	});
	$(function() {
		$("#datepicker2").datepicker({dateFormat:'d/mm/yy'});
	});
}

