/*****************************************************************************************************/
/*                                                                                                   */
/*                                     'FEEDBACK PANEL' CLASS                                        */          
/*                                                                                                   */
/*****************************************************************************************************/

function FEEDBACK_GINFO(parent){
	var JSObject = this;
	this.type = "Feedback"; 
	this.arr_inputs = ["_inp_FullName","_inp_Email","_inp_Subject","_inp_Comment"];
	this.form = document.getElementById("feedback_form");
	this.ajax = false;
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION INIT INPUTS FEEDBACK PANEL                              */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.init = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                          INFORMATION                                              */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		this._inp_FullName = new INPUTFIELD(this, document.getElementById('feedback_fullname'));
		this._inp_Email = new INPUTFIELD(this, document.getElementById('feedback_email'));
		this._inp_Subject = new INPUTFIELD(this, document.getElementById('feedback_subject'));
		this._inp_Comment = new INPUTFIELD(this, document.getElementById('feedback_comment'));
		
		
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION CREATE FEEDBACK PANEL                                   */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.initCreate = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT 'NAME' ACTIONS                                           */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_FullName.input;
		this._inp_FullName.setRequired("yes");
		this._inp_FullName.addData(input.value);
		if (this._inp_FullName.data.length > 0){
			this._inp_FullName.setReadySubmit(true);
		}
		else{
			this._inp_FullName.setReadySubmit(false);
		}
		this._inp_FullName.setForm(this.form); 
		this._inp_FullName.setValidationType("alphanumeric_extended");
		var extentedChars = [".","-","_","'"];
		this._inp_FullName.addExtendedChars(extentedChars);
		var errors = ["This information is required.",
				  	  "Only letters, numbers, underscores, hyphens and dots(.) are allowed."];
		this._inp_FullName.addErrors(errors);
		this._inp_FullName.setErrorsContainer("feedback_fullname_container");
		this._inp_FullName.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("feedback_email_container");
		this._inp_Email.initActions();
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT 'SUBJECT' ACTIONS                                        */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Subject.input;
		this._inp_Subject.setRequired("yes");
		this._inp_Subject.addData(input.value);
		if (this._inp_Subject.data.length > 0){
			this._inp_Subject.setReadySubmit(true);
		}
		else{
			this._inp_Subject.setReadySubmit(false);
		}
		this._inp_Subject.setForm(this.form); 
		this._inp_Subject.setValidationType("alphanumeric_extended");
		var extentedChars = [".","-","_","'"];
		this._inp_Subject.addExtendedChars(extentedChars);
		var errors = ["This information is required.",
				  	  "Only letters, numbers, underscores, hyphens and dots(.) are allowed."];
		this._inp_Subject.addErrors(errors);
		this._inp_Subject.setErrorsContainer("feedback_subject_container");
		this._inp_Subject.initActions();
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'COMMNENT' ACTIONS                                     */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Comment.input;
		this._inp_Comment.setForm(this.form); 
		this._inp_Comment.setValidationType("normal");
		this._inp_Comment.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++;
			}
		}
		
		if (countErrors==0){ 
			www.post(this.form.action,
			 'fullname='+JSObject._inp_FullName.data+
			 '&email='+JSObject._inp_Email.data+
			 '&subject='+JSObject._inp_Subject.data+
			 '&comment='+JSObject._inp_Comment.data,
			 function(response) {
				 if (response.length == 0) return;
				 if (!isNaN(response)){
					 var cell = document.getElementById('feedback_container');
					 cell.vAlign = "middle";
					 cell.align = "center";
					 cell.height = "150px"
					 cell.innerHTML = "";
					 cell.innerHTML = '<table width="100%" cellpadding="0" cellspacing="0">'+
											'<tr><td align="center"><span class="text2"><b>Thank you for your feedback</b>.<bR> You\'ll  be redirected to home page in <span id="seconds" style="color:#FF0000">5</span> seconds.</span></td></tr>'+
										'</table>';
					 sec = 5;
					 setTimeout(redirectFeedback,1000);
				 }
			 }
			 );	
		}
		else return false;
		
	}
	
}