// Bibliothèque de scripts - 


//****************************************************************
// Affichage des sous-menus 
//****************************************************************

sfHover = function() {
	if (document.getElementById('navigation'))
		{
			var sfEls = document.getElementById('navigation').getElementsByTagName("LI");
			for (var i=0; i<sfEls.length; i++) {
				sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


//****************************************************************
// Fonction d'import des animations Flash 
//****************************************************************

function RunFlash(swf, hauteur, largeur, nom) {
	document.write("<object width=\""+largeur+"\" height=\""+hauteur+"\" id=\""+nom+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\">\n");
	document.write("<param name=\"quality\" value=\"high\">\n");
	document.write("<param name=\"wmode\" value=\"transparent\">\n");
	document.write("<param name=\"movie\" value=\""+swf+"\">\n");
	document.write("<embed src=\""+swf+"\" quality=\"high\" wmode=\"transparent\" width=\""+largeur+"\" height=\""+hauteur+"\" name=\""+nom+"\" align=\"middle\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\">\n");
	document.write("</object>\n");
}


//****************************************************************
// Affichage des POPUP 
//****************************************************************

function funcPopup(varUrl, varWidth, varHeight, varResize) {
	var ScreenW = screen.availWidth;
	var ScreenH = screen.availHeight;
	var WinPopUp = window.open(varUrl, 'popup', "toolbar=no, menubar=no, scrollbars=yes, resizable=" + varResize + ", location=no, directories=no, status=no, width=" + varWidth + ", height=" + varHeight);
	WinPopUp.moveTo(Math.round((ScreenW-varWidth)/2), Math.round((ScreenH-varHeight)/2));	
}


//****************************************************************
// Gestion de la hauteur de la page 
//****************************************************************

/* function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
function setHeight() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentHeight = document.getElementById('page').offsetHeight;
			var footerElement = document.getElementById('foot');
			var footerHeight  = footerElement.offsetHeight;
			if (windowHeight - (contentHeight + footerHeight) >= 0) {
				footerElement.style.position = 'relative';
				footerElement.style.top = (windowHeight - (contentHeight + footerHeight)) + 'px';
			}
			else {
				footerElement.style.position = 'static';
			}
		}
	}
}
window.onload = function() {
	setHeight();
}
window.onresize = function() {
	setHeight();
} */


//****************************************************************
// Gestion de l'accordéon
//****************************************************************
//Initialize first demo:
ddaccordion.init({
	headerclass: "mypets", //Shared CSS class name of headers group
	contentclass: "thepet", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: false, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc]. [] denotes no content.
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", "openpet"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})

//****************************************************************
// AJAX pour le formulaire de reservation : Ville => hebergement
//****************************************************************
//--- Création de l'objet 'Ajax''
function funcGetXmlHR(){
    var objXmlHR = null;
    // Firefox et autres
    if(window.XMLHttpRequest) {
        objXmlHR = new XMLHttpRequest();
    // Internet Explorer
    } else if(window.ActiveXObject) {
        try {
            objXmlHR = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            objXmlHR = new ActiveXObject("Microsoft.XMLHTTP");
        }
    // XMLHttpRequest non supporté par le navigateur
    } else {
        alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
        objXmlHR = false;
    }
    return objXmlHR;
}

function majComboVille(varChemin) {

    var objXmlHR    = funcGetXmlHR();
    var strUrl      = "../_inc/CPN_Ajax_Ville.asp";
    var strResult   = "";
    var strParam    = "";
	var IdCombo		= ""
	var objCombo;

    strParam    += "cheminId=" + varChemin;
	
	//Mise a jour de la variable
	$('cheminId').value = varChemin;

    // Action déclenchée à la réception des données de la requête
    objXmlHR.onreadystatechange = function() {
        if(objXmlHR.readyState == 4) {
            strResult       = objXmlHR.responseText;
			//alert(strResult);
			IdComboDep = "VilleDep1";
			IdComboArr = "VilleArr1";
			//alert('Combo a modifier : ' + IdCombo);
            if (strResult != '') {
				//alert('Modification de la combo');
				//Ville de depart
				firstOpt = '<option value="null">DEPART</option>'
                $(IdComboDep).update(firstOpt + strResult);
				$(IdComboDep).activate();
				//Ville d'arrivée
				firstOpt = '<option value="null">ARRIVEE</option>'
				$(IdComboArr).update(firstOpt + strResult);
            }
        }
    }

	//alert('param = ' + strParam);
    // Connexion au serveur
    objXmlHR.open("POST", strUrl, true);
    objXmlHR.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    objXmlHR.send(strParam);
}
function majComboHebergmt(varType, varCptEtap, varVille) {

    var objXmlHR    = funcGetXmlHR();
    var strUrl      = "../_inc/CPN_Ajax_Hebergmt.asp";
    var strResult   = "";
    var strParam    = "";
	var IdCombo		= ""
	var objCombo;

    strParam    += "villeId=" + varVille + "&profilId=" + $('cheminId').value;
	
	//On empeche le changement du chemin
	i = 0;
	j = 0;
	j = $('nbChem').value;
	
	while (i < j) {
	
		$('typeChemin'+i).disable();
		i = i + 1;
	}
	
	

    // Action déclenchée à la réception des données de la requête
    objXmlHR.onreadystatechange = function() {
        if(objXmlHR.readyState == 4) {
            strResult       = objXmlHR.responseText;
			//alert(strResult);
			IdCombo = "Hebergmt"+varType+varCptEtap;
			//alert('Combo a modifier : ' + IdCombo);
            if (strResult != '') {
				//alert('Modification de la combo');
                $(IdCombo).update(strResult);
				$(IdCombo).activate();
            }
        }
    }

	//alert('param = ' + strParam);
    // Connexion au serveur
    objXmlHR.open("POST", strUrl, true);
    objXmlHR.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    objXmlHR.send(strParam);
}
