/** lightbox **/

function utilisateurLog()
{
	var XHR	=	new PrivateXHR();
	XHR.addParam("f_login", document.getElementById('inp-email').value);
	XHR.addParam("f_password", document.getElementById("inp-password").value);
	XHR.addParam("f_autolog", document.getElementById("inp-autlog").checked);
	XHR.outToText (false);
	XHR.sendToPhp(callbackUtilisateurLog,"/ws/login_cart.php","POST");
}

function callbackUtilisateurLog(obj)
{
	var redirect = "/user/profil/";
	var login_ok = obj.getElementsByTagName('login');

	// validation si ok
	if (login_ok[0].firstChild.data == 'true')
	{
		document.location.href = document.location.href;
	}
	// sinon, affichage de l'erreur
	else
	{
		document.getElementById("erreur-login").className = "login-error-cart";
	}
}

/** fin lightbox **/











// pour permetre la modification de la date de naissance ajouter "date", "month", "year" dans a_forms info
var a_forms_info	=	new Array("civilm", "civilMlle", "civilMme", "prenom", "nom", "telephone", 
		"courriel", "mdp", "mdp-verif", "old-mdp", "newsletter", "autolog", "next_sell_n", "next_sell", "sell_begin", "sell_begin_n");
var a_forms_birthdate = new Array("date", "month", "year");

var a_forms_info_popup	=	new Array("prenom", "nom", "telephone", 
		"courriel", "mdp", "mdp-verif");

//var a_forms_newsletter	=	new Array("newsletter");

var b_test= false;

function Unshow_civilite(){

// *************** cache radiodox civilité : *********** //
o_civil_0 = document.getElementById("civil-0");


a_o_civil_0_child = o_civil_0.childNodes;
i_civil_length = a_o_civil_0_child.length;

// test de civilité checked
for (var idx = 0; idx < i_civil_length; ++idx){
	if (a_o_civil_0_child[idx].nodeName == 'INPUT')

	{
		var s_checked = a_o_civil_0_child[idx].checked;
		if (a_o_civil_0_child[idx].checked)
		{
			a_o_civil_0_child[idx].style.display = 'none';

		}
	}
};

o_civil_1 = document.getElementById("civil-1");



a_o_civil_1_child = o_civil_1.childNodes;
i_civil_length = a_o_civil_1_child.length;

// test de civilité checked
for (var idx = 0; idx < i_civil_length; ++idx){
	if (a_o_civil_1_child[idx].nodeName == 'INPUT')
	{
		var s_checked = a_o_civil_1_child[idx].checked;
		if (a_o_civil_1_child[idx].checked)
		{
			a_o_civil_1_child[idx].style.display = 'none';
		}
	}
};

o_civil_2 = document.getElementById("civil-2");


a_o_civil_2_child = o_civil_2.childNodes;
i_civil_length = a_o_civil_2_child.length;

// test de civilité checked
for (var idx = 0; idx < i_civil_length; ++idx){
	if (a_o_civil_2_child[idx].nodeName == 'INPUT')

	{
		var s_checked = a_o_civil_2_child[idx].checked;
		if (a_o_civil_2_child[idx].checked)
		{
			a_o_civil_2_child[idx].style.display = 'none';

		}
	}
};
//*************** cache radiodox civilité : *********** //
return ;
}









function edit_info(s_type_info){


	a_forms = a_forms_info;

	if(!b_test){	
		for (var key in a_forms){
			o_field	=	document.getElementById("i-"+s_type_info+"-"+a_forms[key]);
			if(o_field){
				o_field.disabled	=	false;
				o_field.className	=	"actif";
			}
		}
		
		if (s_date_naissance == "null") {
			for (var key in a_forms_birthdate){
				// specifique a la nouvelle version :
				o_select = document.getElementById("i-info-"+a_forms_birthdate[key]);
				o_select.disabled = false;
			}
		}
		
		
		document.getElementById('mdp').innerHTML = document.getElementById('mdp').innerHTML+'*';
		document.getElementById('mdp-verif').innerHTML = document.getElementById('mdp-verif').innerHTML+'*';
		document.getElementById('courriel').innerHTML = document.getElementById('courriel').innerHTML+'*';
		document.getElementById('prenom').innerHTML = document.getElementById('prenom').innerHTML+'*';
		document.getElementById('nom').innerHTML = document.getElementById('nom').innerHTML+'*';
		document.getElementById('civilite').innerHTML = document.getElementById('civilite').innerHTML+'*';
		
		o_input = document.getElementById("input-"+s_type_info);
		o_input.className = "input_actif";
			
	
		// display de la civilité :
		o_civil_0 = document.getElementById("civil-0");
		o_civil_0.className = "input_actif";

		a_o_civil_0_child = o_civil_0.childNodes;
		i_civil_length = a_o_civil_0_child.length;

		// test de civilité checked
		for (var idx = 0; idx < i_civil_length; ++idx){
			if (a_o_civil_0_child[idx].nodeName == 'INPUT')

			{
				var s_checked = a_o_civil_0_child[idx].checked;
				if (a_o_civil_0_child[idx].checked)
				{
					a_o_civil_0_child[idx].style.display = 'inline';

				}
			}
		};
		
		// edité :
		o_edit = document.getElementById("link_edit");
		o_edit.style.display = "none";
		
		
		// display de la civilité :
		o_civil_1 = document.getElementById("civil-1");
		o_civil_1.className = "input_actif";
		
		a_o_civil_1_child = o_civil_1.childNodes;
		i_civil_length = a_o_civil_1_child.length;

		// test de civilité checked
		for (var idx = 0; idx < i_civil_length; ++idx){
			if (a_o_civil_1_child[idx].nodeName == 'INPUT')

			{
				var s_checked = a_o_civil_1_child[idx].checked;
				if (a_o_civil_1_child[idx].checked)
				{
					a_o_civil_1_child[idx].style.display = 'inline';

				}
			}
		};
		
		

		
		// display de la civilité :
		o_civil_2 = document.getElementById("civil-2");
		o_civil_2.className = "input_actif";
		
		a_o_civil_2_child = o_civil_2.childNodes;
		i_civil_length = a_o_civil_2_child.length;

		// test de civilité checked
		for (var idx = 0; idx < i_civil_length; ++idx){
			if (a_o_civil_2_child[idx].nodeName == 'INPUT')

			{
				var s_checked = a_o_civil_2_child[idx].checked;
				if (a_o_civil_2_child[idx].checked)
				{
					a_o_civil_2_child[idx].style.display = 'inline';

				}
			}
		};


		
		// specifique a la nouvelle version :
		o_msg_modification = document.getElementById("msg_modification");
		o_msg_modification.className = "input_inactif";
		
		
		// specifique a la nouvelle version :
		o_span_tel = document.getElementById("span-tel");
		o_span_tel.className = "italic input_actif";
		
		// specifique a la nouvelle version :
		o_input2 = document.getElementById("input-"+s_type_info+"2");
		o_input2.className = "input_actif";
		
		// specifique a la nouvelle version :
		o_input3 = document.getElementById("input-"+s_type_info+"3");
		o_input3.className = "input_actif";
		
		// specifique a la nouvelle version :
		o_input4 = document.getElementById("input-"+s_type_info+"4");
		o_input4.className = "input_actif";
		
//		// specifique a la nouvelle version :
//		o_input5 = document.getElementById("input-"+s_type_info+"5");
//		o_input5.className = "input_actif";
		
		o_button	=	document.getElementById("b-"+s_type_info+"-modifier");
		o_button.className	= "inputsubmit boutton_actif";			
		b_test	= true;

	}else{
		disable_info(s_type_info);
	}	
}



function disable_info(s_type_info){


if (s_type_info == "info")
{ 
	a_forms = a_forms_info;
}
	
	for (var key in a_forms){
		o_field	=	document.getElementById("i-"+s_type_info+"-"+a_forms[key]);
		if(o_field){
			o_field.disabled	=	true;
			o_field.className	=	"inputtext_disabled_style inactif";
		}
	}
	
	
	
	document.getElementById('mdp').innerHTML = document.getElementById('mdp').innerHTML.substr(0, document.getElementById('mdp').innerHTML.length -1);
	document.getElementById('mdp-verif').innerHTML = document.getElementById('mdp-verif').innerHTML.substr(0, document.getElementById('mdp-verif').innerHTML.length -1);
	document.getElementById('courriel').innerHTML = document.getElementById('courriel').innerHTML.substr(0, document.getElementById('courriel').innerHTML.length -1);
	document.getElementById('prenom').innerHTML = document.getElementById('prenom').innerHTML.substr(0, document.getElementById('prenom').innerHTML.length -1);
	document.getElementById('nom').innerHTML = document.getElementById('nom').innerHTML.substr(0, document.getElementById('nom').innerHTML.length -1);
	document.getElementById('civilite').innerHTML = document.getElementById('civilite').innerHTML.substr(0, document.getElementById('civilite').innerHTML.length -1);
	
	o_input = document.getElementById("input-"+s_type_info);
	o_input.className = "input_inactif";
	
	

	
	
	// display de la civilité :
	o_civil_0 = document.getElementById("civil-0");
	a_o_civil_0_child = o_civil_0.childNodes;
	i_civil_length = a_o_civil_0_child.length;

	// test de civilité checked
	for (var idx = 0; idx < i_civil_length; ++idx){
		if (a_o_civil_0_child[idx].nodeName == 'INPUT')

		{
			var s_checked = a_o_civil_0_child[idx].checked;
			if (!a_o_civil_0_child[idx].checked)
			{
				o_civil_0.className = "input_inactif";
			} else {
				a_o_civil_0_child[idx].style.display = 'none';
			}
		}
	};

	// display de la civilité :
	o_civil_1 = document.getElementById("civil-1");
	a_o_civil_1_child = o_civil_1.childNodes;
	i_civil_length = a_o_civil_1_child.length;

	// test de civilité checked
	for (var idx = 0; idx < i_civil_length; ++idx){
		if (a_o_civil_1_child[idx].nodeName == 'INPUT')

		{
			var s_checked = a_o_civil_1_child[idx].checked;
			if (!a_o_civil_1_child[idx].checked)
			{
				o_civil_1.className = "input_inactif";
			} else {
				a_o_civil_1_child[idx].style.display = 'none';
			}
		}
	};
	
	// display de la civilité :
	o_civil_2 = document.getElementById("civil-2");
	a_o_civil_2_child = o_civil_2.childNodes;
	i_civil_length = a_o_civil_2_child.length;

	// test de civilité checked
	for (var idx = 0; idx < i_civil_length; ++idx){
		if (a_o_civil_2_child[idx].nodeName == 'INPUT')

		{
			var s_checked = a_o_civil_2_child[idx].checked;
			if (!a_o_civil_2_child[idx].checked)
			{
				o_civil_2.className = "input_inactif";
			} else {
				a_o_civil_2_child[idx].style.display = 'none';
			}
		}
	};
	
	
	// specifique a la nouvelle version :
	o_span_tel = document.getElementById("span-tel");
	o_span_tel.className = "italic input_inactif";
	
	// specifique a la nouvelle version :
	o_input2 = document.getElementById("input-"+s_type_info+"2");
	o_input2.className = "input_inactif";
	
	// specifique a la nouvelle version :
	o_input3 = document.getElementById("input-"+s_type_info+"3");
	o_input3.className = "input_inactif";
	
	// specifique a la nouvelle version :
	o_input4 = document.getElementById("input-"+s_type_info+"4");
	o_input4.className = "input_inactif";
	
//	// specifique a la nouvelle version :
//	o_input5 = document.getElementById("input-"+s_type_info+"5");
//	o_input5.className = "input_inactif";
	
	o_button	=	document.getElementById("b-"+s_type_info+"-modifier");
	o_button.className	=	"inputsubmit boutton_inactif";	
	b_test	= false;
}

function assoForm(){
	
	var o_input_sell_begin_n	=	document.getElementById('i-info-sell_begin_n');
	o_input_sell_begin_n.onfocus= function(){
		document.getElementById('div_quoti_info').style.display = "block";
	}
	
	var o_input_next_sell_n	=	document.getElementById('i-info-next_sell_n');
	o_input_next_sell_n.onfocus= function(){	
		document.getElementById('div_hebdo_info').style.display = "block";
	}
	
	
	var o_input_sell_begin	=	document.getElementById('i-info-sell_begin');
	o_input_sell_begin.onfocus= function(){
		document.getElementById('div_quoti_info').style.display = "none";
	}
	
	var o_input_next_sell	=	document.getElementById('i-info-next_sell');
	o_input_next_sell.onfocus= function(){	
		document.getElementById('div_hebdo_info').style.display = "none";
	}
	
	
	
	Unshow_civilite();
	for (var key in a_forms_info_popup){
		// selection de l'element actif
			var full_key = "i-info-"+a_forms_info_popup[key];
			var o_input	=	document.getElementById(full_key);
			
		// action lors de la sortie de l'element

			o_input.onblur= function(){

				var o_popup	=	document.getElementById("p-"+this.id);
				var o_popup_text	=	document.getElementById("pt-"+this.id);		
				
				if (this.id == 'i-info-mdp-verif'){
					var o_input_to_check = document.getElementById('i-info-mdp');
					
					if (this.value == ""){
						o_popup.style.display	=	"block";
						o_popup_text.innerHTML	=	"<em>"+a_forms_verif["pwd_2"]["msg-no-value"]+"</em>";
						o_popup_to_hide	=	o_popup;
						timerClose();
					}
					if (o_input_to_check.value != this.value){
						o_popup.style.display	=	"block";
						o_popup_text.innerHTML	=	"<em>"+a_forms_verif["pwd_2"]["value-equal-msg"]+"</em>";
						o_popup_to_hide	=	o_popup;
						timerClose();
					}
				}
				
				if (this.id == 'i-info-mdp'){
					if (this.value == ""){
						o_popup.style.display	=	"block";
						o_popup_text.innerHTML	=	"<em>"+a_forms_verif["pwd_1"]["msg-no-value"]+"</em>";
						o_popup_to_hide	=	o_popup;
						timerClose();
					} else {
						var Expression = new RegExp("[a-zA-Z0-9]+","g");
						
						if (this.value != Expression.exec(this.value)){
							o_popup.style.display	=	"block";
							o_popup_text.innerHTML	=	"<em>"+a_forms_verif["pwd_1"]["msg-not-alphanum"]+"</em>";
							o_popup_to_hide	=	o_popup;
							timerClose();
						}
					}
					
				}
				
				if (this.id == 'i-info-prenom'){
					if (this.value == ""){
						o_popup.style.display	=	"block";
						o_popup_text.innerHTML	=	"<em>"+a_forms_verif["prenom"]["msg-no-value"]+"</em>";
						o_popup_to_hide	=	o_popup;
						timerClose();
					}
				}
				
				if (this.id == 'i-info-nom'){
					if (this.value == ""){
						o_popup.style.display	=	"block";
						o_popup_text.innerHTML	=	"<em>"+a_forms_verif["nom"]["msg-no-value"]+"</em>";
						o_popup_to_hide	=	o_popup;
						timerClose();
					}
				}
				
				if (this.id == 'i-info-telephone'){
					if (this.value == ""){
						o_popup.style.display	=	"block";
						o_popup_text.innerHTML	=	"<em>"+a_forms_verif["telephone"]["msg-no-value"]+"</em>";
						o_popup_to_hide	=	o_popup;
						timerClose();
					}
					
					if (this.value.length <= 15){
						if (!isDigit(this.value)){
							o_popup.style.display	=	"block";
							o_popup_text.innerHTML	=	"<em>"+a_forms_verif["telephone"]["msg-no-value"]+"</em>";
							o_popup_to_hide	=	o_popup;
							timerClose();
						}
					} else {
						o_popup.style.display	=	"block";
						o_popup_text.innerHTML	=	"<em>"+a_forms_verif["telephone"]["msg-no-value"]+"</em>";
						o_popup_to_hide	=	o_popup;
						timerClose();
					}
				}
				
				if (this.id == 'i-info-courriel'){
					if (this.value == ""){
						o_popup.style.display	=	"block";
						o_popup_text.innerHTML	=	"<em>"+a_forms_verif["mail_1"]["msg-no-value"]+"</em>";
						o_popup_to_hide	=	o_popup;
						timerClose();
					}

					var place = this.value.indexOf("@",1);
					var point = this.value.indexOf(".",place+1);
					if ((place > -1)&&(this.value.length > 4)&&(point > 1)){
						
					} else {
						o_popup.style.display	=	"block";
						o_popup_text.innerHTML	=	"<em>"+a_forms_verif["mail_1"]["msg-invalide"]+"</em>";
						o_popup_to_hide	=	o_popup;
						timerClose();
					}
				}
				

			}
			
			o_input.onfocus	= function(){
				var o_popup	=	document.getElementById("p-"+this.id);
				o_popup.style.display	=	"none";
			}
			
		
	}
}





function isDigit(val)
{
	if(val == "")
		return false;

	var cc; // char courant
	
	for (t = 0 ; t < val.length ; t++)
	{
		cc = val.charAt(t);
		if(!(cc >=0 && cc <= 9))
			return false;
	}
	return true;
} 

function timerClose(){
	timer=setInterval("closePopup()", 2000);

}

function closePopup(){
if(o_popup_to_hide)
	o_popup_to_hide.style.display	=	"none";
	clearInterval(timer);
}


window.onload 	=	assoForm;

