// teste si le champs a la forme d'une adresse mail
function testMail(i) {
	var address = document.forms[0].elements[i].value;
	var pos = address.indexOf('@');
	var posPoint = address.indexOf('.');
	if (address.length < 6 || pos==-1 || pos==0 || pos==address.length-1 ||
		posPoint==-1 || posPoint==0 || posPoint==address.length-1 || posPoint==address.length-2)
		return (false);
	else return (true);
} 

// teste si le champs a la forme d'un numéro de téléphone (>9 chiffres)
function testNum(i) {
	var numTel = document.forms[0].elements[i].value;
	var ch = "+()/-.0123456789 ";
	if (numTel.length < 2) return(false);
	else for(var j = 0; j < numTel.length; j++) {if (ch.indexOf(numTel.charAt(j)) == -1)	return(false);}
return(true)
}

// teste si le champs comporte 5 chiffres (codes postaux)
function testOnlyNum(i) {
	var champ = document.forms[0].elements[i].value;
	var ch = "0123456789";
	if (champ.length != 5) return(false);
	else for(var j = 0; j < champ.length; j++) {if (ch.indexOf(champ.charAt(j)) == -1)	return(false);}
	return(true)
}

function racine_checkbox(nom) {
	var chnum = "0123456789";
	var car = "";
	for (var i=0;i<2;i++) {
		car = nom.charAt(nom.length-1);
		if (chnum.indexOf(car) != -1)
		   nom = nom.substring(0, nom.length-1);
		else break;}
	return nom;
}

function traductor(champ)  {
	if (champ == "Titre") return("Title");
	else if (champ == "Nom") return("Name");
	else if (champ == "Prénom") return("First name");
	else if (champ == "Société") return("Company");
	else if (champ == "Fonction") return("Function");
	else if (champ == "Adresse") return("Address");
	else if (champ == "Code Postal") return("Zip Code");
	else if (champ == "Fonction") return("Function");
	else if (champ == "Ville") return("City");
	else if (champ == "Province") return("State");
	else if (champ == "Pays") return("Country");
	else if (champ == "Téléphone") return("Phone");
	else if (champ == "Type Société") return("Company Type");
	else if (champ == "Accès ISoft") return("ISoft Access");
	else return(champ);
}

function controle(langue) {
//les champs obligatoires du formulaire doivent se terminer par #
	var i = 0;
	var message = "";
	var specialTest = 0; //permet de specifier si un test special a été effectué ou non
	var champ = null;
	var nomchamp = "";
	var precchamp = "";
	var prectype = ""; 
	var coche = false;
	var champtranslated = "";
	for (i=0;i<document.forms[0].elements.length;i++) {
		champ = document.forms[0].elements[i];		
		
		if (champ.name.indexOf("#") != -1){
			nomchamp = champ.name.substring(0,champ.name.length-1);
			// Test de l'adresse mail
			if ((nomchamp == 'Mail') || (nomchamp == 'mail') || (nomchamp == 'mel') || (nomchamp == 'Mel')){		
				if (!testMail(i)) if (langue == 0) message += nomchamp + "\n"; else{champtranslated=traductor(nomchamp); message += champtranslated + "\n";}
				specialTest = 1;
			}// Test des numéros de téléphone
			else if ((nomchamp == 'Téléphone') || (nomchamp == 'Tél') || (nomchamp == 'Mobile') || (nomchamp == 'Fax')){		
				if (!testNum(i)) if (langue == 0) message += nomchamp + "\n"; else{champtranslated=traductor(nomchamp); message += champtranslated + "\n";}
				specialTest = 1;
			}// Test du code postal
			//else if ((nomchamp == 'Code Postal') || (nomchamp == 'code postal') || (nomchamp == 'Code postal')){		
			//	if (!testOnlyNum(i)) if (langue == 0) message += nomchamp + "\n"; else{champtranslated=traductor(nomchamp); message += champtranslated + "\n";}
			//	specialTest = 1;
			//}
				// lorsqu'on a terminé une série de boutons radio, on vérifie s'il l'un d'eux a été coché,
		    	// si ce n'est pas le cas on ajoute le nom des boutons au message
		   else if ((prectype == "radio") && (nomchamp != precchamp)) {
		      prectype = "";
		   	  if (coche) coche = false;
 			  else if (langue == 0) message += precchamp + "\n"; else{champtranslated=traductor(precchamp); message += champtranslated + "\n";}
		   }
		   // idem lorsqu'on a une série de cases à cocher
		   else if ((prectype == "checkbox") && (racine_checkbox(nomchamp) != precchamp)) {
		      prectype = "";
		   	  if (coche) coche = false;
 			  else if (langue == 0) message += precchamp + "\n"; else{champtranslated=traductor(precchamp); message += champtranslated + "\n";}
		   }
		   // contrôle si la sélection d'une liste (à choix unique ou multiple) n'est pas la première
		   if ((champ.type.indexOf("select") != -1) && 
				      ((champ.selectedIndex == 0) || (champ.selectedIndex == -1))) {
		   	    if (langue == 0) message += nomchamp + "\n"; else{champtranslated=traductor(nomchamp); message += champtranslated + "\n";}				
		   }
		   // contrôle si la sélection d'une liste multiple est la dernière et que le champ "other..." suivant n'est pas vide
		   if ((champ.type.indexOf("select") != -1) && (champ.value == "0") && document.forms[0].elements[i+1].value == "") {
		   	    if (langue == 0) message += nomchamp + "\n"; else{champtranslated=traductor(nomchamp); message += champtranslated + "\n";}				
		   }
		   // contrôle si un bouton radio est coché ou pas
		   else if (champ.type == "radio") {
		   		if ((coche == false) && (champ.checked)) coche = true;
				prectype = "radio"; 
		   }
		   // contrôle si une boîte à cocher est cochée ou pas
		   else if (champ.type == "checkbox") {
		   		nomchamp = racine_checkbox(nomchamp);
		   		if ((coche == false) && (champ.checked)) coche = true;
				prectype = "checkbox"; 
		   }
		   // contrôle si une case texte (une ligne ou multiligne) n'est pas vide
		   else if ((champ.value.length < 2)  && (specialTest != 1) && (champ.type.indexOf("select") == -1))
		      if (langue == 0) message += nomchamp + "\n"; else{champtranslated=traductor(nomchamp); message += champtranslated + "\n";}
		   precchamp = nomchamp;
		   specialTest = 0;
		}
	}
	if (message.length) {
	   // francais == 0, sinon anglais
	   if (langue == 0) alert("Les champs obligatoires suivants n'ont pas été remplis correctement: \n\n" + message);
	   else alert("The following fields are required: \n\n" + message);
	   return false;
    }
	else return true;
}


PositionX = 100;
PositionY = 100;
defaultWidth  = 770;
defaultHeight = 600;
var AutoClose = true;
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;

function popImage(imageURL){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<script>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
writeln('width=100-(document.body.clientWidth-document.images[0].width);');
writeln('height=100-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["isoft"].width;');writeln('window.innerHeight=document.images["isoft"].height;}}');
writeln('function doTitle(){document.title="ISOFT";}');writeln('</script>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="isoft" src='+imageURL+' style="display:block"></body></html>');
close();		
}}

function openInfos(URL) {
  var POPUP=window.open(URL,'','width=630,height=455,left=100,top=100,menubars=no,scrollbars=no,statusbar=no,locationbar=no');
	  POPUP.focus();
}

function FtoE() {
	var ch  = document.location+'';
	ch = ch.substring(0,ch.length-4);
	return document.location.href=ch +'_en.htm';
	//return document.location.href='http://www.alice-soft.com';
}

function EtoF() {
	var ch  = document.location+'';
	ch = ch.substring(0,ch.length-7);
	return document.location.href=ch +'.htm';
}

function HideMail(protection,domaine,texte) {
	var adresse = "<a href=\"mailto:" + protection + "@" + domaine + "\"";
	adresse += " onmouseover=\"window.status='mailto...';return true;\" onmouseout=\"window.status='';return true;\">" + texte + "</a>";
	document.write(adresse);
}
