/*****************************************************************************************************/
/*                                                                                                   */
/*                                     'LOGIN PANEL' CLASS                                           */          
/*                                                                                                   */
/*****************************************************************************************************/

function LOGIN_GINFO(parent){
	var JSObject = this;
	this.type = "Login"; 
	this.arr_inputs = ["_inp_Username","_inp_Password"];
	this.form = document.getElementById("login_form");
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION INIT INPUTS LOGIN PANEL                                  */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.init = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                          INFORMATION                                              */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		this._inp_Username = new INPUTFIELD(this, this.form.login_username);
		this._inp_Password = new INPUTFIELD(this, this.form.login_password);
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION CREATE LOGIN PANEL                                      */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.initCreate = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT 'USERNAME' ACTIONS                                       */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Username.input;
		this._inp_Username.setRequired("no");
		this._inp_Username.addData(input.value);
		this._inp_Username.setReadySubmit(true);
		this._inp_Username.setForm(this.form); 
		this._inp_Username.setValidationType("normal");
		this._inp_Username.setSubmitFunction(validateLogin);
		this._inp_Username.initActions();
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT 'PASSWORD' ACTIONS                                       */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Password.input;
		this._inp_Password.setRequired("no");
		this._inp_Password.addData(input.value);
		this._inp_Password.setReadySubmit(true);
		this._inp_Password.setForm(this.form);
		this._inp_Password.setValidationType("normal");
		this._inp_Password.setSubmitFunction(validateLogin);
		this._inp_Password.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){ 
			www.post(document.getElementById("checkloginpath").value,
			 'username='+this._inp_Username.data+'&password='+this._inp_Password.data, 
			 function(response) {
				 if (parseInt(response)==1){ 
				 	JSObject.form.submit();
				 }
				 else document.getElementById('login_error_container').style.display = 'block';
			 }
			 );
		}
		else return false;
		
	}
	
}