var preloadFlag = false;
var movieName = "soundPlay";
var msgWindow = null;
var currentImageName = "";

document.writeln("\n	<LINK REL=\"icon\" HREF=\"/favicon.ico\" TYPE=\"image/x-icon\">");
document.writeln("	<LINK REL=\"SHORTCUT ICON\" HREF=\"/favicon.ico\" TYPE=\"image/x-icon\">");

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document.getElementById(changeImages.arguments[i]).src = changeImages.arguments[i+1];
		}
	}
}

function mapCtrl(imgNum, overState) {
	if (document.images && (preloadFlag == true)) {
		imgSrc = "n" + imgNum;
		if (overState == "on"){
			document.getElementById(imgSrc).src = eval('pre_n'+imgNum).src;
		} else {
			document.getElementById(imgSrc).src = "/images/controls/n" + imgNum + ".gif";
		}
	}
}

function frameImage(imgName, iLink, imgWidth, imgHeight, tM, rM, bM, lM, alignLCR, figCap) {
  var tWidth=imgWidth+6;
  if (iLink != "") {linkStart="<A href=\""+iLink+"\">"; linkEnd="</A>"} else {linkStart=""; linkEnd=""};
  document.writeln("<table style=\"float: "+alignLCR+"; margin: 0px; margin-right:"+rM+"px; margin-left:"+lM+"px; margin-top:"+tM+"px; margin-bottom:"+bM+"px;\" border=0 cellpadding=0 cellspacing=0 align=\""+alignLCR+"\" width=\""+tWidth+"\">");
  document.writeln("	<tr><td><div style=\"border: 1px solid #c0c8c0; padding: 0px;\"><div style=\"padding: 2px;\">"+linkStart+"<img src=\""+imgName+"\" width=\""+imgWidth+"\" height=\""+imgHeight+"\" hspace=\"0\" vspace=\"0\" border=\"0\" alt=\"\">"+linkEnd+"</div></div></td></tr>");
  document.writeln("	<tr><td><p class=\"caption\">"+figCap+"</td></tr>");
  document.writeln("</table>");
};


if (document.images) {
	spacerLoad = newImage("/images/spacer.gif");
}


function preloadImages() {
	pre_n1 = newImage("/images/controls/n1on.gif");
	pre_n2 = newImage("/images/controls/n2on.gif");
	pre_n3 = newImage("/images/controls/n3on.gif");
	pre_n4 = newImage("/images/controls/n4on.gif");
	pre_n5 = newImage("/images/controls/n5on.gif");
	pre_n6 = newImage("/images/controls/n6on.gif");
	pre_n7 = newImage("/images/controls/n7on.gif");
	pre_n8 = newImage("/images/controls/n8on.gif");
	pre_n9 = newImage("/images/controls/n9on.gif");
	pre_n10 = newImage("/images/controls/n10on.gif");
	pre_n11 = newImage("/images/controls/n11on.gif");
	pre_n12 = newImage("/images/controls/n12on.gif");
	pre_n13 = newImage("/images/controls/n13on.gif");
	pre_n14 = newImage("/images/controls/n14on.gif");
	logButtonP = newImage("/images/log.gif");
	logButtonOnP = newImage("/images/logon.gif");
	logButtonClickP = newImage("/images/logclick.gif");
	goButtonP = newImage("/images/go.gif");
	goButtonOnP = newImage("/images/goon.gif");
	goButtonClickP = newImage("/images/goclick.gif");
  	preloadFlag = true;
  	if (window.location.pathname.substring(1,3)) {
		setCookie("myLanguage", window.location.pathname.substring(1,3), 365);
	}
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function dummyF() {
}

function goBackClear() {
	history.back();
}

function getCookie(name){
	var cname = name + "=";
	var dc = document.cookie;
	if (dc.length > 0) {
		begin = dc.indexOf(cname);
		if (begin != -1) {
			begin += cname.length;
			end = dc.indexOf(";", begin);
			if (end == -1) end = dc.length;
				return unescape(dc.substring(begin, end));
		}
	}
	return null;
}

function setCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString() + ";path=/";
}

function changeButton(imgSrc, overState) {
	if (document.images && (preloadFlag == true)) {
		if ((overState == "On") || (overState == "Click") ){
			document.getElementById(imgSrc+'Button').src = eval(imgSrc+'Button'+overState+'P').src;
		} else {
			document.getElementById(imgSrc+'Button').src = eval(imgSrc+'Button'+'P').src;
		}
	}
}

function changeImages2(imgSrc, overState) {
	if (document.images && (preloadFlag == true)) {
		document.getElementById(imgSrc).src = eval(imgSrc+overState).src;
	}
}

function switchLanguage(newLang) {
	setCookie("myLanguage", newLang, 365);
	myURL = "http://" + window.location.hostname + "/" + newLang + window.location.pathname.substring(3,window.location.pathname.length);
	window.location.href=myURL;
}

function tabOnEnter (field, evt, nextfield) {
	var keyCode = document.layers ? evt.which : document.all ? evt.keyCode : evt.keyCode;
	if ((keyCode != 13) && (keyCode != 9))
		return true;
	else {
		if (nextfield == "soumettre") {document.getElementById("checpassword").submit()} else {document.getElementById(nextfield).focus()};
		return false;
	}
}
function focusField () {
	if (document.getElementById("email")) {
		document.getElementById("email").value = document.getElementById("email").value;
		document.getElementById("email").focus();
	};
}

function checkNewPassword (myLanguage) {
	if (myLanguage == 'fr') {
		message00 = "Votre mot de passe a été changé.";
		message01 = "SVP réessayez. Les deux entrées du mot de passe ne sont pas identiques.";
		message02 = "SVP réessayez. Votre mot de passe doit contenir au moins 5 charactères.";
		message03 = "SVP réessayez. Votre mot de passe contient des caractères non permis (seuls des chiffres et des lettres sont permis).";
	} else {
		message00 = "Your password has been changed.";
		message01 = "Please try again. The two password values do not match.";
		message02 = "Please try again. Your password must contain at least 5 characters.";
		message03 = "Please try again. Your password contains illegal characters (only letters and numbers are allowed).";
	}
	
	var illegalChars = /[\W_]/;
	if (illegalChars.test(document.getElementById("pwd1").value)) {
		alert(message03);
	} else {
		if (document.getElementById("pwd1").value == document.getElementById("pwd2").value) {
			if (document.getElementById("pwd1").value.length < 5) {
				alert(message02);
			} else {
				alert(message00);
				document.getElementById("changepassword").submit();
			};
		} else {
			alert(message01);
		};
	};
};
