/* Scripts Javascripts*/

function InsereImage(source,rang,nombre,texte,format,largeur,hauteur)
	{
		a = Math.round((Math.random()*(nombre-1))+(rang-1)*nombre+1);
		document.write('<img src="'+source+a+'.'+format+'" alt="'+texte+'" width="'+largeur+'" height="'+hauteur+'" />');
	}

function PopupImage(image,titre,commentaire){ 
	w=open("",'image','width=400, height=400, top=100, left=100, toolbar=no, scrollbars=no, resizable=yes');
	w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE><link href=\"styles.css\" rel=\"stylesheet\" type=\"text/css\" /></HEAD>");
	w.document.write("<SCRIPT language=javascript>function checksize() { if (document.images[0].complete) { window.resizeTo(document.images[0].width+10,document.images[0].height+130); window.focus();} else { setTimeout('checksize()',250) } }</"+"SCRIPT>");
	w.document.write("<BODY onload='checksize()' onblur='window.close()' onclick='window.close()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0>");
	w.document.write("<div id= \"popuptitle\">"+titre+"</div>");
	w.document.write("<TABLE width='100%' border='0' cellspacing='0' cellpadding='0' ><TR>");
	w.document.write("<TD valign='middle' align='center'><IMG src='"+image+"' border=0 alt='Image agrandie'>");
	w.document.write("</TD></TR></TABLE>");
	w.document.write("<div id= \"popupcomment\">"+commentaire+"</div>");
	w.document.write("<div id= \"popupclose\">Cliquez dans la fenêtre pour la fermer</div>");
	w.document.write("</BODY></HTML>");
	w.document.close();
}

// Fonction getWeek pour déterminer le numéro de la semaine dans la fonction InserePromotion
Date.prototype.getWeek = function() {
	var premierjanvier = new Date(this.getFullYear(),0,1);
	return Math.ceil(((((this - premierjanvier) / 86400000) + premierjanvier.getDay()+1)/7)-1);
}

// Fonction pour déterminer le texte de promotion et son style à insérer en fonction des mois et semaines
function InserePromotion(){
	var LaDate = new Date();
	var LAnnee = LaDate.getYear();
	//LAnnee += 2;	// ajustement manuel pour tester les dates futures à commenter une fois les tests terminés
	var LeMois = LaDate.getMonth();
	//LeMois += 10;	// ajustement manuel pour tester les dates futures à commenter une fois les tests terminés
	var LaSemaine = LaDate.getWeek();
	//LaSemaine -= 2;	// ajustement manuel pour tester les dates futures à commenter une fois les tests terminés
	//alert('Semaine ' LaSemaine)	//message de vérification de la valeur de la semaine
	//alert('Mois' LeMois)	//message de vérification de la valeur du mois
	//alert('Année' LAnnee)	//message de vérification de la valeur de l'année

//Promotions basées sur une durée mensuelle (attention janvier = 0, février = 1...)
	switch (LeMois) {
	case 6:
	case 7:
	document.write("<div id='ete'><p><a href='promos_ete.html' >Cliquez ici<br/>pour voir le<br/>programme</a></p></div>");
	break;
	case 9:
	document.write("<div id='choucroute'><p><br/><br/><br/><a href='promos_choucroute.html' >Cliquez ici pour découvrir notre offre spéciale</a></p></div>");
	break;
	case 11:
	document.write("<div id='fetes'><p><a href='promos_fetes.html' >Cliquez ici pour<br/>découvrir nos<br/>Menus de Fêtes</a></p></div>");
	break;
//	Pour ajouter une ou plusieurs valeurs à tester décommenter les lignes suivantes
//	case 2:		// adapter la ou les valeurs de mois à tester
//	case 3:
//	document.write("Texte à insérer");	// ajouter le code html qui devra être inséré dans les pages
//	break;
	default: 
	document.write("")	// inutile mais ça permet de gérer un éventuel texte par défaut
	break;
	}

//Promotions basées sur une durée hebdomadaire (la première semaine, celle qui finit l'année précédente, = 0, la vraie première semaine = 1)
	switch (LaSemaine) {
	case 5:
	case 6:
	case 7:
	document.write("<div id='valentin'><p><a href='promos_valentin.html' >Cliquez ici pour découvrir<br/>nos menus amoureux <br/>pour la Saint-Valentin</a></p></div>");
	break;
//	Pour ajouter une ou plusieurs valeurs à tester décommenter les lignes suivantes
//	case 8:		// adapter la ou les valeurs de semaines à tester
//	case 9:
//	document.write("Texte à insérer");	// ajouter le code html qui devra être inséré dans les pages
//	break;
	default: 
	document.write("");	// inutile mais ça permet de gérer un éventuel texte par défaut
	break;
	}

//Promotions de Pâques - Calcul spécifique à cause de la mobilité de la date
//Détermination préalable de la semaine de Pâques pour les 10 ans à venir (ça suffira)
	switch (LAnnee) {
	case 2010:
	var SemainePaques = 13;
	break;
	case 2011:
	var SemainePaques = 16;
	break;
	case 2012:
	var SemainePaques = 14;
	break;
	case 2013:
	var SemainePaques = 13;
	break;
	case 2014:
	var SemainePaques = 16;
	break;
	case 2015:
	var SemainePaques = 14;
	break;
	case 2016:
	var SemainePaques = 12;
	break;
	case 2017:
	var SemainePaques = 15;
	break;
	case 2018:
	var SemainePaques = 13;
	break;
	case 2019:
	var SemainePaques = 16;
	break;
	default: 
	var SemainePaques = 14; //valeur moyenne au cas où...
	break;
	}

if ((LaSemaine >= (SemainePaques - 3)) && (LaSemaine <= (SemainePaques + 1))) {
	document.write("<div id='paques'><p><a href='promos_paques.html' >Cliquez ici pour <br />découvrir nos <br />spécialités de Pâques</a></p></div>");
}

}


/*

CUSTOM FORM ELEMENTS

Created by Ryan Fait
www.ryanfait.com
Visit http://ryanfait.com/ for more information.

*/

var checkboxHeight = "25";
var radioHeight = "25";
var selectWidth = "190";

document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');

var Custom = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].type;

				if(inputs[a].checked == true) {
					if(inputs[a].type == "checkbox") {
						position = "0 -" + (checkboxHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					} else {
						position = "0 -" + (radioHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					}
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.clear;
				if(!inputs[a].getAttribute("disabled")) {
					span[a].onmousedown = Custom.pushed;
					span[a].onmouseup = Custom.check;
				} else {
					span[a].className = span[a].className += " disabled";
				}
			}
		}
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className == "styled") {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				if(!inputs[a].getAttribute("disabled")) {
					inputs[a].onchange = Custom.choose;
				} else {
					inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled";
				}
			}
		}
		document.onmouseup = Custom.clear;
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked == true && element.type == "radio") {
			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
		} else if(element.checked != true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			if(element.type == "checkbox") {
				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else {
				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
				group = this.nextSibling.name;
				inputs = document.getElementsByTagName("input");
				for(a = 0; a < inputs.length; a++) {
					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
						inputs[a].previousSibling.style.backgroundPosition = "0 0";
					}
				}
			}
			element.checked = true;
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
	}
}
window.onload = Custom.init;

/* Fonctions de validation de formulaire */

function couleur(obj) {
	obj.style.backgroundColor = "#FFFFFF";
}

function verif_date(input)
{
	var separateur = new RegExp("[/-]");
	var date = input.split(separateur);
	var nbJours = new Array('',31,28,31,30,31,30,31,31,30,31,30,31);
	var resultat = true;
	var DateCourante = new Date();

	if ( date['2']%4 == 0 && date['2']%100 > 0 || date['2']%400 == 0 )
	nbJours['2'] = 29;

	if( isNaN(date['2']) )
	resultat=false;

	if ( isNaN(date['1']) || date['1'] > 12 || date['1'] < 1 )
	resultat=false;

	if ( isNaN(date['0']) || date['0'] > nbJours[Math.round(date['1'])] || date['0'] < 1 )
	resultat=false;

	var DateJS = new Date(parseInt(date['2']),parseInt(date['1']),parseInt(date['0']));	
	var dDate = Date.parse(DateJS);
	var dDateCourante = Date.parse(DateCourante);
	if ( dDate < dDateCourante )
	resultat=false;

	return resultat;
}

                
function verif_heure(input){
	var separateur = new RegExp("[:h-]");
	var temps = input.split(separateur);
	var heures = parseInt(temps[0]);
	var minutes = parseInt(temps[1]);
	return  (heures >= 0 && heures < 24) && (minutes >= 0 && minutes < 60);
}

function check() {
	var oblig = "";
	var option = "";
	var reg_noms = new RegExp("^[a-zéèçàùâêîôûäëïöü\\'\\- ]{2,}$", "i");
	var reg_codpos = new RegExp("^[0-9]{5}$", "i");
	var reg_tel = new RegExp("^0[1-59]([-. ]?[0-9]{2}){4}$", "i");
	var reg_portable = new RegExp("^0[67]([-. ]?[0-9]{2}){4}$", "i");
	var reg_mail = new RegExp("^[a-z0-9-_]+(\.[a-z0-9-_]+)*@[a-z0-9-_]+(\.[a-z0-9-_]+)*\.[a-z0-9-_]{2,}$", "i");
	var reg_nombre = new RegExp("^[0-9]{1,3}$", "i");

	if (!reg_noms.test(document.forms[0].elements["Nom"].value))
		{
		oblig += "\n  - votre nom";
		document.forms[0].elements["Nom"].style.backgroundColor = "#FF8000";
		}
 
	if (!reg_noms.test(document.forms[0].elements["Prenom"].value))
		{
		if (oblig != "") 	oblig += " ;";
		oblig += "\n  - votre prénom";
		document.forms[0].elements["Prenom"].style.backgroundColor = "#FF8000";
		}
 
	if (!reg_noms.test(document.forms[0].elements["Profession"].value))
		{
		if (oblig != "") 	oblig += " ;";
		oblig += "\n  - le champ Profession n'a pas à être rempli, c'est juste une protection anti-robots";
		}
 
	if (document.forms[0].elements["Adresse"].value == "")
		{
		if (oblig != "") 	oblig += " ;";
		oblig += "\n  - votre adresse";
		document.forms[0].elements["Adresse"].style.backgroundColor = "#FF8000";
		}
 
	if (!reg_codpos.test(document.forms[0].elements["CodePostal"].value))
		{
		if (oblig != "") 	oblig += " ;";
		oblig += "\n  - votre code postal";
		document.forms[0].elements["CodePostal"].style.backgroundColor = "#FF8000";
		}
 
	if (!reg_noms.test(document.forms[0].elements["Ville"].value))
		{
		if (oblig != "") 	oblig += " ;";
		oblig += "\n  - votre ville";
		document.forms[0].elements["Ville"].style.backgroundColor = "#FF8000";
		}

	if (!reg_tel.test(document.forms[0].elements["Telephone"].value))
		{
		option += "\n  - votre téléphone";
		document.forms[0].elements["Telephone"].style.backgroundColor = "#F3C200";
		}

	if (!reg_tel.test(document.forms[0].elements["Fax"].value))
		{
		if (option != "") option += " ;";
		option += "\n  - votre fax";
		document.forms[0].elements["Fax"].style.backgroundColor = "#F3C200";
		}

	if (!reg_portable.test(document.forms[0].elements["Portable"].value))
		{
		if (option != "")	option += " ;";
		option += "\n  - votre portable";
		document.forms[0].elements["Portable"].style.backgroundColor = "#F3C200";
		}

	if (!reg_mail.test(document.forms[0].elements["Mail"].value))
		{
		if (option != "") option += " ;";
		option += "\n  - votre adresse mail";
		document.forms[0].elements["Mail"].style.backgroundColor = "#F3C200";
		}

	if (document.forms[0].elements["Telephone"].value + document.forms[0].elements["Fax"].value + document.forms[0].elements["Portable"].value + document.forms[0].elements["Mail"].value == "")
		{
		if (oblig != "") 	oblig += " ;";
		oblig += "\n  - un numéro de téléphone, de fax, ou une adresse mail";
		}

	if (!verif_date(document.forms[0].elements["Jour"].value))
		{
		if (oblig != "") 	oblig += " ;";
		oblig += "\n  - la date de la manifestation";
		document.forms[0].elements["Jour"].style.backgroundColor = "#FF8000";
		}
		
	if (!verif_heure(document.forms[0].elements["Heure"].value))
		{
		if (oblig != "") 	oblig += " ;";
		oblig += "\n  - l'heure de la manifestation";
		document.forms[0].elements["Heure"].style.backgroundColor = "#FF8000";
		}
 
	if (!reg_nombre.test(document.forms[0].elements["Adultes"].value) || document.forms[0].elements["Adultes"].value < 2 )
		{
		if (oblig != "") 	oblig += " ;";
		oblig += "\n  - le nombre d'adultes";
		document.forms[0].elements["Adultes"].style.backgroundColor = "#FF8000";
		}
 
	if (!reg_nombre.test(document.forms[0].elements["Enfants"].value))
		{
		if (oblig != "") 	oblig += " ;";
		oblig += "\n  - le nombre d'enfants";
		document.forms[0].elements["Enfants"].style.backgroundColor = "#FF8000";
		}
 
	if (!reg_nombre.test(document.forms[0].elements["Budget"].value))
		{
		if (oblig != "") 	oblig += " ;";
		oblig += "\n  - le budget par convive";
		document.forms[0].elements["Budget"].style.backgroundColor = "#FF8000";
		}
 
	var msg = 0;
	if (oblig != "") msg += 1;
	if (option != "") msg += 2;
	switch(msg) {
		case 0:
			var defmsg = "Tous les champs semblent correctement renseignés.\nConfirmez-vous l'envoi de votre demande de devis ?";
			if (confirm(defmsg)) return(true); else return(false);
			break;			
		case 1:
			oblig = "Vous n'avez pas correctement renseigné les champs obligatoires suivants :\n" + oblig + ".";
			alert(oblig);
			return(false);
			break;
		case 2:
			option = "Nous vous informons qu'un ou plusieurs des champs optionnels suivants n'ont pas été correctement renseignés :\n" + option + ".\n\nVoulez-vous cependant envoyer maintenant votre demande de devis ?";
			if (confirm(option)) return(true); else return(false);
			break;
		case 3:
			oblig = "Vous n'avez pas correctement renseigné les champs obligatoires suivants :\n" + oblig + ".";
			option = "\n\nNous vous informons qu'en outre un ou plusieurs des champs optionnels suivants n'ont pas été correctement renseignés :\n" + option + ".";
			alert(oblig + option);
			return(false);
			break;
		}
}
