var $j = jQuery.noConflict();
$j(document).ready(function () {
    $j('a.popup-box').click(function () {
        var id = $j(this).attr('id');
        load_cantfindyoursize(id);
        return false;
    });

    /* Show QUICKSHOP on product hover */
    $j('ul.products li a').hover(function () {
        $j(this).find('span.quickshop').show();
    }, function () {
        $j(this).find('span.quickshop').hide();
    });

});

function CheckoutHover(t) {
    var i = $j('#ContentPlaceHolder1_GoToCheckout');
    if (t == 'over') {
        i.attr('src', '/images/button_checkout_2b.gif');
    } else {
        i.attr('src', '/images/button_checkout_2a.gif');
    }
}

function initPopup(obj, close) {
    $j('.wrapper').height($j(document).height());
    $j('.wrapper').width($j(window).width());
    $j('.wrapper, ' + obj).show();
    document.getElementById("realZOOMHighlight").style.width = "0px";
    document.getElementById("realZOOMImageOuter").style.width = "0px";
    document.getElementById("realZOOMBG").style.width = "0px";
    document.getElementById("realZOOMBGText").style.display = "none";
    $j(close + ', .wrapper').click(function () {
        $j('.wrapper, ' + obj).hide();
        document.getElementById("realZOOMHighlight").style.width = "auto";
        document.getElementById("realZOOMImageOuter").style.width = "465px";
        document.getElementById("realZOOMBG").style.width = "auto";
        document.getElementById("realZOOMBGText").style.display = "block";
    });
}

function load_cantfindyoursize(id) {
    var url = '/store/product_email_signup.aspx?productid=' + id;
    $j.ajax({
        url: url,
        success: function (html) {
            $j('.popup').html(html);
            initPopup('.popup', '.popup .close');
        },
        error: function (e) {
            alert(e.responseText);
        }
    });
}

function OutOfStock(productid) {
    var modelname = document.getElementById('ModelName').innerHTML;
    var size = document.getElementById('ProductSizes').value;
    var color = null;
    if (document.getElementById('ProductColors') != null) {
        color = document.getElementById('ProductColors').value;
    } else {
        color = document.getElementById('ContentPlaceHolder1_ProductColors').value;
    }
    var name = document.getElementById('Name').value;
    var email = document.getElementById('EmailAddress').value;
    var newsletterchk = null;
    if (document.getElementById('NewsLetterChk') != null)
        newsletterchk = document.getElementById('NewsLetterChk').checked;

    if (size == '-1') {
        $j('#message').show();
        $j('#message').css('display', 'block');
        $j('#message').html('Please select a size!');
        return false;
    }

    if (color != null && color == '-1') {
        $j('#message').show();
        $j('#message').css('display', 'block');
        $j('#message').html('Please select a color!');
        return false;
    }

    if (name == '') {
        $j('#message').show();
        $j('#message').css('display', 'block');
        $j('#message').html('Please enter a name!');
        return false;
    }

    if (email == '') {
        $j('#message').show();
        $j('#message').css('display', 'block');
        $j('#message').html('Please enter a email!');
        return false;
    }

    if (email != "") {
        if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
            var url = '/store/cantfindyoursize.aspx';
            var params = '?productid=' + productid + '&colorid=' + color + '&sizeid=' + size + "&name=" + name + "&email=" + email + "&newsletterchk=" + newsletterchk + "&modelname=" + modelname;

            url += params;

            $j('#message').show();
            $j('#message').html('processing...');

            $j.ajax({
                url: url,
                success: function (transport) {
                    $j('#message').html('Thank you. Your request has been submitted.  This window will close in 5 seconds.');
                    t = setTimeout("$j('.popup').hide()", 5000);
                },
                error: function () {
                    $j('#message').html('Your request has not been submitted!');
                }
            });

        } else {
            $j('#message').show();
            $j('#message').css('display', 'block');
            $j('#message').html('Invalid E-mail Address! Please re-enter.');
            return false;
        }
    }
    return false;
}

function popup_sizechart(w) {
    var pw;
    var paramstring = "height=357,width=462" + ",toolbar=no,resizable=no,scrollbars=no";
    pw = window.open(w, 'SizeChart', paramstring);
    pw.focus();
}
