
  function search()
  {
    var trade = $("#txtTrade").val();
    //var tradeID = $("#txtTrade").val();
    var valLocation = $("#txtLocation").val();
    var regionID = $('#regionID').val();

    if (regionID != '')
    {
      window.location = "/find/" + escape(trade) + "_t0/" + regionID + '_r' + regionID + '/';
    }
    else    
    {
      if (valLocation != '')
        window.location = "/find/" + escape(trade) + "_t0/" + valLocation + '_p' + valLocation + '/';
      else
        window.location = "/find/" + escape(trade) + "_t0/" + valLocation + '_s0/';
    }
  }  

  function setState(state,fullState)
  {
    //http://www.mastertradie.com.au/autocomplete_locations.php?q=8&ajax=true
    //highlight the text area...
    $(".StateSelected").removeClass("StateSelected");
    $("#State_" + state).addClass("StateSelected");
    $("#regionalLocations1").html("");
    $("#regionalLocations2").html("");
    $("#regionalLocations3").html("");
    $.getJSON("/autocomplete_locations.php",{q: state, ajax: 'true'}, function(j)
    {
      var output = '';
      var currentOutput = "regionalLocations1";
      var maxInEach = Math.round((j.length/3));
      for (var i = 0; i < j.length; i++) {
        output += '<a href="javascript:setRegion(' + j[i].LocationID + ',\''+j[i].Name+'\');">' + j[i].Name + '</a><br/>';
        if (i == maxInEach)
        {
          $("#" + currentOutput).html(output);
          output = '';
          currentOutput = "regionalLocations2";
        }
        if (i == ((maxInEach*2)+1))
        {
          $("#" + currentOutput).html(output);
          output = '';
          currentOutput = "regionalLocations3";
        }
        if (i == j.length-1)
        {
          //The last one?
          $("#" + currentOutput).html(output);
        }
      }
    })

    //If this hasn't been done before, 
    /*if (state == null || fullState == null)
    {
      $("#locationSearch").html('');
      //$("#find").animate({height: "300px"}, "slow");
      $("#locationSearch").animate({height: "50px"}, "slow");
    }
    else
    {
      //$("#locationSearch").slideDown("slow");
      $("#locationSearch").html('<h3>Select a region from '+fullState+':</h3><br/>or return to the <a href="javascript:setState(null,null);">basic search</a><br/><div id="regions_'+state+'" style="height: 80px; padding-top: 5px;"></div>');
      $('#regions_'+state).load('/index_getRegions.php', { 's': state});
      $("#locationSearch").animate({height: "330px"}, "slow")
      //$("#find").animate({height: "385px"}, "slow");;
    }*/
  };

  function setRegion(regionID,description)
  {
    $('#txtLocation').val(description);
    $('#txtLocation').removeClass('blur');
    $("#txtLocation").colorBlend([{param:"background-color",fromColor:"#ffffff",toColor:"#316e8d",duration:1000,cycles:1}]);
    $('#txtTrade').focus();
  }

  $(document).ready(function() 
  {
    if ($('#txtLocation').val() == 'Enter a location')
      $('#txtLocation').val('');
    $('#txtTrade').val('');
    $('input:text').hint();
  });
