
function ShowProductDetail(productCode) {
    $get('infodialog').style.display = '';
    ShowListPopup();
    $('#infodialog').dialog('open');
    $get("imgbranddetail").style.display = 'none';
    $get("imgproductdetail").style.display = 'none';
    $get("imgbranddetailajax").style.display = '';
    $get("imgproductdetailajax").style.display = '';

    $("#imgbranddetail").removeAttr('width');
    $("#imgbranddetail").removeAttr('height');
    $("#imgproductdetail").removeAttr('width');
    $("#imgproductdetail").removeAttr('height');

    var message = 'Loading...';
    //$get("productname").innerHTML = message;
    $get("productbrand").innerHTML = message;
    $get("productcategory").innerHTML = message;
    $get("producttype").innerHTML = message;
    $get("productsubtype").innerHTML = message;
    $get("productdetail").innerHTML = message;

    PageMethods.GetProductInfo(productCode, OnSucceeded, OnFailed);
}

function OnSucceeded(result) {
    var productInfo = Sys.Serialization.JavaScriptSerializer.deserialize(result);
    //$get("productname").innerHTML = productInfo.ProductName;           
    $("#ui-dialog-title-infodialog").attr('innerHTML', productInfo.ProductName);
    $get("productbrand").innerHTML = productInfo.Brand;
    $get("productcategory").innerHTML = productInfo.Category;
    $get("producttype").innerHTML = productInfo.Type;
    $get("productsubtype").innerHTML = productInfo.SubType;
    $get("productdetail").innerHTML = productInfo.Detail;
    $get("imgbranddetailajax").style.display = 'none';
    $get("imgproductdetailajax").style.display = 'none';
    if (productInfo.BrandPhoto != null && productInfo.BrandPhoto != '') {
        $get("imgbranddetail").src = productInfo.BrandPhoto;
        $get("imgbranddetail").style.display = '';
        if (productInfo.BrandHeight != 0 && productInfo.BrandWidth != 0) {
            var imgRatio = productInfo.BrandHeight / productInfo.BrandWidth;
            var holderRatio = 1;
            if (imgRatio > holderRatio) {
                $("#imgbranddetail").height(200);
                $("#imgbranddetail").width((productInfo.BrandWidth * 200) / productInfo.BrandHeight);
            }
            else {
                $("#imgbranddetail").width(200);
                $("#imgbranddetail").height((productInfo.BrandHeight * 200) / productInfo.BrandWidth);
            }

            //fix for ie6
            if (jQuery.browser.msie && jQuery.browser.version < 7) {
                $get("imgbranddetail").style.behavior = "url(script/iepngfix.htc)";
            }
        }
    }

    if (productInfo.ProductPhoto != null && productInfo.ProductPhoto != '') {
        $get("imgproductdetail").src = productInfo.ProductPhoto;
        $get("aProductFullImage").href = productInfo.ProductPhoto;
        $get("imgproductdetail").style.display = '';
        $get("pnlProductPhoto").style.display = '';


        if (productInfo.Height != 0 && productInfo.Width != 0) {
            var imgRatio = productInfo.Height / productInfo.Width;
            var holderRatio = 1;
            if (imgRatio > holderRatio) {
                $("#imgproductdetail").height(200);
                $("#imgproductdetail").width((productInfo.Width * 200) / productInfo.Height);
            }
            else {
                $("#imgproductdetail").width(200);
                $("#imgproductdetail").height((productInfo.Height * 200) / productInfo.Width);
            }

            //fix for ie6
            if (jQuery.browser.msie && jQuery.browser.version < 7) {
                $get("imgproductdetail").style.behavior = "url(script/iepngfix.htc)";
            }

        }


    } else {
        $get("pnlProductPhoto").style.display = 'none';
    }
}

function OnFailed(error) {
    alert(error.get_message());
}

$(function() {
    $('#infodialog').dialog({
        autoOpen: false,
        width: 800,
        height: 600,
        modal: true,
        buttons: {
            "Ok": function() {
                $(this).dialog("close");
            }
        }
    });

    $('#infodialog').bind('dialogclose', function(event) {
        CloseListPopup();
    });

});