﻿/***************************************/
/* Launch/Common Myaccount
/***************************************/
$(document).ready(function(){

	//Je cache les messages d'alert pour les champs input
	$('form#logAccount').find('span[name=log_mess]').each(function(){
		$('#'+$(this).attr("id")).hide();
		$('#'+$(this).attr("id")).removeClass('error');
	});
	
	//Je cache les pictos pour les champs input
	$('form#logAccount').find('span[name=log_sta]').each(function(){
		$('#'+$(this).attr("id")).hide();
		$('#'+$(this).attr("id")).removeClass('at8_form_valide_i_ok');
		$('#'+$(this).attr("id")).removeClass('at8_form_valide_i_ko');
	});

	//Je cache les messages d'alert pour les champs input
	$('form#logCustomer').find('span[name=log_mess]').each(function(){
		$('#'+$(this).attr("id")).hide();
		$('#'+$(this).attr("id")).removeClass('error');
	});
	
	//Je cache les pictos pour les champs input
	$('form#logCustomer').find('span[name=log_sta]').each(function(){
		$('#'+$(this).attr("id")).hide();
		$('#'+$(this).attr("id")).removeClass('at8_form_valide_i_ok');
		$('#'+$(this).attr("id")).removeClass('at8_form_valide_i_ko');
	});

	//Je cache les messages d'alert pour les champs input
	$('form#modCustomer_coor').find('span[name=log_mess]').each(function(){
		$('#'+$(this).attr("id")).hide();
		$('#'+$(this).attr("id")).removeClass('error');
	});
	
	//Je cache les pictos pour les champs input
	$('form#modCustomer_coor').find('span[name=log_sta]').each(function(){
		$('#'+$(this).attr("id")).hide();
		$('#'+$(this).attr("id")).removeClass('at8_form_valide_i_ok');
		$('#'+$(this).attr("id")).removeClass('at8_form_valide_i_ko');
	});	
	
	
	

	//Cache les boites de dialogue
	setTimeout("$('div#response_message').hide();", 0);
	setTimeout("$('div#response_ok').hide();", 0);
	setTimeout("$('div#response_ko').hide();", 0);
	
	setTimeout("$('div#response_message_pop').hide();", 0);
	setTimeout("$('div#response_ok_pop').hide();", 0);
	setTimeout("$('div#response_ko_pop').hide();", 0);

	//Lance la boite de dialogue
	$("#dialog").dialog({
			bgiframe: true,
			autoOpen: false,
			width:600,
			modal: true,
			close: function() {
				//allFields.val('').removeClass('ui-state-error');
			}
	});		
	
	//Lancement des tabs
	$("#tabs").tabs();

});

/***************************************/
/* Vérification de l'inscription
/***************************************/
function validateFormlogCustomer_jq(form,lang,action,item,url,l_c,l_n,l_s,l_i)
{
	//Tableau des champs input pour le formulaire de l'étape 2 du caddy 		
	var arrayInputData = new Array('_genderCustomer','_nameCustomer','_firstnameCustomer','_companyCustomer','_emailCustomer','_reemailCustomer','_pwdCustomer','_repwdCustomer','_birthdayCustomer_day','_birthdayCustomer_month','_birthdayCustomer_year','_adress3Customer','_adress2Customer','_adress1Customer','_countryCustomer','_cityCustomer','_zipcodeCustomer','_phoneCustomer','_phoneCustomer_fix','_isaccountCustomer');		
	
	//Tableau des types à verifier en fonction des inputs pour le formulaire de l'étape 2 du caddy 
		allRegExp = new Array("strict","name","name","strict","mail","mail","strict","strict","int","int","int","alphanum","alphanum","alphanum","strict","alphanum","alphanum","phone","phone","alphanum");
		
	//Variables		
	var bValid = true; //Validation générale du script
		theId = 'log_i'; //Préfix pour les champs inputs
		dataString=''; //Passage des paramètres			
	
	//Parcours tous les champs			
	for(var i=0;i<arrayInputData.length;i++)
	{
		//Tout faire si c'est la vérification générale ou si c'est le champ correspondant
		if(action=='all' || (action=='item' && (theId+arrayInputData[i])==item))
		{
			//Application spéciale pour l'anniversaire
			if(arrayInputData[i]=='_birthdayCustomer_day' || arrayInputData[i]=='_birthdayCustomer_month' || arrayInputData[i]=='_birthdayCustomer_year')
			{
				bValid = bValid && checkRegexp_v2($('#'+theId+arrayInputData[i]),arrayRegExp[allRegExp[i]],l_c+" "+$('#log_etq_birthdayCustomer').text()+" "+l_n,'log_mess_birthdayCustomer',0);
			}
			else
			{
				//Champs qui ne sont pas obligatoires
				if((arrayInputData[i]=='_adress2Customer' && $('#'+theId+'_adress2Customer').val()=='') || (arrayInputData[i]=='_adress1Customer' && $('#'+theId+'_adress1Customer').val()=='') || (arrayInputData[i]=='_companyCustomer' && $('#'+theId+'_companyCustomer').val()=='') || (arrayInputData[i]=='_phoneCustomer_fix' && $('#'+theId+'_phoneCustomer_fix').val()==''))
				{						
				}
				//Coche les infos perso
				else if(arrayInputData[i]=='_isaccountCustomer')
				{
					bValid = bValid && ckeckCheck_v2($('#log_i_isaccountCustomer'),l_i,'log_mess_isaccountCustomer',0);
				}
				//On verifie les champs 
				else
				{
					bValid = bValid && checkRegexp_v2($('#'+theId+arrayInputData[i]),arrayRegExp[allRegExp[i]],l_c+" "+$('#'+theId.replace("_i", "_etq")+arrayInputData[i]).text()+" "+l_n,theId.replace("_i", "_mess")+arrayInputData[i],0);				
				}
			}
			//Si c'est le champ de vérification d'email je check qu'il ressemble bien au champ email 
			if((action=='all' && arrayInputData[i]=='_reemailCustomer') || item==theId+'_reemailCustomer')
			{
				bValid = bValid && checkSame_v2($('#'+theId+'_emailCustomer'),$('#'+theId+arrayInputData[i]),l_c+" "+$('#'+theId.replace("_i", "_etq")+arrayInputData[i]).text()+" "+l_s,theId.replace("_i", "_mess")+arrayInputData[i],0);	
			}
			//Si c'est le champ de vérification du pwd je check qu'il ressemble bien au champ pwd 
			if((action=='all' && arrayInputData[i]=='_repwdCustomer') || item==theId+'_repwdCustomer')
			{
				bValid = bValid && checkSame_v2($('#'+theId+'_pwdCustomer'),$('#'+theId+arrayInputData[i]),l_c+" "+$('#'+theId.replace("_i", "_etq")+arrayInputData[i]).text()+" "+l_s,theId.replace("_i", "_mess")+arrayInputData[i],0);	
			}				
		}
	}
	
	//Si tout est ok
	if(action=='all' && bValid==true)
	{
		//Construction du passage des paramètres 
		$("form#"+form).find("input,select").each(function(){
			dataString+="&"+$(this).attr("id")+"="+$(this).val();
		});			
		
		//alert('dataString'); 
		
		//On lance l'action
		actionFormlogCustomer_jq(form,lang,action,addslashes(dataString),url);
	}

	
} 

/***************************************/
/* Action d'inscription
/***************************************/
function actionFormlogCustomer_jq(form,lang,action,dataString,url)
{	
	$('#logCustomer_mess').text('');
	$('#logCustomer_mess').removeClass('valid');
	$('#logCustomer_mess').removeClass('ui-state-error');

	$.ajax({
		type: "POST",
		url: url+"/inc/create_account.inc.php",
		data: "show=1&action="+action+"&lang="+lang+dataString,
		dataType:"xml",
		success: function(xml){

			$(xml).find('informations').each(function(){
	
				var status = $(this).attr('status');
				var message = $(this).attr('message');
				var messageerror = $(this).attr('messageerror');
			
				if(status==1)
				{
					window.location.href = url+"/"+lang.toLowerCase()+"/myaccount";
				}
				else
				{	
					$('#logCustomer_mess').text(message);
					$('#logCustomer_mess').addClass('ui-state-error');
				
					$(xml).find('vars').each(function(){
					
						if($(this).attr('log_i_emailCustomer')!=undefined)
						{
							ckeckerror_v2('log_i_emailCustomer',$(this).attr('log_i_emailCustomer'),0);
						}
						if($(this).attr('log_i_birthdayCustomer')!=undefined)
						{
							ckeckerror_v2('log_i_birthdayCustomer',$(this).attr('log_i_birthdayCustomer'),0);
						}
						if($(this).attr('log_i_codeSecuCustomer')!=undefined)
						{
							ckeckerror_v2('log_i_codeSecuCustomer',$(this).attr('log_i_codeSecuCustomer'),0);
						}						
					});
				}					
			});	
		}
	});
}

/***************************************/
/* Vérification de la modification des coordonnées
/***************************************/
function validateFormModCustomer_jq(form,lang,action,item,url,l_c,l_n,l_s,l_i)
{
	//Tableau des champs input pour le formulaire de l'étape 2 du caddy 		
	var arrayInputData = new Array('_idCustomer','_codeCustomer','_genderCustomer','_nameCustomer','_firstnameCustomer','_companyCustomer','_emailCustomer','_reemailCustomer','_pwdCustomer','_repwdCustomer','_birthdayCustomer_day','_birthdayCustomer_month','_birthdayCustomer_year','_adress3Customer','_adress2Customer','_adress1Customer','_countryCustomer','_cityCustomer','_zipcodeCustomer','_phoneCustomer','_phoneCustomer_fix','_isaccountCustomer');		
	
	//Tableau des types à verifier en fonction des inputs pour le formulaire de l'étape 2 du caddy 
		allRegExp = new Array("strict","strict","strict","name","name","strict","mail","mail","strict","strict","int","int","int","alphanum","alphanum","alphanum","strict","alphanum","alphanum","phone","phone","alphanum");
		
	//Variables		
	var bValid = true; //Validation générale du script
		theId = 'log_i'; //Préfix pour les champs inputs
		dataString=''; //Passage des paramètres			
	
	//Parcours tous les champs			
	for(var i=0;i<arrayInputData.length;i++)
	{
		//Tout faire si c'est la vérification générale ou si c'est le champ correspondant
		if(action=='all' || (action=='item' && (theId+arrayInputData[i])==item))
		{
			//Application spéciale pour l'anniversaire
			if(arrayInputData[i]=='_birthdayCustomer_day' || arrayInputData[i]=='_birthdayCustomer_month' || arrayInputData[i]=='_birthdayCustomer_year')
			{
				bValid = bValid && checkRegexp_v2($('#'+theId+arrayInputData[i]),arrayRegExp[allRegExp[i]],l_c+" "+$('#log_etq_birthdayCustomer').text()+" "+l_n,'log_mess_birthdayCustomer',0);
			}
			else
			{
				//Champs qui ne sont pas obligatoires
				if((arrayInputData[i]=='_adress2Customer' && $('#'+theId+'_adress2Customer').val()=='') || (arrayInputData[i]=='_adress1Customer' && $('#'+theId+'_adress1Customer').val()=='') || (arrayInputData[i]=='_pwdCustomer' && $('#'+theId+'_pwdCustomer').val()=='') || (arrayInputData[i]=='_repwdCustomer' && $('#'+theId+'_repwdCustomer').val()=='') || (arrayInputData[i]=='_companyCustomer' && $('#'+theId+'_companyCustomer').val()=='') || (arrayInputData[i]=='_phoneCustomer_fix' && $('#'+theId+'_phoneCustomer_fix').val()==''))
				{						
				}
				//Coche les infos perso
				else if(arrayInputData[i]=='_isaccountCustomer')
				{
					bValid = bValid && ckeckCheck_v2($('#log_i_isaccountCustomer'),l_i,'log_mess_isaccountCustomer',0);
				}
				//On verifie les champs 
				else
				{
					bValid = bValid && checkRegexp_v2($('#'+theId+arrayInputData[i]),arrayRegExp[allRegExp[i]],l_c+" "+$('#'+theId.replace("_i", "_etq")+arrayInputData[i]).text()+" "+l_n,theId.replace("_i", "_mess")+arrayInputData[i],0);				
				}
			}
			//Si c'est le champ de vérification d'email je check qu'il ressemble bien au champ email 
			if((action=='all' && arrayInputData[i]=='_reemailCustomer') || item==theId+'_reemailCustomer')
			{
				bValid = bValid && checkSame_v2($('#'+theId+'_emailCustomer'),$('#'+theId+arrayInputData[i]),l_c+" "+$('#'+theId.replace("_i", "_etq")+arrayInputData[i]).text()+" "+l_s,theId.replace("_i", "_mess")+arrayInputData[i],0);	
			}
			//Si c'est le champ de vérification du pwd je check qu'il ressemble bien au champ pwd 
			if((action=='all' && arrayInputData[i]=='_repwdCustomer') || item==theId+'_repwdCustomer')
			{
				if($('#'+theId+'_pwdCustomer').val()!="" && $('#'+theId+arrayInputData[i]).val()!="")
				{
					bValid = bValid && checkSame_v2($('#'+theId+'_pwdCustomer'),$('#'+theId+arrayInputData[i]),l_c+" "+$('#'+theId.replace("_i", "_etq")+arrayInputData[i]).text()+" "+l_s,theId.replace("_i", "_mess")+arrayInputData[i],0);
				}	
			}				
		}
	}
	
	//Si tout est ok
	if(action=='all' && bValid==true)
	{
		//Construction du passage des paramètres 
		$("form#"+form).find("input,select").each(function(){
			dataString+="&"+$(this).attr("id")+"="+$(this).val();
		});			
		
		//On lance l'action
		actionFormModCustomer_jq(form,lang,'mod',addslashes(dataString),url);
	}	
} 

/***************************************/
/* Action de modification des coordonnées
/***************************************/
function actionFormModCustomer_jq(idform,lang,action,dataString,url)
{

	$('#modCustomer_coor_mess').text('');
	$('#modCustomer_coor_mess').removeClass('valid');
	$('#modCustomer_coor_mess').removeClass('ui-state-error');

	$.ajax({
		type: "POST",
		url: url+"/inc/myaccount/myaccount_coor.inc.php",
		data: "show=1&action="+action+"&lang="+lang+dataString+"&url="+url,
		dataType:"xml",
		success: function(xml){

			$(xml).find('informations').each(function(){
	
				var status = $(this).attr('status');
				var message = $(this).attr('message');
				var messageerror = $(this).attr('messageerror');
			
				/*if(status==1)
				{
					$('#modCustomer_coor_mess').addClass('at8_font_green');					
				}
				else
				{	
					$('#modCustomer_coor_mess').addClass('ui-state-error');
				}
				setTimeout("$('#modCustomer_coor_mess').show('fast');", 0);
				$('#modCustomer_coor_mess').text(message);
				setTimeout("$('#modCustomer_coor_mess').hide('fast');", 8000);*/	
				
				if(status==1)
				{
					setTimeout("$('#response_ok').show('fast');", 0);
					setTimeout("$('#response_ko').hide('fast');", 0);
					//$("div#zoneGlobalMessageUnder_1").html("Enregistrement : OK");
				}
				else
				{
					setTimeout("$('#response_ok').hide('fast');", 0);
					setTimeout("$('#response_ko').show('fast');", 0);
					//$("div#zoneGlobalMessageUnder_1").html("Problème lors de l'enregistrement");
				}
				setTimeout("$('#response_message').show('fast');", 0);
				$("div#zoneGlobalMessage_1").html(message);
				//$("div#zoneGlobalMessageUnder_1_pop").html(messageerror);
				
				setTimeout("$('#response_message').hide('fast');", 5000);
				setTimeout("$('#response_ok').hide('fast');", 5000);
				setTimeout("$('#response_ko').hide('fast');", 5000);					
			});	
		}
	});	
}




/***************************************/
/* Reconstruction du caddy
/***************************************/
function rebluid_caddy(idOrder,refOrder,lang,url)
{
	if(confirm($("input#message_orders_rebluid").val()+refOrder))
	{	
		$.ajax({
			type: "POST",
			url: url+"/inc/gestionCaddy.inc.php",
			data: "show=1&actionCaddy=rebuild&language="+lang+"&idOrder="+idOrder+"&url="+url,
			dataType:"xml",
			success: function(xml){
	
				$(xml).find('informations').each(function(){
		
					var status = $(this).attr('status');
					var message = $(this).attr('message');
					var messageerror = $(this).attr('messageerror');
				
					if(status==1)
					{
						setTimeout("$('#response_ok').show('fast');", 0);
						setTimeout("$('#response_ko').hide('fast');", 0);
						//$("div#zoneGlobalMessageUnder_1").html("Enregistrement : OK");
						$(xml).find('vars').each(function(){
							//MAJSmallcart($(this).attr('url'),lang);
						});	
						
					}
					else
					{
						setTimeout("$('#response_ok').hide('fast');", 0);
						setTimeout("$('#response_ko').show('fast');", 0);
						//$("div#zoneGlobalMessageUnder_1").html("Problème lors de l'enregistrement");
					}
					
					setTimeout("$('#response_message').show('fast');", 0);
					$("div#zoneGlobalMessage_1").html(message);
					//$("div#zoneGlobalMessageUnder_1_pop").html(messageerror);
					
					setTimeout("$('#response_message').hide('fast');", 7000);
					setTimeout("$('#response_ok').hide('fast');", 7000);
					setTimeout("$('#response_ko').hide('fast');", 7000);					
				});	
			}
		});
		//return false;	
	}	
}





/***************************************/
/* Chargement de la liste des paramètres de la newsletter
/***************************************/
function loadList_newsletter_myaccount(idCust,lang,url,idAbo)
{
	$.ajax({
		type: "POST",
		url: url+"/inc/myaccount/myaccount_loadList_newsletter.inc.php",
		data: "show=1&idCust="+idCust+"&lang="+lang+"&idAbo="+idAbo,
		dataType:"text",
		success: function(message){
			$("div#at8_myaccount_zone_newsletter_list").html(message);
		}
	});
	//return false;		
}

/***************************************/
/* Verifications des checkbox pour le master
/***************************************/
function check_master_newsletter(idMaster)
{
	var inputMaster = $("input#"+idMaster);
	if(inputMaster.is(':checked'))
	{
		$("div#at8_myaccount_zone_newsletter_list").find("input[type=checkbox]").each(function(){
			$(this).attr("checked",true);
			$(this).val("1");
			
		});		
		inputMaster.val("1");
	}
	else
	{
		$("div#at8_myaccount_zone_newsletter_list").find("input[type=checkbox]").each(function(){
			$(this).removeAttr("checked");
			$(this).val("0");			
		});
		inputMaster.val("0");
	}
}
/***************************************/
/* Verifications des checkbox pour ses fils
/***************************************/
function check_item_newsletter(idItem)
{
	var inputMaster = $("input#manageNewsletter_isNewsletter");
	var idItem = $("input#"+idItem);
	if(idItem.is(':checked'))
	{
		idItem.val("1");
	}
	else
	{
		idItem.val("0");
	}
	if(!inputMaster.is(':checked'))
	{
		inputMaster.attr("checked",true);
		inputMaster.val("1");
	}
}
/***************************************/
/* Modification des paramètre de la newsletter pour le client
/***************************************/
function addFormlogNewsletter_my(idform,lang,url)
{
	var dataString="";
	
	$("form#"+idform).find("input,[type=checkbox]").each(function(){
		dataString+="&"+$(this).attr("name")+"="+$(this).val();
	});
	
	$.ajax({
		type: "POST",
		url: url+"/inc/myaccount/myaccount_newsletter.inc.php",
		data: "show=1&action=addmod&lang="+lang+dataString,
		dataType:"xml",
		success: function(xml){

			$(xml).find('informations').each(function(){
	
				var status = $(this).attr('status');
				var message = $(this).attr('message');
				var messageerror = $(this).attr('messageerror');
			
				if(status==1)
				{
					setTimeout("$('#response_ok').show('fast');", 0);
					setTimeout("$('#response_ko').hide('fast');", 0);
					//$("div#zoneGlobalMessageUnder_1").html("Enregistrement : OK");
				}
				else
				{
					setTimeout("$('#response_ok').hide('fast');", 0);
					setTimeout("$('#response_ko').show('fast');", 0);
					//$("div#zoneGlobalMessageUnder_1").html("Problème lors de l'enregistrement");
				}
				setTimeout("$('#response_message').show('fast');", 0);
				$("div#zoneGlobalMessage_1").html(message);
				//$("div#zoneGlobalMessageUnder_1_pop").html(messageerror);
				
				setTimeout("$('#response_message').hide('fast');", 7000);
				setTimeout("$('#response_ok').hide('fast');", 7000);
				setTimeout("$('#response_ko').hide('fast');", 7000);					
			});	
		}
	});
	//return false;		
}


/***************************************/
/* Chargement de la liste des parrainages
/***************************************/
function loadList_parrain_myaccount(idCust,lang,url)
{
	$.ajax({
		type: "POST",
		url: url+"/inc/myaccount/myaccount_loadList_parrain.inc.php",
		data: "show=1&idCust="+idCust+"&lang="+lang,
		dataType:"xml",
		success: function(xml){
			
			if($(xml).find('fl').length>0)
			{
				var flux='';
				$(xml).find('fl').each(function(){
					flux+='<div class=\"at8_myaccount_parrain_line\"><div class=\"at8_myaccount_parrain_line_it_email\">'+$(this).attr('email')+'</div><div class=\"at8_myaccount_parrain_line_it_price\">'+$(this).attr('price')+'</div><div class=\"at8_myaccount_parrain_line_it_datei\">'+$(this).attr('datei')+'</div><div class=\"at8_myaccount_parrain_line_it_dateo\">'+$(this).attr('dateo')+'</div><div class=\"at8_myaccount_parrain_line_it_isok\">'+$(this).attr('isok')+'</div><div class=\"at8_myaccount_parrain_line_it_isused\">'+$(this).attr('isused')+'</div><div class=\"at8_spacer\"></div></div>';
				})
				$("div#at8_myaccount_zone_parrain_list").html(flux);
			}
			else
			{
				$("div#at8_myaccount_zone_parrain_list").html('<div class=\"at8_myaccount_parrain_line\">'+$(xml).find('listParrains').attr('message')+'</div>');
			}
		}
	});
	//return false;		
}

/***************************************/
/* Vérification du formulaire de parrainage
/***************************************/
function validateFormParrain_my(idform,lang)
{
	//Variables
	var name = $("#from_nameParrain"),
		email = $("#from_emailParrain"),
		mess = $("#from_messParrain"),
		
		allFields = $([]).add(name).add(email).add(mess);
		
		var bValid = true;
		var tips = "validateTips_p";
		allFields.removeClass('ui-state-error');
		
		//Name
		bValid = bValid && checkLength(name,"Prénom et Nom",4,40,tips);
		bValid = bValid && checkRegexp(name,arrayRegExp['name'],"Le prénom et le nom ne comporte que des lettres avec la possibilité de mettre des tirets ou des espaces ou des apostrophes",tips);
		
		//Email
		bValid = bValid && checkLength(email,"E-mail",6,80,tips);
		bValid = bValid && checkRegexp(email,arrayRegExp['mail'],"L'Email doit respecter le format suivant : xxxx@xxx.xx",tips);
		
		//mess
		bValid = bValid && checkLength(mess,"Message",4,500,tips);
		bValid = bValid && checkRegexp(mess,arrayRegExp['alphanum'],"Le message ne comporte que des lettres avec la possibilité de mettre des tirets ou des espaces ou des apostrophes et des chiffres",tips);
	
		
		//si tout est ok alors on peut lancer le script
		if (bValid) 
		{
			//alert("ok");
			add_parrain_myaccount(idform,lang);
		}	
}
/***************************************/
/* Ajout parrainage
/***************************************/
function add_parrain_myaccount(idform,lang)
{

	var dataString="";
	
	$("p#validateTips_p").html("");

	$("form#"+idform).find("input,select,textarea").each(function(){
		dataString+="&"+$(this).attr("name")+"="+$(this).val();
		
	});
	
	$.ajax({
		type: "POST",
		url: $("input#form_send_url").val()+"/inc/myaccount/myaccount_parrain.inc.php",
		data: "show=1&action=add&lang="+lang+dataString,
		dataType:"xml",
		success: function(xml){

			$(xml).find('informations').each(function(){
	
				var status = $(this).attr('status');
				var message = $(this).attr('message');
				var messageerror = $(this).attr('messageerror');
			
				if(status==1)
				{
					setTimeout("$('#response_ok').show('fast');", 0);
					setTimeout("$('#response_ko').hide('fast');", 0);
					
					$('#from_nameParrain').val('');
					$('#from_emailParrain').val('');
					$('#from_messParrain').val('');
										
					//$("div#zoneGlobalMessageUnder_1").html("Enregistrement : OK");
				}
				else
				{
					setTimeout("$('#response_ok').hide('fast');", 0);
					setTimeout("$('#response_ko').show('fast');", 0);
					//$("div#zoneGlobalMessageUnder_1").html("Problème lors de l'enregistrement");
				}
				setTimeout("$('#response_message').show('fast');", 0);
				$("div#zoneGlobalMessage_1").html(message);
				//$("div#zoneGlobalMessageUnder_1_pop").html(messageerror);
				
				setTimeout("$('#response_message').hide('fast');", 5000);
				setTimeout("$('#response_ok').hide('fast');", 5000);
				setTimeout("$('#response_ko').hide('fast');", 5000);	
			});
			$(xml).find('vars').each(function(){
				loadList_parrain_myaccount($(this).attr('idcust'),$(this).attr('lang'),$(this).attr('url'));
			})
			
		}
	});
	//return false;		
}

/***************************************/
/* Lance la boite de dialogue
/***************************************/
function openDial(form_dial_order_id,refOrder,lang,url)
{
	$.ajax({
		type: "POST",
		url: url+"/inc/myaccount/myaccount_messShow.inc.php",
		data: "show=1&action=showFormPopIn&form_dial_order_id="+form_dial_order_id+"&url="+url+"&lang="+lang+"&refOrder="+refOrder,
		dataType:"text",
		success: function(message){
			if(message!=0)
			{
				if(lang=='fr')
				{
					$('div#dialog').dialog('option', 'buttons', { 'Envoyer': function() { validateFormDialMess('form_dial_order');}, 'Fermer': function() { $(this).dialog('close');} });
				}
				else if(lang=='en')
				{
					$('div#dialog').dialog('option', 'buttons', { 'Send': function() { validateFormDialMess('form_dial_order');}, 'Close': function() { $(this).dialog('close');} });
				}
				else if(lang=='es')
				{
					$('div#dialog').dialog('option', 'buttons', { 'Enviar': function() { validateFormDialMess('form_dial_order');}, 'Cerrar': function() { $(this).dialog('close');} });
				}
				else
				{
					$('div#dialog').dialog('option', 'buttons', { 'Send': function() { validateFormDialMess('form_dial_order');}, 'Close': function() { $(this).dialog('close');} });
				}			
						
				$("div#form_dial_order").html(message);			
				
				$('#dialog').dialog('open');			
			}
			else
			{
			}		
		}
	});	
}

/***************************************/
/* Vérification du formulaire de message
/***************************************/
function validateFormDialMess(idform)
{
	//Variables
	var mess = $("#form_dial_mess"),
		
		allFields = $([]).add(mess);
		
		var bValid = true;
		var tips = "validateTips_pop";
		allFields.removeClass('ui-state-error');
		
		//mess
		bValid = bValid && checkLength(mess,"Message",4,1000,tips);
		bValid = bValid && checkRegexp(mess,arrayRegExp['alphanum'],"Le message ne comporte que des lettres avec la possibilité de mettre des tirets ou des espaces ou des apostrophes et des chiffres",tips);

		//si tout est ok alors on peut lancer le script
		if (bValid) 
		{
			//alert("ok");
			add_mess_myaccount(idform,$("#form_dial_order_lang").val());
		}	
}

/***************************************/
/* Ajout message
/***************************************/
function add_mess_myaccount(idform,lang)
{

	var dataString="";
	
	$("p#validateTips_pop").html("");

	$("form#"+idform).find("input,select,textarea").each(function(){
		dataString+="&"+$(this).attr("name")+"="+$(this).val();
		
	});
	
	$.ajax({
		type: "POST",
		url: $("input#form_dial_order_url").val()+"/inc/myaccount/myaccount_messShow.inc.php",
		data: "show=1&action=add&lang="+lang+dataString,
		dataType:"xml",
		success: function(xml){

			$(xml).find('informations').each(function(){
	
				var status = $(this).attr('status');
				var message = $(this).attr('message');
				var messageerror = $(this).attr('messageerror');
			
				if(status==1)
				{
					setTimeout("$('#response_ok_pop').show('fast');", 0);
					setTimeout("$('#response_ko_pop').hide('fast');", 0);
					//$("div#zoneGlobalMessageUnder_1").html("Enregistrement : OK");
				}
				else
				{
					setTimeout("$('#response_ok_pop').hide('fast');", 0);
					setTimeout("$('#response_ko_pop').show('fast');", 0);
					//$("div#zoneGlobalMessageUnder_1").html("Problème lors de l'enregistrement");
				}
				setTimeout("$('#response_message_pop').show('fast');", 0);
				$("div#zoneGlobalMessage_1_pop").html(message);
				//$("div#zoneGlobalMessageUnder_1_pop").html(messageerror);
				
				setTimeout("$('#response_message_pop').hide('fast');", 3000);
				setTimeout("$('#response_ok_pop').hide('fast');", 3000);
				setTimeout("$('#response_ko_pop').hide('fast');", 3000);
				setTimeout("$('#dialog').dialog('close');", 4000);					
			});	
		}
	});
	//return false;		
}

/*******************************/
//Mutualisation avec le caddy ET2
/*******************************/

/***************************************/
/* Chargement d'un formulaire pour la modification d'une adresse de livraison
/***************************************/
function loadForm_adresse_myaccount(from,action,actype,idCust,idAdd,lang,url,template)
{
	if(actype=='add' || actype=='addnew')
	{
		$("div#zone_choose_adress_select").find("input[type=radio]").each(function(){
			$(this).removeAttr("checked");
		});	
	}

	$.ajax({
		type: "POST",
		url: url+"/inc/myaccount/myaccount_adress.inc.php",
		data: "show=1&action="+action+"&actype="+actype+"&idCust="+idCust+"&idAdd="+idAdd+"&lang="+lang+"&url="+url+"&template="+template+"&from="+from,
		dataType:"text",
		success: function(message){
			$("div#at8_myaccount_zone_delevery_right").html(message);
		}
	});
	//return false;		
}

/***************************************/
/* Vérification du formulaire pour l'adresse
/***************************************/
function validateFormlogAdresse_jq(actype,form,lang,action,item,url,template,l_c,l_n,l_s,l_i)
{
	//Tableau des champs input pour le formulaire de l'étape 2 du caddy 		
	var arrayInputData = new Array('_typeCustomer','_genderCustomer','_nameCustomer','_firstnameCustomer','_companyCustomer','_emailCustomer','_reemailCustomer','_adress3Customer','_adress2Customer','_adress1Customer','_countryCustomer','_cityCustomer','_zipcodeCustomer','_phoneCustomer','_phoneCustomer_fix');		
	
	//Tableau des types à verifier en fonction des inputs pour le formulaire de l'étape 2 du caddy 
		allRegExp = new Array("alphanum","strict","name","name","strict","mail","mail","alphanum","alphanum","alphanum","strict","alphanum","alphanum","phone","phone");
		
	//Variables		
	var bValid = true; //Validation générale du script
		theId = 'logAdd_i'; //Préfix pour les champs inputs
		dataString=''; //Passage des paramètres			
	
	//Parcours tous les champs			
	for(var i=0;i<arrayInputData.length;i++)
	{
		//Tout faire si c'est la vérification générale ou si c'est le champ correspondant
		if(action=='all' || (action=='item' && (theId+arrayInputData[i])==item))
		{
			//Champs qui ne sont pas obligatoires
			if((arrayInputData[i]=='_adress2Customer' && $('#'+theId+'_adress2Customer').val()=='') || (arrayInputData[i]=='_adress1Customer' && $('#'+theId+'_adress1Customer').val()=='') || (arrayInputData[i]=='_companyCustomer' && $('#'+theId+'_companyCustomer').val()=='') || (arrayInputData[i]=='_phoneCustomer_fix' && $('#'+theId+'_phoneCustomer_fix').val()==''))
			{						
			}
			//On verifie les champs 
			else
			{
				bValid = bValid && checkRegexp_v2($('#'+theId+arrayInputData[i]),arrayRegExp[allRegExp[i]],l_c+" "+$('#'+theId.replace("_i", "_etq")+arrayInputData[i]).text()+" "+l_n,theId.replace("_i", "_mess")+arrayInputData[i],0);				
			}
			
			//Si c'est le champ de vérification d'email je check qu'il ressemble bien au champ email 
			if((action=='all' && arrayInputData[i]=='_reemailCustomer') || item==theId+'_reemailCustomer')
			{
				bValid = bValid && checkSame_v2($('#'+theId+'_emailCustomer'),$('#'+theId+arrayInputData[i]),l_c+" "+$('#'+theId.replace("_i", "_etq")+arrayInputData[i]).text()+" "+l_s,theId.replace("_i", "_mess")+arrayInputData[i],0);	
			}			
		}
	}
	
	//Si tout est ok
	if(action=='all' && bValid==true)
	{
		//Construction du passage des paramètres 
		$("form#"+form).find("input,select").each(function(){
			dataString+="&"+$(this).attr("id")+"="+$(this).val();
		});					
		modify_address_myaccount(actype,form,lang,url,template,addslashes(dataString));
	}
	else if(action=='addverif')
	{
		return bValid;
	}
}

function modify_address_myaccount(action,idform,lang,url,template,dataString) //actionFormlogCustomer_jq
{
	$("p#validateTips_add").removeClass("at8_font_green");
	$("p#validateTips_add").removeClass("at8_font_red");
	$("p#validateTips_add").html("");
	
	$.ajax({
		type: "POST",
		url: $("input#form_sendAdd_url").val()+"/inc/myaccount/myaccount_adress.inc.php",
		data: "show=1&action="+action+"&lang="+lang+dataString,
		dataType:"xml",
		success: function(xml){

			$(xml).find('informations').each(function(){
	
				var status = $(this).attr('status');
				var message = $(this).attr('message');
				var messageerror = $(this).attr('messageerror');
			
				if(status==1)
				{
					setTimeout("$('#response_ok').show('fast');", 0);
					setTimeout("$('#response_ko').hide('fast');", 0);
					$("p#validateTips_add").addClass("at8_font_green");
					//$("div#zoneGlobalMessageUnder_1").html("Enregistrement : OK");
				}
				else
				{
					setTimeout("$('#response_ok').hide('fast');", 0);
					setTimeout("$('#response_ko').show('fast');", 0);
					$("p#validateTips_add").addClass("at8_font_red");
					//$("div#zoneGlobalMessageUnder_1").html("Problème lors de l'enregistrement");
				}
				setTimeout("$('#response_message').show('fast');", 0);
				setTimeout("$('p#validateTips_add').show('fast');", 0);
				$("div#zoneGlobalMessage_1").html(message);
				$("p#validateTips_add").html(message);
				//$("div#zoneGlobalMessageUnder_1_pop").html(messageerror);
				

				$(xml).find('vars').each(function(){
					maj_filter_select($(this).attr('idAdd'),$(this).attr('idcust'),'zone_choose_adress_select',lang,url,template);
				});				
				
				setTimeout("$('#response_message').hide('fast');", 5000);
				setTimeout("$('#response_ok').hide('fast');", 5000);
				setTimeout("$('#response_ko').hide('fast');", 5000);
				setTimeout("$('p#validateTips_add').hide('fast');", 5000);	
			});	
		}
	});
	//return false;		
}

//Suppression d'une adresse de livraison
function delete_adress_myaccount(idcust,idadd,lang,url,template)
{	
	$.ajax({
		type: "POST",
		url: url+"/inc/myaccount/myaccount_adress.inc.php",
		data: "show=1&action=delete&lang="+lang+"&url="+url+"&template="+template+"&idadd="+idadd+"&idcust="+idcust,
		dataType:"xml",
		success: function(xml){

			$(xml).find('informations').each(function(){
	
				var status = $(this).attr('status');
				var message = $(this).attr('message');
				var messageerror = $(this).attr('messageerror');
			
				if(status==1)
				{
					//alert($('#at8_myaccount_zone_delevery_right_hidden').text());		
					$('#at8_myaccount_zone_delevery_right').html($('#at8_myaccount_zone_delevery_right_hidden').html());
				
					maj_filter_select('',idcust,'zone_choose_adress_select',lang,url,template)
				}
				else
				{

				}

			});	
		}
	});
}

function maj_filter_select(idAdd,idcust,idselect,lang,url,template)
{
	$.ajax({
		type: "POST",
		url: url+"/inc/myaccount/myaccount_adress.inc.php",
		data: "show=1&action=MAJ_select&idAdd="+idAdd+"&idcust="+idcust+"&lang="+lang+"&url="+url+"&template="+template,
		dataType:"text",
		success: function(message){
			$("#"+idselect).html(message);
		}
	});
	//return false;	
}
