
jQuery.noConflict();

jQuery.fn.updateDate = function() {
    jQuery(this[0]).change(function() {
			var datePick = jQuery("#collectionDate").val();
		  jQuery("#biebersdorfCustomerOrderComment").val(formatDate(parseDate(datePick),'ddS MMM, yyyy') + ' - ' + jQuery("input[@name='collectionTime']:checked").val());
		});
};

jQuery(document).ready(function(){

	if (jQuery("#CityLocal").length) {
		
		if(!jQuery("#CityLocal").val().length)
			jQuery("#CityLocal").val("Please enter your town");
		
		jQuery("#CityLocal").click( function () {
			if(jQuery("#CityLocal").val() == "Please enter your town")
				jQuery("#CityLocal").val("");
		});
		
		jQuery("#CityLocal").blur( function () {
			if(!jQuery("#CityLocal").val().length)
				jQuery("#CityLocal").val("Please enter your town");
		});
		
	}
	if (jQuery("#home-slider").length) {
			
			jQuery("#home-slider").easySlider({
				auto: true, 
				speed: 1200,
				pause: 3000,
				continuous: true
			});
	}
	if (jQuery("#product-slider").length) {
			
			jQuery("#product-slider").easySlider({
				auto: true, 
				speed: 1200,
				pause: 3000,
				continuous: true
			});
	}

	if (jQuery("#collectionDate").length > 0) {
		jQuery("#collectionDate").datepicker({minDate: '+1', maxDate: '+20D', dateFormat: 'dd-mm-yy'});
	}
	if (jQuery("#collectionDate").length) {
		jQuery(".updateDate").each( function() { jQuery(this).updateDate()});
	}
	
	if (jQuery("#goPostCode").length) {
		jQuery("#formPostCode").validate ({
			errorPlacement: function(error, element) {
		       error.appendTo("#msgPostCode");
		   },
		  rules: {
		  	postcode: { required: true,  remote: '/ajaxcities?d=1&f=1'	}
			},
			messages: {
				postcode: { required: "Error: Please enter a town name", remote: "Error: This town doesn't exist in our database" }
			}

		 });

		
		 /* jQuery("#formPostCode").submit ( function() { 
			jQuery("#goPostCode").attr('disabled', 'disabled');
			if(!jQuery("#CityLocal").val().length) {
				jQuery("#goPostCode").removeAttr('disabled');
				jQuery("#msgPostCode").html('Error: Please enter a town name');
				return false;
			}
			else {
				bodyContent = jQuery.ajax({
				      url: "ajaxcities",
				      global: false,
				      type: "GET",
				      data: ({q : jQuery("#CityLocal").val(), d : 1}),
				      dataType: "html",
				      success: function(html){
				      	if(!html.length) {
				      		jQuery("#goPostCode").removeAttr('disabled');
						    	jQuery("#msgPostCode").html('Error: This town doesn\'t exist in our database');
						    	return false;
						    }
						    else {
						    	jQuery("#msgPostCode").html('');
						    	return true;
						    }
						  }
				   }
				).responseText;

			}
		});
		*/

		//jQuery("#CityLocal").keydown( function() { jQuery("#").html(''); });
	} 
	//Reset the image bouncers
	//jQuery.cookie("nav-bounce",0);
	/*
	if(jQuery("#start-selection").length && parseInt(jQuery.cookie("nav-bounce")) < 3) {
		if(jQuery(".catalog-category-view").length) {
			jQuery.cookie("nav-bounce", parseInt(jQuery.cookie("nav-bounce"))+1 );
		}
		jQuery("#start-selection").effect("bounce", { times:5 }, 300);
	} else {
		jQuery("#start-selection").hide();
	}
	if(jQuery("#postcode_enter").length) {
		jQuery("#postcode_enter").effect("bounce", { times:5 }, 300);
	}*/
});

