a_forms_verif	=	new Array();

a_forms_verif["civilite"]	=	new Array();
a_forms_verif["civilite"]["type"]	=	"radio";
a_forms_verif["nom"]	=	new Array();
a_forms_verif["nom"]["type"]	=	"text";
a_forms_verif["prenom"]	=	new Array();
a_forms_verif["prenom"]["type"]	=	"text";
a_forms_verif["prenom"]["msg-no-value"]	=	"Merci de saisir votre prénom";
a_forms_verif["mail_1"]	=	new Array();
a_forms_verif["mail_1"]["type"]	=	"text";

a_forms_verif["mail_2"]	=	new Array();
a_forms_verif["mail_2"]["type"]	=	"text";

a_forms_verif["mail_2"]["value-equal"]	=	"mail_1";

a_forms_verif["pwd_1"]	=	new Array();
a_forms_verif["pwd_1"]["type"]	=	"text";

a_forms_verif["pwd_2"]	=	new Array();
a_forms_verif["pwd_2"]["type"]	=	"text";

a_forms_verif["pwd_2"]["value-equal"]	=	"pwd_1";

a_forms_verif["captcha"]	=	new Array();
a_forms_verif["captcha"]["type"]	=	"text";

a_forms_verif["date_naissance"]	=	new Array();
a_forms_verif["date_naissance"]["type"]	=	"date";


var o_popup_to_hide	= 	null;
var timer			=	null;
function assoForm(){
	for (var key in a_forms_verif){
		if(a_forms_verif[key]["type"]=="text"){
			var o_input	=	document.getElementById(key);
			o_input.onblur= function(){
				var o_li	=	document.getElementById("l_"+this.id);
				var o_popup	=	document.getElementById("p_"+this.id);
				var o_popup_text	=	document.getElementById("pt_"+this.id);				
				if(this.value!=""){
					if(a_forms_verif[this.id]["value-equal"]){
						
						o_input_to_check	=	document.getElementById(a_forms_verif[this.id]["value-equal"]);
						if(o_input_to_check.value!=this.value){
							o_li.className="no";							
							o_popup_text.innerHTML	=	"<em>"+a_forms_verif[this.id]["value-equal-msg"]+"</em>";
							if(o_popup_to_hide)
								o_popup_to_hide.style.display	=	"none";	
							o_popup.style.display	=	"block";					
							o_popup_to_hide	=	o_popup;		
							timerClose();													
						}else{
							o_li.className="yes";
							o_popup.style.display	=	"none";						
						}						
					}else{
						o_li.className="yes";
						o_popup.style.display	=	"none";
					}
				}else{
					o_li.className="no";
					
					o_popup_text.innerHTML	=	"<em>"+a_forms_verif[this.id]["msg-no-value"]+"</em>";
					if(o_popup_to_hide)
						o_popup_to_hide.style.display	=	"none";	
					o_popup.style.display	=	"block";					
					o_popup_to_hide	=	o_popup;			
					timerClose();					
				}
			}
			
			o_input.onfocus	= function(){
				var o_popup	=	document.getElementById("p_"+this.id);
				var o_li	=	document.getElementById("l_"+this.id);
				o_li.className="";				
				o_popup.style.display	=	"none";
			}
			
		}
		
		// Pour le champ de date de naissance
		else if (a_forms_verif[key]["type"] == "date"){
			var date_selects = ["i-info-year", "i-info-month", "i-info-date"];
			for (var indice = 0; indice < 3; indice ++) {
				var o_input	=	document.getElementById(date_selects[indice]);
				o_input.onblur= function(){
					var o_li	=	document.getElementById("l_date_naissance");
	//				var o_popup	=	document.getElementById("p_date_naissance");
	//				var o_popup_text	=	document.getElementById("pt_date_naissance");
					
					if ((document.getElementById("i-info-year").value == "") || (document.getElementById("i-info-month").value == "") || (document.getElementById("i-info-date").value == "") || !checkdate(document.getElementById("i-info-month").value, document.getElementById("i-info-date").value, document.getElementById("i-info-year").value))
					{
						o_li.className="no";
	//					o_popup_text.innerHTML	=	"<em>"+a_forms_verif["date_naissance"]["msg-no-value"]+"</em>";
	//					if(o_popup_to_hide)
	//						o_popup_to_hide.style.display	=	"none";	
	//					o_popup.style.display	=	"block";					
	//					o_popup_to_hide	=	o_popup;			
						timerClose();
					}
					else
					{
						o_li.className="yes";
	//					o_popup.style.display	=	"none";	
					}
				}
			}
				
		}
		
	}
	
}

window.onload 	=	assoForm;

function submitInscription(){
	o_form	=	document.getElementById('f_register');
	for (var key in a_forms_verif){
		if(a_forms_verif[key]["type"]=="text"){
			var o_input	=	document.getElementById(key);
			var o_li	=	document.getElementById("l_"+o_input.id);
			var o_popup	=	document.getElementById("p_"+o_input.id);
			var o_popup_text	=	document.getElementById("pt_"+o_input.id);				
			if(o_input.value!=""){
				if(a_forms_verif[o_input.id]["value-equal"]){
					
					o_input_to_check	=	document.getElementById(a_forms_verif[o_input.id]["value-equal"]);
					if(o_input_to_check.value!=o_input.value){
						o_li.className="no";							
						o_popup_text.innerHTML	=	"<em>"+a_forms_verif[o_input.id]["value-equal-msg"]+"</em>";
						if(o_popup_to_hide)
							o_popup_to_hide.style.display	=	"none";	
						o_popup.style.display	=	"block";					
						o_popup_to_hide	=	o_popup;						
						timerClose();									
					}else{
						o_li.className="yes";
						o_popup.style.display	=	"none";						
					}						
				}else{
					o_li.className="yes";
					o_popup.style.display	=	"none";
				}
			}else{
				o_li.className="no";
				
				o_popup_text.innerHTML	=	"<em>"+a_forms_verif[o_input.id]["msg-no-value"]+"</em>";
				if(o_popup_to_hide)
					o_popup_to_hide.style.display	=	"none";	
				o_popup.style.display	=	"block";					
				o_popup_to_hide	=	o_popup;
				timerClose();
				return false;								
			}
		}
	}
		/*
			var o_input_1	=	document.getElementById("civilite_1");
			var o_input_2	=	document.getElementById("civilite_2");
			var o_input_3	=	document.getElementById("civilite_3");			
			if(!o_input_1.checked&&!o_input_2.checked&&!o_input_3.checked){			
				var o_li	=	document.getElementById("l_civilite");
				var o_popup	=	document.getElementById("p_civilite");
				var o_popup_text	=	document.getElementById("pt_civilite");				
				o_li.className="no";				
				o_popup_text.innerHTML	=	"<em>Please your civility ;)</em>";				
				if(o_popup_to_hide)
					o_popup_to_hide.style.display	=	"none";						
				o_popup.style.display	=	"block";					
				o_popup_to_hide	=	o_popup;
				return false;		
			}		
		*/
	var o_input_cgu	=	document.getElementById("cgu");
	if(!o_input_cgu.checked){	
		var o_popup	=	document.getElementById("p_cgu");
		var o_popup_text	=	document.getElementById("pt_cgu");	
		o_popup_text.innerHTML	=	"<em>"+a_forms_verif["cgu"]+"</em>";				
		if(o_popup_to_hide)
			o_popup_to_hide.style.display	=	"none";						
		o_popup.style.display	=	"block";					
		o_popup_to_hide	=	o_popup;
		timerClose();
		return false;		
	}	
	
	
	
	// Vérification de la date de naissance
	var date_selects = ["i-info-year", "i-info-month", "i-info-date"];
	for (var indice = 0; indice < 3; indice ++) {
		var o_input	=	document.getElementById(date_selects[indice]);
		var o_li	=	document.getElementById("l_date_naissance");
		var o_popup	=	document.getElementById("p_date_naissance");
		var o_popup_text	=	document.getElementById("pt_date_naissance");
		
		if ((document.getElementById("i-info-year").value == "") || (document.getElementById("i-info-month").value == "") || (document.getElementById("i-info-date").value == "") || !checkdate(document.getElementById("i-info-month").value, document.getElementById("i-info-date").value, document.getElementById("i-info-year").value))
		{
			o_li.className="no";
			o_popup_text.innerHTML	=	"<em>"+a_forms_verif["date_naissance"]["msg-no-value"]+"</em>";
			if(o_popup_to_hide)
				o_popup_to_hide.style.display	=	"none";	
			o_popup.style.display	=	"block";					
			o_popup_to_hide	=	o_popup;			
			timerClose();
			return false;
		}
		else
		{
			o_li.className="yes";
			o_popup.style.display	=	"none";	
		}
	}
	
	
	

	o_form	=	document.getElementById('f_register');
	o_form.submit();
}

function DestroyPopup(){
	if(o_popup_to_hide)
		o_popup_to_hide.style.display	=	"none";
	clearInterval(timer);
}

function closePopup(){
	/*
	if(o_popup_to_hide)
		o_popup_to_hide.style.display	=	"none";
	clearInterval(timer);
	*/
	DestroyPopup();
}

function timerClose(){

	timer = setInterval('DestroyPopup()', 4000);
	 
}



function checkdate (month, day, year) {
    // Returns true(1) if it is a valid date in gregorian calendar  
    // 
    // version: 908.406
    // discuss at: http://phpjs.org/functions/checkdate
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Pyerre
    // *     example 1: checkdate(12, 31, 2000);
    // *     returns 1: true
    // *     example 2: checkdate(2, 29, 2001);
    // *     returns 2: false
    // *     example 3: checkdate(03, 31, 2008);
    // *     returns 3: true
    // *     example 4: checkdate(1, 390, 2000);
    // *     returns 4: false
    var myDate = new Date();
    myDate.setFullYear( year, (month - 1), day );

    return month >= 1 && month <= 12 && year >= 1 && year <= 32767 && ((myDate.getMonth()+1) == month && day<32);
}
