/*****************************************************************************************************/
/*                                                                                                   */
/*                                     'ADVERT PANEL' CLASS                                        */          
/*                                                                                                   */
/*****************************************************************************************************/

function ADVERT_GINFO(parent){
	var JSObject = this;
	this.type = "Advert"; 
	this.arr_inputs = ["_inp_FullName","_inp_Company","_inp_Address","_inp_County","_inp_PostalCode","_inp_Phone","_inp_Fax","_inp_Email","_inp_Size","_inp_SpecialRequest"];
	this.form = document.getElementById("advert_form");
	this.ajax = false;

	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION INIT INPUTS ADVERT PANEL                                */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.init = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                          INFORMATION                                              */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		this._inp_FullName = new INPUTFIELD(this, document.getElementById('advert_fullname'));		
		this._inp_Company = new INPUTFIELD(this, document.getElementById('advert_company'));
		this._inp_Address = new INPUTFIELD(this, document.getElementById('advert_address'));
		this._inp_County = new INPUTFIELD(this, document.getElementById('advert_county'));
		this._inp_PostalCode = new INPUTFIELD(this, document.getElementById('advert_postalcode'));
		this._inp_Phone = new INPUTFIELD(this, document.getElementById('advert_phone'));
		this._inp_Fax = new INPUTFIELD(this, document.getElementById('advert_fax'));
		this._inp_Email = new INPUTFIELD(this, document.getElementById('advert_email'));
		this._inp_Size = new INPUTFIELD(this, document.getElementById('advert_size'));
		this._inp_SpecialRequest = new INPUTFIELD(this, document.getElementById('advert_specialrequest'));

		
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                  FUNCTION CREATE FEEDBACK PANEL                                   */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.initCreate = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT 'NAME' ACTIONS                                           */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_FullName.input;
		this._inp_FullName.setRequired("yes");
		this._inp_FullName.addData(input.value);
		if (this._inp_FullName.data.length > 0){
			this._inp_FullName.setReadySubmit(true);
		}
		else{
			this._inp_FullName.setReadySubmit(false);
		}
		this._inp_FullName.setForm(this.form); 
		this._inp_FullName.setValidationType("alphanumeric_extended");
		var extentedChars = [".","-","_","'"," "];
		this._inp_FullName.addExtendedChars(extentedChars);
		var errors = ["This information is required.",
				  	  "Only letters, numbers, underscores, hyphens and dots(.) are allowed."];
		this._inp_FullName.addErrors(errors);
		this._inp_FullName.setErrorsContainer("advert_fullname_container");
		this._inp_FullName.initActions();
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT 'COMPANY' ACTIONS                                        */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Company.input;
		this._inp_Company.setRequired("yes");
		this._inp_Company.addData(input.value);
		if (this._inp_Company.data.length > 0){
			this._inp_Company.setReadySubmit(true);
		}
		else{
			this._inp_Company.setReadySubmit(false);
		}
		this._inp_Company.setForm(this.form); 
		this._inp_Company.setValidationType("alphanumeric_extended");
		var extentedChars = [".","-","_","'"," "];
		this._inp_Company.addExtendedChars(extentedChars);
		var errors = ["This information is required.",
				  	  "Only letters, numbers, underscores, hyphens and dots(.) are allowed."];
		this._inp_Company.addErrors(errors);
		this._inp_Company.setErrorsContainer("advert_company_container");
		this._inp_Company.initActions();
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT 'ADDRESS' ACTIONS                                        */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Address.input;
		this._inp_Address.setForm(this.form); 
		this._inp_Address.setValidationType("normal");
		this._inp_Address.initActions();
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT 'COUNTY' ACTIONS                                         */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_County.input;
		this._inp_County.setForm(this.form); 
		this._inp_County.setValidationType("normal");
		this._inp_County.initActions();
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT 'POSTAL CODE' ACTIONS                                    */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_PostalCode.input;
		this._inp_PostalCode.setForm(this.form); 
		this._inp_PostalCode.setValidationType("normal");
		this._inp_PostalCode.initActions();
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT 'PHONE' ACTIONS                                          */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Phone.input;
		this._inp_Phone.setRequired("yes");
		this._inp_Phone.addData(input.value);
		if (this._inp_Phone.data.length > 0){
			this._inp_Phone.setReadySubmit(true);
		}
		else{
			this._inp_Phone.setReadySubmit(false);
		}
		this._inp_Phone.setForm(this.form); 
		this._inp_Phone.setValidationType("numeric_extended");
		var extentedChars = [".","-"," "];
		this._inp_Phone.addExtendedChars(extentedChars);
		var errors = ["This information is required.",
				  	  "Only numbers, hyphens and dots(.) are allowed."];
		this._inp_Phone.addErrors(errors);
		this._inp_Phone.setErrorsContainer("advert_phone_container");
		this._inp_Phone.initActions();
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT 'FAX' ACTIONS                                            */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Fax.input;
		this._inp_Fax.setForm(this.form); 
		this._inp_Fax.setValidationType("normal");
		this._inp_Fax.initActions();
		
				
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                      INPUT 'EMAIL' ACTIONS                                        */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Email.input;
		this._inp_Email.setRequired("yes");
		this._inp_Email.setReadySubmit(false);
		this._inp_Email.setValidationType("email");
		this._inp_Email.setForm(this.form);
		var errors = ["This information is required.",
				      "Only letters, numbers, underscores, dots(.) and one @ are allowed."];
		this._inp_Email.addErrors(errors);
		this._inp_Email.setErrorsContainer("advert_email_container");
		this._inp_Email.initActions();
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT 'SIZE' ACTIONS                                           */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_Size.input;
		this._inp_Size.setForm(this.form); 
		this._inp_Size.setValidationType("normal");
		this._inp_Size.initActions();
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    INPUT 'SPECIAL REQUEST' ACTIONS                                */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		var input = this._inp_SpecialRequest.input;
		this._inp_SpecialRequest.setForm(this.form); 
		this._inp_SpecialRequest.setValidationType("normal");
		this._inp_SpecialRequest.initActions();
			
		
	}
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                 FUNCTION VALIDATE INFORMATION                                     */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.validate = function(){
		this.ajax = false;
		
		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(this.form.action,
			 'fullname='+JSObject._inp_FullName.data+
			 '&company='+JSObject._inp_Company.data+
			 '&address='+JSObject._inp_Address.data+
			 '&county='+JSObject._inp_County.data+
			 '&postalcode='+JSObject._inp_PostalCode.data+
			 '&phone='+JSObject._inp_Phone.data+
			 '&fax='+JSObject._inp_Fax.data+
			 '&email='+JSObject._inp_Email.data+
			 '&size='+JSObject._inp_Size.data+
			 '&specialrequest='+JSObject._inp_SpecialRequest.data,
			 function(response) {
				 if (response.length == 0) return;
				 if (!isNaN(response)){
					 var cell = document.getElementById('advert_container');
					 cell.vAlign = "middle";
					 cell.align = "center";
					 cell.height = "150px"
					 cell.innerHTML = "";
					 cell.innerHTML = '<table width="100%" cellpadding="0" cellspacing="0">'+
											'<tr><td align="center"><span class="text2"><b>Thank you for your message</b>.<bR> You\'ll  be redirected to home page in <span id="seconds" style="color:#FF0000">5</span> seconds.</span></td></tr>'+
										'</table>';
					 sec = 5;
					 setTimeout(redirectFeedback,1000);
				 }
			 }
			 );	
		}
		else return false;
		
	}
	
}