function InitForm1(){
	
	var fields=new Array();
	fields.push(
	{id:'nomB',fct:isValidLastNameForm},
	{id:'prenomB',fct:isValidFirstNameForm},
	{id:'mailB',fct:isValidEmailForm},
	{id:'pwdB',fct:isValidPwdForm},
	{id:'ischeckcondition',fct:isValidchecCoditionForm}
	);
	InitForm(fields);
	
}
function ValidForm1() {
	calculate_time_zone();
	var fields=new Array();
	fields.push(
	{id:'nomB',fct:isValidLastNameForm},
	{id:'prenomB',fct:isValidFirstNameForm},
	{id:'mailB',fct:isValidEmailForm},
	{id:'pwdB',fct:isValidPwdForm},
	{id:'ischeckcondition',fct:isValidchecCoditionForm}
	);
	var result=ValidForm(fields);
	return result;
}
function InitForm(fields){
	
	 for (var i = 0; i < fields.length; i++){
	 	var myId=fields[i].id;
		var myFct=fields[i].fct;
		 if(document.getElementById(myId)!=null){
		 	
			document.getElementById(myId).onkeyup = function() {
				
				var errors=new Array();
				var myLocalId=this.id;
				var myLocalFct=null;
				for (var j=0;j<fields.length;++j)
					if (fields[j].id==myLocalId) myLocalFct = fields[j].fct;
				if (myLocalFct!=null)
					myLocalFct(myLocalId,errors);
				if (errors.length>0) {
					//pas ok
					var myError=errors[0].txt;
					if(document.getElementById(myLocalId+"OK")!=null)
						document.getElementById(myLocalId+"OK").innerHTML = "<img src='images/error_icon.png' width='15px' height='15px' alt='"+myError+"'/>";
				}
				else {
					//ok
					if(document.getElementById(myLocalId+"OK")!=null)
						document.getElementById(myLocalId+"OK").innerHTML ="<img src='images/ok_icon.png' width='15px' height='15px'/>";
				}
			}
			document.getElementById(myId).onclick  = function() {
			var errors=new Array();
			var myLocalId=this.id;
			var myLocalFct=null;
			for (var j=0;j<fields.length;++j)
				if (fields[j].id==myLocalId) myLocalFct = fields[j].fct;
			if (myLocalFct!=null)
				myLocalFct(myLocalId,errors);
			
			if (errors.length>0) {
				//pas ok
				var myError=errors[0].txt;
				if(document.getElementById(myLocalId+"OK")!=null)
					document.getElementById(myLocalId+"OK").innerHTML = "<img src='images/error_icon.png' width='15px' height='15px' alt='"+myError+"'/>";
			}
			else {
				//ok
				if(document.getElementById(myLocalId+"OK")!=null)
					document.getElementById(myLocalId+"OK").innerHTML ="<img src='images/ok_icon.png' width='15px' height='15px'/>";
			}
		}
		document.getElementById(myId).onfocus = function() {
			var myLocalId=this.id;
			document.getElementById(myLocalId).style.background= "url(images/roundedinput.png) no-repeat left top";
		}
	 }
	 }
}

function ValidForm(fields){
	
	var errors=new Array();
	 for (var i = 0; i < fields.length; i++){
	 	var myId=fields[i].id;
		document.getElementById(myId).style.background= "url(images/roundedinput.png) no-repeat left top";
		var myFct=fields[i].fct;
		myFct(myId,errors);
		
	 }
	 var totalerror="";
	 
	  for (var i = 0; i < errors.length; i++){
	  	var myId=errors[i].id;
		var myError=errors[i].txt;
		document.getElementById(myId).style.background= "url(images/roundedinputred.png) no-repeat left top";
		 totalerror+=myError+"<br>";
	  }
	  if(totalerror!=""){
	 	
		  showalertpanel(MLJS("txtattention"),totalerror,'',3,1,'');
		 return false;
		 
		}
	else 
	return true;
}

function isValidEmailForm(myId,err){
	if (!(isValidEmail(document.getElementById(myId).value)))
		err.push({id:myId,txt:MLJS("txtemailinvalide")});
}

 
function isValidPwdForm(myId,err){
	if (!(isValidPwd(document.getElementById(myId).value)))
		err.push({id:myId,txt:MLJS("txtsaisirmdpvalide")});
}

function isValidFirstNameForm(myId,err){
	if (!(isValidName(document.getElementById(myId).value)))
		err.push({id:myId,txt:MLJS("txtprenominvalide")});
}

function isValidLastNameForm(myId,err){
	if (!(isValidName(document.getElementById(myId).value)))
		err.push({id:myId,txt:MLJS("txtnominvalide")});
}
function isValidName(name){
	
	var strValidChars = "0123456789";
	var strChar;
    var nombredepoint = 0;
    var blnResult = true;
	if(name=="")
		return false;
    for (i = 0; i < name.length && blnResult == true; i++) {
        strChar = name.charAt(i);
        if ((strValidChars.indexOf(strChar) != -1)) 
            blnResult = false;
    }
    return blnResult;
}
function isValidPwd(str){
    return (str.length >= 4);
}
function isValidchecCoditionForm(myId,err){

if ((document.getElementById(myId).checked)==false)
		err.push({id:myId,txt:MLJS("txtacceptercgu")});
}
function calculate_time_zone() {
	var dateuser = new Date();
	var jan1 = new Date(dateuser.getFullYear(), 0, 1, 0, 0, 0, 0);  // jan 1st
	var june1 = new Date(dateuser.getFullYear(), 6, 1, 0, 0, 0, 0); // june 1st
	var temp = jan1.toGMTString();
	var jan2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	temp = june1.toGMTString();
	var june2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	var std_time_offset = (jan1 - jan2) / (1000 * 60 * 60);
	var daylight_time_offset = (june1 - june2) / (1000 * 60 * 60);
	var dst="0";
	
	if (std_time_offset == daylight_time_offset) {
		dst = "0"; // daylight savings time is NOT observed
	} else {
		// positive is southern, negative is northern hemisphere
		var hemisphere = std_time_offset - daylight_time_offset;
		if (hemisphere >= 0)
			std_time_offset = daylight_time_offset;
		dst = "1"; // daylight savings time is observed
	}
	var hour= parseInt(std_time_offset);
   	var mins =parseInt((std_time_offset-hour)*60);
	
	if (hour == 0) 
		hour = "00";
	else if (hour >9) 
		hour ="+"+hour;
	else if (hour >0&&hour <10) 
		hour = "+0"+hour;
	else if (std_time_offset<-9) 
		hour = "-"+hour;
	else
		hour = "-0"+hour;
	if (mins == 0) 
		mins = "00";
	document.getElementById('decalage').value=hour+":"+mins;
	document.getElementById('dst').value=dst;
}
