﻿
function notifyStock(id) {
    iBox.load();
    var status = '';
    var statusback = "<br><div style=\"text-align:center;font-size:14px;font-weight:bold;\"><a href=\"javascript:iBox.close()\">Continue Shopping</a></div>";
    var email = $$('input[id$=txtEmail]')[0].get('value');
    if (email != "") {

        var jsonReq = new Request.JSON({ 'url': 'beads.aspx/notifyStock',
            onComplete: function(result) {

                if (result.charAt(0) == 'A') {
                    status = genStatus('pass', 'Email added to stock notification list', result);
                }
                else {
                    status = genStatus('fail', 'Unable to add email to stock notification list', result);
                }
                iBox.open(status + statusback);

            },
            onFailure: function(result) {

                status = genStatus("fail", "Unable to add email to notify list", "Please contact shop@beadcharm.com for assistance.");
                iBox.open(status + statusback);

            }

        }
                ).send({ 'id': id, 'email': email });
    }
    else {
        status = genStatus("fail", "Unable to add email to notify list", "Email field empty. Please enter your email address.");
        iBox.open(status + statusback);
    }
}

function registerEvents() {

    $$('a[id^=aProd]').each(
                    function(item, index) {

                        item.addEvents({
                            'mouseover': function(e) {
                                var event = new Event(e);
                                var iPreview = $('iPreview');
                                iPreview.setProperty('src', 'img/products/images/' + item.id.replace('aProd', '') + '.jpg');
                                iPreview.set('styles', { 'display': '', 'left': (item.getPosition().x + 50) + 'px', 'top': item.getPosition().y + 'px' });

                            },
                            'mouseout': function(e) {
                                $('iPreview').set('styles', { 'display': 'none' });
                            }
                        });
                    });
}
function addProduct(id) {
    var error = '';
    var productids = '';
    var packs = $$('input[id$=txtQuantity]')[0].get('value');
    iBox.load();
    var resultback = "<br><div style=\"text-align:center;font-size:14px;font-weight:bold;\"><a href=\"javascript:iBox.close()\">Continue Shopping</a> | <a href=\"basket.aspx\">View Basket</a> | <a href=\"checkout.aspx\">Check Out</a></div>";
    var jsonReq = new Request.JSON({ 'url': 'beads.aspx/addProducts',
        onComplete: function(result) {
            iBox.open(result + resultback);
        },
        onFailure: function(result) {
            iBox.open(genStatus("fail", "Unable to add items to your shopping cart", "Please contact shop@beadcharm.com for assistance.") + resultback);
        }

    }
            ).send({ 'id': id, 'quantity': packs });
}
window.addEvent('domready', registerEvents);
