$(document).ready(function() {
/* Handle Setting up the catagory drop down based on the query string */
// var primaryCatId = $(document).getUrlParam("ddlPrimaryCategory_searchbar");
if ($("#ddlPrimaryCategory_searchbar").val() == null)
return;
GetCategoryValues($('#ddlPrimaryCategory_searchbar').val());
var secondaryCatId = $("#hdnCategoryValueId").val();
/*
if (primaryCatId != null) {
$("#ddlPrimaryCategory_searchbar").val(primaryCatId);
GetCategoryValues(primaryCatId);
}*/
if (secondaryCatId != null) {
$("#ddlSecondaryCategory_searchbar").val(secondaryCatId);
}
/* End*/
/* Adds event to primary cat drop down to update seocndary when selection changed */
$("#ddlPrimaryCategory_searchbar").change(function() {
GetCategoryValues($('#ddlPrimaryCategory_searchbar').val());
});
/* Ensures select box fires validation event on change rather than just onblur */
$("select").change(function() {
$(this).valid();
});
/* Fires saved search event*/
$("#ddlSavedSearch_searchbar").change(function() {
window.location = '/account/saved-searches/default.aspx?SearchId=' + $(this).val();
});
$("#tbKeywords").autocomplete({
source: "/handlers/search-term-auto-suggest.ashx",
minLength: 1,
select : function(event, ui){
if(document.selection) {
this.focus();
var oSel = document.selection.createRange();
oSel.moveStart('character',this.value.length);
oSel.moveEnd('character',0);
oSel.select();
}
}
});
$("#tbPostcode").autocomplete({
source: "/handlers/postcode-auto-suggest.ashx",
minLength: 3,
select : function(event, ui){
if(document.selection) {
this.focus();
var oSel = document.selection.createRange();
oSel.moveStart('character',this.value.length);
oSel.moveEnd('character',0);
oSel.select();
}
}
});
});
function GetCategoryValues(primaryCategoryId) {
// Remove all options
$('#ddlSecondaryCategory_searchbar').empty();
if (primaryCategoryId == "") {
$('#ddlSecondaryCategory_searchbar').append("");
return;
}
$.ajax({
type: "GET",
dataType: "xml",
url: "/handlers/category-value-handler.ashx?PrimaryCategoryId=" + primaryCategoryId + "&WhyDoYouNeedThisIE=" + new Date().getTime() + "&WithResults=False&WithDisplayTrue=True",
success: function(xml) {
$(xml).find('CategoryValue').each(function() {
var valueId = $(this).find('CategoryValueId').text();
var valueText = $(this).find('CategoryText').text();
var selected = 0 == valueId ? 'selected' : '';
$('#ddlSecondaryCategory_searchbar').append("");
});
},
async: false
});
}
$(function() {
$('.clearOnFocus').focus(function() {
// ok, need a bit a of a hack here
//postcode and keyword autosuggest clash with this as they trigger
// focus when inserting an item
var value = $(this).val().toLowerCase();
if (value == 'minimum price..' || value == 'maximum price..' || value == 'enter postcode' || value == 'enter keywords') {
$(this).val('');
}
});
});