<!--

initEnv();

function getURLParam(strParamName){
	var strReturn = "";
	var strHref = window.location.href;
	if(strHref.indexOf("&") > -1) {
		var strQueryString = strHref.substr(strHref.indexOf("&")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for(var iParam = 0; iParam < aQueryString.length; iParam++ ) {
			if(aQueryString[iParam].indexOf(strParamName + "=") > -1 ) {
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return strReturn;
}

function check_fields_submit() {
    var check = true;
    for(var i = 0; i < arguments.length && check; i++)
        if(document.forms[0][arguments[i]].value == '') {
            alert('Ce champ est obligatoire');
            document.forms[0][arguments[i]].focus();
            check = false;
        }
    if(check)
        document.forms[0].submit();
}

// setCookie
function setCookie(nom, valeur) {
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = nom + "=" + escape(valeur) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + "; path= / " + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}

// getCookieVal
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf(";", offset);
	if(endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

// getCookie
function getCookie(nom) {
	var arg = nom + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while(i < clen) {
		var j = i + alen;
		if(document.cookie.substring(i, j) == arg)
			return getCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if(i == 0)
			break;
	}
	return null;
}

function getQueryVariable(variable) {
	query = window.location.href;
	vars = query.split("&");
	for(i = 0; i < vars.length; i++) {
		pair = vars[i].split("=");
		if(pair[0] == variable)
			return pair[1];
	}
}

// init
function initEnv() {
	if(getCookie("typo") == null)
		setCookie("typo", "std");
	url = getQueryVariable("url");
	if(url != undefined && url != "")
		Ref = url;
	else
		if(top.document.referrer == undefined || top.document.referrer == '')
			Ref = "aucun";
		else
			Ref = top.document.referrer;
	setCookie("web_referrer", Ref);
	CookieVal = getCookie("link_com");
	if(CookieVal == undefined || CookieVal == "")
		setCookie("link_com", getQueryVariable("link_com"));
}

// clientsSetPage : open page to clients space
function clientsConnect() {
	if(document.location.protocol == "http:" || document.location.href.match(/formLGFrHomePage/gi) != null)
		top.document.location.href = "https://" + document.location.hostname + "/lag/public.nsf/formLGFrLoadPage?OpenForm&clients=1";
	else
		top.ifr_content.document.location.href = "/lagssl/lagrealm.nsf/LagMyDoc?CreateDocument&par=reve";
}

function clientsDisconnect() {
	top.document.location.href = "/names.nsf?Logout&RedirectTo=http://" + document.location.hostname + "/lag/public.nsf/formLGFrHomePage?OpenForm";
}

// pageLoad : called on body onLoad in documents (content pages)
function pageLoad(db, alias) {
	if(getURLParam("print") == "" && db != "") {
		if(hasRequestedVersion)
			top.ifr_news.document.location.replace(db + "/formLGFrNews?OpenForm" + (alias != "" ? "&alias=" + alias : ""));
		top.ifr_tree.document.location.replace(db + "/formLGFrTree?OpenForm" + (alias != "" ? "&alias=" + alias : ""));
	}
	removeFontTags();
}

// formLoad : called on body onLoad in forms (static pages)
function formLoad(db, frm) {
	if(getURLParam("print") == "" && db != "") {
		if(hasRequestedVersion)
			top.ifr_news.document.location.replace(db + "/formLGFrNews?OpenForm" + (frm != "" ? "&form=" + frm : ""));
		top.ifr_tree.document.location.replace(db + "/formLGFrTree?OpenForm" + (frm != "" ? "&form=" + frm : ""));
	}
	removeFontTags();
}

function clientsPageLoad() {
	step = getURLParam("step");
	if(getURLParam("print") == "" && (step == "" || step != "2")) {
		if(hasRequestedVersion)
			top.ifr_news.document.location.replace("/lag/public.nsf/formLGFrNews?OpenForm&form=formLogin");
		top.ifr_tree.document.location.replace("/lag/public.nsf/formLGFrTree?OpenForm&form=formLogin");
	}
}

// redirEn
function redirEn(userID) {
	sessionID =  getCookie('DomAuthSessId');
	top.ifr_tree.document.location.href = 'tree?open&sessionID=' + sessionID + '&userID=' + userID;
}

// logOut
function logOutEn() {
	top.document.location = "/names.nsf?Logout&RedirectTo=/lagssl/auth.nsf/index?open";
}

// setTree : pseudo href from an iframe
function setTree(url) {
	if(url != "")
		top.ifr_tree.document.location.replace(url);
}

// setNews : pseudo href from an iframe
function setNews(url) {
	if(url != "")
		top.ifr_news.document.location.replace(url);
}

// setContent : pseudo href from an iframe
function setContent(url) {
	if(url != "")
		top.ifr_content.document.location.href = url;
}

function setPageHP(hp, extURL, intURL) {
	if(hp == "1")
		top.document.location.href = extURL;
	else
		top.ifr_content.document.location.href = intURL;
}

// removeFontTags : remove domino font tags
function removeFontTags() {
	richtext = document.getElementById("nofont").innerHTML;
	nofonts = richtext.replace(/<(font)[^>]*>/gi, "");
	noslashfonts = nofonts.replace(/<(\/font)>/gi, "");
	document.getElementById("nofont").innerHTML = noslashfonts;
}

function printTitleLine(color) {
	text = document.getElementById("nofont");
	s = text.innerHTML.replace(/(<tr.*>\s*<td class="?pta"?.*>\s*.*<\/tr>)/gi, '$1<tr><td><img src="/lg/img/' + color + '/title_line.png"></td></tr>');
	text.innerHTML = s;
}

function popup_close() {
    document.getElementById('popup').style.display = 'none';
}

// print
function printPage() {
	url = ifr_content.document.location.href;
	url = url.replace(/#errors/, "");
	if(url.match(/.*\?.*/g) == null)
		url += "?open";
	url += "&print=1";
	window.open(url);
}

// changeTypo
function changeTypo(typo) {
	setCookie("typo", typo);
	ifr_content.document.location.reload();
}

function writeFlash(name, url, width, height) {
	if(hasRequestedVersion)
		document.write(
			'<center>' +
				'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="' + document.location.protocol + '//fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + width + '" height="' + height + '" id="' + name + '" align="top">' +
					'<param name="allowScriptAccess" value="sameDomain">' +
					'<param name="movie" value="' + url + '">' +
					'<param name="quality" value="high">' +
					'<param name="wmode" value="transparent">' +
					'<param name="bgcolor" value="#ffffff">' +
					'<embed align="top" src="' + url + '" quality="high" wmode="transparent" bgcolor="#ffffff" width="' + width + '" height="' + height + '" name="' + name + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">' +
				'</object>' +
			'</center>');
}

function writeFlashHTML(name, url, width, height, trans, html) {
	document.write(hasRequestedVersion ?
		'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="' + document.location.protocol + '//fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + width + '" height="' + height + '" id="' + name + '" align="top">' +
			'<param name="allowScriptAccess" value="sameDomain">' +
			'<param name="movie" value="' + url + '">' +
			'<param name="quality" value="high">' +
			( trans== 1 ? '<param name="wmode" value="transparent">' : '') +
			'<param name="bgcolor" value="#ffffff">' +
			'<embed align="top" src="' + url + '" quality="high" ' + (trans == 1 ? 'wmode="transparent"' : '') + 'bgcolor="#ffffff" width="' + width + '" height="' + height + '" name="' + name + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">' +
		'</object>'
		:
		html);
}

function writeFlashEn(name, url, width, height) {
	if(hasRequestedVersion)
		document.write(
			'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="' + document.location.protocol + '//fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + width + '" height="' + height + '" id="' + name + '" align="top">' +
				'<param name="movie" value="' + url + '" />' +
				'<param name="quality" value="high" />' +
				'<param name="wmode" value="transparent" />' +
				'<param name="bgcolor" value="#ffffff" />' +
				'<embed src="' + url + '" align="top" quality="high" wmode="transparent" bgcolor="#ffffff" width="' + width + '" height="' + height + '" name="' + name + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
			'</object>');
}

function helpTip1(txt1, txt2) {
	return overlib("<table class=\"ppa\"><tr><td>Prix de revient unitaire : </td><td align=\"right\">" + txt1 + "</td></tr><tr><td>Plus ou moins value latente : </td><td align=\"right\">" + txt2 + "</td></tr></table>", WIDTH, -1, FGCOLOR, "#FFDD00");
}

function helpTip2(txt1, txt2, txt3) {
	return overlib("<table class=\"ppa\"><tr><td>Prix de revient moyen pond&eacute;r&eacute; : </td><td align=\"right\">" + txt1 + "</td></tr><tr><td>Plus ou moins value latente : </td><td align=\"right\">" + txt2 + "</td></tr><tr><td>Int?r?ts courus : </td><td align=\"right\">" + txt3 + "</td></tr></table>", WIDTH, -1, FGCOLOR, "#FFDD00");
}

function helpTip1En(txt1, txt2) {
	return overlib("<table class=\"ppa\"><tr><td>Unit cost price : </td><td align=\"right\">" + txt1 + "</td></tr><tr><td>Potential gain or loss : </td><td align=\"right\">" + txt2 + "</td></tr></table>", WIDTH, -1, FGCOLOR, "#FFDD00");
}

// online forms
function testmail(val) {
	for(var j = 1; j < val.length; j++) {
		if(val.charAt(j) == '@') {
			if(j < (val.length - 4)) {
				for(var k = j; k < (val.length - 2); k++) {
					if(val.charAt(k) == '.')
						return false;
				}
			}
		}
	}
	return true;
}

function prospect_send() {
	prospForm = document.forms[0];
	msg = "";
	if(prospForm["sex"].value == "-") {
		msg = "Le champ Civilit&eacute; est obligatoire";
		field = "sex";
	}
	else
		if(prospForm["surname"].value == "") {
			msg = "Le champ Nom est obligatoire";
			field = "surname";
		}
		else
			if(prospForm["name"].value == "") {
				msg = "Le champ Pr&eacute;nom est obligatoire";
				field = "name";
			}
			else
				if(prospForm["address"].value == "") {
					msg = "Le champ Adresse est obligatoire";
					field = "address";
				}
				else
					if(prospForm["postal_code"].value == "") {
						msg = "Le champ Code postal est obligatoire";
						field = "postal_code";
					} 
					else
						if(isNaN(prospForm["postal_code"].value)) {
							msg = "Le champ Code postal doit &ecirc;tre num&eacute;rique";
							field = "postal_code";
						}
						else
							if(prospForm["city"].value == "") {
								msg = "Le champ Ville est obligatoire";
								field = "city";
							}
							else
								if(prospForm["phone"].value == "") {
									msg = "Le champ T&eacute;l&eacute;phone est obligatoire";
									field = "phone";
								}
								else
									 if(prospForm["email"].value != "" && testmail(prospForm["email"].value)) {
										msg = "Votre adresse mail n'est pas valide.";
										field = "email";
									}
	if(msg != "") {
		document.getElementById("div_errors").innerHTML = '<div class="txt_decal ppc">' + msg + '</div><br>';
		prospForm[field].focus();
	}
	else
		prospForm.submit();
}

function webmaster_send() {
	webmForm = document.forms[0];
	msg = "";
	if(webmForm["surname"].value == "") {
		msg = "Le champ Nom est obligatoire";
		field = "surname";
	}
	else
		if(webmForm["name"].value == "") {
			msg += "Le champ Pr&eacute;nom est obligatoire";
				field = "name";
		}
		else
			if(webmForm["email"].value == "" ) {
				msg = "Le champ Email est obligatoire";
				field = "email";
			}
			else
				if(testmail(webmForm["email"].value)) {
					msg = "Votre adresse mail n'est pas valide.";
					field = "email";
				}
	if(msg != "") {
		document.getElementById("div_errors").innerHTML = '<div class="txt_decal ppc">' + msg + '</div><br>';
		webmForm[field].focus();
	}
	else
		webmForm.submit();
}

function passwordValidate() {
	pwd = document.forms[0];
	msg = "";
	passStr = new String(pwd["NewPassword"].value);
	if(pwd["OldPassword"].value == "") {
		msg = "Merci de saisir votre ancien mot de passe.";
		field = "OldPassword";
	}
	else
		if(pwd["NewPassword"].value == "") {
			msg = "Merci de saisir votre nouveau mot de passe.";
			field = "NewPassword";
		}
		else
			if((pwd["NewPassword"].value != "") && (passStr.length < 6 )) {
				msg = "Le mot de passe doit &ecirc;tre d'une longueur minimum de 6 caract&egrave;res.";
				field = "NewPassword";
			}
			else
				if(passwordTest(pwd["NewPassword"].value)) {
					msg = "Merci de saisir un mot de passe valide.";
					field = "NewPassword";
				}
				else
					if(pwd["NewPassword"].value != pwd["ConfirmedNewPassword"].value) {
						msg = "Le mot de passe saisi dans le champ de confirmation ne correspond pas &agrave; votre nouveau mot de passe.";
						field = "NewPassword";
					}
	if(msg != '') {
		document.getElementById("div_errors").innerHTML = '<div class="ppb">' + msg + '</div><br>';
		pwd[field].focus();
	}
	else
		pwd.submit();
}

function passwordValidateEn() {
	pwd = document.forms[0];
	msg = "";
	passStr = new String(pwd["newPassword"].value);
	if(pwd["oldPassword"].value == "") {
		msg = "Please type your previous password.";
		field = "oldPassword";
	}
	else
		if(pwd["newPassword"].value == "") {
			msg = "Please type your next password.";
			field = "newPassword";
		}
		else
			if((pwd["newPassword"].value != "") && (passStr.length < 6 )) {
				msg = "Minimum length for your password must be 6 digits.";
				field = "newPassword";
			}
			else
				if(passwordTest(pwd["newPassword"].value)) {
					msg = "Please type a valid next password.";
					field = "newPassword";
				}
				else
					if(pwd["newPassword"].value != pwd["confirmation"].value) {
						msg = "Confirmed password does not match with the next password.";
						field = "newPassword";
					}
	if(msg != '') {
		document.getElementById("div_errors").innerHTML = '<div class="ppb">' + msg + '</div><br>';
		pwd[field].focus();
	}
	else
		pwd.submit();
}

function passwordTest(val) {
	var psw = new String(val);
	var pswindex1 = psw.indexOf("(");
	var pswindex2 = psw.indexOf(")");
	var pswindex3 = psw.indexOf("#");
	var pswindex4 = psw.indexOf("&");
	var pswindex5 = psw.indexOf("~");
	var pswindex6 = psw.indexOf("*");
	var pswindex7 = psw.indexOf("=");
	var pswindex8 = psw.indexOf("}");
	var pswindex9 = psw.indexOf("{");
	var pswindex10 = psw.indexOf("|");
	var pswindex11 = psw.indexOf("/");
	var pswindex12 = psw.indexOf(":");
	return (pswindex1 !=-1) || (pswindex2 !=-1) || (pswindex3 !=-1) || (pswindex4 !=-1) || (pswindex5 !=-1) || (pswindex6 !=-1) || (pswindex7 !=-1) || (pswindex8 !=-1) || (pswindex9 !=-1) || (pswindex10 !=-1) || (pswindex11 !=-1) || (pswindex12 !=-1);
}

function internetPasswordSubmit() {
    if(document.forms[0].LGId.value != '') {
        document.forms[0].action = '/lagssl/laginternetpasswd.nsf/checkId?OpenAgent';
        document.forms[0].submit();
    }
    else
        alert("Vous devez d'abord saisir un numero d'identifiant");
}

function checkform_submit() {
    var nb_to_check = arguments[0];
    var check = true;

    for(var i = 1; i <= nb_to_check && check; i++)
        if(document.main[arguments[i]].value == '') {
            alert('Ce champ est obligatoire');
            document.main[arguments[i]].className = 'required';
            document.main[arguments[i]].focus();
            check = false;
        }
    if(check) {
        for(i = nb_to_check + 1; i < arguments.length; i += 2)
            if(document.main[arguments[i]] != undefined)
                document.main[arguments[i]].value = arguments[i+1];
        document.main.submit();
    }
}

// -->
