$(document).ready(function(){
	// Check for correct zip code
	$("div#main div#content div#spotlight form#spotlight_form").submit(function (e) {
                
                // data submitted
                var zipcode   = jQuery.trim($('div#main div#content div#spotlight form#spotlight_form input#zipcode').val());
                var selection = jQuery.trim($('div#main div#content div#spotlight form#spotlight_form select#selecttype option:selected').val().toLowerCase());
		
                // zipcode validation
                reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
		if (!reZip.test(zipcode)) {
			alert("Please Enter a Valid Zip Code");
			return false;
		}
                
                // redirect to correct place
        if (selection != 'auto'){
		    e.preventDefault();
		    var loc = 'http://www.goinsurancerates.com/' + selection + '-insurance/results/?zipcode=' + zipcode;
		    window.location.href = loc;
        }
        else{
            $("#spotlight_form").attr("action","http://secure.goinsurancerates.com/process/");
            return true;
        }
        return false;
	});
});
