﻿function loadWishlist() {
    if (document.getElementById(txt_wishlish_name_search).value == "") {
        alert('please input wishlist name');
        return false;
    }
    document.location = '?wishlist=' + document.getElementById(txt_wishlish_name_search).value;
    return false;
}

function saveWishlist() {
    if (document.getElementById(txt_wishlish_name).value == "") {
        alert('please input wishlist name');
        return false;
    }

    YAHOO.util.Dom.get('cartprogress').style.display = '';
    YAHOO.util.Connect.asyncRequest(
                'get'
                , "AjaxStation.aspx?method=savewishlist&wishlistname=" + document.getElementById(txt_wishlish_name).value + "&rnd=" + Math.random()
                , {
                    success: function(o) {
                        YAHOO.util.Dom.get('cartprogress').style.display = 'none';
                        if (o.responseText == success)
                            document.getElementById(lbl_warn1).innerHTML = "Saved";
                        else if (o.responseText == success)
                            document.getElementById(lbl_warn1).innerHTML = "Fail";
                        else
                            document.getElementById(lbl_warn1).innerHTML = o.responseText;
                    }
                    , failure: function(o) {
                        alert(o.responseText);
                        YAHOO.util.Dom.get('cartprogress').style.display = 'none';
                    }
                }
            );
    return false;
}

function addToCartFromWishList(obj, shoppingcartid, producttype) {
    YAHOO.util.Dom.get('cartprogress').style.display = '';
    YAHOO.util.Connect.asyncRequest(
                'get'
                , "AjaxStation.aspx?method=addtocartfromwishlist&shoppingcartid=" + shoppingcartid + "&producttype=" + producttype + "&rnd=" + Math.random()
                , {
                    success: function(o) {
                        YAHOO.util.Dom.get('cartprogress').style.display = 'none';
                        if (o.responseText == success)
                            document.location = 'Cart.aspx';
                        else if (o.responseText == soldout)
                            document.location = "SoldOut.aspx";
                        else {
                            alert(o.responseText);
                        }
                    }
                    , failure: function(o) {
                        alert(o.responseText);
                        YAHOO.util.Dom.get('cartprogress').style.display = 'none';
                    }
                }
            );
}

function removeFromWishList(id, shoppingcartid) {
    var handleYes = function() {
        this.hide();
        YAHOO.util.Dom.get('cartprogress').style.display = '';


        YAHOO.util.Connect.asyncRequest(
                        'get'
                        , "AjaxStation.aspx?method=removefromwishlist&shoppingcartid=" + shoppingcartid + "&rnd=" + Math.random()
                        , {
                            success: function(o) {
                                if (o.responseText == success)
                                    YAHOO.util.Dom.get(id).style.display = 'none';
                                else {
                                    alert("failure");
                                }
                                YAHOO.util.Dom.get('cartprogress').style.display = 'none';
                            }
                            , failure: function(o) {
                                alert(o.responseText);
                                YAHOO.util.Dom.get('cartprogress').style.display = 'none';
                            }
                        }
                    );

    };

    var handleNo = function() {
        this.hide();
    };

    var conf = new YAHOO.widget.SimpleDialog(
                            "conf",
					         { width: "300px",
					             fixedcenter: true,
					             visible: false,
					             draggable: false,
					             modal: true,
					             close: false,
					             text: "Are you sure you want to remove this item from your wish list?",
					             icon: YAHOO.widget.SimpleDialog.ICON_WARN,
					             constraintoviewport: true,
					             buttons: [{ text: "Yes", handler: handleYes, isDefault: true }, { text: "No", handler: handleNo}]
					         });

    conf.setHeader("Confirm Remove");
    conf.render(document.body);
    conf.show();
}