/*****************************************************************************************************/
/*                                                                                                   */
/*                                  'CONTACT PANEL' CLASS                                            */          
/*                                                                                                   */
/*****************************************************************************************************/

function CONTACT_GINFO(parent){
	var JSObject = this;
	this.type = "Newsletter"; 
	this.arr_inputs = ["_inp_Lastname","_inp_Firstname","_inp_Email","_inp_Company","_inp_Address",
					   "_inp_Postcode","_inp_City","_inp_Country","_inp_Phone","_inp_Domain","_inp_Function",
					   "_inp_Remarks"];
	this.form = document.getElementById("contact_form");
	this.ajax = false;
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                            FUNCTION INIT INPUTS CONTACT PANEL                                     */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.init = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                          INFORMATION                                              */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		this._inp_Lastname = new INPUTFIELD(this, document.getElementById('contact_lastname'));
		this._inp_Firstname = new INPUTFIELD(this, document.getElementById('contact_firstname'));
		this._inp_Gender = new INPUTFIELD(this, document.getElementById('contact_gender'));
		this._inp_Email = new INPUTFIELD(this, document.getElementById('contact_email'));
		this._inp_Company = new INPUTFIELD(this, document.getElementById('contact_company'));
		this._inp_Address = new INPUTFIELD(this, document.getElementById('contact_address'));
		this._inp_Postcode = new INPUTFIELD(this, document.getElementById('contact_postcode'));
		this._inp_City = new INPUTFIELD(this, document.getElementById('contact_city'));
		this._inp_Country = new INPUTFIELD(this, document.getElementById('contact_country'));
		this._inp_Phone = new INPUTFIELD(this, document.getElementById('contact_phone'));
		this._inp_Domain = new INPUTFIELD(this, document.getElementById('contact_domain'));
		this._inp_Function = new INPUTFIELD(this, document.getElementById('contact_function'));
		this._inp_Remarks = new INPUTFIELD(this, document.getElementById('contact_remarks'));
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION CREATE RECOVERPASSWORD PANEL                            */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.initCreate = function(){
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'LASTNAME' ACTIONS                                     */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Lastname.input;
		this._inp_Lastname.setRequired("yes"); 
		this._inp_Lastname.setReadySubmit(false);
		this._inp_Lastname.setValidationType("alpha_extended");
		var extentedChars = String(" '-Ã€Ã‚Ã†Ã‡Ã‰ÃŠÃ‹ÃŒÃ?ÃŽÃ Ã¡Ã¢Ã£Ã¤Ã¦Ã§Ã¨Ã©ÃªÃ«Ã¬Ã­Ã®Ã¯Ã²Ã³Ã´ÃµÃ¶Ã¹Ã»Ã¼Ã½").split("");
		this._inp_Lastname.addExtendedChars(extentedChars);
		var errors = ["Champ obligatoire.",
			          "Seules les lettres sont autoris&eacute;s."];
		this._inp_Lastname.addErrors(errors);
		this._inp_Lastname.setErrorsContainer("contact_lastname_container");
		this._inp_Lastname.initActions();
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'FIRSTNAME' ACTIONS                                    */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Firstname.input;
		this._inp_Firstname.setRequired("yes"); 
		this._inp_Firstname.setReadySubmit(false);
		this._inp_Firstname.setValidationType("alpha_extended");
		var extentedChars = String(" '-Ã€Ã‚Ã†Ã‡Ã‰ÃŠÃ‹ÃŒÃ?ÃŽÃ Ã¡Ã¢Ã£Ã¤Ã¦Ã§Ã¨Ã©ÃªÃ«Ã¬Ã­Ã®Ã¯Ã²Ã³Ã´ÃµÃ¶Ã¹Ã»Ã¼Ã½").split("");
		this._inp_Firstname.addExtendedChars(extentedChars);
		var errors = ["Champ obligatoire.",
			          "Seules les lettres sont autoris&eacute;s."];
		this._inp_Firstname.addErrors(errors);
		this._inp_Firstname.setErrorsContainer("contact_firstname_container");
		this._inp_Firstname.initActions();
		
		
		
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'EMAIL' ACTIONS                                        */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Email.input;
		this._inp_Email.setRequired("yes");
		this._inp_Email.setReadySubmit(false);	
		this._inp_Email.setValidationType("email");
		var errors = ["Champ obligatoire.",
					  "L'adresse e-mail n'est pas valide."];
		this._inp_Email.addErrors(errors);
		this._inp_Email.setErrorsContainer("contact_email_container");
		this._inp_Email.initActions();
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'COMPANY' ACTIONS                                      */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Company.input;
		this._inp_Company.setRequired("yes"); 
		this._inp_Company.setReadySubmit(false);
		this._inp_Company.setValidationType("alphanumeric_extended");
		var extentedChars = String(" :;',./?!@#$%^*()[]{}|-+Ã€ï¿½?Ã‚ï¿½?Ã†Ã‡ï¿½?Ã‰ÃŠÃ‹ÃŒÃ?ÃŽÃ Ã¡Ã¢Ã£Ã¤Ã¦Ã§Ã¨Ã©ÃªÃ«Ã¬Ã­Ã®Ã¯Ã²Ã³Ã´ÃµÃ¶Ã¹Ã»Ã¼Ã½Â»").split("");
		this._inp_Company.addExtendedChars(extentedChars);
		var errors = ["Champ obligatoire.",
			          "CaractÃ¨res invalides."];
		this._inp_Company.addErrors(errors);
		this._inp_Company.setErrorsContainer("contact_company_container");
		this._inp_Company.initActions();
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'ADDRESS' ACTIONS                                      */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Address.input;
		this._inp_Address.setRequired("no"); 
		this._inp_Address.setReadySubmit(true);
		this._inp_Address.setValidationType("alphanumeric_extended");
		var extentedChars = String(" :;',./?!@#$%^*()[]{}|-+Ã€ï¿½?Ã‚ï¿½?Ã†Ã‡ï¿½?Ã‰ÃŠÃ‹ÃŒÃ?ÃŽÃ Ã¡Ã¢Ã£Ã¤Ã¦Ã§Ã¨Ã©ÃªÃ«Ã¬Ã­Ã®Ã¯Ã²Ã³Ã´ÃµÃ¶Ã¹Ã»Ã¼Ã½Â»").split("");
		this._inp_Address.addExtendedChars(extentedChars);
		var errors = ["Champ obligatoire.",
			          "CaractÃ¨res invalides."];
		this._inp_Address.addErrors(errors);
		this._inp_Address.setErrorsContainer("contact_address_container");
		this._inp_Address.initActions();
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'POSTCODE' ACTIONS                                     */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Postcode.input;
		this._inp_Postcode.setRequired("no"); 
		this._inp_Postcode.setReadySubmit(true);
		this._inp_Postcode.setValidationType("alphanumeric");
		var errors = ["Champ obligatoire.",
			          "Seul les lettres et num&eacute;ros sont autoris&eacute;s."];
		this._inp_Postcode.addErrors(errors);
		this._inp_Postcode.setErrorsContainer("contact_postcode_container");
		this._inp_Postcode.initActions();
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'CITY' ACTIONS                                         */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_City.input;
		this._inp_City.setRequired("no"); 
		this._inp_City.setReadySubmit(true);
		this._inp_City.setValidationType("alphanumeric_extended");
		var extentedChars = String(" :;',./?!@#$%^*()[]{}|-+Ã€ï¿½?Ã‚ï¿½?Ã†Ã‡ï¿½?Ã‰ÃŠÃ‹ÃŒÃ?ÃŽÃ Ã¡Ã¢Ã£Ã¤Ã¦Ã§Ã¨Ã©ÃªÃ«Ã¬Ã­Ã®Ã¯Ã²Ã³Ã´ÃµÃ¶Ã¹Ã»Ã¼Ã½Â»").split("");
		this._inp_City.addExtendedChars(extentedChars);
		var errors = ["Champ obligatoire.",
			          "CaractÃ¨res invalides."];
		this._inp_City.addErrors(errors);
		this._inp_City.setErrorsContainer("contact_city_container");
		this._inp_City.initActions();
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'COUNTRY' ACTIONS                                      */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Country.input;
		this._inp_Country.setRequired("no"); 
		this._inp_Country.setReadySubmit(true);
		this._inp_Country.setValidationType("alphanumeric_extended");
		var extentedChars = String(" :;',./?!@#$%^*()[]{}|-+Ã€ï¿½?Ã‚ï¿½?Ã†Ã‡ï¿½?Ã‰ÃŠÃ‹ÃŒÃ?ÃŽÃ Ã¡Ã¢Ã£Ã¤Ã¦Ã§Ã¨Ã©ÃªÃ«Ã¬Ã­Ã®Ã¯Ã²Ã³Ã´ÃµÃ¶Ã¹Ã»Ã¼Ã½Â»").split("");
		this._inp_Country.addExtendedChars(extentedChars);
		var errors = ["",
			          "CaractÃ¨res invalides."];
		this._inp_Country.addErrors(errors);
		this._inp_Country.setErrorsContainer("contact_country_container");
		this._inp_Country.initActions();
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'PHONE' ACTIONS                                        */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Phone.input;
		this._inp_Phone.setRequired("no"); 
		this._inp_Phone.setReadySubmit(true);
		this._inp_Phone.setValidationType("numeric");
		var errors = ["Champ obligatoire.",
			          "Seules les num&eacute;ros sont autoris&eacute;s."];
		this._inp_Phone.addErrors(errors);
		this._inp_Phone.setErrorsContainer("contact_phone_container");
		this._inp_Phone.initActions();
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'DOMAIN' ACTIONS                                       */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Domain.input;
		this._inp_Domain.setRequired("no"); 
		this._inp_Domain.setReadySubmit(true);
		this._inp_Domain.setValidationType("alphanumeric_extended");
		var extentedChars = String(" :;',./?!@#$%^*()[]{}|-+Ã€ï¿½?Ã‚ï¿½?Ã†Ã‡ï¿½?Ã‰ÃŠÃ‹ÃŒÃ?ÃŽÃ Ã¡Ã¢Ã£Ã¤Ã¦Ã§Ã¨Ã©ÃªÃ«Ã¬Ã­Ã®Ã¯Ã²Ã³Ã´ÃµÃ¶Ã¹Ã»Ã¼Ã½Â»").split("");
		this._inp_Domain.addExtendedChars(extentedChars);
		var errors = ["",
			          "CaractÃ¨res invalides."];
		this._inp_Domain.addErrors(errors);
		this._inp_Domain.setErrorsContainer("contact_domain_container");
		this._inp_Domain.initActions();
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'FUNCTION' ACTIONS                                     */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Function.input;
		this._inp_Function.setRequired("no"); 
		this._inp_Function.setReadySubmit(true);
		this._inp_Function.setValidationType("alphanumeric_extended");
		var extentedChars = String(" :;',./?!@#$%^*()[]{}|-+Ã€ï¿½?Ã‚ï¿½?Ã†Ã‡ï¿½?Ã‰ÃŠÃ‹ÃŒÃ?ÃŽÃ Ã¡Ã¢Ã£Ã¤Ã¦Ã§Ã¨Ã©ÃªÃ«Ã¬Ã­Ã®Ã¯Ã²Ã³Ã´ÃµÃ¶Ã¹Ã»Ã¼Ã½Â»").split("");
		this._inp_Function.addExtendedChars(extentedChars);
		var errors = ["Champ obligatoire.",
			          "CaractÃ¨res invalides."];
		this._inp_Function.addErrors(errors);
		this._inp_Function.setErrorsContainer("contact_function_container");
		this._inp_Function.initActions();
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'REMARKS' ACTIONS                                      */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Remarks.input;
		this._inp_Remarks.setRequired("no"); 
		this._inp_Remarks.setReadySubmit(true);
		this._inp_Remarks.setValidationType("normal");
		var errors = ["",
			          "CaractÃ¨res invalides."];
		this._inp_Remarks.addErrors(errors);
		this._inp_Remarks.setErrorsContainer("contact_remarks_container");
		this._inp_Remarks.initActions();
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'COMMENT CONNU' ACTIONS                                */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		for (var i=0; i<document.getElementsByName('contact_comment').length; i++){
			var checkbox = document.getElementsByName('contact_comment')[i];
			checkbox.index = i;
			checkbox.onclick = function(){
				document.getElementById('contact_comment_container').style.display = 'none';	
				
			}
		}
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'OTHER COMMENT CONNU' ACTIONS                          */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		 document.getElementById('contact_comment_other').onkeyup = function(){
			 document.getElementsByName('contact_comment')[4].value = this.value;
		 }
		
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                             FUNCTION SERVER VALIDATE(AJAX - Email)                                */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.initServerValidate = function(){
		this.validate();
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                 FUNCTION VALIDATE INFORMATION                                     */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.validate = function(){
		this.ajax = false;
		
		var countErrors = 0;
		// aflam cate erori sunt in formular
		for (var i=0; i<this.arr_inputs.length; i++){
			var obj = this[this.arr_inputs[i]];
			if (obj.submit_ready == false && obj.data.length == 0 && obj.required=="yes"){
				//alert("1")
				obj.displayError(obj.errors[0]);
				obj.setReadySubmit(false);
				countErrors++;
			}
			else if (obj.submit_ready == true && obj.data.length == 0 && obj.required=="yes"){
				//alert("2")
				obj.displayError(obj.errors[0]);
				obj.setReadySubmit(false);
				countErrors++;
			}
			else if (obj.submit_ready == false){ 
				//alert("3")
				countErrors++;
			}
		}
		
		
		/*var valid = false;
		for (var i=0; i<document.getElementsByName('contact_comment').length; i++){
			var checkbox = document.getElementsByName('contact_comment')[i];
			if (checkbox.checked == true) valid = true;
		}
		if (valid == false){
			countErrors++;
			document.getElementById('contact_comment_container').style.display = 'block';
			document.getElementById('contact_comment_container').innerHTML = "<p class='error_text'>Champ obligatoire.</p>";
		}*/
		
		
		if (countErrors==0){ 
			
			var comment_connu_str = "";
			for (var i=0; i<document.getElementsByName('contact_comment').length; i++){
				var checkbox = document.getElementsByName('contact_comment')[i];
				if (checkbox.checked == true) comment_connu_str += checkbox.value+",";
			}
			comment_connu_str = comment_connu_str.substring(0,comment_connu_str.length-2);
						
			www.post(LOCALPATH+"contact_action.php",
			 'lastname='+JSObject._inp_Lastname.data+
			 '&firstname='+JSObject._inp_Firstname.data+
			 '&gender='+JSObject._inp_Gender.input.value+
			 '&email='+JSObject._inp_Email.data+
			 '&company='+JSObject._inp_Company.data+
			 '&address='+JSObject._inp_Address.data+
			 '&postcode='+JSObject._inp_Postcode.data+
			 '&city='+JSObject._inp_City.data+
			 '&country='+JSObject._inp_Country.data+
			 '&phone='+JSObject._inp_Phone.data+
			 '&domain='+JSObject._inp_Domain.data+
			 '&function='+JSObject._inp_Function.data+
			 '&remarks='+JSObject._inp_Remarks.data+
			 '&comment_connu='+comment_connu_str, 
			 function(response) {
				
				 if (response == 1){
					// alert("aci")
					 var cell = document.getElementById('contact_container');
					 cell.innerHTML = "";
					 cell.vAlign = "middle";
					 cell.align = "center";
					 
					cell.innerHTML = '<table width="100%" cellpadding="0" cellspacing="0">'+
												'<tr><td align="left" style="padding-top:7px; padding-right:10px">Merci pour votre message, nous vous r&eacute;pondrons dans les meilleurs d&eacute;lais!</td></tr>'+
											'</table>';
					 
				 }
				 else{
					 //
				 }
				 //alert(response)
			 }
			 );	
		}
		else{ 
			return false;
		}
		
	}
	
}