/*****************************************************************************************************/
/*                                                                                                   */
/*                                     'BROKER PANEL' CLASS                                          */          
/*                                                                                                   */
/*****************************************************************************************************/

function BROKER_GINFO(parent){
	var JSObject = this;
	this.type = "Broker"; 
	this.arr_inputs = ["_inp_Name","_inp_Address","_inp_Email","_inp_Contact","_inp_Telephone","_inp_Deposit",
					   "_inp_BuyCommission","_inp_SellCommission"];
	this.form = document.getElementById("broker_form");
	this.ajax = false;
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION INIT INPUTS REGISTER PANEL                              */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.init = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                          INFORMATION                                              */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		this._inp_Name = new INPUTFIELD(this, document.getElementById('broker_name'));
		this._inp_Address = new INPUTFIELD(this, document.getElementById('broker_address'));
		this._inp_Email = new INPUTFIELD(this, document.getElementById('broker_email'));
		this._inp_Contact = new INPUTFIELD(this, document.getElementById('broker_contact'));
		this._inp_Telephone = new INPUTFIELD(this, document.getElementById('broker_phone'));
		this._inp_Deposit = new INPUTFIELD(this, document.getElementById('broker_deposit'));
		this._inp_BuyCommission = new INPUTFIELD(this, document.getElementById('broker_buy_commission'));
		this._inp_SellCommission = new INPUTFIELD(this, document.getElementById('broker_sell_commission'));
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION CREATE BROKER PANEL                                     */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.initCreate = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                       INPUT 'NAME' ACTIONS                                        */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Name.input;
		this._inp_Name.setRequired("yes");
		this._inp_Name.setForm(this.form); 
		this._inp_Name.setValidationType("alpha_extended");
		var extentedChars = [" ",".","-","'"];
		this._inp_Name.addExtendedChars(extentedChars);
		var errors = ["This information is required.",
				      "Only letters, spaces, hyphens, dots(.) and apostrophes are allowed."];
		this._inp_Name.addErrors(errors);
		this._inp_Name.setErrorsContainer("broker_name_container");
		this._inp_Name.initActions();
		//anulez functia de apasare buton
		this._inp_Name.input.onfocus = function(){
			JSObject.ajax = false;	
		}
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      TEXTAREA 'ADDRESS' ACTIONS                                   */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Address.input;
		this._inp_Address.setForm(this.form); 
		this._inp_Address.setValidationType("normal");
		this._inp_Address.initActions();
		//anulez functia de apasare buton
		this._inp_Address.input.onfocus = function(){
			JSObject.ajax = false;	
		}
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                       INPUT 'EMAIL' ACTIONS                                       */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Email.input;
		this._inp_Email.setForm(this.form); 
		this._inp_Email.setValidationType("email");
		var errors = ["",
				      "Only letters, numbers, underscores, dots(.) and one @ are allowed."];
		this._inp_Email.addErrors(errors);
		this._inp_Email.setErrorsContainer("broker_email_container");
		this._inp_Email.initActions();
		//anulez functia de apasare buton
		this._inp_Email.input.onfocus = function(){
			JSObject.ajax = false;	
		}
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      TEXTAREA 'CONTACT' ACTIONS                                   */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Contact.input;
		this._inp_Contact.setForm(this.form); 
		this._inp_Contact.setValidationType("normal");
		this._inp_Contact.initActions();
		//anulez functia de apasare buton
		this._inp_Contact.input.onfocus = function(){
			JSObject.ajax = false;	
		}
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                       INPUT 'PHONE' ACTIONS                                       */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Telephone.input;
		this._inp_Telephone.setForm(this.form); 
		this._inp_Telephone.setValidationType("numeric_extended");
		var extentedChars = ["+",".","-","/"];
		this._inp_Telephone.addExtendedChars(extentedChars);
		var errors = ["",
				      "Only numbers, hyphens, pluses, dots(.) and slashes(/) are allowed."];
		this._inp_Telephone.addErrors(errors);
		this._inp_Telephone.setErrorsContainer("broker_phone_container");
		this._inp_Telephone.initActions();
		//anulez functia de apasare buton
		this._inp_Telephone.input.onfocus = function(){
			JSObject.ajax = false;	
		}
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                INPUT 'AVAILABLE DEPOSIT' ACTIONS                                  */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Deposit.input;
		this._inp_Deposit.addData(input.value);
		this._inp_Deposit.setRequired("yes");
		this._inp_Deposit.setValidationType("float");
		this._inp_Deposit.decimals = 2;
		this._inp_Deposit.negative = true;
		this._inp_Deposit.initActions();
		//anulez functia de apasare buton
		this._inp_Deposit.input.onfocus = function(){
			JSObject.ajax = false;	
		}
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                 INPUT 'BUY COMMISSION' ACTIONS                                    */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_BuyCommission.input;
		this._inp_BuyCommission.addData(input.value);
		this._inp_BuyCommission.setRequired("yes");
		this._inp_BuyCommission.setValidationType("float");
		this._inp_BuyCommission.decimals = 2;
		this._inp_BuyCommission.negative = true;
		this._inp_BuyCommission.initActions();
		//anulez functia de apasare buton
		this._inp_BuyCommission.input.onfocus = function(){
			JSObject.ajax = false;	
		}
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                 INPUT 'SELL COMMISSION' ACTIONS                                   */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_SellCommission.input;
		this._inp_SellCommission.addData(input.value);
		this._inp_SellCommission.setRequired("yes");
		this._inp_SellCommission.setValidationType("float");
		this._inp_SellCommission.decimals = 2;
		this._inp_SellCommission.negative = true;
		this._inp_SellCommission.initActions();
		//anulez functia de apasare buton
		this._inp_SellCommission.input.onfocus = function(){
			JSObject.ajax = false;	
		}
	}
	
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION MODIFY BROKER PANEL                                     */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.initModify = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                       INPUT 'NAME' ACTIONS                                        */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Name.input;
		this._inp_Name.addData(input.value);
		this._inp_Name.setRequired("yes");
		this._inp_Name.setForm(this.form); 
		this._inp_Name.setValidationType("alpha_extended");
		var extentedChars = [" ",".","-","'"];
		this._inp_Name.addExtendedChars(extentedChars);
		var errors = ["This information is required.",
				      "Only letters, spaces, hyphens, dots(.) and apostrophes are allowed."];
		this._inp_Name.addErrors(errors);
		this._inp_Name.setErrorsContainer("broker_name_container");
		this._inp_Name.initActions();
		//anulez functia de apasare buton
		this._inp_Name.input.onfocus = function(){
			JSObject.ajax = false;	
		}
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      TEXTAREA 'ADDRESS' ACTIONS                                   */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Address.input;
		this._inp_Address.addData(input.value);
		this._inp_Address.setForm(this.form); 
		this._inp_Address.setValidationType("normal");
		this._inp_Address.initActions();
		//anulez functia de apasare buton
		this._inp_Address.input.onfocus = function(){
			JSObject.ajax = false;	
		}
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                       INPUT 'EMAIL' ACTIONS                                       */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Email.input;
		this._inp_Email.addData(input.value);
		this._inp_Email.setForm(this.form); 
		this._inp_Email.setValidationType("email");
		var errors = ["",
				      "Only letters, numbers, underscores, dots(.) and one @ are allowed."];
		this._inp_Email.addErrors(errors);
		this._inp_Email.setErrorsContainer("broker_email_container");
		this._inp_Email.initActions();
		//anulez functia de apasare buton
		this._inp_Email.input.onfocus = function(){
			JSObject.ajax = false;	
		}
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      TEXTAREA 'CONTACT' ACTIONS                                   */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Contact.input;
		this._inp_Contact.addData(input.value);
		this._inp_Contact.setForm(this.form); 
		this._inp_Contact.setValidationType("normal");
		this._inp_Contact.initActions();
		//anulez functia de apasare buton
		this._inp_Contact.input.onfocus = function(){
			JSObject.ajax = false;	
		}
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                       INPUT 'PHONE' ACTIONS                                       */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Telephone.input;
		this._inp_Telephone.addData(input.value);
		this._inp_Telephone.setForm(this.form); 
		this._inp_Telephone.setValidationType("numeric_extended");
		var extentedChars = ["+",".","-","/"];
		this._inp_Telephone.addExtendedChars(extentedChars);
		var errors = ["",
				      "Only numbers, hyphens, pluses, dots(.) and slashes(/) are allowed."];
		this._inp_Telephone.addErrors(errors);
		this._inp_Telephone.setErrorsContainer("broker_phone_container");
		this._inp_Telephone.initActions();
		//anulez functia de apasare buton
		this._inp_Telephone.input.onfocus = function(){
			JSObject.ajax = false;	
		}
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                INPUT 'AVAILABLE DEPOSIT' ACTIONS                                  */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Deposit.input;
		this._inp_Deposit.addData(input.value);
		this._inp_Deposit.setRequired("yes");
		this._inp_Deposit.setValidationType("float");
		this._inp_Deposit.decimals = 2;
		this._inp_Deposit.negative = true;
		this._inp_Deposit.initActions();
		//anulez functia de apasare buton
		this._inp_Deposit.input.onfocus = function(){
			JSObject.ajax = false;	
		}
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                 INPUT 'BUY COMMISSION' ACTIONS                                    */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_BuyCommission.input;
		this._inp_BuyCommission.addData(input.value);
		this._inp_BuyCommission.setRequired("yes");
		this._inp_BuyCommission.setValidationType("float");
		this._inp_BuyCommission.decimals = 2;
		this._inp_BuyCommission.negative = true;
		this._inp_BuyCommission.initActions();
		//anulez functia de apasare buton
		this._inp_BuyCommission.input.onfocus = function(){
			JSObject.ajax = false;	
		}
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                 INPUT 'SELL COMMISSION' ACTIONS                                   */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_SellCommission.input;
		this._inp_SellCommission.addData(input.value);
		this._inp_SellCommission.setRequired("yes");
		this._inp_SellCommission.setValidationType("float");
		this._inp_SellCommission.decimals = 2;
		this._inp_SellCommission.negative = true;
		this._inp_SellCommission.initActions();
		//anulez functia de apasare buton
		this._inp_SellCommission.input.onfocus = function(){
			JSObject.ajax = false;	
		}
		
		
	}
	
	
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                 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;
		
	}
	
}