﻿
/*
Makes necessary style modifications to the main content div
so that it best matches the currently visible client area
*/
/*<![CDATA[*/
function MoveAndResizeMainContentToFitClientArea() {
    var defaultMainContentLeftOffset = 25;
    var mainContentLeftShadowWidth = 20;
    
    var divMainContentId = 'MainContentMainWrapper';

    var divMainContent = document.getElementById(divMainContentId);

    if (divMainContent == null)
        return;

    var windowHeight = 0;
    var windowWidth = 0;

    if (typeof (window.innerWidth) == 'number') {
        windowHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        windowHeight = document.documentElement.clientHeight;
    }

    if (typeof (window.innerWidth) == 'number') {
        windowWidth = window.innerWidth;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        windowWidth = document.documentElement.clientWidth;
    }

    if (divMainContent.clientWidth + defaultMainContentLeftOffset <= windowWidth) {
        divMainContent.style.left = defaultMainContentLeftOffset + 'px';
        return;
    }

    var newMainContentLeftOffset = windowWidth - divMainContent.clientWidth;
    newMainContentLeftOffset = newMainContentLeftOffset < -mainContentLeftShadowWidth ? -mainContentLeftShadowWidth : newMainContentLeftOffset;

    divMainContent.style.left = newMainContentLeftOffset + 'px';
}

/*
This method will make the Offers box and the Request products box have the same height.
*/
$(document).ready(function() {
    var offerBoxHeight = $("#OfferTableContainer").height();
    var productsBoxHeight = $("#ProductRequestTableContainer").height();

    if (offerBoxHeight > 0 && productsBoxHeight > 0) {
        if (offerBoxHeight > productsBoxHeight)
            $("#ProductRequestTableContainer").height(offerBoxHeight);
        else if (productsBoxHeight > offerBoxHeight)
            $("#OfferTableContainer").height(productsBoxHeight);
    }

    // enable the hover on Knoblinks (both Hyperlink & LinkButton)
    $(".KnobLinkMainPlaceholder").live('mouseover', function() {
        $(this).children('.HyperlinkKnobHolder').children('.HyperlinkKnobClass').addClass('Active');
        $(this).children('.Text').addClass('Active');
        $(this).parent('a').addClass('Active');
    });

    $(".KnobLinkMainPlaceholder").live('mouseout', function() {
    $(this).children('.HyperlinkKnobHolder').children('.HyperlinkKnobClass').removeClass('Active');
        $(this).children('.Text').removeClass('Active');
        $(this).parent('a').removeClass('Active');
    });
});

window.onload = function() {
    MoveAndResizeMainContentToFitClientArea();
}

window.onresize = function() {
    MoveAndResizeMainContentToFitClientArea();
}

function ToggleLightbox(visible) {
    var fullScreenCover = document.getElementById('FullScreenCover');
    if (fullScreenCover == null)
        return;

    fullScreenCover.style.visibility = visible == true ? 'visible' : 'hidden';
    fullScreenCover.style.display = visible == true ? '' : 'none';

    var fullScreenProgressCover = document.getElementById('FullScreenCoverProgress');
    if (fullScreenProgressCover != null && visible == false) {
        fullScreenProgressCover.style.visibility = 'hidden';
    }
    
    ToggleEmbedAndObjectVisibility(visible);

    if (typeof ToggleLightboxIE6Specific == 'function') {
        ToggleLightboxIE6Specific(visible);
    }
}

/*Toggles Embed And Object Visibility*/
function ToggleEmbedAndObjectVisibility(isVisible) {
    var dropDownArray = document.getElementsByTagName('embed');

    if (dropDownArray != null) {
        for (var index = 0; index < dropDownArray.length; index++) {
            dropDownArray.item(index).style.visibility = isVisible == false ? 'hidden' : 'visible';
        }
    }

    var dropDownArray = document.getElementsByTagName('object');
    if (dropDownArray != null) {
        for (var index = 0; index < dropDownArray.length; index++) {
            if (dropDownArray.item(index).type != "application/x-silverlight") {
                dropDownArray.item(index).style.visibility = isVisible == false ? 'hidden' : 'visible';
            }
            
        }
    }
}

function SetupDTP(clientId, language, initDate) {

    $.datepicker.setDefaults($.datepicker.regional[language]);
    
    $("#" + clientId).datepicker({
        defaultDate: initDate,
        onSelect: function(dateText, inst) {
            $(this).val(dateText);
        },
        direction: 'up'
    });
}


function IsBrowserIe7() {
    if (navigator.appName != "Microsoft Internet Explorer")
        return false;

    if (navigator.appVersion.indexOf("MSIE 7") == -1)
        return false;

    return true;
}
//////////////////////////////////////////////////////////////////
//Checks to see if the correct Silverlight version is installed
//NOTE:This was copied from: http://code.msdn.microsoft.com/silverlightjs
//We should use this file to create more advanced Silverlight installation and instantiation experiences. 
//////////////////////////////////////////////////////////////////
SilverlightIsInstalled = function(version) {
    if (version == undefined)
        version = null;

    var isVersionSupported = false;
    var container = null;

    try {
        var control = null;
        var tryNS = false;

        if (window.ActiveXObject) {
            try {
                control = new ActiveXObject('AgControl.AgControl');
                if (version === null) {
                    isVersionSupported = true;
                }
                else if (control.IsVersionSupported(version)) {
                    isVersionSupported = true;
                }
                control = null;
            }
            catch (e) {
                tryNS = true;
            }
        }
        else {
            tryNS = true;
        }
        if (tryNS) {
            var plugin = navigator.plugins["Silverlight Plug-In"];
            if (plugin) {
                if (version === null) {
                    isVersionSupported = true;
                }
                else {
                    var actualVer = plugin.description;
                    if (actualVer === "1.0.30226.2")
                        actualVer = "2.0.30226.2";
                    var actualVerArray = actualVer.split(".");
                    while (actualVerArray.length > 3) {
                        actualVerArray.pop();
                    }
                    while (actualVerArray.length < 4) {
                        actualVerArray.push(0);
                    }
                    var reqVerArray = version.split(".");
                    while (reqVerArray.length > 4) {
                        reqVerArray.pop();
                    }

                    var requiredVersionPart;
                    var actualVersionPart;
                    var index = 0;


                    do {
                        requiredVersionPart = parseInt(reqVerArray[index]);
                        actualVersionPart = parseInt(actualVerArray[index]);
                        index++;
                    }
                    while (index < reqVerArray.length && requiredVersionPart === actualVersionPart);

                    if (requiredVersionPart <= actualVersionPart && !isNaN(requiredVersionPart)) {
                        isVersionSupported = true;
                    }
                }
            }
        }
    }
    catch (e) {
        isVersionSupported = false;
    }

    return isVersionSupported;
};