function hasParameter(uri, name)
{
	re = new RegExp("[\?\&]" + name + "=");
	return (uri.search(re) != -1);
}

function addParameter(uri, name, value)
{	
	re = new RegExp("[\?]");	
	if (uri.search(re) != -1) {uri2 = uri + "&";}
	else {uri2 = uri + "?";}	
	uri2 = uri2 + name + "=" + value;
	return uri2;
}

function replaceParameter(uri, name, value)
{	
	if (hasParameter(uri, name)) {	
		re = new RegExp("([\?\&])" + name + "=([^\&]*)(.*)$","");
		uri2 = uri.replace(re, "$1" + name + "=" + value + "$3");			
	} else {
		uri2 = addParameter(uri, name, value);
	}
	return uri2;
}

function deleteParameter(uri, name)
{
	re = new RegExp("([\&])" + name + "=([^\&]*)");
	uri = uri.replace(re, "");
	re = new RegExp("([\?])" + name + "=([^\&]*)");
	uri = uri.replace(re, "$1");
	re = new RegExp("[\?][\&]");
	uri = uri.replace(re, "?");	
	re = new RegExp("[\?]$");
	uri = uri.replace(re, "");	
	return uri;
}

function getURL(page, content, params)
{
	uri = URI;
	
	if (page > "") {
		uri = replaceParameter(uri, "page", page);
		if (content > "") {
			uri = replaceParameter(uri, "portlet", content);
		} else {
			uri = deleteParameter(uri, "portlet");
		}		
	} else {
		if (content > "") {
			if (hasParameter(uri, "page")) {
				uri = replaceParameter(uri, "portlet", content);
			} else {
				uri = replaceParameter(uri, "page", content);
			}
		}
	}
	
	return (uri + params);
}

function goToPage(page, content, params)
{	
	window.location = getURL(page, content, params);
}

function goToPopup(name, page, content, params, width, height, left, top, options)
{		
	if (options == '') 
	{
		options = "toolbar=no,location=no,directories=no,status=no,";
		options += "menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,";
	}	
	if (left > '') options += "left=" + left + ",";
	if (top > '') options += "top=" + top + ",";
	options += "width=" + width + ",height=" + height;
	if (name == '') name = "atlantal";
	
	window.open(getURL(page, content, params), name, options);
	return false;
}

function OuvrePage(urlpage, width, height, left, top)
{		
	stropt = "toolbar=no,location=no,directories=no,status=no,";
	stropt += "menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,";
	
	if (left > '') stropt += "left=" + left + ",";
	if (top > '') stropt += "top=" + top + ",";
	stropt += "width=" + width + ",height=" + height;
	var newFen = window.open(urlpage, 'Popup', stropt);
	newFen.focus();
	return false;
}

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.0
  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 && document.getElementById) x=document.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];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function VerifNonVide()
{
	var args=VerifNonVide.arguments;
	
	if (document.forms[args[0]]!="undefined")
	{
		for(i=1;i<args.length;i++)
		{
			le_champ = document.forms[args[0]].elements[args[i]];
			if (!chpRempli(le_champ))
				return false;
		}
	}
			
	return true;
}

function VerifMail() {
	var args=VerifMail.arguments;
	
	if (document.forms[args[0]]!="undefined")
	{
		for(i=1;i<args.length;i++)
		{
			le_champ = document.forms[args[0]].elements[args[i]];
			if ((le_champ.value.indexOf("@")==-1)||(le_champ.value.indexOf(".",le_champ.value.indexOf("@"))==-1)) {
				alert("Adresse e-mail incorrecte!! Vérifiez que vous ne vous êtes pas trompé.");
				le_champ.focus();
				return (false);
			}			
		}
	}
			
	return true;
}

function chpRempli(champ) {
	if (lngChamp(champ)==0) {
		alert('Renseignez le champ " '+champ.name+' " SVP');
		champ.focus();
		return false;
	}
	
	return true;
}

function lngChamp(chp) {
	strMot = chp.value;
	while (strMot.search(' ')!=-1)
		strMot = strMot.replace(' ', '');
	while (strMot.search('\r\n')!=-1)
		strMot = strMot.replace('\r\n', '');
	
	return strMot.length;
}

function OuvreGraph(urlpage, width, height, left, top)
{		
	stropt = "toolbar=no,location=no,directories=no,status=no,";
	stropt += "menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,";
	
	if (left > '') stropt += "left=" + left + ",";
	if (top > '') stropt += "top=" + top + ",";
	stropt += "width=" + width + ",height=" + height;
	var newFen = window.open(urlpage, 'PopupGraph', stropt);
	newFen.focus();
}
