







//=================================================================================================================
/**
 * Fonction qui ouvre une msgBox de type confirm (bouton Ok et cancel)
 * params : 
 *			msg			, type String	, Message qui s'affichera dans la msgBox
 *			urlValidate	, type String	, Si l'utilisateur click sur oui, on redirige l'utilisateur vers cette url
 *
 **/
function msgConfirme(msg, urlValidate)
{
	if (confirm(msg))
	{
		document.location.href = urlValidate;
	}
}


//=================================================================================================================
/**
 * fonctions nécéssaires pour gérer les bandeaux du menu
 */
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//=================================================================================================================
/**
 * Fonction qui ouvre une fenetre popUp avec la taille specifie
 * params : 
 *			url		, type String	, url de la page affiche dans la fenetre pop up
 *			name	, type String	, nom de la fenetre
 *			width	, type integer	, largeur de la fenetre pop up
 *			height	, type integer	, hauteur de la fenetre pop up
 * 
 */
var WindowObjectReference = null;
function openWindow(strUrl, strWindowName,  width, height)
{
	/*alert(strUrl);*/
	if(WindowObjectReference == null || WindowObjectReference.closed)
	{
		WindowObjectReference = window.open(strUrl, strWindowName,
			'height=' + height + ',width=' + width + ',toolbar=no,status=no,directories=no,menubar=yes,location=no,scrollbars=yes,resizable=no');
	}
	else
	{
		WindowObjectReference.top.document.location.href=strUrl;
		WindowObjectReference.focus();
	};
}
		

//=================================================================================================================
/**
 * Fonction qui limite le nombres de caractères saisis dans un champ text ou textarea 
 * identifié par son id. 
 * Lorsqu'on atteint le maximum, la fonction efface les caractères en trop. 
 * 
 * @params	txt_id  : l'id du champ à contrôler 
 *			max		: le nombre maximum de caractères autorisé 
 */
function countCar(txt_id, max) 
{
	var txt = document.getElementById(txt_id);
	
	if (txt.value.length > max) 
	{
		txt.value = txt.value.substr(0, max); // substr(0, max) <=> substring(0, max-1)
	}
}


//=================================================================================================================
/**
 * Fonction utilisée pour le tracking de la pub du haut 
 */	
function countClickPub(idPub) 
{
	var MyXhr = new httpRequest(docRoot + "/_application/_fonctions/trackingPub.aspx", "id=" + idPub + "&action=click", "get");
	// ( docRoot est initialisé dans le contrôle bandeau_pub.ascx ) 
	MyXhr.createRequestObject();
	MyXhr.sendPostReq();

	MyXhr.xmlhttp.onreadystatechange = function()
	{
		if (MyXhr.xmlhttp.readyState == 4) /* 4 : état "complete" */
		{
			eval(MyXhr.xmlhttp.responseText);
		}
	}
}


//=================================================================================================================

function validateFormulaire(idForm)
{
	document.getElementById(idForm).submit();
}

//==============================================================================================
	/**
	 * Fonction qui renvoie True ssi la chaine passée en paramètre a bien le format d'un e-mail valide : 
	 **/
	function check_email(chaine)
	{
		//var regexp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9]+)+$/;
		var regexp = /^[_a-z0-9-]+([_a-z0-9-\.]+)*@[a-z0-9-]+([_a-z0-9-\.]+)*\.[a-z0-9]{2,}$/;
		
		return (regexp.test(chaine));
	}
	
//cette fonction vérifie si la chaine passée en paramétre, est bien une adresse URL
    function isURLValid(chaine)
   {
		var RegexpURL = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/; //"http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?";
		return (RegexpURL.test(chaine));
   }
     //==============================================================================================
	/**
	 * Fonction qui ouvre une fenetre popUp centrée sur l'écran 
	 * params : 
	 *			url		, type String	, url de la page affichée dans la fenetre pop up 
	 *			nom		, type String	, nom de la fenetre 
	 *			largeur	, type Integer	, largeur de la fenetre pop up 
	 *			hauteur	, type Integer	, hauteur de la fenetre pop up 
	 *			options	, type String	, options de la méthode window.open() MAIS SANS les attributs width et height ! 
	 * 
	 **/
	function centerPopup(url, nom, largeur, hauteur, options) 
	{
		//alert(url);
		
		var x = (screen.width/2) - (largeur/2);
		var y = (screen.height/2) - (hauteur/2);
		
		if (options != '') {
			options += ',';
		}
		
		options += 'width=' + largeur + ',height=' + hauteur + ',top=' + y + ',left=' + x;
		//alert(options);
		//alert('centerPopup OK, now window.open...');
		window.open(url, nom, options);
		//alert('...window.open OK !');
	}
	
	//************************************
	//=================================================================================================================
/**
 * Fonction qui ouvre une fenetre popUp avec la taille specifie et sans menu bar et sans scrollbars
 * params : 
 *			url		, type String	, url de la page affiche dans la fenetre pop up
 *			name	, type String	, nom de la fenetre
 *			width	, type integer	, largeur de la fenetre pop up
 *			height	, type integer	, hauteur de la fenetre pop up
 * 
 */
var WindowObjectReference = null;
function openWindowWithoutMenuScroll(strUrl, strWindowName,  width, height)
{
	if(WindowObjectReference == null || WindowObjectReference.closed)
	{
		WindowObjectReference = window.open(strUrl, strWindowName,
			'height=' + height + ',width=' + width + ',toolbar=no,status=no,directories=no,menubar=no,location=no,scrollbars=no,resizable=no');
	}
	else
	{
		WindowObjectReference.top.document.location.href=strUrl;
		WindowObjectReference.focus();
	};
}

function loadDept(value, idSelDept, selectedIndex)
{
	var selectDept = document.getElementById(idSelDept); 
	var xhr_object = null; 
		  	
	// si Firefox 
	if(window.XMLHttpRequest) 
	{xhr_object = new XMLHttpRequest();} // Sinon si Internt Explorer .... beurk
	else if(window.ActiveXObject) 
	{xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); } // XMLHttpRequest non supporté par le navigateur 
	 else { alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); return;}
		

	xhr_object.open("POST", "/agenda_manifestation/remplirSelectDepartement.aspx", true); 
		     
	xhr_object.onreadystatechange = function() 
	{ 	
		if (xhr_object.readyState == 4) 
		{
			eval(xhr_object.responseText); 
			if (selectedIndex > 0){selectIndexForThisValue(selectDept,selectedIndex);}
		}
	} 
	 
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
		
	var data = "region=" + value + "&idListeDeroulante=" + idSelDept ;

	xhr_object.send(data); 	



} 
	
	function selectIndexForThisValue(selectBox, value)
	{
		var i = 0;
		
		while (selectBox.length > i )
		{
			if (selectBox.options[i].value == value)
			{
				selectBox.options[i].selected = true;
			}
			
			i = i + 1;
		}
	}
	
	function regEnabled(theValue)
	{
		if (theValue == 1) // 1 est le code de la France dans BDD
		{
			document.getElementById("selDepartement").disabled = false;
			document.getElementById("ListReg").disabled = false;
		}
		else
		{
			document.getElementById("selDepartement").selectedIndex = 0;
			document.getElementById("ListReg").selectedIndex= 0;
			document.getElementById("selDepartement").disabled = true;
			document.getElementById("ListReg").disabled = true;
			
		}
	}