﻿<!--
$(document).ready(function () {
    var radWorking = $("#Working");
    var radBroken = $("#Broken");
    var divConditionsWorking = $("#ConditionsWorking");
    var divConditionsBroken = $("#ConditionsBroken");
    var divAccessoriesWorking = $("#AccessoriesWorking");
    var divAccessoriesBroken = $("#AccessoriesBroken");
    var lnkPrice = $("#price");
    var lnkSell = $("#sell");
    var image = $("#ctl00_ctl00_cph_content_imgImage300");
    
    radWorking.click(function () { change_working(true); });
    radBroken.click(function () { change_working(false); });
    
    function change_working (working)
    {
        if (working == true)
        {
            divConditionsWorking.show();
            divConditionsBroken.hide();
            divAccessoriesWorking.show();
            divAccessoriesBroken.hide();
        }
        else
        {
            divConditionsWorking.hide();
            divConditionsBroken.show();
            divAccessoriesWorking.hide();
            divAccessoriesBroken.show();
        }
        lnkPrice.html("click here to calculate your <span>PRICE</span>");
        lnkSell.html("SELL NOW");
    }
    
    lnkPrice.click(function () { get_price("false"); });
    image.click(function () { get_price("false"); });
    lnkSell.click(function () { get_price("true"); });
    
    function get_condition() { return $("input:radio[@name=Working]:checked").val(); }
    function get_price(add)
    {
        var id = $("#product_id").val();
        var condition = get_condition();
        
        var grades = "";
        $("." + condition + "Grade:checked").each(function(id)
        {
            var g = $(this).val();
            if (g != "")
            {
                if (grades != "") grades += "-";
                grades += g;
            }
        });
        
        $.ajax({
            url: BasePath + 'product_pricing.aspx',
            data: 'ID=' + id + '&Condition=' + condition + '&Grades=' + grades + '&Add=' + add,
            type: 'post',
            cache: false,
            success: function (html) {
                //listing_results.animate({opacity: 1}, 250);
                //listing_results.fadeIn();
                //listing_results.html(html);
                //listing_spinner.html("");
                if (html.indexOf("error") != -1)
                {
                    lnkPrice.html("click here to calculate your <span>PRICE</span>");
                    $("#popupfeedback").html(html.substring(6)).show();
                    setTimeout(function(){ $("#popupfeedback").fadeOut(500); }, 2000);
                }
                else
                {
                    lnkPrice.html("click to recalculate your price: <span>" + html + "</span>");
                    if (add == "true")
                    {
                        //LoadShoppingCart();
                        //if ($("#shoppingcartcount").val() < "5")
                        //{
                            window.location= BasePath + "recyclecart.aspx";
                        //}
                        //else
                        //{
                            //$("#popupfeedback").html("The TRONIC has been added<br />to your recycle cart.").show();
                            //setTimeout(function(){ $("#popupfeedback").fadeOut(500); }, 2000);
                        //}
                    }
                }
            }
        });
    }
    
    change_working(get_condition() == "Working" ? true : false);
});
//-->

