﻿// JScript File

function ReceiveServerData(arg, context) {
    var splitArgs = arg.split("&&&&");
    var Response = splitArgs[0].toQueryParams();
    //First lets update the shopping cart totals in Navigation Bar
    $("TopMenuCart1_litCartItemCount").update(Response["CartCount"]);
    $("TopMenuCart1_litCartItemTotal").update(Response["CartAmount"]);
    if (Response['CallFunction'] == "fireplace") {
        AskChimney(splitArgs[1]);
    } else {
        //Now lets display the result of adding this item to the cart
        $(Response["ResultDivID"]).update(splitArgs[1]);
        DivBox.show($(Response["ResultDivID"]), { title: 'Item(s) added to shopping Cart!', width: 400, height: 75, overlayOpacity: .6, overlayClose: true });
    }
}

function AskChimney(value) {
    //Now lets display the result of adding this item to the cart
    //$(Response["ResultDivID"]).update(splitArgs[1]);
    var Div = $("AddToCartResultDiv");
    if (!Div) {
        Div = document.createElement("div");
        Div.setAttribute('id', 'AddToCartResultDiv');
        window.document.body.appendChild(Div);
    }
    $("AddToCartResultDiv").update(value);

    var showDiv = document.createElement("div");
    //$(showDiv).style = $("Chimney_Request_Div").style;
    $(showDiv).style.backgroundColor = "white";
    $(showDiv).style.padding = "25px";
    $(showDiv).style.paddingLeft = "90px";
    $(showDiv).style.backgroundImage = "url('images/Adobes/Kivas/Chimney-System.jpg')";
    $(showDiv).style.backgroundRepeat = "no-repeat";
    $(showDiv).style.textAlign = "center";
    $(showDiv).innerHTML = $("Chimney_Request_Div").innerHTML;
    //$("Chimney_Request_Div").show();
    DivBox.show($(showDiv), { title: 'Fireplace(s) added to shopping Cart!', width: 500, height: 250, overlayOpacity: .6, overlayClose: true });
}

function ReceiveServerDataTimber(arg, context) {
    var splitArgs = arg.split("&&&&");
    var Response = splitArgs[0].toQueryParams();
    //First lets update the shopping cart totals in Navigation Bar
    $("TopMenuCart1_litCartItemCount").update(Response["CartCount"]);
    $("TopMenuCart1_litCartItemTotal").update(Response["CartAmount"]);

    //Now lets display the result of adding this item to the cart
    $(Response["ResultDivID"]).update(splitArgs[1]);
    DivBox.show($(Response["ResultDivID"]), { title: 'Item(s) added to shopping Cart!', width: 400, height: 75, overlayOpacity: .6, overlayClose: true, closeButton: "../images/popup/close_green.gif" });
}

/*Verify existance of quantity textbox, get value and clear if exists 
otherwise return "1"
QuantityTextBox : Textbox object or ID
returns         : Quantity of 1 or greater */
function GetQuantity(QuantityTextBox) {
    var textbox = $(QuantityTextBox);
    var quantity;
    if (textbox != null) {
        quantity = (textbox.value > 0) ? textbox.value : 1;
        textbox.value = "";
    } else {
        quantity = 1;
    }
    return quantity;
}

//function DoCallBack(ProductID, TextBoxID) {
//  var Quantity = GetQuantity(TextBoxID);
//  args = ProductID + "&" + Quantity;
//  CallServer(args,"");
//  return false;
//}
function DoCallBack(ProductID, TextBoxID, UseVendorProducts) {
    var Quantity = GetQuantity(TextBoxID);
    args = ProductID + "&" + Quantity + "&" + UseVendorProducts;
    CallServer(args, "");
    return false;
}

function DoTimberCallBack(ProductID, BuyButton, ItemIndex) {
    var Quantity = GetQuantity(BuyButton.id.substring(0, BuyButton.id.indexOf("BuyButton")) + "txtQuantity");

    args = ProductID + "&" + Quantity + "&" + ItemIndex;
    CallServer(args, "");
    return false;
}

function DoCatalogCallBack(NodePath, NodeID, TextBoxID) {
    var Quantity = GetQuantity(TextBoxID);
    args = NodePath + "&" + NodeID + "&" + Quantity;
    CallServer(args, "");
    return false;
}

function ShowWizard(WizardURL, TextBoxID, Title) {
    //WizardFrame
    var Quantity = GetQuantity(TextBoxID);
    if (Title == null) {
        Title = "Hardware Customization Wizard"
    }
    WizardURL += Quantity
    if (!$("WizardFrame")) {
        var newFrame = document.createElement("iframe");
        newFrame.setAttribute("id", "WizardFrame");
        newFrame.setAttribute("frameborder", "0");
        newFrame.setAttribute("style", "display: none");
        //newDiv.style.display = 'block';
        window.document.body.appendChild(newFrame);
    }
    $("WizardFrame").src = WizardURL;
    DivBox.show($("WizardFrame"), { title: Title, width: 615, height: 455, overlayOpacity: .4, vAlignMiddle: false, overlayClose: false });
}

function ShowWizardMessage(CartCount, CartAmount, setHeight) {
    if (setHeight == null) setHeight = 100;
    $("TopMenuCart1_litCartItemCount").update(CartCount);
    $("TopMenuCart1_litCartItemTotal").update(CartAmount);
    DivBox.show($("WizardMessage"), { title: 'Item added to shopping Cart!', width: 400, height: setHeight , overlayOpacity: .6, vAlignMiddle: true, overlayClose: true });
}


function CloseWizard(CartCount, CartAmount) {
    parent.ShowWizardMessage(CartCount, CartAmount);
   /* parent.$("TopMenuCart1_litCartItemCount").update(CartCount);
    parent.$("TopMenuCart1_litCartItemTotal").update(CartAmount);
    parent.DivBox.hide();*/
}