//------------------------------------------------------------------------------------------------//
// MAIN FUNCTIONS SECTION                                                                         //
//------------------------------------------------------------------------------------------------//


/* objects functions */

function GetElementName(n,mf)
{
	if (n==null || n=="") return null;
	var i, s, j;
	for (i=0;i<document.forms[mf].elements.length;i++)
	{
		if (document.forms[mf].elements[i].name.toLowerCase().indexOf(n.toLowerCase()) != -1)
		{
			var strform = document.forms[mf].elements[i].name.toLowerCase();			
			var strformname = strform.substr(strform.indexOf(n.toLowerCase()),n.length);
			if (strformname == n)
			{
				return document.forms[mf].elements[i].name;
			}
		}	
	}
	return null;
}

function GetElement(ElementName, formName)
{
	return document.forms[formName].elements[GetElementName(ElementName,formName)];
}


function getElementByName(tagName,name)
{
	if(isExplorer())
		return document.all.tags(tagName)[name];
	else
		return getElement(name,false);
}

function GetMainFormName()
{
	var i;
	for (i=0;i<document.forms.length;i++)
	{
		// Framework v1.0.3705
		if (document.forms[i].name.indexOf("_ServerForm") != -1)
			return document.forms[i].name;
		// Framework v1.1.4322
		if (document.forms[i].name.indexOf("__aspnetForm") != -1)
			return document.forms[i].name;
	}
	return null;
}

function getMainForm(){
	localForm=(document.all || document.layers)? document.forms[0]:document.getElementsByTagName("FORM")[0];
	return localForm;
}

function EnvoiForm(){
	if (document.layers || document.all) document.forms[0].submit()
	else document.getElementByTagName(FORM)[0];
}

/* login functions */
function SetLogin(loginname)
		{
		var mf = GetMainFormName();
		if (mf==null) return;
			var login = GetElementName("login",mf)
			if (login!= null)
			{
				document.forms[mf].elements[login].value = loginname;
			}
		}
function SetRegisterLogin(loginname)
		{
		var mf = GetMainFormName();
		if (mf==null) return;
			var login = GetElementName("hidden_login",mf);
			if (login!= null)
			{
				document.forms[mf].elements[login].value = loginname;
			}
		}

function SaveElement(ElementObject,ElementValue)
{
		var mf = GetMainFormName();					
		if (mf==null) return;
		//var element  = GetElementName(ElementObject,mf);
		var element  = GetElement(ElementObject,mf);
		if (element!=null) 
//		  document.forms[0].elements[element].value = ElementValue;
		  element.value = ElementValue;
}

/* popup functions */
function sesame(url,winObj,longueur,hauteur,scroll){
	window.open(url,winObj,"status=0,toolbar=no,scrollbars=0,width="+longueur+",height="+hauteur+",scrollbars="+scroll+"")
}

function sesame2(url,winObj,longueur,hauteur,scroll){
	window.open(url,winObj,"status=1,toolbar=no,scrollbars=0,width="+longueur+",height="+hauteur+",scrollbars="+scroll+"")
}

function sesame3(url,winObj,longueur,hauteur,scroll){
	window.open(url,winObj,"status=1,toolbar=no,width="+longueur+",height="+hauteur+",scrollbars="+scroll+"")
}

function sesame4(url,winObj){
	window.open(url,winObj,"status=1,toolbar=1,width=800,height=600,scrollbars=1,location=1,menubar=yes,resizable=1")
}

/*function sesameProd(url,winObj,longueur,hauteur,scroll){
	if(document.PageLoaded)	window.open(url,winObj,"status=0,toolbar=no,scrollbars=0,width="+longueur+",height="+hauteur+",scrollbars="+scroll+"");
}*/

/* anim functions */
function roll(ImgNme){
	ClicName=(document.clicImgFafa)? document.clicImgFafa.name:"";
	if(ClicName!=ImgNme){	
		obj=document.images[ImgNme];
		obj.src=(obj.src.lastIndexOf('-on')!=-1)? obj.src.replace(/-on/gi,"-off"):obj.src.replace(/-off/gi,"-on");
	}
}

function roll(ImgNme){
	ClicName=(document.clicImgFafa)? document.clicImgFafa.name:"";
	if(ClicName!=ImgNme){	
		obj=document.images[ImgNme];
		obj.src=(obj.src.lastIndexOf('-on')!=-1)? obj.src.replace(/-on/gi,"-off"):obj.src.replace(/-off/gi,"-on");
	}
}

function Clic(ImgNme){
        obj=(document.images)? document.images[ImgNme]:0; ClicNme=(document.clicImgFafa)? document.clicImgFafa.name:""; 
        if (!obj && document.layers) {
                for (i=0; i<document.layers.length; i++) { ObjLyr=document.layers[i].document;
                        if (ObjLyr.images && ObjLyr.images[ImgNme]) obj=ObjLyr.images[ImgNme];}}        
      	if (document.clicImgFafa){
				 document.clicImgFafa.src=document.clicImgFafa.src.replace(/-on/gi,"-off");        
		}
		obj.src=obj.src.replace(/-off/gi,"-on");
       document.clicImgFafa=obj;		
}
 
function rollOver(ImgNme){ 
	imgsrc=dlib_po(ImgNme,"image").src;
	isOn=(imgsrc.indexOf("_on")!=-1)?1:0;
	dlib_po(ImgNme,"image").src=(isOn)? imgsrc.replace(/_on/gi,"_off"):imgsrc.replace(/_off/gi,"_on"); 
}

function ChangeLayersContent(LyrName,contenu){
	if ( (document.all) && (!document.getElementById) ) document.all[LyrName].innerHTML=contenu;
	else if(document.getElementById) document.getElementById(LyrName).innerHTML=contenu;
	else {
		document.layers[LyrName].document.write(contenu);
		document.close();
	}
}

/* divers */

function SetSuccessurl(url){
	url = url + '?RetourUrl=' + document.location;
	window.open(url, '_self');
}

function desLiens(hurle){
	top.location = hurle;
}

function getRelativRootURL(RootIndex){
	ShortURL=self.location.href.substring(self.location.href.indexOf(RootIndex)+RootIndex.length);
	ShortURL=ShortURL.split("/");
	RelativPath="";
	for(i=0; i<ShortURL.length-1; i++) RelativPath+="../";
	 return RelativPath;
}

