/*****************************************************************************************************/
/*                                                                                                   */
/*                                     'SEARCH PANEL' CLASS                                          */          
/*                                                                                                   */
/*****************************************************************************************************/

function SEARCH_GINFO(parent){
	var JSObject = this;
	this.type = "Search"; 
	this.arr_inputs = ["_inp_Symbol"];
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION INIT INPUTS LOGIN PANEL                                  */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.init = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                          INFORMATION                                              */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		this._inp_Symbol = new INPUTFIELD(this, document.getElementById('search_company_symbol'));
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION CREATE SEARCH PANEL                                     */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.initCreate = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT 'SYMBOL' ACTIONS                                         */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Symbol.input;
		this._inp_Symbol.setRequired("no");
		this._inp_Symbol.addData(input.value);
		this._inp_Symbol.setReadySubmit(true);
		this._inp_Symbol.setValidationType("normal");
		this._inp_Symbol.setSubmitFunction(validateSearch);
		this._inp_Symbol.initActions();
		this._inp_Symbol.input.onkeyup = function(){
			if (event.keyCode == 13){
				JSObject._inp_Symbol.addData(this.value);
				validateSearch();
			}
		}
		this._inp_Symbol.input.onfocus = function(){
			if (this.value == 'write a company name') 
				this.value='';
		}
		this._inp_Symbol.input.onfocusout = function(){
			if (this.value == '') 
				this.value='write a company name';
		}
											
		
		
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                 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){ 

			document.location.href= "search.php?name="+JSObject._inp_Symbol.data;
			
		}
		else return false;
		
	}
	
}