/*****************************************************************************************************/
/*                                                                                                   */
/*                                     'MY ALERTS' CLASS                                             */          
/*                                                                                                   */
/*****************************************************************************************************/

function ALERT(parent, EmailInput, EmailContainerID, Checkbox){
	var JSObject = this;
	this.type = "Alert"; 
	this.arr_inputs = ["_inp_Email"];
	this.parent = parent;
	
	this.id;//portfolio id
	this._inp_Email = new INPUTFIELD(this, EmailInput);
	this.errorContainer = EmailContainerID;
	this.checkbox = Checkbox;
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION INIT INPUTS                                             */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.init = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'EMAIL' ACTIONS                                        */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Email.input;
		this._inp_Email.setRequired("yes");
		
		if (this.checkbox.checked){
			this._inp_Email.addData(input.value);
			this._inp_Email.setReadySubmit(true);
		}
		else{
			this._inp_Email.addData(input.value);
			this._inp_Email.setReadySubmit(true);
			this._inp_Email.input.className = "input_field2_disabled";	
		}
		
		this._inp_Email.setValidationType("email");
		var errors = ["This information is required.",
				      "Only letters, numbers, underscores, dots(.)<br> and one @ are allowed."];
		this._inp_Email.addErrors(errors);
		this._inp_Email.setErrorsContainer(this.errorContainer);
		this._inp_Email.initActions();
		
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    CHECKBOX 'ACTIVATE' ACTIONS                                    */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		this.checkbox.onclick = function(){
			if (this.checked){
				JSObject._inp_Email.input.className = "input_field2";
				JSObject._inp_Email.input.focus();
			}
			else{
				JSObject._inp_Email.input.className = "input_field2_disabled";
			}
		}
		
		
		
		
	}
	
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                 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++;
			}
		}
		
		return (countErrors);
			
	}
	
}