function Search()
{
    this.sSurname = "";
    this.sGivenName = "";
    this.iTeamId = "";
    this.iCountryId = "";
    this.cPosition = "";
    this.iCurrentPage = 1;

    var root = this;
    $("#ctl00_phContent_btnSearch").click
    (
        function(e)
        {
            e.preventDefault();
            this.iCurrentPage = 1;
            root.search();
        }
    )

    // set up the text boxes
    $("input:text", "#conSearchOptions").each 
    (
        function()
        {
            $(this).focus
            (
                function(e)
                {
                    if ($(this).val() == sDefaultText)
                    {
                        $(this).removeClass("TextPlaceholder");
                        $(this).val("");
                    }
                }
            ).blur
            (
                function(e)
                {
                    if ($(this).val() == "")
                    {
                        $(this).addClass("TextPlaceholder");
                        $(this).val(sDefaultText);
                    }
                }
            )

            if ($(this).val() == "")
            {
                $(this).val(sDefaultText).addClass("TextPlaceholder");
            }
        }
     )        

    // attach events to the form elements
    $("input, select", "#conSearchOptions").keypress
    (
        function(e)
        {
            if (e.keyCode == 13)
            {
                e.preventDefault();
                oSearch.doSearch();
            }
        }
    )
}

Search.prototype.resetSearch = function()
{
    this.sSurname = "";
    this.sGivenName = "";
    this.iTeamId = "";
    this.iCountryId = "";
    this.cPosition = "";
}

Search.prototype.searchByTeam = function(iTeamId)
{
    var _this = this;
    this.resetSearch();
    this.iTeamId = iTeamId;

    $("#ctl00_phContent_cbTeams option").each
    (
        function()
        {
            if ($(this).val() == _this.iTeamId)
            {
                $(this).attr("selected", true);
            }
            else
            {
                $(this).attr("selected", false);
            }
        }
    )

    this.doSearch();
}

Search.prototype.searchBySurnameCharacter = function (sChar)
{
    this.iCurrentPage = 1;
    this.resetSearch();
    this.sSurname = sChar;
    $("#ctl00_phContent_txtSurname").val(sChar);
    this.doSearch();
}

Search.prototype.search = function()
{
    this.resetSearch();
    
    this.sSurname = $("#ctl00_phContent_txtSurname").val();
    this.sGivenName = $("#ctl00_phContent_txtGivenName").val();
    this.iTeamId = $("#ctl00_phContent_cbTeams").val();
    this.iCountryId = $("#ctl00_phContent_cbAllegiance").val();
    this.cPosition = $("#ctl00_phContent_cbPosition").val();

    this.sSurname = (this.sSurname == sDefaultText) ? "" : this.sSurname;
    this.sGivenName = (this.sGivenName == sDefaultText) ? "" : this.sGivenName;
    
    this.doSearch();
}

Search.prototype.doSearch = function ()
{
    oRecordPaging.iCurrentPage = this.iCurrentPage;

    $.get("SearchXml.aspx", { SN: this.sSurname, GN: this.sGivenName, C: this.iCountryId, T: this.iTeamId, PG: this.iCurrentPage, P: this.cPosition },
        function (data)
        {
            // build the paging for the object
            $("#conSearchResults div.Content").empty().html(data);
            $("#conSearchResults div.Content").empty().html(data).append("<div id=\"conSearchPagingContainer\"/>");
            $("#conSearchResults").css("display", "block");
            $("#conConference").css("display", "none");
            oRecordPaging.iTotalRecords = $("#conSearchResults .NHLPARecordPagingTotalRecords").attr("value");
            oRecordPaging.generate();

        }, "html");
}
    