/*****************************************************************************************************/
/*                                                                                                   */
/*                                     'LOGIN PANEL' CLASS                                           */          
/*                                                                                                   */
/*****************************************************************************************************/

function DEALER_LOGIN_GINFO(parent){
	var JSObject = this;
	this.type = "Login"; 
	this.arr_inputs = ["_inp_Email","_inp_Password"];
	this.form = document.getElementById("login_form");
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION INIT INPUTS LOGIN PANEL                                  */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.init = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                          INFORMATION                                              */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		this._inp_Email = new INPUTFIELD(this, this.form["login_email"]);
		this._inp_Password = new INPUTFIELD(this, this.form["login_password"]);
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION CREATE LOGIN PANEL                                      */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.initCreate = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'EMAIL' ACTIONS                                        */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Email.input;
		this._inp_Email.setRequired("no");
		this._inp_Email.addData(input.value);
		this._inp_Email.setReadySubmit(true);
		this._inp_Email.setValidationType("normal");
		this._inp_Email.setForm(this.form);
		this._inp_Email.setSubmitFunction(validateLogin);
		this._inp_Email.initActions();
		/*this._inp_Email.input.onclick = function(){
			if (this.value.toLowerCase() == "your e-mail address")	{
				this.value = "";
				JSObject._inp_Email.addData(this.value);
				JSObject._inp_Password.input.value = "";
				JSObject._inp_Password.addData(JSObject._inp_Password.input.value);
			}
		}*/
		
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    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();
		/*this._inp_Password.input.onclick = function(){
			if (this.value.toLowerCase() == "password")	{
				this.value = "";
				JSObject._inp_Password.addData(this.value);
				JSObject._inp_Email.input.value = "";
				JSObject._inp_Email.addData(JSObject._inp_Email.input.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++;
			}
		}
		//alert(countErrors)
		if (countErrors==0){ 
			www.post(document.getElementById("checkloginpath").value,
			 'email='+this._inp_Email.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;
		
	}
	
}