
function fTypeFureteurInternetExplorer()
{
	var fureteurNom = navigator.appName; 
	if (fureteurNom=="Microsoft Internet Explorer")
	{
		return 1;
	}
	return 0;
}

function fStatusAlert(pSel, pMessage)
{
	if(pSel == 0)
	{
		document.getElementById("show_status").style.backgroundImage = "url(img/status_offline.gif)"; 
	}
	if(pSel == 1)
	{
		document.getElementById("show_status").style.backgroundImage = "url(img/status_online.gif)"; 
	}
	if(pSel == 2)
	{
		document.getElementById("show_status").style.backgroundImage = "url(img/status_draft.gif)"; 
	}
	if(pSel == 3)
	{
		document.getElementById("show_status").style.backgroundImage = "url(img/status_delete.gif)"; 
	}
	if(pSel == 4)
	{
		document.getElementById("show_status").style.backgroundImage = "url(img/status_online.gif)"; 
	}
	if(pSel == 5)
	{
		document.getElementById("show_status").style.backgroundImage = "url(img/status_deleted.gif)"; 
	}

}

function fValiderLien(pObjet, pValeur)
{
	var expressionUrl = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;

	//alert(pValeur.match(expressionUrl));
	if (pValeur != "")
	{
		if (pValeur.match(expressionUrl) == null)
		{
			pObjet.style.border = "solid 1px #FF585B";
		}
		else
		{
			pObjet.style.border = "solid 1px #ABFF58";
		}
	}
	else
		 pObjet.style.border = "solid 1px #cccccc";
}

function fRetireItemTableau(pTableau, pNomTableau, pItem, pObjet, pNomTableau2)
{
	tableau = eval(pNomTableau);
	tableau2 = eval(pNomTableau2);
	vId = tableau2[pItem];
	tableau.splice(pItem, 1);
	tableau2.splice(pItem, 1);
	eval("document.getElementById('inv_"+pObjet+"')").value = tableau2.join();
	document.getElementById(pObjet).innerHTML = fAfficheContenuTableau(pObjet, tableau, pNomTableau, pNomTableau2);
	//alert(pObjet+'_'+vId);
	
	eval("document.getElementById('list_item_"+pObjet+"_"+vId+"')").style.display = 'block';
}

function fAfficheContenuTableau(pObjet, pTableau, pNomTableau, pNomTableau2)
{
	
	var data = "";
	for(i=0; i<pTableau.length; i++)
	{
		data = data + "<div class='selection_item'><a onclick='fRetireItemTableau("+ pNomTableau +", \""+ pNomTableau +"\", "+ i +", \""+pObjet+"\", \""+pNomTableau2+"\"); ' class='btn_item'>X</a> " +pTableau[i] + " </div>";
	}
	return data;
	
}

var tableau_objet = new Array();

function indexDuTableau(pTableau, pValeur)
{
	var longueur = pTableau.length;
	for(var i=0; i <= longueur; i++)
	{
		if (pTableau[i] == pValeur)
		{
			return i;
		}
	}
	return -1;
}

function fChangeStyle(pObjet, pClasse)
{
	//alert(document.getElementById(pObjet).className);
	document.getElementById(pObjet).className = pClasse;
}

function fPopup(pPage, pLargeur, pHauteur, pSource, pTitre)
{
	if(window.popupImage)
	{
		if(!window.popupImage.closed)
			window.popupImage.close();
	}
	popupImage=open(""+pPage+"?source="+pSource+"&titre="+pTitre+"","popupImage","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width="+ pLargeur+",height="+ pHauteur+"")
	window.popupImage.moveTo ((((screen.availWidth / 2) - (pLargeur/2))) , (((screen.availHeight / 2) - (pHauteur/2))) )     
}

function fAjax(pUrl, pContenant, pMessageTelechargement, pParametre)
{
    if (pMessageTelechargement != "" && pContenant != "")
    {
		//if (pMode == "")
			document.getElementById(pContenant).innerHTML = "<img src='img/loading.gif' alt='' />" + document.getElementById(pContenant).innerHTML;
		//else
			//document.getElementById(pContenant).innerHTML = pMessageTelechargement;
	}
	var requete_http = false;
	//document.getElementById(pContenant).outerHTML = pMessageTelechargement;
	// Safari, Firefox...
	if (window.XMLHttpRequest) 
	{
		requete_http = new XMLHttpRequest();
		if (requete_http.overrideMimeType) 
		{
			requete_http.overrideMimeType('text/xml');
		}
	} 
	//IE
	else if (window.ActiveXObject) 
	{
		try 
		{
			requete_http = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				requete_http = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) 
			{}
		}
	}

	if (!requete_http) 
	{
		alert('Impossible de créer une requête http.');
		return false;
	}
	requete_http.onreadystatechange = function() 
	{ 
        if (requete_http.readyState == 4) 
        {
            if (requete_http.status == 200) 
            {
                //new Effect.Highlight(document.getElementById(pContenant), {startcolor:'#eeeeee', endcolor:'#ffffff'})
                //if (pContenant != "")
                	document.getElementById(pContenant).innerHTML = requete_http.responseText;
                	//Effect.Appear(pContenant);
            	//document.getElementById(pContenant).style.height =  "auto";
            } 
            else 
            {
                //alert('Http request is not valid.');
            }
        }

	};
	//Pour POST
	requete_http.open("POST", pUrl, true);
	requete_http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 	strParametre = pParametre;
 	var vReplace = eval("/&amp;/ig");
 	requete_http.send(strParametre.replace(vReplace, "&"));
}

function fAjaxParent(pUrl, pContenant, pMessageTelechargement, pParametre)
{
    if (pMessageTelechargement != "" && pContenant != "")
    {
		//if (pMode == "")
			parent.document.getElementById(pContenant).innerHTML =  parent.document.getElementById(pContenant).innerHTML;
		//else
			//parent.document.getElementById(pContenant).innerHTML = pMessageTelechargement;
	}
	var requete_http = false;
	//document.getElementById(pContenant).outerHTML = pMessageTelechargement;
	// Safari, Firefox...
	if (window.XMLHttpRequest) 
	{
		requete_http = new XMLHttpRequest();
		if (requete_http.overrideMimeType) 
		{
			requete_http.overrideMimeType('text/xml');
		}
	} 
	//IE
	else if (window.ActiveXObject) 
	{
		try 
		{
			requete_http = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				requete_http = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) 
			{}
		}
	}

	if (!requete_http) 
	{
		alert('Impossible de créer une requête http.');
		return false;
	}
	requete_http.onreadystatechange = function() 
	{ 
        if (requete_http.readyState == 4) 
        {
            if (requete_http.status == 200) 
            {
                //new Effect.Highlight(document.getElementById(pContenant), {startcolor:'#eeeeee', endcolor:'#ffffff'})
                //if (pContenant != "")
                	parent.document.getElementById(pContenant).innerHTML = requete_http.responseText;
                	//Effect.Appear(pContenant);
            	//document.getElementById(pContenant).style.height =  "auto";
            } 
            else 
            {
                //alert('Http request is not valid.');
            }
        }

	};
	//Pour POST
	requete_http.open("POST", pUrl, true);
	requete_http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 	strParametre = pParametre;
 	var vReplace = eval("/&amp;/ig");
 	requete_http.send(strParametre.replace(vReplace, "&"));
}


function fAjaxGet(pUrl, pContenant, pMessageTelechargement)
{
	var requete_http = false;
	document.getElementById(pContenant).innerHTML = "<img src='img/loading.gif' alt='' />";
	// Safari, Firefox...
	if (window.XMLHttpRequest) 
	{
		requete_http = new XMLHttpRequest();
		if (requete_http.overrideMimeType) 
		{
			requete_http.overrideMimeType('text/xml');
		}
	} 
	//IE
	else if (window.ActiveXObject) 
	{
		try 
		{
			requete_http = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				requete_http = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) 
			{}
		}
	}

	if (!requete_http) 
	{
		return false;
	}
	requete_http.onreadystatechange = function() 
	{ 
        if (requete_http.readyState == 4) 
        {
            if (requete_http.status == 200) 
            {
                //alert(requete_http.responseText);
                // Afficher avant autre code
                /*var r = document.getElementById(pContenant).ownerDocument.createRange();
				r.setStartBefore(document.getElementById(pContenant));
				var parsedHTML = r.createContextualFragment(requete_http.responseText);
				document.getElementById(pContenant).appendChild(parsedHTML);*/
				document.getElementById(pContenant).innerHTML = requete_http.responseText;
            } 
        }

	};
	//Pour POST
	//requete_http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	requete_http.open('GET', pUrl, true);
	requete_http.send(null);
}


function fViderContenant(pContenant, pValeur)
{
	document.getElementById(pContenant).innerHTML = '';
}

function fAction(pSection)
{
	document.frmAction.invSection.value = pSection;
	document.frmAction.invMode.value = pMode;
	document.frmAction.submit();
}



function fRemplaceDiv(pNomDiv,pNomNouveauDiv)
{
	document.getElementById(pNomDiv).style.display = "none"; 
	if (pNomNouveauDiv != '')
	{
		document.getElementById(pNomNouveauDiv).style.display = "block";
	}
}

function fLayerPopup(pDiv, pContent, pStatus)
{
	if (pStatus == "show")
	{
		Effect.BlindDown(pDiv); 
		var content_height = parseInt(document.getElementById(pContent).style.height);
		var content_width = parseInt(document.getElementById(pContent).style.width);
		document.getElementById(pContent).style.top = ((document.body.offsetHeight / 2) - (content_height / 2) )+ 'px';
		document.getElementById(pContent).style.left = ((document.body.offsetWidth / 2) - (content_width / 2) )+ 'px';
		
    }
	if (pStatus == "hide")
	{
		Effect.Fade(pDiv); 
	}
}

function fReset_form(pForm, pMessage)
{
	var color0 = "#FFFFFF";
	var message = document.getElementById(pMessage);
	message.innerHTML = "";
	message.style.background = "transparent";
	message.style.border = "dashed 0px #aaaaaa";
	message.style.padding = "0px 0px 0px 0px";
	eval("document."+pForm).reset();
	for (i=0; i < eval("document."+pForm+".length"); i++)
	{
		var style = eval("document."+pForm+"["+i+"].style");
		style.background = color0;
	}
}
function fIsValueUniqueUrl(pObject, pOriginal, pValue, pListValue, pMessage)
{
	var array_value = pListValue.split(":::");
	for (i=0; i < array_value.length; i++)
	{
		if (array_value[i] == pValue && array_value[i] != pOriginal)
		{
			alert(pMessage);
			eval(pObject).value = pOriginal;
			eval(pObject).focus();
		}
	}
	var expressionFriendlyUrl =/^([A-Za-z0-9_\-\/]+)$/;
	if (pValue.match(expressionFriendlyUrl) == null)
	{
		alert("Special characters such as . ! ? % @ & $ ' \ | [ ] ( ) # are not allowed. Please enter a new friendly url.");
		Effect.Pulsate(pObject, { pulses: 2, duration: 0.5 });
		eval(pObject).value = pOriginal;
		eval(pObject).focus();
	}
	else
	{
		if (pValue.substring(0,1) == "/")
		{
			alert("The friendly url cannot start with '/' .")
			Effect.Pulsate(pObject, { pulses: 2, duration: 0.5 });
			eval(pObject).value = pOriginal;
			eval(pObject).focus();
		}
		else if (pValue == "imr" || pValue == "imra" || pValue == "themes" || pValue == "flash" || pValue == "_upload" || pValue == "img" || pValue == "stats" || pValue == "backstats" || pValue == "sorry" || pValue == "about")
		{
			alert("This friendly url is not available.")
			Effect.Pulsate(pObject, { pulses: 2, duration: 0.5 });
			eval(pObject).value = pOriginal;
			eval(pObject).focus();
		}
	}
}

function fIsValueUniqueUsername(pObject, pOriginal, pValue, pListValue, pMessage)
{
	var array_value = pListValue.split(":::");
	for (i=0; i < array_value.length; i++)
	{
		if (array_value[i] == pValue && array_value[i] != pOriginal)
		{
			alert(pMessage);
			eval(pObject).value = pOriginal;
			eval(pObject).focus();
		}
	}
	var expressionUsername =/^([A-Za-z0-9_\-]+)$/;
	if (pValue.match(expressionUsername) == null)
	{
		alert("Special characters such as ! ? % @ & $ ' / \ | [ ] ( ) # are not allowed. Please enter a new username.");
		Effect.Pulsate(pObject, { pulses: 2, duration: 0.5 });
		eval(pObject).value = pOriginal;
		eval(pObject).focus();
	}
}
function fValidation_form(pForm, pMessage, pListValidation, pFocus, pErrorEmpty, pErrorEmail, pErrorUrl, pErrorPassword, pErrorMultipleSelection, pErrorUploadFile, pErrorInsertData)
{
	var color0 = "#FFFFFF";
	var color1 = "#fdffbf";
	var color2 = "#d7f297";
	var color3 = "#fec976";
	var color4 = "#b8e4e0";
	var color5 = "#e4dcf5";
	var color6 = "#ffc1bb";
	var color7 = "#bbffc1";
	var error1 = "<div class='error_code' style='background: "+color1+";'></div><div class='error_message'>"+pErrorEmpty+"</div>";
	var error2 = "<div class='error_code' style='background: "+color2+";'></div><div class='error_message'>"+pErrorUrl+"</div>";
	var error3 = "<div class='error_code' style='background: "+color3+";'></div><div class='error_message'>"+pErrorEmail+"</div>";
	var error4 = "<div class='error_code' style='background: "+color4+";'></div><div class='error_message'>"+pErrorPassword+"</div>";
	var error5 = "<div class='error_code' style='background: "+color5+";'></div><div class='error_message'>"+pErrorMultipleSelection+"</div>";
	var error6 = "<div class='error_code' style='background: "+color6+";'></div><div class='error_message'>"+pErrorUploadFile+"</div>";
	var error7 = "<div class='error_code' style='background: "+color7+";'></div><div class='error_message'>"+pErrorInsertData+"</div>";
	var showError1 = "";
	var showError2 = "";
	var showError3 = "";
	var showError4 = "";
	var showError5 = "";
	var showError6 = "";
	var showError7 = "";
	var message = document.getElementById(pMessage);
	var expressionUrl = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
	var expressionEmail = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	message.innerHTML = "";
	message.style.background = "transparent";
	message.style.border = "dashed 0px #aaaaaa";
	message.style.padding = "0px 0px 0px 0px";
	var arrayValidation = pListValidation.split(",");
	for (i=0; i < arrayValidation.length; i++)
	{
		if (arrayValidation[i].indexOf("(varempty)") >= 0)
		{
			var arrayVar = arrayValidation[i].split("(");
			if (eval("selection_id_"+arrayVar[0]) == "")
			{
				var style = eval("document.getElementById('content_search_"+arrayVar[0]+"')").style;
				showError5 = error5;
				style.background = color5;
				style.border = "dashed 1px #e04a4a";
			}
			else
			{
				var style = eval("document.getElementById('content_search_"+arrayVar[0]+"')").style;
				style.background = color0;
				style.border = "solid 1px #cccccc";
			}
				
		}
		if (arrayValidation[i].indexOf("(fileempty)") >= 0)
		{
			var arrayVar = arrayValidation[i].split("(");
			if (eval("document.getElementById('"+arrayVar[0]+"_listing')").innerHTML == "")
			{
				var style = eval("window.frames['"+arrayVar[0]+"_fra_upload'].document.getElementById('frm_upload')").style;
				showError6 = error6;
				style.background = color6;
				style.border = "dashed 1px #e04a4a";
			}
		}
		if (arrayValidation[i].indexOf("(dataempty)") >= 0)
		{
			var arrayVar = arrayValidation[i].split("(");
			if (eval("document.getElementById('"+arrayVar[0]+"_listing')").innerHTML == "")
			{
				var style = eval("window.frames['"+arrayVar[0]+"_fra_upload'].document.getElementById('frm_upload')").style;
				showError7 = error7;
				style.background = color7;
				style.border = "dashed 1px #e04a4a";
			}
		}
	}
	for (i=0; i < eval("document."+pForm+".length"); i++)
	{
		var type = eval("document."+pForm+"["+i+"]").type;
		var value = eval("document."+pForm+"["+i+"]").value;
		var name = eval("document."+pForm+"["+i+"]").name;
		var parent = eval("document."+pForm+"["+i+"]").parentNode;
		var style = eval("document."+pForm+"["+i+"]").style;
		if (type == "text" || type == "textarea" || type == "password")
		{
			style.background = color0;
			style.border = "solid 1px #CCCCCC";
			if (pListValidation.indexOf(name+"(empty)") >= 0)
			{
				if (type == "textarea")
				{
					if (tinyMCE.getInstanceById(name).getContent() == "")
					{
						var style = eval("document.getElementById('"+name+"_ifr')").style;
						showError1 = error1;
						style.padding = "10px";
						style.width = "770px";
						style.background = color1;
						style.border = "dashed 1px #e04a4a";
					}
					else
					{
						var style = eval("document.getElementById('"+name+"_ifr')").style;
						style.padding = "0px";
						style.width = "794px";
						style.background = color0;
						style.border = "dashed 0px #e04a4a";
					}
					
				}
				else if (value == "")
				{
					showError1 = error1;
					style.background = color1;
					style.border = "dashed 1px #e04a4a";
				}
			}
			if (pListValidation.indexOf(name+"(url)") >= 0 && value !="" && value !="http://")
			{
				if (value.match(expressionUrl) == null)
				{
					showError2 = error2;
					style.background = color2;
				}
			}
			if (pListValidation.indexOf(name+"(email)") >= 0 && value !="")
			{
				array_email = value.split(";");
				for (a=0;  a< array_email.length; a++)
				{
					//alert(array_email[a]);
					var email = array_email[a].replace(/^\s+|\s+$/g,"");
					if (email.match(expressionEmail) == null && email != "")
					{
						//alert(email+" is not a valid email address.");
						showError3 = error3;
						style.background = color3;
					}
				}
				//if (value.match(expressionEmail) == null)
				//{
					//showError3 = error3;
					//style.background = color3;
				//}
			}
			if (pListValidation.indexOf(name+"(password)") >= 0)
			{
				if (value != eval("document."+pForm+".txt_verify_password").value)
				{
					showError4 = error4;
					style.background = color4;
					//eval("document."+pForm+".txt_verify_password").style.background = color4;
				}
			}
		}
	}
	if (showError1 != "" || showError2 != "" || showError3 != "" || showError4 != "" || showError5 != "" || showError6 != "" || showError7 != "")
		message.innerHTML = "<div class='alert'> " + showError1 + showError2 + showError3 + showError4 + showError5 + showError6+ showError7 +"</div>";
	if (message.innerHTML != "" && eval("document."+pForm+".selStatut.value") != 3)
	{
		eval("document."+pForm+"."+pFocus).focus();
		eval("document."+pForm+"."+pFocus).style.display = "none";
	}
	else
		eval("document."+pForm).submit();
}