//ContextURL du site
var contextURL = "";
var jspContextURL = "";
var servletURL = "";

function setContextURL(ctx)
{
	contextURL=ctx;
}
function setJspContextURL(ctx)
{
	jspContextURL=ctx;
}
function setServletURL(servlet)
{
	servletURL=servlet;
}

function checkRedirectToHTTP(pathToRedirect){
	//alert("check for redir");
	
	if(pathToRedirect != ""){
		//alert("redirecting");
		window.location = pathToRedirect;
		return false;
	}
}



//JavaScript Document
function $()
{
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}



function showHide(id)
{
	if (document.getElementById("div_showHide"+id).style.display == 'block')
	{
		document.getElementById("div_showHide"+id).style.display = 'none';
		document.images["img_showHide"+id].src = jspContextURL + '/Multimedia/Images/portail_home_fleche_bas.png';
		document.images["img_showHide"+id].alt = "ouvrir";
	}
	else
	{
		document.getElementById("div_showHide"+id).style.display = 'block';
		document.images["img_showHide"+id].src = jspContextURL + '/Multimedia/Images/portail_home_fleche_haut.png';
		document.images["img_showHide"+id].alt = "fermer";
	}	
}

function showHidePuce2(id, template)
{
	if ($("img_showHide"+id).className == "puceFermer" + template)
	{
		$("div_showHide"+id).style.display = "none";
		if ($("photo_showHide"+id) != null) $("photo_showHide"+id).style.display = "none";
		$("img_showHide"+id).className = "puceOuvrir"  + template;
	}
	else
	{
		$("div_showHide"+id).style.display = "block";
		if ($("photo_showHide"+id) != null) $("photo_showHide"+id).style.display = "block";
		$("img_showHide"+id).className = "puceFermer" + template;
	}	
}

function getCookieVal(offset)
{ 
	var endstr = document.cookie.indexOf (";", offset); 
	if (endstr == -1) endstr = document.cookie.length; 
	return unescape (document.cookie.substring(offset, endstr)); 
} 
 
function GetCookie(name)
{ 
	var arg = name+"="; 
	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 PutCookie(value, idReponse) 
{
	$("sondageIdReponse").value=idReponse;
	var name = "pollId_"+value;
	var expireDate = new Date(); 
	expireDate.setDate(365+expireDate.getDate()); 
	document.cookie = name+"="+value+"; path=/; expires="+expireDate.toGMTString();
	document.forms["voter_sondage" + value].submit();
} 

function readCookie(name){
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    //alert('A cookie was not set. '+name+'. Please ensure your browser accepts cookies.');
    return "Username";
}

function ajouterFavoris(urlAddress, pageName) {
	if (document.all) {
        window.external.AddFavorite(urlAddress,pageName);
    }
    else if (window.sidebar) {
        window.sidebar.addPanel(pageName, urlAddress, "");
    }
    else {
        alert("Désolé! Votre navigateur ne supporte pas cette fonction.");
    }
}


var searchQueryText = "";
function onBlurRecherche(id)
{
	setTimeout("onBlurRechercheAfterTimeout('"+id+"')", 500);
}
function onBlurRechercheAfterTimeout(id)
{
	if ($(id).value == '')
		$(id).value = searchQueryText;
}
function onFocusRecherche(id, defaultText)
{
	if ($(id).value == defaultText){
		searchQueryText = defaultText;
		$(id).value = '';
	}
}

function submitSearch()
{
	$("searchStringHidden").value = $("rechercheActu").value;
	document.forms["jahiapageform"].submit();
	return false;
}

function affichage_popup(nom_de_la_page, nom_interne_de_la_fenetre, width, height)
{
	var top=(screen.height-height)/2;
	var left=(screen.width-width)/2; 
	window.open (nom_de_la_page, nom_interne_de_la_fenetre, 'top=' + top + ',left=' + left + ',height=' + height + ', width=' + width + ', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
}

function affichage_popup_scroll(nom_de_la_page, nom_interne_de_la_fenetre, width, height)
{
	var top=(screen.height-height)/2;
	var left=(screen.width-width)/2; 
	//alert(nom_de_la_page +","+ nom_interne_de_la_fenetre+","+ 'top=' + top + ',left=' + left + ',height=' + height + ', width=' + width + ', toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no');
	window.open (nom_de_la_page, nom_interne_de_la_fenetre, 'top=' + top + ',left=' + left + ',height=' + height + ', width=' + width + ', toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no');
}
