/*****************************************************************************************************/
/*                                                                                                   */
/*                                'LISTENER FEEDBACK PANEL' CLASS                                    */          
/*                                                                                                   */
/*****************************************************************************************************/

function LISTENER_FEEDBACK_GINFO(parent){
	var JSObject = this;
	this.type = "Listener Feedback"; 
	this.arr_inputs = ["_inp_Name","_inp_Email","_inp_Subject","_inp_Message"];
	this.form = document.getElementById("listener_feedback_form");
	this.sendBtn = this.form["sendBtn"];
	this.resetBtn = this.form["resetBtn"];
	this.ajax = false;
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION INIT INPUTS PANEL                                       */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.init = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                          INFORMATION                                              */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		this._inp_Name = new INPUTFIELD(this, document.getElementById('name'));
		this._inp_Email = new INPUTFIELD(this, document.getElementById('email'));
		this._inp_Subject = new INPUTFIELD(this, document.getElementById('subject'));
		this._inp_Message = new INPUTFIELD(this, document.getElementById('message'));
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                       FUNCTION CREATE PANEL                                       */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.initCreate = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'NAME' ACTIONS                                         */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Name.input;
		this._inp_Name.setRequired("no"); 
		this._inp_Name.addData(input.value);
		this._inp_Name.setReadySubmit(true);
		this._inp_Name.setValidationType("alpha_extended");
		var extentedChars = [" ",".","-","'"];
		this._inp_Name.addExtendedChars(extentedChars);
		var errors = ["",
			          "Only letters, spaces, hyphens, dots(.) and apostrophes are allowed."];
		this._inp_Name.addErrors(errors);
		this._inp_Name.setErrorsContainer("name_container");
		this._inp_Name.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 information is required.",
				      "Only letters, numbers, underscores, dots(.) and one @ are allowed."];
		this._inp_Email.addErrors(errors);
		this._inp_Email.setErrorsContainer("email_container");
		this._inp_Email.initActions();
				
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT 'SUBJECT' ACTIONS                                        */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Subject.input;
		this._inp_Subject.setRequired("no"); 
		this._inp_Subject.addData(input.value);
		this._inp_Subject.setReadySubmit(true);
		this._inp_Subject.setValidationType("alphanumeric_extended");
		var extentedChars = [" ",".","-","'","/","+"];
		this._inp_Subject.addExtendedChars(extentedChars);
		var errors = ["",
			          "Only letters, numbers, spaces, hyphens, dots(.), slashes(/) and apostrophes are allowed."];
		this._inp_Subject.addErrors(errors);
		this._inp_Subject.setErrorsContainer("subject_container");
		this._inp_Subject.initActions();
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                     INPUT 'MESSAGE' ACTIONS                                       */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Message.input;
		this._inp_Message.setRequired("yes"); 
		this._inp_Message.addData(input.value);
		if (this._inp_Message.data.length > 0){
			this._inp_Message.setReadySubmit(true);
		}
		else{
			this._inp_Message.setReadySubmit(false);
		}
		this._inp_Message.setValidationType("normal");
		var errors = ["This information is required.",
			          ""];
		this._inp_Message.addErrors(errors);
		this._inp_Message.setErrorsContainer("message_container");
		this._inp_Message.initActions();
		
		
	}
	
	
		
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                 FUNCTION VALIDATE INFORMATION                                     */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.validate = function(){
		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++;
			}
		}
		
		if (countErrors==0){ 
			this.form.submit();
		}
		else{ 
			return false;
		}
		
	}
	
}