OSC = {
	isValidZip: function(zip) {
		var regex = /^\d{5}(-\d{4})?$/;
		return regex.test(zip);
	},
	
	isValidEmail: function(email) {
		var regex = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/;
		return regex.test(email.toLowerCase());
	},
	
	init: function() {
		$("#searchfield").blur(function(e) {
			var s = $(this);
			if(s.val() == "") {
				s.val("zip code");
			}
		}).focus(function(e) {
			var s = $(this);
			if(s.val() == "zip code") {
				s.val("");
			}
		});
		
		$("#searchform").submit(function(e) {
			var field = $("#searchfield");
			if(!OSC.isValidZip(field.val())) {
				field.css("border", "2px solid #f00");
				return false;	
			}
		});
		
		$("#select-county").change(function(e) {
			var county = this.options[this.selectedIndex].value;
			$.ajax({
					type: "GET",
					dataType: "text",
					url: "/cities.php?county=" + county,
					success: function(responseText, statusText) {
						$("#cities-container").html(responseText);
					}
				});
		});
		
		var testimonials = $("#testimonial-carousel");
		
		if(testimonials.length) {
			testimonials.jcarousel({
				wrap: 'last',
				animation: 'slow',
				scroll: 1,
				auto: 4
			});
		}
	}
};

$(document).ready(function() {
	OSC.init();
});