
/****************************************
 * COMMON VARIABLE
 ****************************************/
 
var HOST 		= 'www.cointreau.es';
var WEBSITE 	= 'http://www.cointreau.es/';
var COE_I_ID 	= '800614';
var LANG_ID 	= 'es';

var URL_POPIN_IDENTIFICATION 	= '/index.php?coe_i_id=800638';

var LABEL_ENTRANCE_FORM_ERROR_COUNTRY 	= 'Escoge tu web';

var ISPROFILLOG = false ;
/****************************************
 * CONTACT SPECIAL POPIN LINK TO FULLSIX
 ****************************************/
 
	/*
	* Ajax Form Submission
	* We don't use generic popin form handlers coz we post to external server @see popin.js
	*/
	function postContactData () 
	{   
	   var myForm = $(".formInPopin");

	   var result = "";
	   $(".formInPopin input[@type=hidden]").each(function() {
	      result += $(this).attr("name")+"="+encodeURIComponent($(this).val())+"&";
	   })
	   $(".formInPopin input[@type=text]").each(function() {
	      result += $(this).attr("name")+"="+encodeURIComponent($(this).val())+"&";
	   })
		$(".formInPopin input[@type=radio]:checked").each(function() {
	      result += $(this).attr("name")+"="+$(this).val()+"&";
	   })
		$(".formInPopin input[@type=checkbox]:checked").each(function() {
	      result += $(this).attr("name")+"="+$(this).val()+"&";
	   })
	   $(".formInPopin select").each(function() {
	      result += $(this).attr("name")+"="+$(this).val()+"&";
	   })
	   $(".formInPopin textarea").each(function() {
	      result += $(this).attr("name")+"="+encodeURIComponent($(this).val())+"&";
	   })
	   
		//Envoie les donnees saisies au serveur
	   $.ajax({
	      type:"POST",
	      url: myForm.attr("action"),
	      data: result,
	      success:function(response) {
	      	
	      		//alert(response);
	      		if(response == '&ok=true')
	      		{
	      			document.getElementById('contactForm').style.display = 'none';
					document.getElementById('contactConfirmMessage').style.display = 'block';
	      		}
	      		else
	      		{
	      			document.getElementById('contactErrorMessage').style.display = 'block';
	      		}
	      		
	      		// ADD EVENT
	      		initSubmitFormInPopin(); 
	      		initClosePopin();
	      }
	   });  
	}
	
	/**
	* Check emailVision field and encode values before submission
	*/
	function checkContactForm()
	{   
		//reset error message
		document.getElementById('contactErrorMessage').style.display = 'none';
		
		var oForm 				= document.getElementById('contactForm');
		var filterEmail 		= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
		var oErrorLastname 		= document.getElementById('errorLabel_LASTNAME');
		var oErrorFirstname 	= document.getElementById('errorLabel_FIRSTNAME');
		var oErrorEmail 		= document.getElementById('errorLabel_EMAIL');
		var oErrorBirth 		= document.getElementById('errorLabel_BIRTH');
		var oErrorCountry 		= document.getElementById('errorLabel_COUNTRY');
		var oErrorSubject 		= document.getElementById('errorLabel_SUBJECT');
		var oErrorMessage	 	= document.getElementById('errorLabel_MESSAGE');
		var oErrorStatus 		= document.getElementById('errorLabel_STATUS');
		
		var isError = false;
		
		resetErrorLabel();
		
		// check
		if(oForm.lastname.value=='') 	
		{ oErrorLastname.innerHTML = 'Rellena los siguientes campos';isError = true; }
		
		if(oForm.firstname.value=='') 
		{ oErrorFirstname.innerHTML = 'Rellena los siguientes campos ';isError = true; }
		
		if(oForm.birthMonth.value=='' || oForm.birthDay.value=='' || oForm.birthYear.value=='') 	
		{ oErrorBirth.innerHTML = 'Rellena los siguientes campos';isError = true; }
				
		if(oForm.email.value=='') 	
		{ oErrorEmail.innerHTML = 'Rellena los siguientes campos ';isError = true; }
		else if(!filterEmail.test(oForm.email.value)) 
		{ oErrorEmail.innerHTML ='Rellena los siguientes campos';isError = true; }
		
		if(oForm.countryId.value=='') 	
		{ oErrorCountry.innerHTML = 'Rellena los siguientes campos ';isError = true; }
		
		if(oForm.subjectId.value=='') 	
		{ oErrorSubject.innerHTML = 'Por favor, rellene los campos objeto';isError = true; }
		
		if(oForm.message.value=='') 
		{ oErrorMessage.innerHTML = 'Por favor, introduzca tu pregunta';isError = true; }
	
			
		// cancel submission if there is some errors
		if(isError) return false;

		
		else	    
		{	// we remove class that auto add submission handler to manually handle fullsix submission
			postContactData(); // form ajax submission to fulsix server
			return false; // no submission -> only display the confirmation message
		}
	}
	
	
	/**
	* Reset error label for each submission
	*/
	function resetErrorLabel()
	{   
		var oErrorLastname 		= document.getElementById('errorLabel_LASTNAME');
		var oErrorFirstname 	= document.getElementById('errorLabel_FIRSTNAME');
		var oErrorEmail 		= document.getElementById('errorLabel_EMAIL');
		var oErrorBirth 		= document.getElementById('errorLabel_BIRTH');
		var oErrorCountry 		= document.getElementById('errorLabel_COUNTRY');
		var oErrorSubject 		= document.getElementById('errorLabel_SUBJECT');
		var oErrorMessage	 	= document.getElementById('errorLabel_MESSAGE');
		var oErrorStatus 		= document.getElementById('errorLabel_STATUS');
		
		oErrorLastname.innerHTML = '';
		oErrorFirstname.innerHTML = '';
		oErrorEmail.innerHTML = '';
		oErrorBirth.innerHTML = '';
		oErrorCountry.innerHTML = '';
		oErrorSubject.innerHTML = '';
		oErrorMessage.innerHTML = '';
		oErrorStatus.innerHTML = '';
		
	}