﻿$(document).ready(function() {
    $('.productclass').sSelect({ ddMaxHeight: '300px' });

    $("#btnsearchbustype").click(function() {
        var values = [];
        $(".productclass").each(function() {
            if ($(this).val() != "") {
                values.push($(this).val());
            }
        });

        var key = $("#txtbustype").val();
        window.location.href = 'Result.aspx?id=' + values.join('|') + "&key=" + key;

    });

    if (GetQueryString("id") != null) {
        var ids = GetQueryString("id").split('|');
        if (ids != "") {
            for (var i = 0; i < ids.length; i++) {
                $('.productclass').each(function() {
                    $(this).getSetSSValue(ids[i]);
                });
            }
        }
    }
    if (GetQueryString("key") != null)
        $("#txtbustype").val(GetQueryString("key"));

    $("#txtbustype").autocomplete("../WebServices/SearchProductHandler.ashx", {
        width: 260,
        selectFirst: false
    }).focus(function() {
        this.select();
    });    

});

function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}


