// JavaScript Document

$(function() {
	var inputs = Array();
	
	$('input#submit').hover(function() {
		this.src = "images/st_Rollover.gif";
	}, 
	
	function() {
		this.src = "images/submit.gif";
	});
	
	$('input.validate').each(function(i) {
		inputs[i] = this.value;
		$(this).focus(function() {
			if(this.value == inputs[i]) {
				this.value = '';
			}
		});
		
		$(this).blur(function() {
			if(this.value == '') {
				this.value = inputs[i];
			}
		});
	})
	
	$('form#form').submit(function() {
		
		var noErrors = true;
		
		$('input.validate').each(function(i) {
			if(this.value == '' || this.value == inputs[i]) {
				$(this).removeClass('error').addClass('error');
				noErrors = false;
			} else {
				if($(this).hasClass('email')) {
					if(!emailValid(this.value)) {
						$(this).removeClass('error').addClass('error');
						noErrors = false;
					} else {
						$(this).removeClass('error');
					}
				} else {
					$(this).removeClass('error');
				}
			}
		});
		
		if(!noErrors) {
			if(pageTracker) {
				pageTracker._trackEvent('Forms', 'Submit_Success', 'Form validating and sending', 1);
			}
			alert('Please be sure all required field are filled out and that you have used a valid email address.');
		}
		
		return noErrors;
	});
});

function emailValid(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   return reg.test(email);
}