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


function FAQ_GINFO(parent){
	var JSObject = this;
	this.type = "FAQ"; 
	this.arr_inputs = ["_inp_FirstName","_inp_LastName","_inp_Email","_inp_Question"];
	
	this.form = document.getElementById("faq_form");
	this.sendBtn = this.form["sendBtn"];
	this.resetBtn = this.form["resetBtn"];
	this.ajax = false;
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION INIT INPUTS CONTACT PANEL                               */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.init = function() {
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                          INFORMATION                                              */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		this._inp_FirstName = new INPUTFIELD(this, document.getElementById('FirstName'));
		this._inp_LastName = new INPUTFIELD(this, document.getElementById('LastName'));
		this._inp_Email = new INPUTFIELD(this, document.getElementById('Email'));
		this._inp_Question = new INPUTFIELD(this, document.getElementById('Question'));	
		
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION CREATE CONTACT PANEL                                   */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.initCreate = function(){
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'FIRSTNAME' ACTIONS                                    */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_FirstName.input;
		this._inp_FirstName.setRequired("yes"); 
		this._inp_FirstName.setReadySubmit(true);
		this._inp_FirstName.setValidationType("alpha_extended");
		var errors = ["This field is mandatory.",
			          "Only letters are allowed."];
		var extentedChars = String(" '.").split("");
		this._inp_FirstName.addExtendedChars(extentedChars);
		this._inp_FirstName.addErrors(errors);
		this._inp_FirstName.setErrorsContainer("faq_firstname_container");
		this._inp_FirstName.initActions();
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'LASTNAME' ACTIONS                                     */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_LastName.input;
		this._inp_LastName.setRequired("yes"); 
		this._inp_LastName.setReadySubmit(true);
		this._inp_LastName.setValidationType("alpha_extended");
		var errors = ["This field is mandatory.",
			          "Only letters are allowed."];
		var extentedChars = String(" '.").split("");
		this._inp_LastName.addExtendedChars(extentedChars);
		this._inp_LastName.addErrors(errors);
		this._inp_LastName.setErrorsContainer("faq_lastname_container");
		this._inp_LastName.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");
		this._inp_Email.setForm(this.form);
		
		var errors = ["This field is mandatory.",
				      "The e-mail address is invalid."];
		this._inp_Email.addErrors(errors);
		this._inp_Email.setErrorsContainer("faq_email_container");
		this._inp_Email.initActions();		

		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'QUESTION' ACTIONS                                     */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Question.input;
		this._inp_Question.setRequired("yes"); 
		this._inp_Question.setReadySubmit(true);
		this._inp_Question.setValidationType("alphanumeric_extended");
		var errors = ["This field is mandatory.",
			          "Invalid characters."];
		var extentedChars = String(" :;',./?!@#$%^*()[]{}|-+").split("");
			
		this._inp_Question.addExtendedChars(extentedChars);
		this._inp_Question.addErrors(errors);
		this._inp_Question.setErrorsContainer("faq_question_container");
		this._inp_Question.initActions();
	}
	
	
		
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                 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"){
				obj.displayError(obj.errors[0]);
				obj.setReadySubmit(false);
				countErrors++;
			}
			else if (obj.submit_ready == true && obj.data.length == 0 && obj.required=="yes"){
				obj.displayError(obj.errors[0]);
				obj.setReadySubmit(false);
				countErrors++;
			}
			else if (obj.submit_ready == false){ 
				countErrors++;
			}
		}
		
	
		//submit form
		if (countErrors==0){ 
			this.form.submit();
		}
		else return false;
		
	}
	
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                   FUNCTION RESET INFORMATION                                      */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.resetForm = function(){
		this.ajax = false;
		for (var i=0; i<this.arr_inputs.length; i++){
			var obj = this[this.arr_inputs[i]];
			obj.resetData();
		}
	}
	
}
