/*----------------------------------- GESTION DIV ----------------------------*/
var ns = (navigator.appName.substring(0,3) == "Net") ? true:false;

/*---------------------------------------------------------------------------------*/
function open_close(calque)
	{
	c = getcalque(calque);

	/*--------- On cache ou montre ---------*/
	if(c.style.display == "none") c.style.display = "";
		else c.style.display = "none";
	}

/*---------------------------------------------------------------------------------*/
function getcalque(calque)
	{
	/*--------- Booléen reconnaissant le navigateur (vu en partie 2) ---------*/
	isIE = (document.all)
	isNN6 = (!isIE) && (document.getElementById)

	/*--------- Compatibilité : l'objet menu est détecté selon le navigateur ---------*/
	if(isIE) return document.all[calque];
	if(isNN6) return document.getElementById(calque);
	}



/*----------------------------------- RESERVATION ----------------------------*/
function send_resa(formElem, id_saison)
	{
	//alert('id_saison='+id_saison);
	var thisForm = document.forms[formElem.name];

	var datedep_name = (formElem.name=='form_info_s'+id_saison)?'date_input1':'date_input2';
	datedep = thisForm.elements[datedep_name].value;

	if(datedep!='')
		{
		s = datedep.split("/");
		datedep = s[2]+s[1]+s[0];

		urlbis="index.php?option=com_atlasweb&ds_get_action=RchProExtAct&Itemid=28";
		urlbis+='&incr='+thisForm.elements['incr'].value;	//&prod=NYC.BASIC
		urlbis+='&prod='+thisForm.elements['prod'].value;	//&incr=10
		urlbis+='&dtdep='+datedep;

		//alert(urlbis);
		document.location = "http://atlasweb.datasystem.fr/"+urlbis;
		}
	else
		{
		alert("Veuillez saisir la date de départ.");
		}
	return false;
	}




/*----------------------------------------------------------------------------------*/
/* GESTION DIAPORAMA																*/
/*----------------------------------------------------------------------------------*/

var saison_pointe = 0;

function init_first_content (id_saison)
	{
	var menu_entry = $$('#menu'+id_saison+' li');
	
	if( menu_entry ){ if( menu_entry[0] ){ set_content(menu_entry[0].className, id_saison); } }
	}
function set_content (cat,id_saison)
	{
	refresh_current_menu(id_saison);		// Vider pour chaque menu le style du menu
	set_current_menu(cat, id_saison);		// Appliquer style sur le menu sélectionné

	$('para_content'+id_saison).update();	// Vider le div
	$$('div.para_'+cat).each(function(e)	// Pour chaque élément ajouter le bloc
		{
		new Insertion.Bottom($('para_content'+id_saison), e.innerHTML);
		});
	}
function set_current_menu (cat,id_saison)
	{
	var elem = $$('#menu'+id_saison+' li.'+cat);
	Element.addClassName(elem[0], 'current-menu');
	}
function refresh_current_menu (id_saison)
	{
	$$('#menu'+id_saison+' li').each(function(e){ if(Element.hasClassName(e, 'current-menu')){ Element.removeClassName(e, 'current-menu'); } });
	}
function slideshow(act)
	{
	alert(current_diapo+'//'+list_diapo.length);
	}

var slideShow = Class.create();
slideShow.prototype = {

	img: null,
	options: null,
	list: [],
	legend: [],

	initialize: function (img, options) {
		this.options = {
			'current': 0
		}
		Object.extend(this.options, options || {});
		this.img = img;
	},

	start: function () {
		this.list = new Array();
		this.legend = new Array();
		$$(this.options.entry).each(function(element, i){
			this.list.push(element.readAttribute('src'));
			this.legend.push(element.readAttribute('title'));
			if(i==this.options.current){ this.display(this.options.current); }
		}.bind(this));
	},

	previous: function () {
		if(this.options.current==0){ this.options.current = Number(this.list.length); }
		this.options.current-=1;
		this.display(this.options.current);
	},

	next: function () {
		if(this.options.current==(Number(this.list.length)-1)){ this.options.current = -1; }
		this.options.current+=1;
		this.display(this.options.current);
	},

	display: function (indice) {
		$(this.img).src = this.list[indice];
		if($$(this.options.legendNode)){
			$$(this.options.legendNode).first().update(this.legend[indice]);
		}
	},

	_void: function(){}

}


/*----------------------------------------------------------------------------------*/
/*	GESTION POPUP																	*/
/*----------------------------------------------------------------------------------*/
function openpopup (w,h,page)
	{
	win = window.open(page,w+'x'+h,'top='+(((screen.height)/2)-(h/2))+',left='+(((screen.width)/2)-(w/2))+',toolbar=no,scrollbars=yes,resizable=yes,menu=no,width='+w+',height='+h);
	win.focus();
	}
function closewindow (url) {window.close();}


/*----------------------------------------------------------------------------------*/
/* GESTION DES SAISONS																*/
/*----------------------------------------------------------------------------------*/
function loadSaison()
	{
	saison = getVar("saison");		// Var onglet
	saison_defaut=1;
	//alert("var saison="+saison);

	// Si une date passé en param
	mydate = getVar("dtres");
	if(mydate!=0)
		{
		//alert("mydate="+mydate);
		now = getDate(mydate,1);		// Doit être au format 20070828 pour 28.08.2007
		}
	else
		{
		var now = new Date();		// Sinon prendre aujourd'hui
		//alert("now: "+now+ " "+Date.UTC( now.getFullYear(),now.getMonth(),now.getDate(),0,0,0 ));
		}

//	alert("bornes du xml: "+bornes_saison_1);
	saison1_start = getDate(bornes_saison_1[0]);
	saison1_start.setMonth(Number(saison1_start.getMonth()-1)); // !! Attention 20070930 donne en javascript 20071030 (1 mois de plus)
	saison1_stop = getDate(bornes_saison_1[1]);
	saison1_stop.setMonth(Number(saison1_stop.getMonth()-1));
//	alert(saison1_stop.getMonth());
//	alert(saison1_stop);
	if(compare(now,saison1_start)>=0 && compare(saison1_stop,now)<=0){ saison_defaut=1; }

// alert(bornes_saison);

	if(bornes_saison==2)
		{
		saison2_start = getDate(bornes_saison_2[0]);
		saison2_start.setMonth(Number(saison2_start.getMonth()-1));
		saison2_stop = getDate(bornes_saison_2[1]);
		saison2_stop.setMonth(Number(saison2_stop.getMonth()-1));
		//alert("now="+now+" saison1_start="+saison1_start+" saison1_stop="+saison1_stop);

		if(compare(now,saison2_start)>=0 && compare(saison2_start,now)<=0){ saison_defaut=2; }

		} else {
			saison_defaut = 1;
		}
	
	if(saison==0)	// Si on spécifie pas un onglet
		{
		saison_pointe = saison_defaut;
		$("saison_"+saison_pointe).show();
		}
	else
		{
		saison_pointe = saison;
		$("saison_"+saison_pointe).show();
		}

	/*
		-----------------------------------------------
		Modification
		Christophe le 30/07/2008
		-----------------------------------------------
	*/
	if(bornes_saison == 1){	// Cas d'une seule saison
		var tabs = $$('#menu_saison > .tab-saison');	// Recuperation du premier onglet
		if(tabs){	// si presence d'onglet
			var firstTab = tabs.first();
			if(!firstTab.innerHTML.stripTags().length){	// Si pas de libelle saison dans l'onglet
				firstTab.hide();	// Suppression a l'affichage de l'onglet vide
			}
		}
	}

	var childNode = $("tab_saison_"+saison_pointe).getElementsBySelector('div.tab-saison-inner');
	if(childNode){ childNode.first().addClassName('tab-saison-ACT'); }
//	$("tab_saison_"+saison_pointe).style.background='white';
	if(saison_pointe==2){
		$('menu_saison').addClassName('menu-saison-2');
	} else {
		$('menu_saison').removeClassName('menu-saison-2');
	}
	maj_title(saison_pointe);
	}

/*-----------------------------------------------------*/
function getDate(strDate, type)
	{
	year = strDate.substring(0,4);
	if(type==1) 
		month = strDate.substring(4,6)-1; 
	else
		month = strDate.substring(4,6);
	day = strDate.substring(6,8);
//	alert("year="+year+" month="+month+" day="+day);

	d = new Date();
	d.setDate(day);
	d.setMonth(month);
	d.setFullYear(year);

	return d;
	}

/*-----------------------------------------------------*/
//Retorune:
//   0 si date_1=date_2
//   1 si date_1>date_2
//  -1 si date_1<date_2
function compare(date_1, date_2)
	{
	diff = date_1.getTime()-date_2.getTime();
//	alert("date_1 ["+date_1+"] moins date_2 ["+date_2+"] => diff="+diff);

	return (diff==0?diff:diff/Math.abs(diff));
	}




/*---------- change_onglet_saison ----------------*/
function change_onglet_saison(onglet_saison)
	{
	//alert("onglet_saison="+$('bouton_1 a'));
	/*--- Ancien ---*/
	if(onglet_saison==2){
		$('menu_saison').addClassName('menu-saison-2');
	} else {
		$('menu_saison').removeClassName('menu-saison-2');
	}
	$("saison_"+saison_pointe).hide();
//	$("tab_saison_"+saison_pointe).style.background='';
	var childNode = $("tab_saison_"+saison_pointe).getElementsBySelector('div.tab-saison-inner');
	if(childNode){ childNode.first().removeClassName('tab-saison-ACT'); }

	/*--- Nouveau ---*/
	$("saison_"+onglet_saison).show();
//	$("tab_saison_"+onglet_saison).style.background='white';
	var childNode2 = $("tab_saison_"+onglet_saison).getElementsBySelector('div.tab-saison-inner');
	if(childNode2){ childNode2.first().addClassName('tab-saison-ACT'); }

	saison_pointe = onglet_saison;

	/*--- Titre page ---*/
	maj_title(onglet_saison);
	return false;
	}

/*--------- Titre page ----------*/
function maj_title(saison)
	{
	/*var str = $("tab_saison_"+saison+"_a").innerHTML;
	str = str.stripTags();
	document.title = $("titre_"+saison).innerHTML + ' (' +str+")";*/
	}

/*--------- Lecture vars url ----------*/
function getVar(nomVariable)
	{
	var infos = location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&"
	if (infos.indexOf("#")!=-1)
	infos = infos.substring(0,infos.indexOf("#"))+"&"
		var variable=0
		{
		nomVariable = nomVariable + "="
		var taille = nomVariable.length
		if (infos.indexOf(nomVariable)!=-1)
		variable = infos.substring(infos.indexOf(nomVariable)+taille,infos.length).substring(0,infos.substring(infos.indexOf(nomVariable)+taille,infos.length).indexOf("&"))
		}
	return variable
	}
