  function FindHandler()
  {
    this.findView = 0;
  }

  FindHandler.prototype.rate = function(advertiserID,advertiser)
  {
    $.blockUI({ 
      message: '<div class="review"><h1>Review ' + advertiser+'</h1><br/><div class="errorMessage noShow"></div><form id="rate" method="post" action="/Rate.php"><input type="hidden" name="advertiserID" value="'+advertiserID+'"/><table><tr><td class="ReviewTitle">Professionalism: <span style="color: rgb(255, 0, 0);">*</span></td><td><input name="star1" type="radio" class="star" value="1" title="Terrible"/><input name="star1" type="radio" class="star" value="2" title="Poor"/><input name="star1" type="radio" class="star" value="3" title="Average"/><input name="star1" type="radio" class="star" value="4" title="Good"/><input name="star1" type="radio" class="star" value="5" title="Excellent"/></td><td class="description">click to rate</td></tr><tr><td class="ReviewTitle">Quality: <span style="color: rgb(255, 0, 0);">*</span></td><td><input name="star2" type="radio" class="star" value="1" title="Terrible"/><input name="star2" type="radio" class="star" value="2" title="Poor"/><input name="star2" type="radio" class="star" value="3" title="Average"/><input name="star2" type="radio" class="star" value="4" title="Good"/><input name="star2" type="radio" class="star" value="5" title="Excellent"/></td><td class="description">click to rate</td></tr><tr><td class="ReviewTitle">On time: <span style="color: rgb(255, 0, 0);">*</span></td><td><input name="star3" type="radio" class="star" value="1" title="Terrible"/><input name="star3" type="radio" class="star" value="2" title="Poor"/><input name="star3" type="radio" class="star" value="3" title="Average"/><input name="star3" type="radio" class="star" value="4" title="Good"/><input name="star3" type="radio" class="star" value="5" title="Excellent"/></td><td class="description">click to rate</td></tr><tr><td class="ReviewTitle">Value for money: <span style="color: rgb(255, 0, 0);">*</span></td><td><input name="star4" type="radio" class="star" value="1" title="Terrible"/><input name="star4" type="radio" class="star" value="2" title="Poor"/><input name="star4" type="radio" class="star" value="3" title="Average"/><input name="star4" type="radio" class="star" value="4" title="Good"/><input name="star4" type="radio" class="star" value="5" title="Excellent"/></td><td class="description">click to rate</td></tr><tr class="CommentsRow"><td class="ReviewTitle">Your Review: <span style="color: rgb(255, 0, 0);">*</span></td><td class="inputAreas" colspan="2"><textarea name="comments"></textarea></td></tr><tr class="EmailRow"><td class="ReviewTitle">Your Name: <span style="color: rgb(255, 0, 0);">*</span></td><td class="inputAreas" colspan="2"><input id="txtName" type="text" name="name" value="' + $("#CookieReviewName").val() + '"/></td></tr><tr class="EmailRow"><td class="ReviewTitle">Email Address: <span style="color: rgb(255, 0, 0);">*</span></td><td class="inputAreas" colspan="2"><input type="text" class="required" id="txtEmailAddress" name="emailAddress" value="' + $("#CookieReviewEmail").val() + '"/><br/>you will be sent an email to confirm this review</td></tr></table><br/><input type="submit" class="button buttonNext" value="Submit">&nbsp;&nbsp;<input type="button" class="button" value="Cancel" onclick="javascript:$.unblockUI();"></form></div>',
      css: { border: '8px solid #ccc', top:  ($(window).height() - 400) /2 + 'px', left: ($(window).width() - 500) /2 + 'px', width: '500px', height: '400px', backgroundColor: '#EDEEF0' } });
    $('.blockOverlay').attr('title','Click to cancel').click($.unblockUI);
    $('input.star').rating({
      focus: function(value, link){
        $(this).parent().parent().children(".description").html(link.title);
      },
      blur: function(value, link){
        var selectedStar = $("input[@name='" + this.name + "']:checked");
        if (selectedStar.val() == null)
          $(this).parent().parent().children(".description").html("click to rate");
        else
          $(this).parent().parent().children(".description").html(selectedStar.attr("title"));
      },
      callback: function(value, link){
        //Update the messages...
        var selectedStar = $("input[@name='" + this.name + "']:checked");
        $(this).parent().parent().children(".description").html(selectedStar.attr("title"));
      }
    });
    $('#rate').ajaxForm(findPageHandler.rateResponse);
  }

  FindHandler.prototype.rateResponse = function(responseText)
  {
    if (responseText.substring(0,1) == '0')
    {
      $(".review .errorMessage").removeClass("noShow");
      $(".review .errorMessage").html(responseText.substring(1));
      $(".blockPage").css("height","450px");
    }
    else if (responseText.substring(0,1) == '1')
    {
      $.blockUI({ message: '<div class="errorMessage"><div><br/>You have already reviewed this tradie recently</div></div>',
          css: { width: '280px'}});
      $('.blockOverlay').attr('title','Click to cancel').click($.unblockUI);
      window.setTimeout($.unblockUI,3000);
    }
    else
    {
      //Save the cookies so we store the email address and names
      setCookieNoExp("ReviewName",$("#txtName").val());
      setCookieNoExp("ReviewEmail",$("#txtEmailAddress").val());
      $.blockUI({ message: '<div class="successMessage"><div><br/>Thank you for your review</div></div>',
          css: { width: '280px'}});
      $('.blockOverlay').attr('title','Click to cancel').click($.unblockUI);
      window.setTimeout($.unblockUI,3000);
    }
  }

  FindHandler.prototype.toggleFindView = function()
  {
    if (findPageHandler.findView == 0)
    {
      //$("#advancedFind").animate({height: "200px"}, "slow");
      $("#advancedFind").fadeIn("slow");
      $("#lnkShowAdvanced img").attr("src","/images/buttons/shrink.png");
      findPageHandler.findView = 1;
    }
    else
    {
      $("#advancedFind").fadeOut("slow");
      $("#lnkShowAdvanced img").attr("src","/images/buttons/expand.png");
      findPageHandler.findView = 0;
    }
  }

  var findPageHandler = new FindHandler();

  $(document).ready(function() 
  {
    if ($('#txtTrade').val() == 'Enter a trade name')
      $('#txtTrade').val('');
    if ($('#txtLocation').val() == 'Enter a suburb or postcode')
      $('#txtLocation').val('');

    if (($('#txtBusinessName').val() != null && $('#txtBusinessName').val() != '') || ($("#selAvailability").val() != null && $("#selAvailability").val() != ""))
      findPageHandler.toggleFindView();

    $('input:text').hint();
    $(".rate").bind("mouseenter",function(){
      //what is the value of this mouse move?
      var currentRating = this.title;
      //Mark all of the ratings as grey
      $(this).parent().children("img").each(function()
      {
        if ($(this).attr("title") > currentRating)
        {
          $(this).attr("src","/images/rating/starDisabledGrey.png");
        }
        else
        {
          $(this).attr("src","/images/rating/starRateGrey.png");
        }
      });
    })
    $(".rateLink").bind("mouseleave",function(){
      //Reset the ratings to their original
      var currentRating = $(this).attr("alt");
      $(this).children("img").each(function()
      {
        if (currentRating == -1 || $(this).attr("title") > currentRating)
          $(this).attr("src","/images/rating/starDisabledGrey.png");
        else
          $(this).attr("src","/images/rating/starGrey.png");
      });
    })
  });

