﻿var addButton;

function ShowSalePricingRuleForm(productId, button) {
    addButton = button;
    var win = window.open("ProductSalePricingRule.aspx?Id=" + productId + "&nocache=" + Math.random(), "PriceParams", "location=no,menubar=no,resizable=yes,width=300,height=350");
}

function SubmitPriceParams(array) {
    var theForm = addButton.form;
    for (i in array) {
        param = document.createElement("input");
        param.type = "hidden";
        param.name = "params[" + i + "]";
        param.value = array[i];
        document.forms[0].appendChild(param);
    }
    addButton.onclick = null;
    addButton.click();
}

function onKeyPress(btnId, evt) {
    evt = evt || window.event;
    if (evt.keyCode == 13) {
        var btn = document.getElementById(btnId);
        if (btn != null)
            btn.click();
        return false;
    }
    else
        return true;
}

function copyAddressInfo(fromPrefix, toPrefix) {
    var theForm = document.forms[0];
    theForm.elements[toPrefix + "_tbName"].value = theForm.elements[fromPrefix + "_tbName"].value;
    theForm.elements[toPrefix + "_tbAddress"].value = theForm.elements[fromPrefix + "_tbAddress"].value;
    theForm.elements[toPrefix + "_tbCity"].value = theForm.elements[fromPrefix + "_tbCity"].value;
    theForm.elements[toPrefix + "_tbCounty"].value = theForm.elements[fromPrefix + "_tbCounty"].value;
    theForm.elements[toPrefix + "_tbCountry"].value = theForm.elements[fromPrefix + "_tbCountry"].value;
    theForm.elements[toPrefix + "_tbPhone"].value = theForm.elements[fromPrefix + "_tbPhone"].value;
    theForm.elements[toPrefix + "_tbFax"].value = theForm.elements[fromPrefix + "_tbFax"].value;
    theForm.elements[toPrefix + "_tbEmail"].value = theForm.elements[fromPrefix + "_tbEmail"].value;
    theForm.elements[toPrefix + "_tbMobile"].value = theForm.elements[fromPrefix + "_tbMobile"].value;
}

function paymentMethodChanged() {
    radios = document.getElementsByTagName("input");
    for (i = 0; i < radios.length; i++) {
        if (radios[i].type == "radio" && radios[i].checked) {
            cardDetails = document.getElementById("paymentDetailsDiv");
            if (cardDetails != null) {
                if (radios[i].value == "36") {
                    cardDetails.style.display = "";
                }
                else {
                    cardDetails.style.display = "none";
                }
            }
            break;
        }
    }
}

function toggle(btnObj, id) {
    el = document.getElementById(id);
    if (el.style.display == "none") {
        el.style.display = "";
        btnObj.className = "minusButton";
    }
    else {
        el.style.display = "none";
        btnObj.className = "plusButton";
    }
}

function footer() {
    if (document.body.offsetHeight > 600)
    { document.getElementById("footer").style.top = (document.body.clientHeight - 25) + "px"; }
}

function disableEnterKey(e) {
    var key;
    if (window.event)
        key = window.event.keyCode; //IE
    else
        key = e.which; //firefox     

    return (key != 13);
}