﻿Cwo.RegisterNamespace("Cwo.AutoCompleteGeneric.PropertySearch");

Cwo.AutoCompleteGeneric.PropertySearch = new function () {

    /* Javascript 'hack' to access 'this' from within the object. */
    var propertySearch = this;

    /* InstanceInformation properties */
    this.InstanceInformation = {
        Textbox: Object,
        BaseObject: Object
    };

    // bind the events
    $(document).ready(function () {
        /* Hide the results container until required. */
        $("#" + propertySearch.InstanceInformation.ResultsContainerId).css("display", "none");
    });

    /* Called by the base object 'Cwo.AutoCompleteGeneric' which
    handles the search button click event. */
    this.OverrideSearchClick = function () {
        this.RedirectUser();
    };

    /* Called by the base object 'Cwo.AutoCompleteGeneric' which
    handles the results selected item event (invoked when an
    item in the results list is selected with the return key. */
    this.OverrideItemSelect = function () {
        this.RedirectUser();
    };

    /* The following function retrieves the selected place name
    from the text box and builds up a URL to redirect the user too. */
    this.RedirectUser = function () {
        // Get selected place name.
        var selectedPlaceName = propertySearch.InstanceInformation.Textbox.val();
        // Redirect user.
        window.location = propertySearch.InstanceInformation.BaseObject.SearchItemPrefixURL() + selectedPlaceName;
    };
};
