/*****************************************************************************************************/
/*                                                                                                   */
/*                                  'DICTIONARY PANEL' CLASS                                         */          
/*                                                                                                   */
/*****************************************************************************************************/

function DICTIONARY_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"];
	this.form = document.getElementById("send_dictionary_form");
	this.ajax = false;
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                            FUNCTION INIT INPUTS PANEL                                             */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.init = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                          INFORMATION                                              */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		this._inp_Lastname = new INPUTFIELD(this, document.getElementById('dictionary_lastname'));
		this._inp_Firstname = new INPUTFIELD(this, document.getElementById('dictionary_firstname'));
		this._inp_Gender = new INPUTFIELD(this, document.getElementById('dictionary_gender'));
		this._inp_Email = new INPUTFIELD(this, document.getElementById('dictionary_email'));
		this._inp_Company = new INPUTFIELD(this, document.getElementById('dictionary_company'));
		this._inp_Address = new INPUTFIELD(this, document.getElementById('dictionary_address'));
		this._inp_Postcode = new INPUTFIELD(this, document.getElementById('dictionary_postalcode'));
		this._inp_City = new INPUTFIELD(this, document.getElementById('dictionary_city'));
		this._inp_Country = new INPUTFIELD(this, document.getElementById('dictionary_country'));
		this._inp_Phone = new INPUTFIELD(this, document.getElementById('dictionary_phone'));
		this._inp_Domain = new INPUTFIELD(this, document.getElementById('dictionary_domain'));
		this._inp_Function = new INPUTFIELD(this, document.getElementById('dictionary_function'));
	
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION CREATE 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("dictionary_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("dictionary_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("dictionary_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("dictionary_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("dictionary_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("dictionary_postalcode_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("dictionary_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("dictionary_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("dictionary_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("dictionary_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("dictionary_function_container");
		this._inp_Function.initActions();
		
		
		
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                             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++;
			}
		}
		
		
		
		if (countErrors==0){ 
			
			/*alert(LOCALPATH+JSObject.form.action+'?'+'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)	*/		
			www.post(LOCALPATH+JSObject.form.action,
			 '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, 
			 function(response) {
				//alert(response)
				 if (response == 1){
					// alert("aci")
					 var cell = document.getElementById('dictionary_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:15px; padding-bottom:15px; 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;
		}
		
	}
	
}
