﻿var libelleUtiles = "";

function AfficherDetailCommentaire(idDivDetail, idZoom){
    if(document.getElementById(idZoom).value == "0") {
	    document.getElementById(idDivDetail).style.display = "block";
	    document.getElementById(idZoom).value = "1";
	}
}

function FermerDetailCommentaire(idDivDetail, idZoom){
	document.getElementById(idDivDetail).style.display = "none";
	document.getElementById(idZoom).value = "0";
}

function AfficheFiltreUnAvis(idDivFiltre)
{
    document.getElementById(idDivFiltre).style.display = "block";	
}

function CacheFiltreUnAvis(idDivFiltre)
{
    document.getElementById(idDivFiltre).style.display = "none";	
}

function vote(idAvis,valeur,divVote,divRemerciement,lblNbUtile,adressePage,idLangue,idProfilConnecte,nomdomaine){
	date=new Date;
	date.setMonth(date.getMonth()+80);
	document.getElementById(divVote).style.display="none";
	var Node = document.getElementById(divVote);
	while(Node.hasChildNodes()==true){
		var Enfant = Node.firstChild;
		Node.removeChild(Enfant);
	}
	document.getElementById(divRemerciement).style.display="block";
	EcrireCookie("utile", idAvis+"-"+valeur, date,'/',nomdomaine);
	var xhr = getXmlHttpRequest();
	
	xhr.open('GET', adressePage+"Pages/Avis/DonneVote.aspx?idAvis="+idAvis+"&Vote="+valeur+"&idProfil="+idProfilConnecte+"&idLangue="+idLangue, true);
	xhr.onreadystatechange=function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			var nbOui = parseInt(xhr.responseXML.documentElement.firstChild.childNodes[0].nodeValue);
			var nbVotant = parseInt(xhr.responseXML.documentElement.lastChild.childNodes[0].nodeValue);
			document.getElementById(lblNbUtile).innerHTML = donneLibelleUtilite(nbOui,nbVotant);
		}
	}	
	xhr.send(null);
	return false;
}

function initLibelleUtile(libelleUtile)
{
    libelleUtiles = libelleUtile;
}

function donneLibelleUtilite(nbOui,nbVotant){
    var ret = libelleUtiles;
    var indice;
    
    indice = ret.indexOf("#NB_UTILES#",0);
	ret = ret.substr(0,indice) + nbOui + ret.substr(indice + 11,ret.length - (indice + 11));
	indice = ret.indexOf("#NB_TOTAL#",0);
    ret = ret.substr(0,indice) + nbVotant + ret.substr(indice + 10,ret.length - (indice + 10));
    return ret;
}

function EcrireCookie(nom, valeur)
{	
	var cookie = LireCookie(nom);
	if(cookie == null)
		cookie="";
	var argv = EcrireCookie.arguments;
	var argc = EcrireCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	if(domain == '')
		domain = null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = nom+"="+escape(valeur)+"#"+cookie+((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}

function LireCookie(nom)
{
	var arg=nom+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen)
	{
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg) 
		{
		    return getCookieVal(j);
		    }
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}
	return null;
}

function getCookieVal(offset)
{
    var endstr=document.cookie.indexOf (";", offset);
    if (endstr==-1) 
        endstr=document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

function getXmlHttpRequest(){
    var xhr;
    if (window.XMLHttpRequest)
	    xhr = new XMLHttpRequest();
    else if (window.ActiveXObject)
        xhr = new ActiveXObject("Microsoft.XMLHTTP"); 
    return xhr;
}