function changeLg(lg) {
	document.location.href = "index.php?lang="+lg;
}
function MM_swapImgRestore() {
	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() {
	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) {
	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() {
	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];
		}
}
var globWin;
function wLoader(_URL) {
	var _windowTitle = "_blank";
	var _windowSettings = "top=0,left=0,screenX=0,screenY=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=900,height=600";
	globWin = window.open(_URL,_windowTitle,_windowSettings);
}
function MM_openBrWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}
function selection_all_liste1(formulaire,liste) {
	for (i = 0; i<liste.length; i++) {
		liste[i].selected = true;
	}
	liste.name = ""+liste.name+"[]";
}
function selection_all_liste2(formulaire,liste1,liste2) {
	for (i = 0; i<liste1.length; i++) {
		liste1[i].selected = true;
	}
	for (i = 0; i<liste2.length; i++) {
		liste2[i].selected = true;
	}
	liste1.name = ""+liste1.name+"[]";
	liste2.name = ""+liste2.name+"[]";
}
function selection_all_liste3(formulaire,liste1,liste2,liste3) {
	for (i = 0; i<liste1.length; i++) {
		liste1[i].selected = true;
	}
	for (i = 0; i<liste2.length; i++) {
		liste2[i].selected = true;
	}
	for (i = 0; i<liste3.length; i++) {
		liste3[i].selected = true;
	}
	liste1.name = ""+liste1.name+"[]";
	liste2.name = ""+liste2.name+"[]";
	liste3.name = ""+liste3.name+"[]";
}
var POSTER = true;
function poster(url) {
	if (document.getElementById('form')) {
		var form = document.getElementById('form');
		for (i = 0; i<form.length; i++) {
			var type = form.elements[i].type;
			var name = form.elements[i].name;
			var value = form.elements[i].value;
			var id = form.elements[i].id;
			if (type=="select-multiple"&&POSTER) {
				var liste = document.getElementById(id);
				selectAllOptions(liste);
			}
		}
		form.action = url;
		form.submit();
	} else {
		document.location.href = url;
	}
}
function popup_image(page_html) {
	window.open(page_html,null,"left=1, top=1, status=no, scrollbars=yes");
}
function ajout(from,to) {
	var valeur = to.length;
	var text = ""+from.name+"";
	var select = ""+to.name+"";
	var position = null;
	if (document.all)
		position = position = document.getElementsByName(select)[0].length;
	if (document.getElementsByName(text)[0].value!="") {
		var element = document.createElement("option");
		element.text = document.getElementsByName(text)[0].value;
		element.value = document.getElementsByName(text)[0].value;
		document.getElementsByName(select)[0].add(element,position);
		var o = document.getElementsByName(select)[0];
		o.options[valeur].selected = true;
		document.getElementsByName(text)[0].value = "";
		document.getElementsByName(text)[0].focus();
		valeur += 1;
	}
}
function isDate(d) {
	if (d=="")
		return false;
	var e = new RegExp("^[0-9]{1,2}\/[0-9]{1,2}\/([0-9]{2}|[0-9]{4})$");
	if (!e.test(d))
		return false;
	var j = parseInt(d.split("/")[0],10);
	var m = parseInt(d.split("/")[1],10);
	var a = parseInt(d.split("/")[2],10);
	if (a<1000) {
		if (a<89)
			a += 2000;
		else
			a += 1900;
	}
	if (a%4==0&&a%100!=0||a%400==0)
		var fev = 29;
	else
		var fev = 28;
	nbJours = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);
	return (m>=1&&m<=12&&j>=1&&j<=nbJours[m-1]);
}
function ComparerDates(pDate1,pDate2) {
	var tabDT1 = pDate1.split("/");
	var tabDT2 = pDate2.split("/");
	var englishDate1 = tabDT1[2]+tabDT1[1]+tabDT1[0];
	var englishDate2 = tabDT2[2]+tabDT2[1]+tabDT2[0];
	if (englishDate1==englishDate2) {
		return 0;
	} else
		if (englishDate1>englishDate2) {
			return 1;
		} else {
			return 2;
		}
}
function checkUncheckAllCheckbox(theForm,booleen_coche) {
	for (var z = 0; z<theForm.length; z++) {
		if (theForm[z].type=='checkbox')
			theForm[z].checked = booleen_coche;
	}
}
function checkUncheckAllCheckboxFor(theForm,nom_chk,booleen_coche) {
	for (var z = 0; z<theForm.length; z++) {
		if (theForm[z].type=='checkbox') {
			if (theForm[z].name==nom_chk)
				theForm[z].checked = booleen_coche;
		}
	}
}
function calculeOffsetTop(r) {
	return calculeOffset(r,"offsetTop")
}
function calculeOffsetLeft(r) {
	return calculeOffset(r,"offsetLeft")
}
function calculeOffset(element,attr) {
	var offset = 0;
	while (element) {
		offset += element[attr];
		element = element.offsetParent;
	}
	return offset;
}
var waitSuccess = function(o) {
	removeWaitMessage();
	alert('OK! SUCCESS!');
}
var waitFailure = function(o) {
	alert('Un probleme est survenu lors de la connection au serveur.');
}
var callbackWait = {
	success : waitSuccess,
	failure : waitFailure
}
function formWait() {
	if (window.validator.check(this)) {
		waitMessage();
		YAHOO.util.Connect.initHeader("Content-type","utf-8");
		YAHOO.util.Connect.setForm('formformback');
		YAHOO.util.Connect.asyncRequest('POST','index.php?todo=catalogue_save',callbackWait);
	}
}
function removeWaitMessage() {
	document.body.removeChild(document.getElementById("waitDiv"));
	document.body.removeChild(document.getElementById("waitMod"));
}
function waitMessage() {
	var errF = document.createElement("div");
	var im = document.createElement("img");
	var h2 = document.createElement("h2");
	var mod = document.createElement("iframe");
	var tab = document.getElementById("divformbackwait");
	var tp = calculeOffsetTop(tab)+"px";
	var tl = calculeOffsetLeft(tab)+"px";
	mod.style.width = tab.offsetWidth+"px";
	mod.style.height = tab.offsetHeight+"px";
	mod.style.position = "absolute";
	mod.style.zIndex = "9";
	mod.style.top = tp;
	mod.style.left = tl;
	mod.id = "waitMod";
	mod.frameBorder = "0";
	h2.style.color = "#76919C";
	h2.style.textAlign = "center";
	im.src = "../../../include/themes/"+design_theme+"/img/pictos/indicator.gif";
	im.alt = "Chargement en cours";
	errF.id = "waitDiv";
	errF.style.backgroundColor = "#EFEFEF";
	errF.style.width = tab.offsetWidth+"px";
	errF.style.height = tab.offsetHeight+"px";
	errF.style.position = "absolute";
	errF.style.top = tp;
	errF.style.left = tl;
	errF.style.zIndex = "15";
	h2.appendChild(im);
	h2.appendChild(document.createTextNode(" Veuillez patienter pendant le traitement ..."));
	errF.appendChild(h2);
	if (document.getElementById("waitDiv"))
		removeWaitMessage();
	document.body.appendChild(errF);
	document.body.appendChild(mod);
}

function open_es(eshost,login,password,base,todo) {
	if (base!=0) {
		if (!todo) {
			var todo = 'defaut';
		}
		var form = $("<form target='_blank' id='form_redirect' name='form_redirect' method='post' action='http://"+eshost+"/modules/public/index.php?todo=connexion&base_id&todo_after="+todo+"' enctype='application/x-www-form-urlencoded' />");
		form.append($('<input type="hidden" name="login" value="'+login+'" />'));
		form.append($('<input type="hidden" name="password" value="'+password+'" />'));
		form.append($('<input type="hidden" name="base_id" value="'+base+'" />'));
		form.appendTo('body');
		form.submit();
	}
}

