/*****************************************************************************************************/
/*                                                                                                   */
/*                                     'PORTFOLIO PANEL' CLASS                                       */          
/*                                                                                                   */
/*****************************************************************************************************/

function PORTFOLIO_GINFO(parent){
	var JSObject = this;
	this.type = "Portfolio"; 
	//campuri necesare la crearea unui portofoliu
	this.arr_inputs = ["_inp_Name","_inp_Description"];
	
		
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION INIT INPUTS CREATE                                      */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.initCreate = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                          INFORMATION                                              */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		this._inp_Name = new INPUTFIELD(this, document.getElementById('newportfolio_name'));
		this._inp_Description = new INPUTFIELD(this, document.getElementById('newportfolio_description'));
		
		this.form = document.getElementById("createportfolio_form");
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT 'NAME' ACTIONS                                           */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Name.input;
		this._inp_Name.setRequired("yes");
		this._inp_Name.addData(input.value);
		this._inp_Name.setReadySubmit(false);
		this._inp_Name.setValidationType("alphanumeric_extended");
		var extentedChars = [" ",".","-","_","'","/",","];
		this._inp_Name.addExtendedChars(extentedChars);
		var errors = ["This information is required.",
				  	  "Only letters, numbers, underscores, hyphens, spaces and dots(.) are allowed."];
		this._inp_Name.addErrors(errors);
		this._inp_Name.setErrorsContainer("newportfolio_name_container");
		this._inp_Name.initActions();
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'DESCRIPTION' ACTIONS                                  */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Description.input;
		this._inp_Description.setValidationType("normal");
		this._inp_Description.initActions();
		
	}
	
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION INIT INPUTS MODIFY                                      */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.initModify = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                          INFORMATION                                              */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		this._inp_Name = new INPUTFIELD(this, document.getElementById('editportfolio_name'));
		this._inp_Description = new INPUTFIELD(this, document.getElementById('editportfolio_description'));
		
		this.form = document.getElementById("editportfolioinfo_form");
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT 'NAME' ACTIONS                                           */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Name.input;
		this._inp_Name.setRequired("yes");
		this._inp_Name.addData(input.value);
		this._inp_Name.setReadySubmit(true);
		this._inp_Name.setValidationType("alphanumeric_extended");
		var extentedChars = [" ",".","-","_","'","/",","];
		this._inp_Name.addExtendedChars(extentedChars);
		var errors = ["This information is required.",
				  	  "Only letters, numbers, underscores, hyphens, spaces and dots(.) are allowed."];
		this._inp_Name.addErrors(errors);
		this._inp_Name.setErrorsContainer("editportfolio_name_container");
		this._inp_Name.initActions();
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'DESCRIPTION' ACTIONS                                  */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Description.input;
		this._inp_Description.setValidationType("normal");
		this._inp_Description.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;
		
	}
	
	
}