﻿var oshop_iLastWindowHeight = 0;

function oshop_getWindowSize() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    var arRet = new Array();
    arRet.push(myWidth);
    arRet.push(myHeight);
    return arRet;
}

function oshop_resizer() {
    var arWndSize = oshop_getWindowSize();
    var iWndHeight = arWndSize[1];
    if (iWndHeight != oshop_iLastWindowHeight) {
        jQuery('#oshop_mainbox_container').css('height', 'auto');
        jQuery('#oshop_mainbox').css('height', 'auto');
        
        var iHeaderHeight = jQuery('#oshop_header').attr('offsetHeight');
        var iMiddleHeight = jQuery('#oshop_mainbox').attr('offsetHeight');
        var iFooterHeight = jQuery('#oshop_footer').attr('offsetHeight');

        var iTotalHeight = iHeaderHeight + iMiddleHeight + iFooterHeight;

        if (iTotalHeight < iWndHeight) {
            jQuery('#oshop_mainbox').css('height', (iMiddleHeight + (iWndHeight - iTotalHeight)) + 'px');
            jQuery('#oshop_mainbox_container').css('height', (iMiddleHeight + (iWndHeight - iTotalHeight)) + 'px');
        }

        oshop_iLastWindowHeight = iWndHeight;
    }

    setTimeout('oshop_resizer();', 50);
}

jQuery(document).ready(function() {
    oshop_resizer();
});

var oshop_arOfferProductGUIDS = new Array();
var oshop_arOfferCurProductIndex = 0;

function oshop_OfferNext_FadedOut() {
    var strProductGUID = oshop_arOfferProductGUIDS[oshop_arOfferCurProductIndex];
    if (++oshop_arOfferCurProductIndex >= oshop_arOfferProductGUIDS.length) {
        oshop_arOfferCurProductIndex = 0;
    }

    jQuery.ajax({
        cache: false,
        dataType: 'xml',
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            oshop_OfferNext();
        },
        success: function(data, textStatus) {
            jQuery(data).children('*').each(function() {
                jQuery(this).children('product').each(function() {
                    var strName = jQuery(this).children('Name').text();
                    var strShortDescription = jQuery(this).children('ShortDescription').text();
                    var strImageURL = jQuery(this).children('ImageURL').text();
                    var strProductLink = jQuery(this).children('ProductLink').text();
                    var strOldPrice = jQuery(this).children('OldPrice').text();
                    var strNewPrice = jQuery(this).children('NewPrice').text();

                    jQuery('#' + oshop_offer_hlOfferTitle).attr('href', strProductLink).text(strName);
                    if (strImageURL.length > 0) {
                        jQuery('#' + oshop_offer_hlOfferImage).css('display', 'block').attr('href', strProductLink);
                        jQuery('#' + oshop_offer_imgOffer).attr('src', strImageURL);
                    }
                    else {
                        jQuery('#' + oshop_offer_hlOfferImage).css('display', 'none');
                    }

                    if (strShortDescription.indexOf('<br />') > -1) {
                        jQuery('#' + oshop_offer_lblOfferDescription).html(strShortDescription);
                    }
                    else {
                        jQuery('#' + oshop_offer_lblOfferDescription).text(strShortDescription);
                    }
                    jQuery('#' + oshop_offer_lblOfferOldPrice).text(strOldPrice);
                    jQuery('#' + oshop_offer_lblOfferPrice).text(strNewPrice);

                    jQuery('#' + oshop_offer_panelOffer).fadeTo(500, 1.00, oshop_OfferNext_FadedIn);
                });
            });
        },
        timeout: 60000,
        url: oshop_webBasePath + 'OShop/AJAX/GetPromotionProduct.aspx?ProductGUID=' + strProductGUID
    });
}

function oshop_OfferNext_FadedIn() {
    if (jQuery.browser.msie) {
        this.style.removeAttribute('filter');
    }

    window.setTimeout('oshop_OfferNext();', oshop_offer_nextInterval);
}

function oshop_OfferNext() {
    jQuery('#' + oshop_offer_panelOffer).fadeTo(500, 0.01, oshop_OfferNext_FadedOut);
}

var arOnPageLoadActions = new Array();

if (typeof (CKEDITOR) != 'undefined' && CKEDITOR != null) {
    CKEDITOR.editorConfig = function(config) {

        config.toolbar = [
            [ 'Maximize', '-', 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo', '-', 'Find',
                'Replace', '-', 'SelectAll', '-', 'Image', 'Table', 'HorizontalRule', 'SpecialChar', '-', 'Source'],
                '/',
             ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-',
             'TextColor', 'BGColor', '-', 'NumberedList', 'BulletedList', '-', 'RemoveFormat', '-', 'Link', 'Unlink', 'Anchor'],
             '/',
             ['Format', 'Font', 'FontSize', ',', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'Outdent', 'Indent', 'Blockquote', 'CreateDiv']
        ];
    };
}

function getAjaxObject() {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        return new ActiveXObject('Microsoft.XMLHTTP');
    }
    else {
        return null;
    }
}

function printContent() {
    window.print();
}

function stringStartsWith(str, strStart) {
    if (str.substr(0, strStart.length) == strStart) {
        return true;
    }
    else {
        return false;
    }
}

function refreshShoppingCartCadgetUI(iArticleCount, strTotal, strCurrencySign) {
    return false;
}

function refreshShoppingCartCadgetV2() {
    if (typeof (refreshShoppingCartCadgetV2_impl) != 'undefined') {
        refreshShoppingCartCadgetV2_impl();
    }
}


function refreshShoppingCartCadgetV2_real(strArticleCountID, strTotalID, strWebBasePath) {
    var objRequest = getAjaxObject();
    objRequest.open('GET', strWebBasePath + 'OShop/AJAX/GetShoppingCart.aspx?MNO=' + Math.random(), true);
    objRequest.onreadystatechange = function() {
        if (objRequest.readyState == 4) {
            if (objRequest.status == 200) {
                var elemResponse = objRequest.responseXML.getElementsByTagName('response')[0];
                if (elemResponse.getAttribute('success') == '1') {
                    for (var i = 0; i < elemResponse.childNodes.length; i++) {
                        if (elemResponse.childNodes[i].nodeName == 'ShoppingCart') {
                            var elemShoppingCart = elemResponse.childNodes[i];
                            var strTotal = elemShoppingCart.getAttribute('Total');
                            var iArticleCount = elemShoppingCart.getAttribute('ArticleCount');
                            var strCurrencySign = elemShoppingCart.getAttribute('CurrencySign');

                            if (!refreshShoppingCartCadgetUI(iArticleCount, strTotal, strCurrencySign)) {
                                document.getElementById(strTotalID).innerHTML = '';
                                document.getElementById(strTotalID).appendChild(document.createTextNode(strCurrencySign + ' ' + strTotal));
                                document.getElementById(strArticleCountID).innerHTML = '';
                                document.getElementById(strArticleCountID).appendChild(document.createTextNode(iArticleCount));
                            }

                            break;
                        }
                    }
                }
            }
        }
    }

    objRequest.send(null);
}
