/*****************************************************************************************************/
/*                                                                                                   */
/*                                   'COMMENTS PANEL' CLASS                                          */          
/*                                                                                                   */
/*****************************************************************************************************/

function COMMENTS_GINFO(parent){
	var JSObject = this;
	this.type = "Comment"; 
	this.arr_inputs = ["_inp_Subject","_inp_Message"];
	this.form = document.getElementById("comments_form");
	this.ajax = false;
	
	this.marks = [];
	this.performance = "comment_mark_performance";
	this.design = "comment_mark_design";
	this.reliability = "comment_mark_reliability";
	this.price = "comment_mark_price";
	
	this.marks_table_container = "marks_table_container_";
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                         FUNCTION INIT INPUTS                                      */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.init = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                          INFORMATION                                              */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		this._inp_Subject = new INPUTFIELD(this, this.form.elements['comment_subject']);
		this._inp_Message = new INPUTFIELD(this, this.form.elements['comment_message']);
		
		
		this.setMark("performance",0);
		this.setMark("design",1);
		this.setMark("reliability",2);
		this.setMark("price",3);
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                    FUNCTION CREATE COMMENT PANEL                                  */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.initCreate = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'SUBJECT' ACTIONS                                      */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Subject.input;
		this._inp_Subject.setRequired("yes"); 
		this._inp_Subject.setReadySubmit(false);
		this._inp_Subject.setValidationType("alphanumeric_extended");
		var errors = ["Camp oblogatoriu de completat.",
			          "Anumite caractere nu sunt valide."];
		var extentedChars = String(" :;',./?!@#$%^*()[]{}|-+À?Â?ÆÇ?ÉÊËÌÍÎàáâãäæçèéêëìíîïòóôõöùûüý»").split("");
			
		this._inp_Subject.addExtendedChars(extentedChars);
		this._inp_Subject.addErrors(errors);
		this._inp_Subject.setErrorsContainer("comment_subject_container");
		this._inp_Subject.initActions();
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'MESSAGE' ACTIONS                                      */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Message.input;
		this._inp_Message.setRequired("yes"); 
		this._inp_Message.setReadySubmit(false);
		this._inp_Message.setValidationType("normal");
		var errors = ["Camp oblogatoriu de completat.",
			          "Anumite caractere nu sunt valide."];
		//var extentedChars = String(" :;',./?!@#$%^*()[]{}|-+À?Â?ÆÇ?ÉÊËÌÍÎàáâãäæçèéêëìíîïòóôõöùûüý»").split("");
			
		//this._inp_Message.addExtendedChars(extentedChars);
		this._inp_Message.addErrors(errors);
		this._inp_Message.setErrorsContainer("comment_message_container");
		this._inp_Message.initActions();
		/*this._inp_Message.input.onblur = function(){
			var chars = "<>&";
			if (this.value.hasInvalidChars(chars)){
				JSObject._inp_Message.displayError(JSObject._inp_Message.errors[1]);
				JSObject._inp_Message.setReadySubmit(false);
			}
			else{
				JSObject._inp_Message.setReadySubmit(true);	
			}
		}*/
	}
	
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                    FUNCTION PERFORMANCE MARK                                      */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.setMark = function(type,index){
		
		for (var i=0; i<5; i++){
			
			var radioBtn = this.form.elements[this[type]][i];
			radioBtn.index = index;
			radioBtn.onclick = function(){
				JSObject.marks[this.index] = this.value;
				
				var table = document.getElementById(JSObject.marks_table_container+this.index);
				table.rows[0].cells[0].width = (20*this.value) + "%";
				table.rows[0].cells[1].width = (100 - 20*this.value) + "%";
			}
			
			if (radioBtn.checked == true){
				this.marks[index] = radioBtn.value;	
			}
		}
		
		
		
	}
	
	
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                 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++;
			}
		}
		
		
		//verificam daca s-au acordat note
		for (var i=0; i<4; i++){
			if (this.marks[i] == null || this.marks[i] == "undefined") return false;	
		}
		
				
		if (countErrors==0){ 
			this.form.submit();	
		}
		else{ 
			return false;
		}
		
	}
	
}