$(document).ready(function(){

addZipCodeListeners();
/*
	$('.faves').tooltip({
	delay: 0
	});*/
});
function addZipCodeListeners() {
$('#zipcodeGo')
	.unbind('click')
	.bind('click', function(){
			$errorCount = 0;
			$zipcode = $('#zipcodeValue').val();
			$baseURL = window.location.hostname;
			if ($baseURL == "65.39.65.48") {
			$baseURL = "http://"+$baseURL+"/Goober.Dev/WebSite/";
			} else {
			$baseURL = "http://"+$baseURL+"/";
			}
			if(isNaN($zipcode)) {
			
			
			//alert ('Not a number');
			$errorCount++;
			}
			if ($zipcode.length < 5) {
			//alert('Less than five');
			$errorCount++;
			}
			if ($errorCount == 0) {
			//alert('Test. Value is '+$baseURL);
			$postURL = $baseURL+"ajax_zipcodes_process.php";
			$.post($postURL,
			{zipcode: $zipcode},
			function(json) {
			$status = json.status;
			$deliveryDay = json.deliveryDay;
			//$deliveryDay = json.day;
			// alert('Status is' + $status);
			if (parseInt($status) == 1) {
			//$('#zipResults').html("<b>You are within a free delivery area. Your delivery day is"+$deliveryDay+"</b>");
			
			if($deliveryDay == "Business Day")
			$('#zipResults').html("<br><b>You are in a free next business day delivery area ("+$zipcode+").</b>");
			else
			$('#zipResults').html("<br><b>Delivery for area with zip code ("+$zipcode+") is scheduled for every "+ $deliveryDay +".</b>");
			
			$('#zipResults').show();
			$('#zipResults').fadeOut(7000);

			}
			if (parseInt($status) ==0) {
			$('#zipResults').html("<br><b>You are NOT in a free next business day delivery area ("+$zipcode+".)</b>");
			$('#zipResults').show();
			$('#zipResults').fadeOut(7000);

			}
		}, "json");
			} else {
			$errorMessage = 'Please Enter a valid 5 digit zip code.';
			$('#zipResults').html("<b>"+$errorMessage+"</b>");
			$('#zipResults').show();
			$('#zipResults').fadeOut(7000);
			addZipCodeListeners();
			}
			//alert('Value is ' + $(this).attr('name'));
		/*$.post("ajax_favorites_process.php",
		{product_id: $(this).attr('name'), group_id: $group_id},
		function(json) {
		$status = json.status;
			if (parseInt($status) == 1) {
			$('#myFaves').load('favorites_ajax.php');
			}
		}, "json");
		*/
		

			
			addZipCodeListeners();
			});
}
