
$(document).ready(function() {
	var sKeywordText
	var sMailingListText 

	//default text field text
	sKeywordText = "enter keyword...."
	sMailingListText = "enter your email address...."

	//set default value
	$('input.search-keywords').val(sKeywordText)
	$('input.mailinglist-email').val(sMailingListText)

  $('div.demo-show:eq(0)> div').hide(); 
  $('div.demo-show:eq(0)> h3').click(function() {
	 $(this).next().slideToggle('fast');
  });

  $('input.quantity').blur(function() {
	 if (!IsNumber($(this).val())) {
		 $(this).val("0")
	 }
  });

  $('input.search-keywords').focus(function() {
	 if ( $(this).val() == sKeywordText ) {
		 $(this).val("")
	 }
  });

  $('input.search-keywords').blur(function() {
	 if ( $(this).val() == "" ) {
		 $(this).val(sKeywordText)
	 }
  });
 
  $('input.mailinglist-email').focus(function() {
	 if ( $(this).val() == sMailingListText ) {
		 $(this).val("")
	 }
  });

  $('input.mailinglist-email').blur(function() {
	 if ( $(this).val() == "" ) {
		 $(this).val(sMailingListText)
	 }
  });

  $('select.only-australia').change(function() {
	 if ( $(this).val() != "Australia" ) {
		$('tr.only-australia-row').children("td").addClass("itemerror")
		$('div.only-australia-error').text("You have chosen a product which is only available to be delivered to australia. They should be highlighted green.");
		$('input.submit-order').attr("disabled", "disabled");
	 } else {
		$('tr.only-australia-row').find("td").removeClass("itemerror")
		$('div.only-australia-error').text("");
		$('input.submit-order').removeAttr("disabled");
	}
  });

	$('.update-shipping').change(function() {
		//setting up the variables
		var postcode = $('input.ship-postcode').val()
		var country
		var maintotal
		var shiptotal
		
		//setting the main total
		maintotal = $('input.main-total').val()*1

		//grabbing the select value
		$("select option:selected").each(function () {
			country = $(this).text()
		});

		//running the ajax wich deletes the artist
		$.get("ajaxShipping.asp", { country: country, postcode: postcode }, function(html){
				if (!IsNumber(html)) {
					$('td.show-total').html("$" + maintotal)
					$("td.show-shipping").html(html)
				} else {
					shiptotal = html*1
					$('td.show-total').html("$" + (shiptotal+maintotal).toFixed(2))
					$("td.show-shipping").html("$" + shiptotal.toFixed(2))
				}
			});

		return false;
	});
});


