var eloquaForm={init:function(){this.errors=[];this.$form=jQuery("#UCIContactUsForm");this.$required_fields=jQuery("td.label label.required",this.$form);this.recaptcha();this.text={is_required:"is required.",invalid_email:"Email is not a valid format.",captcha_error:"Security Code is invalid."};},getLabelInput:function($label){return $label.parent().next().find(".inputForm");},getLabelName:function($label){return $label.text().replace(':','');},checkRequired:function(){var self=this;this.$required_fields.each(function(){$label=jQuery(this);$input=self.getLabelInput($label);if($input.val()==''){self.errors.push(self.getLabelName($label)+" "+self.text.is_required);}
else{if($input.attr("type")=="email"||$input.attr("name")=="EmailAddress"){if(!self.isValidEmail($input.val())){self.errors.push(self.text.invalid_email);}}}});},validate:function(){var self=this;this.errors.length=0;this.checkRequired();captcha_guess=self.getCaptchaGuess();jQuery.getJSON(self.getCaptchaValidationURL()+captcha_guess,function(result){if(captcha_guess&&!result.valid){self.errors.push(self.text.captcha_error);}
if(self.errors.length!=0){self.displayErrors();return false;}
else{self.submitForm();}});},submitForm:function(){this.$form.submit();},getCaptchaGuess:function(){return jQuery("#captcha",this.$form).val();},getCaptchaValidationURL:function(){return'/captcha/validate?rand='+Math.random()+'&code=';},displayErrors:function(){alert(this.errors.join("\n"));},isValidEmail:function(email){var email_pattern=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;return email_pattern.test(email);},recaptcha:function(el){el=el||"captcha-img";document.getElementById(el).src='/captcha/show?'+Math.random();return true;},utils:{hostparts:window.location.hostname.split('.'),getTLD:function(){return this.hostparts[this.hostparts.length-1];},getSite:function(){return this.hostparts[this.hostparts.length-2];}}};eloquaForm.init();
