/*Example message arrays for the two demo scrollers*/

var tabMessages=new Array()
tabMessages[0]='<a href="../energiesolaire/thermique.php">1m&sup2; de capteur solaire thermique &eacute;vite d\'&eacute;mettre 250 Kg de CO2 par an</a>'
//tabMessages[1]='<a href="../energiesolaire/cout.php">PROMOTION : 40% de r&eacute;duction sur l\'installation*</a>'
tabMessages[1]='<a href="../energiesolaire/photovoltaique.php">Revendez l\'&eacute;lectricit&eacute; que vous produisez à EDF pendant 20 ans</a>'
tabMessages[2]='<a href="../nosservices/efficacite.php">En 6 heures, une lampe fluocompacte &eacute;conomise son propre poids en p&eacute;trole</a>'
tabMessages[3]='<a href="../nosservices/efficacite.php">Coupez votre facture &eacute;nerg&eacute;tique en 2 grace à la démarche Negawatt</a>'
//tabMessages[4]='<a href="../nosservices/installation.php">Nous vous alertons en cas de dysfonctionnement de votre installation</a>'
//tabMessages[0]='<a href="../consommation/climat.php">Construire avec le climat et non contre lui</a>'



/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
***********************************************/

function pausescroller(){
	this.delay=4500
	this.mouseoverBol=0 
	this.hiddendivpointer=1 
	document.write('<div id="messages"><div class="innerDiv" id="messages1">'+tabMessages[0]+'</div><div class="innerDiv2" id="messages2">'+tabMessages[1]+'</div></div>')
	var scrollerinstance=this
	if (window.addEventListener) 
		window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
	else if (window.attachEvent) 
		window.attachEvent("onload", function(){scrollerinstance.initialize()})
	else if (document.getElementById) 
		setTimeout(function(){scrollerinstance.initialize()}, 500)
}


pausescroller.prototype.initialize=function(){
	this.tickerdiv=document.getElementById("messages")
	this.visiblediv=document.getElementById("messages1")
	this.hiddendiv=document.getElementById("messages2")
	this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
	//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
	this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
	this.getinline(this.visiblediv, this.hiddendiv)
	this.hiddendiv.style.visibility="visible"
	var scrollerinstance=this
	document.getElementById("messages").onmouseover=function(){scrollerinstance.mouseoverBol=1}
	document.getElementById("messages").onmouseout=function(){scrollerinstance.mouseoverBol=0}
	if (window.attachEvent) //Clean up loose references in IE
		window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
	setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
	if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
		this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
		this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
		setTimeout(function(){scrollerinstance.animateup()}, 50)
	}
	else{
		this.getinline(this.hiddendiv, this.visiblediv)
		this.swapdivs()
		setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
	}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
	var tempcontainer=this.visiblediv
	this.visiblediv=this.hiddendiv
	this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
	div1.style.top=this.visibledivtop+"px"
	div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
	var scrollerinstance=this
	if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
		setTimeout(function(){scrollerinstance.setmessage()}, 100)
	else{
		var i=this.hiddendivpointer
		var ceiling=tabMessages.length
		this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
		this.hiddendiv.innerHTML=tabMessages[this.hiddendivpointer]
		this.animateup()
	}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
	if (tickerobj.currentStyle)
		return tickerobj.currentStyle["paddingTop"]
	else if (window.getComputedStyle) //if DOM2
		return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
	else
		return 0
}


function makeRequest(url, id) {
	// envoie d'une requete lorsqu'on fait un choix dans la liste deroulante
	var http_request = false;
	//alert(url);
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
   		http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE      
        try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) {
        alert('Impossible de creer une instance XMLHTTP.');
        return false;
    }
    //action a realiser
    http_request.onreadystatechange = function() { changerListe(http_request, id); };
    //preparation requete
    http_request.open('GET', url, true);
    //envoie de la requete
    http_request.send(null);
}

function changerListe(http_request, id) {
	// traitement du resultat de la requete

	if (http_request.readyState == 4) {
		//requete termin?e
    	
    	if (http_request.status == 200) {
    		//requete HTTP ok => ecriture de la liste
			//document.etiquette.cpo.innerHTML = http_request.responseText; ->marche pas sous IE
			document.getElementById(id).innerHTML = http_request.responseText;
        }
       	else {
        	alert('Un probleme est survenu avec la requete.');
        }
     }
}
