﻿/// <reference path="jquery-1.5.min.js" />
/// <reference path="define-class.js" />
/// <reference path="Util.js" />
/// <reference path="jquery.blockUI.js" />

function LightBox(jqobj, width, height) {
    var close_link = $('#btnCloseLightBox');

    if (close_link.length == 0) {
        jqobj.append('<a id="btnCloseLightBox" href="javascript:CloseLightBox()" style="position: absolute; top: 5px; right: 5px; font-size: small"">close</a>');
    }

    if (!$.browser.msie || $.browser.version >= 8) $('html, body').css('overflow', 'hidden');
    $.blockUI({
        message: jqobj,
        css: {
            'width': width + 'px',
            'height': height + 'px',
            'cursor': 'default',
            'border': '3px solid #8EB8DE'
        },
        overlayCSS: { cursor: 'default' }
    });

    RepositionBlockMsg();
    if ($.browser.msie && $.browser.version < 8) $(window).scroll();
}

function RepositionBlockMsg() {
    var msg_box = $('.blockMsg');

    if (msg_box.length != 0) {
        var win = $(window);

        if ($.browser.msie && $.browser.version < 7) {
            msg_box.css({
                position: 'absolute',
                left: (win.width() - msg_box.outerWidth()) / 2 + 'px',
                top: (win.height() - msg_box.outerHeight()) / 2 + 'px'
            });
        } else {
            msg_box.fixedPosition({
                left: (win.width() - msg_box.outerWidth()) / 2,
                top: (win.height() - msg_box.outerHeight()) / 2
            });
        }
    }
}

if ($.browser.msie && $.browser.version < 8) $(window).resize(RepositionBlockMsg);

function CloseLightBox() {
    $.unblockUI();
    if (!$.browser.msie || $.browser.version >= 8) $('html, body').css('overflow', 'auto');
    setTimeout(function () {
        $('#btnCloseLightBox').remove();
        if ($.browser.msie && $.browser.version < 8) $(window).resize();
    }, 400);
}

$(document).ready(function () {
    PrepareForLightBoxes();
    FixNavigationTabs();
    FixButtonFadingEffect();
    FixPurchaseButtons();

    /* Make all bullet points on the website squares */
    $('ul').attr('type', 'square');
    $('table tr').attr('valign', 'top');
});

function PrepareForLightBoxes() {
    if (!$.browser.msie || $.browser.version >= 8) {
        $('html, body').css('overflow', 'hidden');
        $('html, body').css('overflow', 'auto');
    }
}

function FixNavigationTabs() {
    if ($.browser.msie && $.browser.version < 9) {
        $('#navigation a').corner('top 10px');
        var colours = ['#00ADEA', '#00A5DE', '#009BD1', '#008EC0', '#0084B2', '#00759E', '#006D93', '006386'];
        var i = 0;

        $('#navigation a .jquery-corner').each(function () {
            $(this).find('div').each(function () {
                $(this).css('border-left-color', colours[i]);
                $(this).css('border-right-color', colours[i + 1]);
            });

            i++;
        });

        if ($.browser.version < 8) {
            $('#navigation').css('padding', '0px');
            $('#main').css('padding-top', '24px');
        }
    }

    if (page != 'na') {
        $('#nav_' + page).css({
            'color': '#FFFFFF',
            'background-color': '#000000',
            'text-decoration': 'underline'
        });
    }
}

function FixButtonFadingEffect() {
    if (!$.browser.msie || $.browser.version >= 9) {
        $('.button').fadeTo(0, 0.85);
        $('.button').hover(
            function () {
                $(this).fadeTo('fast', 1);
            },
            function () {
                $(this).fadeTo('fast', 0.85);
            }
        );
    }
}

function FixPurchaseButtons() {
    $('.buy_software_button').click(function () {
        $.ajax({
            type: 'POST',
            url: '/purchase_info.aspx',
            data: 'name=min-qty&val=true',
            async: false
        });
        window.location = '/purchase.aspx';
    });

    $('.buy_setup_training_button').click(function () {
        $.ajax({
            type: 'POST',
            url: '/purchase_info.aspx',
            data: 'name=min-setup&val=true',
            async: false
        });
        window.location = '/purchase.aspx';
    });

    $('.buy_qanda_training_button').click(function () {
        $.ajax({
            type: 'POST',
            url: '/purchase_info.aspx',
            data: 'name=min-qanda&val=true',
            async: false
        });
        window.location = '/purchase.aspx';
    });

    $('.buy_topic_training_button').click(function () {
        $.ajax({
            type: 'POST',
            url: '/purchase_info.aspx',
            data: 'name=min-topic&val=true',
            async: false
        });
        window.location = '/purchase.aspx';
    });
}

function endsWith(str, end) {
    if (str.length >= end.length) {
        if (str.substring(str.length - end.length) == end) {
            return true;
        }
    }

    return false;
}

function buildURL(url, params) {
    var first = true;
    var new_url = url;

    for (param in params) {
        if (first) {
            top_right_img += '?' + param + '=' + params[param];
            first = false;
        } else {
            top_right_img += '&' + param + '=' + params[param];
        }
    }

    return top_right_img;
}

