/**********************************************************/
CLLoadXmlDoc=function()
{
	this.bLoaded=false;
	this.req=null;
	this.caller=null;
	me=this;
	
	this.LoadDoc=function(_caller,_szUrl) {
	    this.caller=_caller;
		try {
			if (window.XMLHttpRequest) {
				this.req = new XMLHttpRequest();
				this.req.onreadystatechange = this.processReqChange;
				this.req.open("GET", _szUrl, true);
				this.req.send(null);
			} else {
				if (window.ActiveXObject) {
					this.req = new ActiveXObject("Microsoft.XMLHTTP");
					if (this.req) {
						this.req.onreadystatechange = this.processReqChange;
						this.req.open("GET", _szUrl, true);
						this.req.send();
					} else {
					    this.req = new ActiveXObject("Msxml2.DOMDocument");
					    if (req!=null) {
					        this.req.setProperty("ServerHTTPRequest", true);
					        this.req.validateOnParse = false;
					        this.req.async = false;
					        this.req.load(_szUrl);
					        this.processReqChange();
                        }
                    }
				}
			}
		}catch(e){this.req=null;}
	}
	this.processReqChange=function() {
		if (me.req.readyState == 4) {
			if (me.req.status == 200) {
				me.caller(me.req.responseText);
			}
		}
	}
}
/*******************************/
function selectTpl(templateName,layerName,id) {
    var oDiv=document.getElementById(layerName);
    if (templateName.length>0 && oDiv!=null) {
	    CLPage.AjaxTemplateForm(id,templateName,callBack);
    }
    function callBack(response) {
        oDiv.innerHTML=response.value;
    }
}
/*
function selectTpl(templateName,ctrlName,layerName) {
    var oDiv=document.getElementById(layerName);
    var oTxt=document.getElementById(ctrlName);
    if (templateName.length>0 && oDiv!=null && oTxt!=null) {
        var loadXmlDoc=new CLLoadXmlDoc();
	    loadXmlDoc.LoadDoc(ready,"http://sberthuhp/templates/"+templateName+".htm");
    }
    function ready(html) {
        oDiv.innerHTML=html;
    }
}
*/
/*******************************/
function setStyle(Ctrl,styleName,styleValue) {
	if (Ctrl) {
		if (Ctrl.style)
			Ctrl.style[styleName]=styleValue;
		else
			Ctrl[styleName]=styleValue;
	}
}
/*******************************/
function checkTextBox(Ctrl,szCaption)
{
	if (Ctrl.value=="")
	{
		alert("You must fill in the field '"+szCaption+"'");
		try {
		    Ctrl.focus();
        } catch (e){}
		return false;
	}
	return true;
}
/*******************************/
function VerifAlphaNum(szPhrase,nbCarMin,nbCarMax)
{
  var exp=new RegExp("^[a-zA-Z0-9]{"+nbCarMin+","+nbCarMax+"}$","g");
  return (exp.test(szPhrase));
}
/*******************************/
function isNum(vid)
{
  var num=parseFloat(vid);
  return !isNaN(num);
}
/*******************************/
function isAlphaNum(vid)
{
	var bRep=VerifAlphaNum(vid,0,255);
	if (!bRep) alert("Incorrect value !");
	return bRep;
}
/*******************************/
function isInt(vid)
{
	oRegEx=new RegExp("^[0-9]*$");
	bRep=oRegEx.test(vid);
	if (!bRep) alert("Incorrect value ! \n Here is an example of a correct format : 25");
	return bRep;
}
/*******************************/
function isCP(vid)
{
	oRegEx=new RegExp("^[0-9]{5}$");
	bRep=oRegEx.test(vid);
	if (!bRep) alert("Le code postal saisi n'est pas valide !! \n Exemple de format valide : 75001");
	return bRep;
}
/*******************************/
function isEMail(vid)
{
	oRegEx=new RegExp("^.+@.+\\..+$");
	bRep=oRegEx.test(vid);
	if (!bRep) alert("L'adresse email saisie n'est pas valide !! \n Exemple de format valide : toto@domaine.fr");
	return bRep;

}
/*******************************/
function isURL(vid)
{
	oRegEx=new RegExp("^http://.+\\..+\\..+$");
	bRep=oRegEx.test(vid);
	if (!bRep) alert("L'URL saisi n'est pas valide !! \n Exemple de format valide : http://www.domaine.fr");
	return bRep;
}
/*******************************/
function isTel(vid)
{
	oRegEx=new RegExp("^0[1-9]\\.[0-9]{2}\\.[0-9]{2}.[0-9]{2}.[0-9]{2}$");
	bRep=oRegEx.test(vid);
	if (!bRep) alert("Le num\xe9ro de t\xe9l\xe9phone saisi n'est pas valide !! \n Exemple de format valide : 04.01.23.14.12");
	return bRep;
}
/*******************************/
function isTime(vid)
{
	oRegEx=new RegExp("^([012][0-9]):([0-5][0-9])$");
	tResult=oRegEx.exec(vid);
	bErr=(oRegEx.lastIndex==0 || tResult[1]>23 || tResult[2]>59);
	if (bErr) alert("L'heure saisie n'est pas valide !! \n Exemple de format valide : 13:30");
	return !bErr;
}
/*******************************/
function isNewDate(unedate)
{
	var bOK=isDate_ex(unedate,2);
	if (!bOK) alert("La date saisie n'est pas valide !! \n Exemple de format valide : 02/02/2001");
	return bOK;
}
/*******************************/
function isOldDate(unedate)
{
	var bOK=isDate_ex(unedate,1);
	if (!bOK) alert("La date saisie n'est pas valide !! \n Exemple de format valide : 02/02/2002");
	return bOK;
}
/*******************************/
function dateok(unedate){
    var bOK = true;
    if(unedate.search(/^[0-3]{1}[0-9]{1}\/[0-1]{1}[0-9]{1}\/[0-9]{4}$/)==-1){
        bOK = false
    }
    if(!bOK) alert("Date is not valid ! \n Here is an example of a valid date format : 31/12/2007 ");
}
/*
function dateok(unedate)
{
	var bOK=isDate_ex(unedate,0);
	if (!bOK) alert("La date saisie n'est pas valide !! \n Exemple de format valide : 02/02/2003");
	return bOK;
}
*/
/*******************************/
function isDate(vid)
{
	return isDate_ex(vid,0);
}
/*******************************/
function isDate_ex(vid,bTestDate)
{
	//*** test formats (jj/mm/yy[yy][hh:mm[:ss]])
	oRegEx=new RegExp("^([0123]\\d)\\/([01]\\d)\\/(\\d{4})(?:|\\ ([0-2]\\d)\\:([0-5]\\d)(?:|\\:([0-5]\\d)))$");
	tResult=oRegEx.exec(vid);
	if (oRegEx.lastIndex==0) return false;
	day=tResult[1];
	month=tResult[2];
	year=tResult[3];
	
	hour=tResult[4];
	minute=tResult[5];
	second=tResult[6];
	
	if (day<1||day>31) return false;
	if (month<1||month>12) return false;
	if (year<1000 || year>2030) return false;

	bBisextil=(((year/4)-parseInt(year/4))==0);
	tMonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	if (bBisextil) tMonth[1]=29;
	if (tMonth[month-1]<day) return false;
	
	if (hour!="" && parseInt(hour)>23) return false;
	if (minute!="" && parseInt(minute)>59) return false;
	if (second!="" && parseInt(second)>59) return false;
	
	if (bTestDate>0)
	{
		theDate=new Date(year,month-1,day);
		today=new Date();
		today=new Date(today.getFullYear(),today.getMonth(),today.getDate());
		if (bTestDate==1 &&  theDate>today) return false;
		if (bTestDate==2 &&  theDate<today) return false;
	}
	return (year*365+(month*30)+day);
}
/*******************************/
function isSelected(oCtrl,szCaption)
{
	if (oCtrl.selectedIndex<=0)
	{
		 alert("Veuillez s\xe9lectionner un(e) "+szCaption);
		 return false;
	}
	return true;
}
/*******************************/
function isMMAAAA(unedate)
{
	var bOK=isMMAAAA_ex(unedate);
	if (!bOK) alert("La date saisie n'est pas valide !! \n Exemple de format valide : 02/2001");
	return bOK;
}
/*******************************/
function isMMAAAA_ex(unedate)
{
	//*** test formats (mm/yyyy)
	oRegEx=new RegExp("^([01]\\d)\\/(\\d{4})$");
	tResult=oRegEx.exec(unedate);
	if (oRegEx.lastIndex==0) return false;
	month=tResult[1];
	year=tResult[2];

	if (month<1||month>12) return false;
	if (year<1000 || year>2030) return false;
	return true;
}
/*******************************/
function selection(nom1,nom2)
{
	for (var i=0;i<nom1.length;i++)
	{
		if (nom1.options[i].value==nom2) nom1.selectedIndex=i;		  
	}
}
/*******************************/
function selectionMulti(nom1,nom2)
{
	var i
	var tValues=nom2.split(',');
	for (i=0;i<nom1.length;i++)
	{
		for (j=0;j<tValues.length;j++)
		{
			if (tValues[j]!="" && nom1.options[i].value==tValues[j]) nom1.options[i].selected=true;
		}
	}
}
/*******************************/
function getSelValue(oCtrl)
{
	return oCtrl.options[oCtrl.selectedIndex].value;
}
/*******************************/
function getMultiSelValue(oCtrl)
{
	var szRetour="";
	for (var i=0;i<oCtrl.options.length;i++)
	{
		if (oCtrl.options[i].selected) szRetour+=oCtrl.options[i].value+",";
	}
	if (szRetour.length>0) szRetour=szRetour.substr(0,szRetour.length-1);
	return szRetour;
}
/*******************************/
function getSelText(oCtrl)
{
	return oCtrl.options[oCtrl.selectedIndex].text;
}
/********************************/
function getRadioValue(oCtrl)
{
	for (var i=0;i<oCtrl.length;i++)
	{
		if (oCtrl[i].checked) return oCtrl[i].value;
	}
	return "";
}
/********************************/
function SetRadio(oCtrl,ctrlValue)
{
	for (var i=0;i<oCtrl.length;i++)
	{
		oCtrl[i].checked=(oCtrl[i].value==ctrlValue);
	}
}
/********************************/
function SetMultiCheckbox(oCtrl,ctrlValue)
{
	for (var i=0;i<oCtrl.length;i++)
	{
		oCtrl[i].checked=(ctrlValue.indexOf(oCtrl[i].value)>=0);
	}	
}
/*******************************/
function unsetCategorie(oLB,oField,oTx,oTxSub)
{
	var szLB=getSelValue(oLB);
	var tLB=szLB.split(" > ");
	if(tLB.length==2 && oTx!=null && oTxSub!=null)
	{
		oTx.value=tLB[0];
		oTxSub.value=tLB[1];
	}
	oField.value=szLB; 
}
/*******************************/
function setCategorie(oField,oTx,oTxSub)
{
	oField.value=oTx.value+" > "+oTxSub.value; 
}
/*******************************/
function ShowMedia(URL,Type,Taille)
{
	switch(Type)
	{
		case 1:
			strResult="<IMG BORDER='0' SRC='/Sources/ResizePicture.aspx?MaxSize="+Taille+"&URLImage=/Upload/Illustration/Fichier/"+URL+"'>";
			break;
	}
	return strResult;
}
/*******************************/
function fcClipboard(szComposant,szIDParent,bCouper)
{
	writeCookie("clipboard-composant",szComposant);
	writeCookie("clipboard-methode",(bCouper ? "Couper":"Copier"));
	writeCookie("clipboard-idparent",szIDParent);
	
	szCookie="";
	id=document.FSaisie.ID;
	for(i=0;i<id.length;i++)
	{
		if (id[i].checked)
		{
			szCookie+=","+id[i].value;
		}
	}
	writeCookie("clipboard-ids",szCookie);
}
function goClipboard(szURL)
{
	document.location.href=szURL;
}
//*************************
function clearCookie()
{
	var monCookie;
	var tCookies;
	var vNom;
	monCookie=document.cookie;
	tCookies=monCookie.split(';');
	for (var i=0;i<tCookies.length;i++)
	{
		tCookies[i]=tCookies[i].split('=');
		vNom=value=encodeString(tCookies[i][0]," ","",false);
		if (vNom.substr(0,3)=="cb-" || vNom.substr(0,4)=="cbs-")
		{
			expires=new Date('01/01/1990');
			param=vNom+"=;path=/;expires="+expires.toGMTString();
			document.cookie=param;
		}
	}
}
/*******************************/
function savToClipboard(oForm)
{
	clearCookie();
	for (var i=0;i<oForm.elements.length;i++)
	{
		var szData="";
		var szSel="";
		oCtrl=oForm.elements[i];
		if (oCtrl.name!="Composant" && 
			oCtrl.name!="Methode" && 
			oCtrl.name!="Action" && 
			oCtrl.name!="IDBase" && 
			oCtrl.name!="IDData" && 
			oCtrl.name!="IDParent")
		{
			switch(oCtrl.type)
			{
				case "select-one":
					szSel=oCtrl.selectedIndex;
					szData=oCtrl.options[oCtrl.selectedIndex].value;
					writeCookie("cb-"+oCtrl.name,szData);
					writeCookie("cbs-"+oCtrl.name,szSel);
					break;
				case "select-multiple":
					szData=szSel=""
					for (j=0;j<oCtrl.options.length;j++)
					{
						if (oCtrl.options[j].selected)
						{
							szSel+=j+"|"
							szData+=oCtrl.options[j].value+";";
						}
					}
					writeCookie("cb-"+oCtrl.name,szData);
					writeCookie("cbs-"+oCtrl.name,szSel);
					break
					
				case "checkbox":
					szData=oCtrl.checked;
					writeCookie("cb-"+oCtrl.name,szData);
					break;
				default:
					szData=oCtrl.value;
					writeCookie("cb-"+oCtrl.name,szData);
					break;
			}
		}
	}
	writeCookie("clipboard-copy");
	alert('ok');
}
/*******************************/
function readFromClipboard(oForm)
{
	for (var i=0;i<oForm.elements.length;i++)
	{
		oCtrl=oForm.elements[i];
		var szData=getCookie("cb-"+oCtrl.name,false);
		var szSel=getCookie("cbs-"+oCtrl.name,false);
		if (szData!="")
		{
			switch(oCtrl.type)
			{
				case "select-one":
					oCtrl.selectedIndex=szSel;
					break;
					
				case "select-multiple":
					oCtrl.selectedIndex=-1;
					var tSel=szSel.split("|");
					for (j=0;j<tSel.length;j++)
					{
						var idx=parseInt(tSel[j]);
						if (!isNaN(idx))
						{
							oCtrl.options[idx].selected=true;
						}
					}
					break;
				case "checkbox":
					oCtrl.checked=(szData=="true");
					break;
				default:
					oCtrl.value=szData;
					break;
			}
		}
	}
	alert('ok');
}
//*************************
function pasteAll(oForm)
{
	oForm.Methode.value="PasteAll";
	oForm.submit();
}
//*************************
function getCookie(vNom,bDelete)
{
	var monCookie;
	var tCookies;
	monCookie=document.cookie;
	tCookies=monCookie.split(';');
	for (var i=0;i<tCookies.length;i++)
	{
		tCookies[i]=tCookies[i].split('=');
		if (tCookies[i][0].match(vNom))
		{
			value=tCookies[i][1]
			if (bDelete)
			{
				expires=new Date('01/01/1990');
				param=vNom+"=;path=/;expires="+expires.toGMTString();
				document.cookie=param;
			}
			value=encodeString(value,";",".,",true);
			value=encodeString(value,"=","-_",true);
			value=encodeString(value,"\r\n","_vbCRLF_",true);
			return value;
		}
	}
	return "";
}
//*************************
function writeCookie(vNom,vValeur)
{
	writeCookie_ex(vNom,vValeur,false);
}
//*************************
function writeCookie_ex(vNom,vValeur,bPersistant)
{
	var expires=new Date('01/01/2010');
	vValeur=new String(vValeur);
	vValeur=encodeString(vValeur,";",".,",false);
	vValeur=encodeString(vValeur,"=","-_",false);
	vValeur=encodeString(vValeur,"\r\n","_vbCRLF_",false);
	szString=vNom + "=" + vValeur + ";path=/;" +(bPersistant ? "expires="+expires.toGMTString():"");
	document.cookie=szString;
}
//*************************
function encodeString(szValue,szFind,szReplace,bReverse)
{
	if (bReverse)
	{
		var szTemp=szFind;
		szFind=szReplace;
		szReplace=szTemp;
	}
	if ((szValue!="" && szValue!=undefined) && szFind!="")
	{
		while (szValue.indexOf(szFind)>=0) szValue=szValue.replace(szFind,szReplace);
	}
	return szValue;
}
//*************************
function formatKeyword(ctrl)
{
	var sz=sz=";"+ctrl.value+";";
	while (sz.search(";;")>-1) {sz=sz.replace(";;",";");}
	ctrl.value=sz;
}
//*************************
function getParam(szName)
{
	var szRetour="";
	var strParam=document.location.search;
	var tParam=strParam.split("&");
	for (var i=0;i<tParam.length;i++)
	{
		var tDonnees=tParam[i].split("=");
		tDonnees[0]=tDonnees[0].replace("?","");
		if (tDonnees[0].toLowerCase()==szName.toLowerCase())
		{
			szRetour=tDonnees[1];
			continue;
		}
	}
	return szRetour;
}
//*************************
function ShowHideLayer(szLayerName,bShow)
{
	var i,p,v,obj;
	if ((obj=MM_findObj(szLayerName))!=null)
	{
		v=(bShow ? "show":"hide");
		if (obj.style)
		{
			obj=obj.style;
			v=(v=='show') ? 'visible' : (v='hide') ? 'hidden':v;
		}
		obj.visibility=v;
		obj.position=(bShow ? "relative":"absolute");
	}
}
/******************************Fonctions Dreamweaver***************************/
function MM_jumpMenu(targ,selObj,restore)
{
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
/******************************/
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_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_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_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}/******************************/
function MM_showHideLayers_ex()
{ //v3.0
	var i,p,v,obj,args=MM_showHideLayers_ex.arguments;
	var bIE=0;
	for (i=0; i<args.length; i++)
	{
		if ((obj=MM_findObj(args[i]))!=null)
		{
			if (obj.style) {bIE=1;obj=obj.style;}
			v=obj.visibility;
			v=(v=='show'|| v=='visible')?'hidden':'visible';
			if (!bIE) v=(v=='visible'?'show':'hide');
			obj.visibility=v;
		}
	}
}

function montreCache(_ID){
    if(document.getElementById(_ID)){
        
        if(document.getElementById(_ID).style.display == 'none' || !document.getElementById(_ID).style.display){
            document.getElementById(_ID).style.display = 'block';
        }else{
            document.getElementById(_ID).style.display = 'none';

        }
    }
}
