/*****************************************************************************************************/
/*                                                                                                   */
/*                                        'STEP 5' CLASS                                             */          
/*                                                                                                   */
/*****************************************************************************************************/

function STEP5(){
	var JSObject = this;
	this.type = "step5"; 
	this.arr_inputs = ["_inp_Recomandation"];
	
	this.form;
	this.DOMDoc; //document object from thickbox window
	
	this.next_btn;
	this.prev_btn;
	
	this.sendValues = false;
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                      FUNCTION INIT                                                */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.init = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                          INFORMATION                                              */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		this._inp_Recomandation = new INPUTFIELD(this, this.DOMDoc.getElementById('Recomandation'));
		
		
		this.next_btn = $('#btn_next',this.DOMDoc).get(0);
		this.prev_btn = $('#btn_prev',this.DOMDoc).get(0);
		
		this.form = this._inp_Recomandation.input.form;
		//$("#"+this.form.id,this.DOMDoc).bind("submit",function(){return false;});
		
		this.initCreate();
		
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION CREATE PANEL                                            */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.initCreate = function(){
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      TEXTAREA 'EMAILS' ACTIONS                                    */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Recomandation.input;
		this._inp_Recomandation.setRequired("no"); 
		this._inp_Recomandation.addData(input.value);
		//if (this._inp_Recomandation.data.length > 0){
			this._inp_Recomandation.setReadySubmit(true);
		//}
		/*else{
			this._inp_Recomandation.setReadySubmit(false);
		}*/
		this._inp_Recomandation.setValidationType("emails");
		
		var err_1 = JSInterface.MultiLanguage.translate("This field is required");
		var err_2 = JSInterface.MultiLanguage.translate("Emails are invalid");
		var errors = [err_1,err_2];
		
		this._inp_Recomandation.addErrors(errors);
		this._inp_Recomandation.setErrorsContainer("recomandation_container");
		this._inp_Recomandation.initActions();
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT BUTTON 'NEXT' ACTIONS                                    */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var save_mouseDown = false;
		$(this.next_btn).mousedown(function(){
										if (JSObject.sendValues == true){ return;}
										
										save_mouseDown = true;
										$(this).unbind("mouseleave");
										$(this).bind("mouseleave",function(){
																		   JSObject.form.focus();
																		   })
										
										
										$(JSObject.DOMDoc.body).mouseup(function(){
																		 
																		 if (save_mouseDown == true){
																			save_mouseDown = false;
																			$(JSObject.next_btn).unbind("mouseleave");
																			$(JSObject.DOMDoc.body).unbind("mouseup");
																			JSObject.sendValues = true;
																			$('form',JSObject.DOMDoc).get(0).focus();
																			JSObject.validate();
																		 }
																		   })
										
									});
		
		
		$(this.next_btn).mouseup(function(){
										if (JSObject.sendValues == true){ return;}
										
										if (save_mouseDown == true){
											save_mouseDown = false;
											$(this).unbind("mouseleave");
											$(JSObject.DOMDoc.body).unbind("mouseup");
											JSObject.sendValues = true;
											JSObject.form.focus();
											JSObject.validate();
										}
									});
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT BUTTON 'PREV' ACTIONS                                    */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var save_mouseDown = false;
		$(this.prev_btn).mousedown(function(){
										if (JSObject.sendValues == true){ return;}
										
										save_mouseDown = true;
										$(this).unbind("mouseleave");
										$(this).bind("mouseleave",function(){
																		   JSObject.form.focus();
																		   })
										
										
										$(JSObject.DOMDoc.body).mouseup(function(){
																		 
																		 if (save_mouseDown == true){
																			save_mouseDown = false;
																			$(JSObject.prev_btn).unbind("mouseleave");
																			$(JSObject.DOMDoc.body).unbind("mouseup");
																			JSObject.sendValues = true;
																			$('form',JSObject.DOMDoc).get(0).focus();
																			window.location.href = JSInterface.localpath+"personnalisation-e-card/";
																		 }
																		   })
										
									});
		
		
		$(this.prev_btn).mouseup(function(){
										if (JSObject.sendValues == true){ return;}
										
										if (save_mouseDown == true){
											save_mouseDown = false;
											$(this).unbind("mouseleave");
											$(JSObject.DOMDoc.body).unbind("mouseup");
											JSObject.sendValues = true;
											JSObject.form.focus();
											window.location.href = JSInterface.localpath+"personnalisation-e-card/";
										}
									});
		
		
	}
	
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                          FUNCTION RUN BEFORE BLUR  -  INPUTS                                      */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.runBeforeBlur = function(obj){
		if (obj.validation_type == "integer" || obj.validation_type == "float"){
			//
		}
		else{
			//
		}
	}
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                              FUNCTION RUN AFTER BLUR   -  INPUTS                                  */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.runAfterBlur = function(obj){
		if (obj.validation_type == "integer" || obj.validation_type == "float"){
			
		}
		else{
			
		}
		
	}
	
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                               FUNCTION SERVER VALIDATE(AJAX - Email)                              */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.initServerValidate = function(){
		
		JSObject.sendData();
		
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                 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]];
			//alert(this.arr_inputs[i])
			if (obj.data.length == 0 && obj.required=="yes"){
				obj.displayError(obj.errors[0]);
				obj.setReadySubmit(false);
				countErrors++;
				//alert("1 "+this.arr_inputs[i]);
			}
			else if (obj.submit_ready == false){ 
				countErrors++;
				//alert("3 "+this.arr_inputs[i]);
			}
			
		}
		
		//alert(countErrors);
		if (countErrors == 0){
			//server validation
			this.initServerValidate();
		}
		else{
			JSObject.sendValues = false;
		}
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                      FUNCTION SUBMIT FORM                                         */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.submitForm = function(){
		
		//return JSInterface.AjaxUpload.dosubmit(JSObject.form, {'onStart' : JSObject.startUploadingData, 'onComplete' : JSObject.completeUploadingData});
		return true;
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                      FUNCTION SEND DATA                                           */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.sendData = function(){
		
		$("#"+this.form.id,this.DOMDoc).unbind("submit");
		$("#"+this.form.id,this.DOMDoc).bind("submit",function(){JSObject.submitForm();});
		$("#"+this.form.id,this.DOMDoc).submit();
				
	}
	
	
}