﻿var browsername = navigator.appName;
var browserversion = parseInt(navigator.appVersion);

function Browsers3_redirect(){ //v3.0
	if (browserversion < 4)
	window.location.href="oldbrowser.htm"
}

function MM_swapImgRestore() { //v3.0
  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() { //v3.0
  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_swapImage() { //v3.0
  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];}
}

function MM_findObj(n, d) { //v4.01
  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 validateLoginForm(){
	var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>? ";
	var invalidun;
	var invalidpw;
	for (var i = 0; i < document.loginform.txtfUserName.value.length; i++) {
		if (iChars.indexOf(document.loginform.txtfUserName.value.charAt(i)) != -1) {
			invalidun = "yes";
		}
	}
	for (var j = 0; j < document.loginform.txtfPassword.value.length; j++) {
		if (iChars.indexOf(document.loginform.txtfPassword.value.charAt(j)) != -1) {
			invalidpw = "yes";
		}
	}
	if (document.loginform.txtfUserName.value.length < 6 || invalidun == "yes"){
		alert("Votre nom d'utilisateur doit excéder 6 caractères alphanumériques (lettres et chiffres).");
	}
	else if (document.loginform.txtfPassword.value.length <6 || invalidpw == "yes"){
	  	alert('Votre mot de passe doit  excéder 6 caractères alphanumériques (lettres et chiffres).');
	}
  	else {
      	document.loginform.submit();
	 }
}

function Clickheretoprint()
{ 
  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
      disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 
  var content_vlue = document.getElementById("print_content").innerHTML; 
  
  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write("<html><head><title>Le Programme CE-FAO « Sécurité alimentaire : l'information pour l'action »</title><link href='ecfao_styles.css' rel='stylesheet' type='text/css'>"); docprint.document.write('</head><body class="bodytext" onLoad="self.print()"><left>');          
   docprint.document.write(content_vlue);          
   docprint.document.write('</left></body></html>'); 
   docprint.document.close(); 
   docprint.focus(); 
}

function openOtherLanguagePage(langcode){
     var thisPage, thisExtension, otherLanguagePage;
     thisPage = location.href.substring((location.href.lastIndexOf("/"))+1) ;
     thisExtension = thisPage.substring(thisPage.lastIndexOf("."),thisPage.length)
     otherLanguagePage = thisPage.substring(0,thisPage.lastIndexOf("_"));
     otherLanguagePage = otherLanguagePage + "_" + langcode +thisExtension;
     window.location.href = otherLanguagePage;
}

function conFirmOrder(){
      document.confirmorderform.submit();
}

function goBack(){
	history.go(-1);
}

function validateEmail(){
	var email = document.forgotpwform.email.value;
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	
	if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
		alert('Veuillez saisir une adresse de courrier électronique correcte.');
		document.forgotpwform.email.focus();
	} else {
		document.forgotpwform.submit();
	}
}

function openCourseWindow(varmodulecode,varlanguagecode,varlearnercode){
	var varlearnercode
	var varmodulecode;
	var varlanguagecode;
	var courselinkstring;
	courselinkstring = 'course/shortcourse' + varmodulecode + '/' + varlanguagecode + '/course.asp?modulecode='+ varmodulecode + '&modulelang=' + varlanguagecode + '&learnercode=' + varlearnercode;
	newWindow=window.open(courselinkstring, 'newWin', 'toolbar=no, location=no, scrollbars=no');
}

function validateOrderForm(){
	var email = document.orderform.email.value;
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	
	var address = document.orderform.address1.value;
    var arrAddress = address.split("@");
		var address2 = document.orderform.address2.value;
	var arrAddress2 = address2.split("@");

	if (arrAddress.length > 1 || arrAddress2.length > 1){
    alert("Dans la section adresse, ne mettez pas votre adresse de courrier électronique, mais veuillez fournir votre adresse complète, rue ou boîte aux lettres.");
	return;
	}
	
	if ((document.orderform.firstname.value == "")||(document.orderform.firstname.value == "undefined")){
		alert("Veuillez saisir votre prénom.");
		document.orderform.firstname.focus();
	}
	else if ((document.orderform.lastname.value == "")||(document.orderform.lastname.value == "undefined")){
		alert("Veuillez saisir votre nom.");
		document.orderform.lastname.focus();
	}
	else if (((document.orderform.address1.value == "")||(document.orderform.address1.value == "undefined"))&&((document.orderform.address2.value == "")||(document.orderform.address2.value == "undefined"))){
		alert("Veuillez fournir votre adresse postale.");
		document.orderform.address1.focus();
	}
	else if ((document.orderform.city.value == "")||(document.orderform.city.value == "undefined")){
		alert("Veuillez fournir le nom de votre ville ou village.");
		document.orderform.city.focus();
	}
	else if (document.orderform.selectcountry.options[0].selected){
		alert("Veuillez sélectionner votre pays.");
	}
	else if(!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
		alert('Veuillez saisir une adresse de courrier électronique correcte.');
		document.orderform.email.focus();
	}
	else{
		document.orderform.submit();
	}
}

function resetOrderForm(){
	document.orderform.reset();
}

function validateRegistrationForm(){
	var email = document.registrationform.email.value;
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>? ";
	var invalidun;
	var invalidpw;
	
	for (var i = 0; i < document.registrationform.username.value.length; i++) {
		if (iChars.indexOf(document.registrationform.username.value.charAt(i)) != -1) {
			invalidun = "yes";
		}
	}
	for (var j = 0; j < document.registrationform.password.value.length; j++) {
		if (iChars.indexOf(document.registrationform.password.value.charAt(j)) != -1) {
			invalidpw = "yes";
		}
	}
	if ((document.registrationform.firstname.value == "")||(document.registrationform.firstname.value == "undefined")){
		alert("Veuillez saisir votre prénom.");
		document.registrationform.firstname.focus();
	}
	else if ((document.registrationform.lastname.value == "")||(document.registrationform.lastname.value == "undefined")){
		alert("Veuillez saisir votre nom.");
		document.registrationform.lastname.focus();
	}
	else if(!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
		alert("Veuillez saisir une adresse de courrier électronique correcte.");
		document.registrationform.email.focus();
	}
	else if ((document.registrationform.gender[0].checked==false)&&(document.registrationform.gender[1].checked==false)){
		alert("Veuillez préciser votre genre.");
	}
	else if (document.registrationform.selectcountry.options[0].selected){
		alert("Veuillez sélectionner votre pays.");
	}
	else if (document.registrationform.username.value.length < 6 || invalidun == "yes"){
		alert("Votre nom d'utilisateur doit excéder 6 caractères alphanumériques (lettres et chiffres).");
		document.registrationform.username.focus();
	}
	else if (document.registrationform.password.value.length <6 || invalidpw == "yes"){
	  	alert("Votre mot de passe doit excéder 6 caractères alphanumériques (lettres et chiffres).");
		document.registrationform.password.focus();
	}
	else if (document.registrationform.password.value!=document.registrationform.retypepassword.value){
	  	alert("Votre « mot de passe » et « confirmer mot de passe » sont différents. Veuillez  réessayer.'");
		document.registrationform.password.focus();
	}	
	else{
		document.registrationform.submit();
	}
}

function resetRegistrationForm(){
	document.registrationform.reset();
}

var coursecode,langcode,lessoncode;
function openLesson(coursecode,langcode,lessoncode){
	window.open('course/shortcourse' + coursecode + '/' + langcode +  '/lesson.asp?lessoncode=' + lessoncode, 'lessonpage', 'location=no, menubar=no, toolbar=no, scrollbars=no');
}
function winalert(url) {
    newwindow=window.open(url,"Alertwindow","menubar=no,width=450,height=220,toolbar=no,top=200,left=300");	
}
function validateUpdateRegistrationForm(){
	var email = document.updateregistrationform.email.value;
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	
	if ((document.updateregistrationform.firstname.value == "")||(document.updateregistrationform.firstname.value == "undefined")){
		alert("Veuillez saisir votre nom.");
		document.updateregistrationform.firstname.focus();
	}
	else if ((document.updateregistrationform.lastname.value == "")||(document.updateregistrationform.lastname.value == "undefined")){
		alert("Veuillez saisir votre prénom.");
		document.updateregistrationform.lastname.focus();
	}
	else if(!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
		alert('Veuillez saisir une adresse de courrier électronique correcte');
		document.updateregistrationform.email.focus();	}
	
	else if (document.updateregistrationform.selectcountry.options[0].selected){
		alert("Veuillez sélectionner votre pays.");
	}
	else{
		document.updateregistrationform.submit();
	}
}

function resetUpdateRegistrationForm(){
	document.updateregistrationform.reset();
}
