/* ---------------- MAIL FRIEND --------------------------------*/
function OpenSendMailFriend() {
	window.open('/mail/friend.aspx?url=' + escape(document.location.href), '_blank', 'width=800, height=400, resizable=no, scrollbars=no');
}
/* ---------------- AFFICHAGE MOTEUR --------------------------------*/
function showMoteurAll() {
	$("searchBudget").hide();
	$("searchBudgetM").hide();
	$("searchTheme").hide();
	$("searchThemeM").hide();
	$("searchAll").show();
	$("searchAllM").show();
}
function showMoteurBudget() {
	$("searchAll").hide();
	$("searchAllM").hide();
	$("searchTheme").hide();
	$("searchThemeM").hide();
	$("searchBudget").show();
	$("searchBudgetM").show();
}
function showMoteurTheme() {
	$("searchBudget").hide();
	$("searchBudgetM").hide();
	$("searchAll").hide();
	$("searchAllM").hide();
	$("searchTheme").show();
	$("searchThemeM").show();
}
// string => int
function stringToInt(val) {
	val = parseInt(val);
	if (isNaN(val)) { val = 0; }
	return val
}
/* ---------------- DATES --------------------------------*/
function parseDate(txtDate) {
	// string "dd/mm/yyyy" => obj Date
	if (!isDate2(txtDate)) {
		alert("parseDate() : '" + txtDate + "' date invalide"); return;
	}
	var tt = txtDate.split('/');
	var oDate = new Date(Number(tt[2]), Number(tt[1]) - 1, Number(tt[0]));
	return oDate;
}

function dateAdd(oDate, nbj) {
	if (typeof oDate != 'object' || oDate.constructor != Date) {
		alert("Erreur : la fonction dateAdd() doit recevoir un object Date en paramètre"); return;
	}
	var newDate = new Date(oDate.getFullYear(), oDate.getMonth(), oDate.getDate());
	newDate.setDate(newDate.getDate() + parseFloat(nbj));
	return newDate;
}
function date2String(oDate, sepi) {
	// obj Date => string "dd sepi mm sepi yyyy"
	if (typeof oDate != 'object' || oDate.constructor != Date) {
		alert("Erreur : la fonction date2String() doit recevoir un object Date en paramètre"); return;
	}
	return (oDate.getDate() < 10 ? "0" : "") + oDate.getDate()
  + sepi + (oDate.getMonth() < 9 ? "0" : "") + (oDate.getMonth() + 1)
  + sepi + oDate.getFullYear();
}

/* ---------------- AFFICHAGE DU CALENDRIER ------------- */
function getCalendar_Calendar1()
{
	var oCalendar = $('Calendar_Frame_Calendar1');
	if(oCalendar)
	{
		if(oCalendar.style.display=="none" || oCalendar.style.display=="")
		{
			var date = $$('input.date2cal')[0].value;
			var src = oCalendar.src;
			var reg = new RegExp("&today=.*$", "g");
			src = src.replace(reg,"");
			src = src + '&today=' + date;
			oCalendar.src = src;
			oCalendar.style.display = "block";
		}
		else
			oCalendar.style.display = "none";
	}
}
/* --------------- resizeIframe (height,idframe) ------------- */
function resizeIframe(idname, height) {
	height = height + 20;
	elt = $(idname);
	if (elt) elt.style.height = height + 'px';
}
/* ----------------TRIAGE MOTEUR */
function sortMoteur(idTri) {
	if(!$(idTri)) return;
	var sort = $(idTri).value;
	if(sort == "") return;
	var form = getFormctl00_MThome("");
	if (window.location.href.indexOf("/mer") >= 0) form += "&theme=1";
	if (window.location.href.indexOf("/montagne") >= 0) form += "&theme=2";
	if (window.location.href.indexOf("/campagne") >= 0) form += "&theme=3";
	if (window.location.href.indexOf("/courts-sejours") >= 0) form += "&theme=4";
	if (window.location.href.indexOf("/packs-tout-compris") >= 0) form += "&themepack=5";
	DrawMoteurResultatctl00_MiddleContent1_MR(form,'',0,sort);
}
/* ----------------REMISE A ZERO MOTEUR ------------- */
function remisazero() {
	var onlyPromo = false;
	var moteurs = new Array("MTHome", "ctl00_MiddleContent1_MT");
	for (var i = 0; i < moteurs.length; i++) {
		moteur = moteurs[i];
		if ($(moteur)) {
			oLieuDest = $(moteur + 'lieudest');
			if (oLieuDest) oLieuDest.value = "";

			oLieuLoc = $(moteur + 'lieuloc');
			if (oLieuLoc) oLieuLoc.value = "";

			oDate2 = $(moteur + 'date2');
			if (oDate2) oDate2.value = "";

			oDuree = $(moteur + 'duree');
			if (oDuree) oDuree.value = "";

			obudgetMax = $(moteur + 'budget_max');
			if (obudgetMax) obudgetMax.value = "1000";

			obudgetMin = $(moteur + 'budget_min');
			if (obudgetMin) obudgetMin.value = "0";

			if (moteur == "ctl00_MiddleContent1_MT") { DrawMoteurTemplatectl00_MiddleContent1_MT('', onlyPromo); return; }
			if (moteur == "MTHome") {DrawMoteurTemplateMTHome('', onlyPromo);return;}
		}
	}
}
/* ----------------PROMOS DU MOTEUR 2------------- */
function showPromo(id) {
	if ($(id).checked) { DrawMoteurTemplatectl00_MThome(false, true); }
	else { DrawMoteurTemplatectl00_MThome(false, false); }
}

/* ----------------REMISE A ZERO MOTEUR 2------------- */
function remisazero2() {
	var onlyPromo = true;
	oLieuDest = $('ctl00_MThomelieudest');
	if (oLieuDest) oLieuDest.value = "";
	oLieuLoc = $('ctl00_MThomelieuloc');
	if (oLieuLoc) oLieuLoc.value = "";
	oTypehebe = $('ctl00_MThometypelieuhebe');
	if (oTypehebe) oTypehebe.value = "";
	oDate2 = $('ctl00_MThomedate2');
	if (oDate2) oDate2.value = "";
	oPersonne = $('ctl00_MThomenbpersonne');
	if (oPersonne) oPersonne.value = "";
	oDuree = $('ctl00_MThomeduree');
	if (oDuree) oDuree.value = "";
	oPromo = $('ctl00_CheckPromos');
	if (oPromo) { oPromo.checked = false;onlyPromo = false;}
	DrawMoteurTemplatectl00_MThome('', onlyPromo);
}
/* ----------------VERIF DATE MOTEUR ------------- */
function isDate2(s) {
	var re = /^\d{2}\/\d{2}\/\d{2,4}$/;
	if (re.test(s)) {
		var yyyy = "";
		var dd = s.substring(0, 2);
		var mm = s.substring(3, 5);
		if (s.length == 10) {
			yyyy = s.substring(6, 10);
		}
		else if (s.length == 8) {
			yyyy = '20' + s.substring(6, 8);

		}
		var datTest = new Date(yyyy, mm - 1, dd);

		// date valide
		if ((yyyy == datTest.getFullYear()) && (mm - 1 == datTest.getMonth()) && (dd == datTest.getDate())) {
			return true;
		}
		else
		 return false;
	}
	else 
		return false;
}
// ----------------------REMPLI LES CHAMPS MOTEUR PAR FLASH ---------------
function SetLieuMoteurTemplatectl00_MThomeDest(lieuid)
{
	var oLieuDest = $('ctl00_MThomelieudest');
	if(oLieuDest) {
		for(var i=0; i<oLieuDest.options.length; i++){
			oLieuDest.options[i].selected = oLieuDest.options[i].value == lieuid;
		}
	}
}
function SetLieuMoteurTemplatectl00_MThomeLoc(lieuid)
{
	var oLieuLoc = $('ctl00_MThomelieuloc');
	if(oLieuLoc) {
		for(var i=0; i<oLieuLoc.options.length; i++){
			oLieuLoc.options[i].selected = oLieuLoc.options[i].value == lieuid;
		}
	}
}
// ----------------------AFFICHAGE DIAPO --------------------
function affBIG(src) {
	imgmoy = document.getElementById('toto');
	if (imgmoy) {
		imgmoy.src = src;
	}
}

function affBIG2(src) {
	imgmoy = document.getElementById('toto2');
	if (imgmoy) {
		imgmoy.src = src;
	}
}

//---------------------AFFICHAGE IMAGE LARGE----------------

function afflarge() {
	imglarg = document.getElementById('large');
	imgmoy = document.getElementById('toto');
	bt_fermer = document.getElementById('fermer');
	if (imgmoy) {
		imglarg.src = imgmoy.src;
		imglarg.style.display = '';
		bt_fermer.style.display = '';
	}
}
function cachlarge() {
	imglarg = document.getElementById('large');
	imgmoy = document.getElementById('toto');
	bt_fermer = document.getElementById('fermer');
	if (imgmoy) {
		imglarg.style.display = 'none';
		bt_fermer.style.display = 'none';
	}
}
function affrance() {
	fr = document.getElementById('france');
	eu = document.getElementById('europe');
	if (france) {
		fr.style.display = '';
		eu.style.display = 'none';
	}
}
function affeurop() {
	fr = document.getElementById('france');
	eu = document.getElementById('europe');
	if (france) {
		fr.style.display = 'none';
		eu.style.display = '';
	}
}
function affinfo() {
	inf = document.getElementById('blockinfo');
	hot = document.getElementById('blockhotel');
	if (inf) {
		inf.style.display = '';
		hot.style.display = 'none';
	}
}
function affhot() {
	inf = document.getElementById('blockinfo');
	hot = document.getElementById('blockhotel');
	if (hot) {
		inf.style.display = 'none';
		hot.style.display = '';
	}
}
function visibilite(thingId) {
	targetElement = document.getElementById(thingId);
	if (targetElement)
		targetElement.style.display = "";
}
function unvisibilite(thingId) {
	targetElement = document.getElementById(thingId);
	if (targetElement)
		targetElement.style.display = "none";
}
function changeimag(){
  var imgbiga = $('toto').src;  
	document.write("<a href=\"" + imgbiga + "\" rel=\"lightbox\">");
}

/**********************  MENU LEFT GUIDE *************************/

function MenuLeftIn(){
  $('menu_guide').style.display = "block";
  }
function MenuLeftOut(){
  $('menu_guide').style.display = "none";
    }
    
    
// -------------------- SCROLL MOTEUR  --------------------
	var scrollTimer; //global
	function stopScroll() 
	{
		if(scrollTimer)clearTimeout(scrollTimer);
	}
	function scrollVertic(px, myDiv) 
	{
		var div = document.getElementById(myDiv);
		if(!div) return;
		div.scrollTop = div.scrollTop+px;
		scrollTimer = setTimeout("scrollVertic("+px+",'"+myDiv+"')", 30);
	}
	function scrollHorizontal(px, myDiv) 
	{
		var div = document.getElementById(myDiv);
		if(!div) return;
		div.scrollLeft = div.scrollLeft+px;
		scrollTimer = setTimeout("scrollHorizontal("+px+",'"+myDiv+"')", 30);
	}	
	function scrollzero(myDiv)
	{
		var div = document.getElementById(myDiv);
		if(!div) return;
		div.scrollTop = 0;
	}
