var CouponWindow = null;
var ReceiptWindow = null;
var NotifyWindow = null;

function viewCoupon(coupon) {
    if (CouponWindow != null && CouponWindow.open) { 
        CouponWindow.close();
    }
    CouponWindow = window.open('http://www.sodapopstop.com/coupon/coupon.cfm?link='+coupon,'CouponWindow','TOOLBAR=0,STATUS=0,WIDTH=515,HEIGHT=235,TOP=75,LEFT=100,RESIZE=0,SCROLLBARS=0,MENUBAR=0')
}

function printReceipt(o,m) {
    if (ReceiptWindow != null && ReceiptWindow.open) { 
        ReceiptWindow.close();
    }
    ReceiptWindow = window.open('https://www.sodapopstop.com/cart/dt_printablereceipt.cfm?o='+o+'&m='+m,'ReceiptWindow','TOOLBAR=0,STATUS=0,WIDTH=600,HEIGHT=435,TOP=15,LEFT=100,RESIZE=0,SCROLLBARS=1,MENUBAR=0')
}

function notifyWhenStocked(productid) {
    if (NotifyWindow != null && NotifyWindow.open) { 
        NotifyWindow.close();
    }
    NotifyWindow = window.open('http://www.sodapopstop.com/products/notify.cfm?link='+productid,'NotifyWindow','TOOLBAR=0,STATUS=0,WIDTH=515,HEIGHT=235,TOP=75,LEFT=100,RESIZE=0,SCROLLBARS=0,MENUBAR=0')
}

function setProductID(productid) {
    document.CartForm.productid.value = productid;
}

function setPriceType(pricetype) { // pricetype= UnitPrice or CasePrice
    document.CartForm.pricetype.value = pricetype;
}

function setQuantity(quantity) {
    document.CartForm.quantity.value = quantity;
}

function priceTypeChanged() {
    if (document.CartForm.price.selectedIndex == 0) {       // unit price
        setPriceType('UnitPrice');        
    } else if (document.CartForm.price.selectedIndex == 1) {// case price
        setPriceType('CasePrice');
    }
}

function submitCartForm(cartaction, formaction) { // formaction = empty string = use default
    document.CartForm.ACTION.value = cartaction;
    if (formaction.length) {
        document.CartForm.action.value = formaction;
    }
    document.CartForm.submit();
}

function addToCart(productid, pricetype, quantity) {
    setProductID(productid);
    setPriceType(pricetype);
    setQuantity(quantity);
    submitCartForm('add','');
}