/*      OS detection					        */
/*      ----------------------------------------------------------------*/
/*
	
*/
/*      ----------------------------------------------------------------*/


var isWin = (navigator.platform  ==  "win32") || (navigator.platform == "windows");

var isMac = (navigator.platform  == "Mac68K") || (navigator.platform == "MacPPC");

var isUnix = (navigator.platform  ==  "X11") || (navigator.platform  ==  "Linux x86_64") && !isWin && !isMac;

/*      Verdana font adaptation		        */
/*      ----------------------------------------------------------------*/
/*
	check for OS who don't support ISOCPEUR
	modify properties to have Verdana font 
	looks good.
*/
/*      ----------------------------------------------------------------*/

function adaptationToVerdanaFont() {
	if (isUnix || isMac){
		var oTarget = document.getElementById("indexTitle");
		oTarget.style.top = "60px";
		var oTarget = document.getElementById("indexEnterList");
		oTarget.style.width = "355px";
		oTarget.style.left = "17px";
	} /* else if (isMac){
		var oTarget = document.getElementById("indexTitle");
		oTarget.style.top = "60px";
		var oTarget = document.getElementById("indexEnterList");
		oTarget.style.width = "355px";
		oTarget.style.left = "17px";		
	}*/

}

/*      Form object					        */
/*      ----------------------------------------------------------------*/
/*
	
*/
/*      ----------------------------------------------------------------*/

var oFormUtil = new Object;

/*      Focus on first form field			        */
/*      ----------------------------------------------------------------*/
/*
	
*/
/*      ----------------------------------------------------------------*/

oFormUtil.focusOnFirst = function (){
	if (document.forms.length > 0){
		for (var i = 0; i < document.forms[0].elements.length; i++){
			var oField = document.forms[0].elements[i];
			if (oField.type != "hidden"){
				oField.focus();
				return;
			}
		}
	}
}

/*      Mail integrity check			        */
/*      ----------------------------------------------------------------*/
/*
	compare input with RegEx
	if true focus on next
	else delete input and alert invalid email format
*/
/*      ----------------------------------------------------------------*/

function checkMail(oTarget){
	var reEmail = /^(?:\w+\.?)*\w+@(?:\w+-?)*\.\w+$/i;
	var reEmail2 = /^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i;
	var bResult = reEmail2.test(oTarget.value);
	if (!bResult){
		return false;
	} else {
		return true;
	}	
}

/*      Check field					        */
/*      ----------------------------------------------------------------*/
/*
	
*/
/*      ----------------------------------------------------------------*/

function checkField(oTarget,sValue){
	switch (sValue == ""){
		case true:
			if (oTarget.value == sValue){
				return false;
			} else {
				return true;
			}
			break;
		default:
			if (oTarget.value !== sValue){
				return false;
			} else {
				return true;
			}
		}
}

/*      Define language				        */
/*      ----------------------------------------------------------------*/
/*
	find fr, nl or de in URL string
*/
/*      ----------------------------------------------------------------*/

function defineLang(){
	var oUrl = new String(document.location);
	var sLang = oUrl.substring(oUrl.length-7,oUrl.length-5);
	switch (sLang){
		case 'fr': iResult = 0;
			break;
		case 'nl': iResult = 1;
			break;
		case 'de': iResult = 2;
			break;
		default: iResult = "language not found in URL";
	}
	return iResult;
}

/*      Check fields and submit			        */
/*      ----------------------------------------------------------------*/
/*
	list of fields to check
	list of text in different languages to show
	if negative test.
	defining language
	checking fields of list
	checking email mal formation
	submitting or alerting bad fields
*/
/*      ----------------------------------------------------------------*/

function submitForm(){

	var aFieldsToCheckIds = [
						     ['Nom','Naam','Name',document.getElementById('name'),''],
						     ['Pr\u00e9nom','Voornaam','Vorname',document.getElementById('firstname'),''],
						     ['Test anti-spam','Anti-spam test','Test',document.getElementById('test'),'2']
						    ];
						     
	var aAlertText = [['le champ suivant est obligatoire:','de volgende gegevens zijn verplicht:','im bau'],
				      ['les champs suivants sont obligatoires:','de volgende gegevens zijn verplicht:','im bau'],
				      ['votre adresse courriel semble incorecte','U email adres blijkt niet goed gevormd te zijn','im bau']
				     ];
	
	
	var langSelector = defineLang();
	
	var aBadFields = new Array;
	
	for (var i = 0; i < aFieldsToCheckIds.length; i++){
		var bResult = checkField(aFieldsToCheckIds[i][3],aFieldsToCheckIds[i][4]);
		if(!bResult){
			aBadFields.push(aFieldsToCheckIds[i][langSelector]);
		}
	}
	
	var bBadEmail = checkMail(document.getElementById('mail'));
	
	var sAlert = new String;
	
	switch (aBadFields.length){
		case 0: switch (bBadEmail){
				case false: sAlert = aAlertText[2][langSelector];
					alert(sAlert);
					break;
				default: /*alert('ok');*/
					var aSubmitButton = document.getElementsByName('submit');
					for (var i = 0; i < aSubmitButton.length; i++){
						aSubmitButton[i].disabled = true;
						aSubmitButton[i].style.background = "#babdb6";
						aSubmitButton[i].style.color = "#888a85";
					}
			}
			break;
		case 1: switch (bBadEmail){
				case false: sAlert = aAlertText[0][langSelector] + '\n\t' + aBadFields[0] + '\n' + aAlertText[2][langSelector];
					alert(sAlert);
					break;
				default: sAlert = aAlertText[0][langSelector] + '\n\t' + aBadFields[0];
					alert(sAlert);
			}
			break;
		default:  sAlert = aAlertText[1][langSelector];
			for (var j = 0; j < aBadFields.length; j++){
				 sAlert = sAlert + '\n\t' + aBadFields[j];
			}
			switch (bBadEmail){
				case false: sAlert = sAlert + '\n' + aAlertText[2][langSelector];
					alert(sAlert);
					break;
				default: alert(sAlert);			
			}
	}
	
	
	
}







/*      Unlock submit buttons			        */
/*      ----------------------------------------------------------------*/
/*
	
*/
/*      ----------------------------------------------------------------*/

function unlockSubmitButtons(){
	var aSubmitButton = document.getElementsByName('submit');
		if(aSubmitButton[0].disabled){
			for (var i = 0; i < aSubmitButton.length; i++){
				aSubmitButton[i].disabled = false;
				aSubmitButton[i].style.background = "#73d216";
				aSubmitButton[i].style.color = "black";
			}
		}
}










