﻿function AddToWishList() {
    var hid = new Element('input', { 'type': 'hidden', 'name': 'WishList', 'value': '1' })
    $('frmCart').adopt(hid);
    document.getElementById('frmCart').submit();
}

function numbersonly(e) {
	var unicode=e.charCode? e.charCode : e.keyCode;
	if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
	if (unicode<48||unicode>57) //if not a number return false 
		//disable key press
		return false
	}
}

function GreaterThan0(elem) {
    if ($(elem).get('value') == '0') {
        $(elem).set('value','1');
    }
}


function QuickView(elem) {
    var a = $(elem);
    var div = $('quick-view');
    
    if (div == null) {
        new Element('div', { 'id': 'quick-view' }).inject(document.body);
        div = $('quick-view');
    }

    if ($('alert')) {
        $('alert').destroy();
    }
    var intWidth = document.body.offsetWidth;
    var intHeight = document.documentElement.scrollTop + 140;
    
    var strCloseBtn = "<div class='close-btn'><a href=\"#\" onclick=\"$('quick-view').dispose();return false;\">close</a></div>";
    div.set('html', strCloseBtn + "<div class='loader'><img src='/Content/img/loading2.gif' alt='loader' /></div>").setStyles({ "display": "block", "position": "absolute", "left": (intWidth / 2 - 270) + "px", "top": (intHeight) + "px" });
    var quickView = new Request.HTML({
        url: a.getProperty('href'),
        onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript) {
            div.set('html', strCloseBtn + responseHTML);
            var aryProductPricingAttribteIds = Array();
            try {
                aryProductPricingAttribteIds = ProductPricingAttribteIds.split(",");
            }
            catch (e) {
                aryProductPricingAttribteIds = Array();
            }
            if (aryProductPricingAttribteIds.length > 0) {
                for (var i = 0; i < aryProductPricingAttribteIds.length; i++) {
                    toggleDetailCheck(div.getElement('#detailattribute' + aryProductPricingAttribteIds[i]), true);
                }
            }
            else {
                for (var i = 0; i < aryCheckElem.length; i++) {
                    toggleDetailCheck($(aryCheckElem[i]), true);
                }
            }


            var quickdiv = div.getChildren()[1].getChildren()[1].getChildren()[1];
            var mooLbl = $("lblProductOptions");
            if (quickdiv) {
                var quickdivchildren = quickdiv.getChildren();
                if (mooLbl) {
                    var bDestroy = true;
                    $('pnlProductOptions').getElements('fieldset').each(function(el) {
                        if (el.getStyle('display') != 'none') {
                            bDestroy = false;
                        }
                    });
                }
            }
            else {
                bDestroy = true;
            }
            if (mooLbl && bDestroy) {
                mooLbl.destroy();
            }
            SetActiveTab('liPricing', 'product-pricing');


        }
    }).send();
    return false;
}


function ShowOrientationImg(elem,src) {
    var img = $('imgOrientation');
    var mooElem = $(elem);
    if (img == null) {
        new Element('img', { 'id': 'imgOrientation' }).inject(document.body);
        img = $('imgOrientation');
    }

    if (src != "") {
        var c = mooElem.getCoordinates();
        img.setProperty('src', '/Content/img/' + src).setStyles({ "display": "block", "position": "absolute", "left": (c.left -40), "top": (c.top + 40) });
    }
    else {
        img.destroy();
    }

}


window.addEvent("domready", function() {
    if ($('gallery-img')) {
        var ZoomZoom = new Zoomer('gallery-img', {
            big: $('gallery-xl').getProperty('href'),
            smooth: 10
        });
    }
});

function SetActiveTab(tab, panel) {
    var mooTab = $(tab);
    var mooPnl = $(panel);
    if (mooTab && mooPnl) {
        $('product-details-nav').getChildren('li').removeClass('active');
        mooTab.toggleClass('active');
        mooPnl.getParent('div').getChildren('div').each(function(el) {
            el.setStyle('display', 'none');
        });
        mooPnl.setStyle('display', 'block');
    }
    return false;
}
