/// <reference path="jquery.js"/>

function productSearch(){
  var searchterm = $("#searchstr").val();

  if(searchterm != '' && searchterm != 'Søg'){
    document.location.href = "/Produkter/Search.aspx?searchstr=" + searchterm;
  }
  return false;
}


$(document).ready(function() {

  $("#searchstr").keydown(function(e){
    if (e.keyCode == 13) {
      productSearch();
      return false;
    }
  });

  $("button#search-button").bind("click", function(){
    productSearch();
  });


// this should be refactored to another file (Lars Buur - 25.jan 09)


$(".zipcode-lookup").blur(function(){
	
	var targetfield = $(this).attr('lookuptarget');
	
	$.get("/?altTemplate=AjaxProxy&ajax-lookupzip=" + this.value,
	  function(data){
	  	$('#' + targetfield).val(jQuery.trim(data));
	  });
	}
);

  // Enter gets info as opposed to submitting form
  $("#lookup-phone").keydown(function(e){
    if (e.keyCode == 13) {
      document.location.href='/?altTemplate=Checkout+Deliveryinformation&lookup-phone=' + $('#lookup-phone').val()
      return false;
    }
  });

  // Handle multiple email inputs
  $("#contact_username").keyup(function(){
    userstr = $(this).val();
    $("#contact_email").val(userstr).parent().css("display","none");
  });


});
