﻿$(document).ready(function () {
    Products.GetAllProducts();
    $('#btnGo').live('click', function () {
        if ($('#ddlProducts').val() != '')
            window.location.href = 'productdetails.aspx?pid=' + $('#ddlProducts').val();
    });
});

var Products = {
    Id: 0,
    Name: '',
    GetAllProducts: function () {
        ajaxcall.data = "{}";
        ajaxcall.url = ajaxcall.SitePath + "products.aspx/GetAllProducts";
        ajaxcall.callbackfunction = Products.GetAllProductsSuccess;
        ajaxcall.Call();
    },
    GetAllProductsSuccess: function (result) {
        if (result.d != null && result.d != 'undefinded') {
            if (result.d.length > 0) {
                var str = '';
                $('#ddlProducts').append($("<option></option>")
                                    .attr("value", "")
                                    .text("Select a Product"));
                for (var i = 0; i < result.d.length; i++) {
                    $('#ddlProducts').append($("<option></option>")
                                    .attr("value", result.d[i].ID)
                                    .text(result.d[i].Product_Name));
                }
            }
        }
        else {
            $('#ddlProducts').append($("<option></option>")
                                .attr("value", "")
                                .text("No product found."));
        }
        $("form.jqtransform").jqTransform();
    }
}
