// JavaScript Document

//fonction qui sort la page d'une frame non désirée ------------------------------------------------------------------------------------------------
function check_frame()
{
	if (top.location != self.location)
	{
		top.location.replace(self.location);
	}
}
//---------------------------------------------------------------------------------------------------------------------------------------------------
//fonctions qui ouvrent et ferme les menus ----------------------------------------------------------------------------------------------------------

opened_menu = null;

function ouvrir_fermer(menu_options,action)
{
	if (action == 'ouvrir')
	{
		opened_menu = menu_options;
		document.getElementById(menu_options).style.visibility='visible';
		(menu_options.substring(8,16)=='cocktail')?increment=60:increment=30;
	}
	else
	{
		opened_menu = null;
		document.getElementById(menu_options).style.visibility='hidden';
		(menu_options.substring(8,16)=='cocktail')?increment=-60:increment=-30;
	}
	//***************************************************** pour le cocktails ******************************************************************
	if (menu_options == 'options_cocktail_francais')
	{
		document.getElementById('menu_cocktail_chinois').style.top=parseInt(document.getElementById('menu_cocktail_chinois').style.top)+increment+'px';
		document.getElementById('menu_cocktail_japonais').style.top=parseInt(document.getElementById('menu_cocktail_japonais').style.top)+increment+'px';
		document.getElementById('menu_cocktail_oriental').style.top=parseInt(document.getElementById('menu_cocktail_oriental').style.top)+increment+'px';
		document.getElementById('menu_cocktail_indien').style.top=parseInt(document.getElementById('menu_cocktail_indien').style.top)+increment+'px';
		document.getElementById('menu_cocktail_africain').style.top=parseInt(document.getElementById('menu_cocktail_africain').style.top)+increment+'px';
		document.getElementById('menu_cocktail_antillais').style.top=parseInt(document.getElementById('menu_cocktail_antillais').style.top)+increment+'px';
		document.getElementById('menu_cocktail_espagnol').style.top=parseInt(document.getElementById('menu_cocktail_espagnol').style.top)+increment+'px';
		document.getElementById('menu_cocktail_italien').style.top=parseInt(document.getElementById('menu_cocktail_italien').style.top)+increment+'px';
		document.getElementById('menu_cocktail_tourdumonde').style.top=parseInt(document.getElementById('menu_cocktail_tourdumonde').style.top)+increment+'px';
	}
	if (menu_options == 'options_cocktail_chinois')
	{
		document.getElementById('menu_cocktail_japonais').style.top=parseInt(document.getElementById('menu_cocktail_japonais').style.top)+increment+'px';
		document.getElementById('menu_cocktail_oriental').style.top=parseInt(document.getElementById('menu_cocktail_oriental').style.top)+increment+'px';
		document.getElementById('menu_cocktail_indien').style.top=parseInt(document.getElementById('menu_cocktail_indien').style.top)+increment+'px';
		document.getElementById('menu_cocktail_africain').style.top=parseInt(document.getElementById('menu_cocktail_africain').style.top)+increment+'px';
		document.getElementById('menu_cocktail_antillais').style.top=parseInt(document.getElementById('menu_cocktail_antillais').style.top)+increment+'px';
		document.getElementById('menu_cocktail_espagnol').style.top=parseInt(document.getElementById('menu_cocktail_espagnol').style.top)+increment+'px';
		document.getElementById('menu_cocktail_italien').style.top=parseInt(document.getElementById('menu_cocktail_italien').style.top)+increment+'px';
		document.getElementById('menu_cocktail_tourdumonde').style.top=parseInt(document.getElementById('menu_cocktail_tourdumonde').style.top)+increment+'px';
	}
	if (menu_options == 'options_cocktail_japonais')
	{
		document.getElementById('menu_cocktail_oriental').style.top=parseInt(document.getElementById('menu_cocktail_oriental').style.top)+increment+'px';
		document.getElementById('menu_cocktail_indien').style.top=parseInt(document.getElementById('menu_cocktail_indien').style.top)+increment+'px';
		document.getElementById('menu_cocktail_africain').style.top=parseInt(document.getElementById('menu_cocktail_africain').style.top)+increment+'px';
		document.getElementById('menu_cocktail_antillais').style.top=parseInt(document.getElementById('menu_cocktail_antillais').style.top)+increment+'px';
		document.getElementById('menu_cocktail_espagnol').style.top=parseInt(document.getElementById('menu_cocktail_espagnol').style.top)+increment+'px';
		document.getElementById('menu_cocktail_italien').style.top=parseInt(document.getElementById('menu_cocktail_italien').style.top)+increment+'px';
		document.getElementById('menu_cocktail_tourdumonde').style.top=parseInt(document.getElementById('menu_cocktail_tourdumonde').style.top)+increment+'px';
	}
	if (menu_options == 'options_cocktail_oriental')
	{
		document.getElementById('menu_cocktail_indien').style.top=parseInt(document.getElementById('menu_cocktail_indien').style.top)+increment+'px';
		document.getElementById('menu_cocktail_africain').style.top=parseInt(document.getElementById('menu_cocktail_africain').style.top)+increment+'px';
		document.getElementById('menu_cocktail_antillais').style.top=parseInt(document.getElementById('menu_cocktail_antillais').style.top)+increment+'px';
		document.getElementById('menu_cocktail_espagnol').style.top=parseInt(document.getElementById('menu_cocktail_espagnol').style.top)+increment+'px';
		document.getElementById('menu_cocktail_italien').style.top=parseInt(document.getElementById('menu_cocktail_italien').style.top)+increment+'px';
		document.getElementById('menu_cocktail_tourdumonde').style.top=parseInt(document.getElementById('menu_cocktail_tourdumonde').style.top)+increment+'px';
	}
	if (menu_options == 'options_cocktail_indien')
	{
		document.getElementById('menu_cocktail_africain').style.top=parseInt(document.getElementById('menu_cocktail_africain').style.top)+increment+'px';
		document.getElementById('menu_cocktail_antillais').style.top=parseInt(document.getElementById('menu_cocktail_antillais').style.top)+increment+'px';
		document.getElementById('menu_cocktail_espagnol').style.top=parseInt(document.getElementById('menu_cocktail_espagnol').style.top)+increment+'px';
		document.getElementById('menu_cocktail_italien').style.top=parseInt(document.getElementById('menu_cocktail_italien').style.top)+increment+'px';
		document.getElementById('menu_cocktail_tourdumonde').style.top=parseInt(document.getElementById('menu_cocktail_tourdumonde').style.top)+increment+'px';
	}
	if (menu_options == 'options_cocktail_africain')
	{
		document.getElementById('menu_cocktail_antillais').style.top=parseInt(document.getElementById('menu_cocktail_antillais').style.top)+increment+'px';
		document.getElementById('menu_cocktail_espagnol').style.top=parseInt(document.getElementById('menu_cocktail_espagnol').style.top)+increment+'px';
		document.getElementById('menu_cocktail_italien').style.top=parseInt(document.getElementById('menu_cocktail_italien').style.top)+increment+'px';
		document.getElementById('menu_cocktail_tourdumonde').style.top=parseInt(document.getElementById('menu_cocktail_tourdumonde').style.top)+increment+'px';
	}
	if (menu_options == 'options_cocktail_antillais')
	{
		document.getElementById('menu_cocktail_espagnol').style.top=parseInt(document.getElementById('menu_cocktail_espagnol').style.top)+increment+'px';
		document.getElementById('menu_cocktail_italien').style.top=parseInt(document.getElementById('menu_cocktail_italien').style.top)+increment+'px';
		document.getElementById('menu_cocktail_tourdumonde').style.top=parseInt(document.getElementById('menu_cocktail_tourdumonde').style.top)+increment+'px';
	}
	if (menu_options == 'options_cocktail_espagnol')
	{
		document.getElementById('menu_cocktail_italien').style.top=parseInt(document.getElementById('menu_cocktail_italien').style.top)+increment+'px';
		document.getElementById('menu_cocktail_tourdumonde').style.top=parseInt(document.getElementById('menu_cocktail_tourdumonde').style.top)+increment+'px';
	}
	if (menu_options == 'options_cocktail_italien')
	{
		document.getElementById('menu_cocktail_tourdumonde').style.top=parseInt(document.getElementById('menu_cocktail_tourdumonde').style.top)+increment+'px';
	}
	//*************************************************************************************************************************************************
	//************************************************ pour les buffets *******************************************************************************
	if (menu_options == 'options_buffet_grec')
	{
		document.getElementById('menu_buffet_italien').style.top=parseInt(document.getElementById('menu_buffet_italien').style.top)+increment+'px';
		document.getElementById('menu_buffet_espagnol').style.top=parseInt(document.getElementById('menu_buffet_espagnol').style.top)+increment+'px';
		document.getElementById('menu_buffet_chinois').style.top=parseInt(document.getElementById('menu_buffet_chinois').style.top)+increment+'px';
		document.getElementById('menu_buffet_indien').style.top=parseInt(document.getElementById('menu_buffet_indien').style.top)+increment+'px';
		document.getElementById('menu_buffet_africain').style.top=parseInt(document.getElementById('menu_buffet_africain').style.top)+increment+'px';
		document.getElementById('menu_buffet_oriental').style.top=parseInt(document.getElementById('menu_buffet_oriental').style.top)+increment+'px';
		document.getElementById('menu_buffet_antillais').style.top=parseInt(document.getElementById('menu_buffet_antillais').style.top)+increment+'px';
		document.getElementById('menu_buffet_tourdumonde').style.top=parseInt(document.getElementById('menu_buffet_tourdumonde').style.top)+increment+'px';
	}
	if (menu_options == 'options_buffet_italien')
	{
		document.getElementById('menu_buffet_espagnol').style.top=parseInt(document.getElementById('menu_buffet_espagnol').style.top)+increment+'px';
		document.getElementById('menu_buffet_chinois').style.top=parseInt(document.getElementById('menu_buffet_chinois').style.top)+increment+'px';
		document.getElementById('menu_buffet_indien').style.top=parseInt(document.getElementById('menu_buffet_indien').style.top)+increment+'px';
		document.getElementById('menu_buffet_africain').style.top=parseInt(document.getElementById('menu_buffet_africain').style.top)+increment+'px';
		document.getElementById('menu_buffet_oriental').style.top=parseInt(document.getElementById('menu_buffet_oriental').style.top)+increment+'px';
		document.getElementById('menu_buffet_antillais').style.top=parseInt(document.getElementById('menu_buffet_antillais').style.top)+increment+'px';
		document.getElementById('menu_buffet_tourdumonde').style.top=parseInt(document.getElementById('menu_buffet_tourdumonde').style.top)+increment+'px';
	}
	if (menu_options == 'options_buffet_espagnol')
	{
		document.getElementById('menu_buffet_chinois').style.top=parseInt(document.getElementById('menu_buffet_chinois').style.top)+increment+'px';
		document.getElementById('menu_buffet_indien').style.top=parseInt(document.getElementById('menu_buffet_indien').style.top)+increment+'px';
		document.getElementById('menu_buffet_africain').style.top=parseInt(document.getElementById('menu_buffet_africain').style.top)+increment+'px';
		document.getElementById('menu_buffet_oriental').style.top=parseInt(document.getElementById('menu_buffet_oriental').style.top)+increment+'px';
		document.getElementById('menu_buffet_antillais').style.top=parseInt(document.getElementById('menu_buffet_antillais').style.top)+increment+'px';
		document.getElementById('menu_buffet_tourdumonde').style.top=parseInt(document.getElementById('menu_buffet_tourdumonde').style.top)+increment+'px';
	}
	if (menu_options == 'options_buffet_chinois')
	{
		document.getElementById('menu_buffet_indien').style.top=parseInt(document.getElementById('menu_buffet_indien').style.top)+increment+'px';
		document.getElementById('menu_buffet_africain').style.top=parseInt(document.getElementById('menu_buffet_africain').style.top)+increment+'px';
		document.getElementById('menu_buffet_oriental').style.top=parseInt(document.getElementById('menu_buffet_oriental').style.top)+increment+'px';
		document.getElementById('menu_buffet_antillais').style.top=parseInt(document.getElementById('menu_buffet_antillais').style.top)+increment+'px';
		document.getElementById('menu_buffet_tourdumonde').style.top=parseInt(document.getElementById('menu_buffet_tourdumonde').style.top)+increment+'px';
	}
	if (menu_options == 'options_buffet_indien')
	{
		document.getElementById('menu_buffet_africain').style.top=parseInt(document.getElementById('menu_buffet_africain').style.top)+increment+'px';
		document.getElementById('menu_buffet_oriental').style.top=parseInt(document.getElementById('menu_buffet_oriental').style.top)+increment+'px';
		document.getElementById('menu_buffet_antillais').style.top=parseInt(document.getElementById('menu_buffet_antillais').style.top)+increment+'px';
		document.getElementById('menu_buffet_tourdumonde').style.top=parseInt(document.getElementById('menu_buffet_tourdumonde').style.top)+increment+'px';
	}
	if (menu_options == 'options_buffet_africain')
	{
		document.getElementById('menu_buffet_oriental').style.top=parseInt(document.getElementById('menu_buffet_oriental').style.top)+increment+'px';
		document.getElementById('menu_buffet_antillais').style.top=parseInt(document.getElementById('menu_buffet_antillais').style.top)+increment+'px';
		document.getElementById('menu_buffet_tourdumonde').style.top=parseInt(document.getElementById('menu_buffet_tourdumonde').style.top)+increment+'px';
	}
	if (menu_options == 'options_buffet_oriental')
	{
		document.getElementById('menu_buffet_antillais').style.top=parseInt(document.getElementById('menu_buffet_antillais').style.top)+increment+'px';
		document.getElementById('menu_buffet_tourdumonde').style.top=parseInt(document.getElementById('menu_buffet_tourdumonde').style.top)+increment+'px';
	}
	if (menu_options == 'options_buffet_antillais')
	{
		document.getElementById('menu_buffet_tourdumonde').style.top=parseInt(document.getElementById('menu_buffet_tourdumonde').style.top)+increment+'px';
	}
	//*************************************************************************************************************************************************
	
}

function change_menu_status(menu_options)
{
	if (opened_menu == null)
	{
		ouvrir_fermer(menu_options,'ouvrir');
	}
	else
	{
		if (opened_menu != menu_options)
		{
			ouvrir_fermer(opened_menu,'fermer');
			ouvrir_fermer(menu_options,'ouvrir');
		}
		else
		{
			ouvrir_fermer(menu_options,'fermer');
		}
	}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------

function check_nb_invites()
{
	if (parseInt(details_reception.nombre_invites.value)) 
	{
		details_reception.nombre_invites.value=parseInt(details_reception.nombre_invites.value);
		//definition du minimum pour les differents types de receptions
		if (parseInt(details_reception.nombre_invites.value)<10 && (details_reception.formule_choisie.value.substr(0,6)=='buffet'))
		{
			//pour buffet, minimum = 10 personnes
			alert ("10 personnes minimum pour nos Buffets !");
			details_reception.nombre_invites.value = 10;
		}
		if (parseInt(details_reception.nombre_invites.value)<20 && (details_reception.formule_choisie.value.substr(0,8)=='cocktail'))
		{
			//pour cocktail et buffet, minimum = 20 personnes
			alert ("20 personnes minimum pour nos Cocktails et Buffets !");
			details_reception.nombre_invites.value = 20;
		}
		if (parseInt(details_reception.nombre_invites.value)<40 && (details_reception.formule_choisie.value.substr(0,7)=='mariage'))
		{
			//pour mariage, minimum = 40 personnes
			alert ("40 personnes minimum pour nos Mariages !");
			details_reception.nombre_invites.value = 40;
		}
		//force multiple of 5 for number of guests
		if ((parseInt(details_reception.nombre_invites.value)%5)>0)
		{
			alert('Veuillez entrer un multiple de 5.');
			details_reception.nombre_invites.value = parseInt(details_reception.nombre_invites.value)-parseInt(details_reception.nombre_invites.value)%5;
		}
	} 
	else 
	{
		details_reception.nombre_invites.value = '50';
	}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------
//Verification du code postal
function check_postalcode()
{
	if (!foundIn(details_reception.codepostal_reception.value.substr(0,2),'60','75','77','78','91','92','93','94','95'))
	{
		alert('Nous ne prenons des réceptions que pour Paris et sa proche banlieue.');
		details_reception.codepostal_reception.value = '75001';
		return false;
	}
	else
	{
		if ((parseInt(details_reception.codepostal_reception.value)+'').length!=5) //si pas nombre
		{
			alert('Departement errone')
			details_reception.codepostal_reception.value = '75001';
			return false;
		}
	}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------
//verifie la validité des infos du formulaire---------------------------------------------------------------------------------------------------------
function check_details()
{
	//verifier que tous les champs sont renseignés
	if (details_reception.nombre_invites=='' || details_reception.adresse_reception=='' || details_reception.codepostal_reception=='' || details_reception.first_name=='' || details_reception.last_name=='' || details_reception.telephone=='' || details_reception.email=='')
	{
		alert ('Renseignez tous les champs précédés d\'un «*»');
		return false;
	}
	
	//L'authenticité de la date
	if (foundIn(details_reception.date_mois.value,'04','06','09','11')) //mois à 30 jours
	{
		if (parseInt(details_reception.date_jour.value)>30)
		{
			alert ('Date invalide !');
			details_reception.date_jour.value = '30';
			return false;
		}
	}
	if (details_reception.date_mois.value=='02') //mois de fevrier
	{
		if (details_reception.date_annee.value%4==0) //année bisextile, février = 29 jours
		{
			if (parseInt(details_reception.date_jour.value)>29)
			{
				alert ('Date invalide !');
				details_reception.date_jour.value = '29';
				return false;
			}
		}
		else //anné nonrmale
		{
			if (parseInt(details_reception.date_jour.value)>28)
			{
				alert ('Date invalide !');
				details_reception.date_jour.value = '28';
				return false;
			}
		}
	}
	//now+3jours ouvrables
	reception_date=new Date(details_reception.date_annee.value,details_reception.date_mois.value-1,details_reception.date_jour.value);
	difference = roundup(reception_date.getTime()-now.getTime(),86400000);
	if (difference<3 || (difference==3 && (reception_date.getDay()>=4 || reception_date.getDay()==0))) //moins de 3 jours ou (plus de 3 jours et a partir de jeudi car dimanche = pas ouvrable)
	{
		alert ('Nous avons besoin d\'un minimum de 3 jours ouvrables pour la prise de commande.\nVeuillez, svp, resaisir la date de réception.');
		return false;
	}
	//champs vides
	if (isNull(details_reception.adresse_reception)||isNull(details_reception.ville_reception)||isNull(details_reception.codepostal_reception)||isNull(details_reception.first_name)||isNull(details_reception.last_name)||isNull(details_reception.telephone)||isNull(details_reception.email)) //champs vides
	{
		alert('Veuillez renseigner tous les champs précédés d\'un *');
		return false;
	}
	
	details_reception.nom_jour.value=reception_date.getDay();
	details_reception.submit();
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------
//fonction qui definit si un champs est null
function isNull(x)
{
	x=x.value;
	y = false;
	if (x==null) {y=true;}
	if (x==''||x==' '||x=='  '|| x=='   '||x=='    ') {y=true;}	
	return y;
}
//fonction qui compare une valeur a une liste de valeurs
function foundIn()
{
	y = false;
	for (x=1;x<arguments.length;x++)
	{
		if (arguments[0] == arguments[x]) {y=true;}
	}
	return y;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------

//foncion qui retourne la valeur entiere. au dessus, d'un réel # 5.2 => 6
function roundup(x,y)
{
	//Fonction qui arrondit à l'entier supérieur
	z = Math.round(x/y);
	if ((((x % y)/y) < 0.5) && (((x % y)/y) > 0)) {z=z+1;}
	return z;
}

