/*
	Fonction Check EMAIL
*/


function checkrequired(which){
var pass=true
if (document.images){
for (i=0;i<which.length;i++){
var tempobj=which.elements[i]
if (tempobj.name.substring(0,8)=="required"){
if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
pass=false
break
}
}
}
}
if (!pass){
alert("Certains champs de ce formulaire sont obligatoires. Merci de bien vouloir les renseigner.")
return false
}
else
return true
}


/*
	Fonction Affichage date au format FR
*/


navvers = navigator.appVersion.substring(0,1);


if (navvers > 3)
	navok = true;
else
	navok = false;


today = new Date;
jour = today.getDay();
numero = today.getDate();
if (numero<10)
	numero = "0"+numero;
mois = today.getMonth();
if (navok)
	annee = today.getFullYear();
else
	annee = today.getYear();
TabJour = new Array("Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi");
TabMois = new Array("janvier","f&eacute;vrier","mars","avril","mai","juin","juillet","aout","septembre","octobre","novembre","d&eacute;cembre");
messageDate = TabJour[jour] + " " + numero + " " + TabMois[mois] + " " + annee;


/*
	Fonction Impression de la page en cours
*/


function printpage() {
	if (window.print) {
		window.focus();
		window.print();
	} else {
		alert('Votre système ne permet pas d\'activer cette fonction. Pour imprimer, sélectionnez Imprimer dans le menu de votre Navigateur.');
	}
}


/*
	Fonction Ajouter le site aux favoris
*/


function addToFavorite(favTitle){
  if (navigator.appVersion.indexOf("Mac") > 0) {
	alert('Votre système ne permet pas d\'activer cette fonction. Pour ajouter cette page à vos favoris, cliquez sur Ctrl+D sur PC ou Pomme+D sur MAC.');
  } else {
    window.external.AddFavorite(location.href, unescape(favTitle));
  }
}


/*
	Fonction POPUP revu par MC&C HP 2002
*/

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

/*
	Fonction Affichage message dans la barre de Status
*/


function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}


function initializeDates()
{
	var thisdate = new Date();
	var thismonth = thisdate.getMonth();
	var thisday = thisdate.getDate();
	var thisyear = thisdate.getFullYear();


	document.MForm.CIMonth.value = thismonth+1;
	document.MForm.CIYear.value = thisyear;
	document.MForm.CIDay.value = thisday;


	document.MForm.COMonth.value = thismonth+1;
	document.MForm.COYear.value = thisyear;
	document.MForm.CODay.value = thisday+1;
	
	document.MForm.nuits.value = (MForm.CODay.value - MForm.CIDay.value) + ' nuitée(s)';
}


function doSelectOptions(theValue,theField) {


	var objForm = document.MForm;
	for (i=0; i< objForm[theField].options.length; i++)
		if (objForm[theField].options[i].value == theValue) {
			objForm[theField].options[i].selected = true;
		}
}


function updateBothDates(theForm)
{
	var worker	= new Date();
	calcBothDates(theForm, (worker.getYear()%1900+1900), worker.getMonth()+1, worker.getDate());
}
function calcBothDates(theForm, ty, tm, td)
{
	var today	= new Date((ty%1900+1900), tm-1, td, 0,0,0);
	var inDate	= new Date((ty%1900+1900), parseInt(document.MForm.CIMonth[document.MForm.CIMonth.selectedIndex].value)-1, document.MForm.CIDay[document.MForm.CIDay.selectedIndex].value, 0,0,0);
	var outDate	= new Date((ty%1900+1900), parseInt(document.MForm.CIMonth[document.MForm.CIMonth.selectedIndex].value)-1, parseInt(document.MForm.CIDay[document.MForm.CIDay.selectedIndex].value)+2, 0,0,0);


	if (inDate.getTime()  < today.getTime()) { // Crossed the newyear boundary
		inDate.setYear((today.getYear()%1900+1900)+1);
		outDate.setYear((today.getYear()%1900+1900)+1);
	}


	theForm.CIYear.value	= (inDate.getYear()%1900) + 1900;
	doSelectOptions(inDate.getMonth()+1, 'CIMonth');
	doSelectOptions(inDate.getDate(), 'CIDay');


	theForm.COYear.value	= (outDate.getYear()%1900) + 1900;
	doSelectOptions(outDate.getMonth()+1, 'COMonth');
	doSelectOptions(outDate.getDate(), 'CODay');
	
	var tmp1 = (outDate.getYear()%1900) + 1900;
	var monarr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	// check for leap year
	if (((tmp1 % 4 == 0) && (tmp1 % 100 != 0)) || (tmp1 % 400 == 0)) monarr[1] = "29";
	//Finds the First Day for the Current Month
	
	var tmp2 = monarr[theForm.CIMonth.value - 1];
	tmp2 = (tmp2 - MForm.CIDay.value);
	if (theForm.COMonth.value == theForm.CIMonth.value) {
		tmp2 = (MForm.CODay.value - MForm.CIDay.value);
	} else {
		tmp2 = tmp2 + parseInt(MForm.CODay.value);
	}

	document.MForm.nuits.value = tmp2 + ' nuitée(s)';
}


function updateCIDate(theForm)

{
	var worker	= new Date();
	calcCIDate(theForm, (worker.getYear()%1900+1900), worker.getMonth()+1, worker.getDate());
}
function calcCIDate(theForm, ty, tm, td)
{
	var today	= new Date((ty%1900+1900), tm-1, td, 0,0,0);
	var inDate	= new Date((ty%1900+1900), parseInt(document.MForm.CIMonth[document.MForm.CIMonth.selectedIndex].value)-1, document.MForm.CIDay[document.MForm.CIDay.selectedIndex].value, 0,0,0);


	if (inDate.getTime()  < today.getTime()) { // Crossed the newyear boundary
		inDate. setYear((today.getYear()%1900+1900)+1);
	}


	theForm.CIYear.value	= (inDate.getYear()%1900) + 1900;
	doSelectOptions(inDate.getMonth()+1, 'CIMonth');
	doSelectOptions(inDate.getDate(), 'CIDay');


	document.MForm.nuits.value = (MForm.CODay.value - MForm.CIDay.value) + ' nuitée(s)';


}


function updateCODate(theForm)
{
	var worker	= new Date();
	calcCODate(theForm, (worker.getYear()%1900+1900), worker.getMonth()+1, worker.getDate());
}
function calcCODate(theForm, ty, tm, td)
{
	var today	= new Date((ty%1900+1900), tm-1, td, 0,0,0);
	var outDate	= new Date((ty%1900+1900), parseInt(document.MForm.COMonth[document.MForm.COMonth.selectedIndex].value)-1, parseInt(document.MForm.CODay[document.MForm.CODay.selectedIndex].value), 0,0,0);


	if ((parseInt(theForm.CIYear.value)%1900) >(today.getYear()%1900)) {
		outDate.setYear((today.getYear()%1900+1900)+1);	// Already a year ahead for in date
	} else if (outDate.getTime() < today.getTime()) {
		outDate.setYear((today.getYear()%1900+1900)+1);	// Crossed the newyear boundary
	}


	theForm.COYear.value	= (outDate.getYear()%1900) + 1900;
	doSelectOptions(outDate.getMonth()+1, 'COMonth');
	doSelectOptions(outDate.getDate(), 'CODay');

	var tmp1 = (outDate.getYear()%1900) + 1900;
	var monarr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	// check for leap year
	if (((tmp1 % 4 == 0) && (tmp1 % 100 != 0)) || (tmp1 % 400 == 0)) monarr[1] = "29";
	//Finds the First Day for the Current Month
	
	var tmp2 = monarr[theForm.CIMonth.value - 1];
	tmp2 = (tmp2 - MForm.CIDay.value);
	if (theForm.COMonth.value == theForm.CIMonth.value) {
		tmp2 = (MForm.CODay.value - MForm.CIDay.value);
	} else {
		tmp2 = tmp2 + parseInt(MForm.CODay.value);
	}

	document.MForm.nuits.value = tmp2 + ' nuitée(s)';

}


function searchDebug() { alert('CIYear='+MForm.CIYear.value+', COYear='+MForm.COYear.value); }
function changeRezDebug() { alert('CIYear='+MForm.CIYear.value+', COYear='+MForm.COYear.value); }
function debugRefineLeftnav() { alert('CIYear='+MForm.CIYear.value+', COYear='+MForm.COYear.value); }
