﻿//setSilverlightInstalled
if (Get_Cookie("setSilverlightInstalled") == "false") {
    globalVars.set("silverlightInstalled", false);
} else if (Get_Cookie("setSilverlightInstalled") == "true") {
    globalVars.set("silverlightInstalled", true);
} else {
    globalVars.set("silverlightInstalled", Silverlight.isInstalled("1.0"));
}

var wtTrack = Class.create({
    initialize: function(wtUrl, wtTitle, wtProfil, wtDl) {

        if (typeof dcsMultiTrack === 'function' && globalVars.get("WebtrendsTracking")) {
            dcsMultiTrack('DCS.dcsuri', wtUrl, 'WT.ti', this.cleanTitle(wtTitle), 'WT.sp', wtProfil, 'WT.dl', wtDl);
            if (globalVars.get("WebtrendsTrackingAlert")) {
                alert('DCS.dcsuri: ' + wtUrl + '\nWT.ti: ' + this.cleanTitle(wtTitle) + '\nWT.sp: ' + wtProfil + '\nWT.dl: ' + wtDl);
            }
        }
    },
    cleanTitle: function(input) {
        input = input.stripTags();
        input = input.strip();
        input = input.gsub(' ', '%20');
        input = input.gsub('ä', 'ae');
        input = input.gsub('ü', 'ue');
        input = input.gsub('ö', 'oe');
        input = input.gsub('Ä', 'Ae');
        input = input.gsub('Ü', 'Ue');
        input = input.gsub('Ö', 'Oe');
        input = input.gsub('ß', 'ss');

        while (-1 != input.indexOf("%20%20")) {
            input = input.gsub('%20%20', '%20');
        }
        return input;
    }
});

var convertText = Class.create({
    initialize: function(input) {
        this.input = input;
        this.input = this.input.stripTags();
        this.input = this.input.strip();
        this.input = this.input.gsub(' ', '%20');
        this.input = this.input.gsub('ä', 'ae');
        this.input = this.input.gsub('ü', 'ue');
        this.input = this.input.gsub('ö', 'oe');
        this.input = this.input.gsub('Ä', 'Ae');
        this.input = this.input.gsub('Ü', 'Ue');
        this.input = this.input.gsub('Ö', 'Oe');
        this.input = this.input.gsub('ß', 'ss');
        this.input = this.input.gsub('\n', '%0A');
        this.input = this.input.replace(/\\/g, "/");
        this.input = this.input.gsub('–', '-');
    },
    output: function() {
        return this.input;
    }
});

//Count User Silverlight installed Visits
var countSilverlightInstalled = Class.create({
    initialize: function(cookieValueTitle, cookieExpireTime, wtUrl, wtTitle, wtProfil, wtDl) {
        this.trackSlInstalled = false;
        if (Get_Cookie(cookieValueTitle) == "true:1") {
            new wtTrack(wtUrl, wtTitle, wtProfil, wtDl);
        }
    }
});

var applicationCore = Class.create({
    initialize: function() {
        if (Get_Cookie("cookieActive") == "true") {
            globalVars.set("cookieActive", true);
        } else {
            globalVars.set("cookieActive", false);
        }
        if (Get_Cookie("visitWithSilverlight") == "init") {
            if (globalVars.get("silverlightInstalled") && globalVars.get("cookieActive")) {
                new wtTrack(globalVars.get("globalRelativeUrl") + "vistwithsilverlight", globalVars.get("visitWithSilverlightWtTitle"), globalVars.get("WebtrendsChannel"), 7);
            }
        }
        $$("#overlayMoreLink span")[0].innerHTML = globalVars.get("overlayMoreLinkText");
        if (globalVars.get("silverlightInstalled")) {
            $("silverlightDownload").innerHTML = "";

        } else {
            if (window.location.pathname == globalVars.get("globalRelativeUrl") + "default.aspx" || window.location.pathname == globalVars.get("globalRelativeUrl")) {
                Effect.Pulsate('silverlightDownloadBtn', { pulses: 6, duration: 5, from: 0.2 });
            }
        }
        //find Microsoft Partner Tracking
        if ($("findMicrosoftPartner")) {
            $("findMicrosoftPartner").observe('click', function() {
                new wtTrack($("findMicrosoftPartner").href, globalVars.get("findMicrosoftPartnerWtTitle") + document.title, globalVars.get("WebtrendsChannel"), 1);
            });
        }

        //CreateNavi Hovers
        globalVars.set("navi", new naviCore());
        globalVars.get("navi").setNavi();

        //init Navi Video Overlay Links
        if (window.location.pathname != globalVars.get("globalRelativeUrl") + "default.aspx" || window.location.pathname != globalVars.get("globalRelativeUrl")) {
            var initNaviVideos = new naviVideos();
        }

        //init call overlay
        globalVars.set("createHtmlOverlay", new overlayClass());

        createSilverlightOverlay();

        //image preloader
        img_preload(globalVars.get("globalRelativeUrl") + "_sub/img/homeBtn-hvr.gif", globalVars.get("globalRelativeUrl") + "_sub/img/navi" + globalVars.get("NumberOfVideos") + "/navi-1-hvr.jpg", globalVars.get("globalRelativeUrl") + "_sub/img/navi" + globalVars.get("NumberOfVideos") + "/navi-2-hvr.jpg", globalVars.get("globalRelativeUrl") + "_sub/img/navi" + globalVars.get("NumberOfVideos") + "/navi-3-hvr.jpg", globalVars.get("globalRelativeUrl") + "_sub/img/navi" + globalVars.get("NumberOfVideos") + "/navi-1-hvr2.jpg", globalVars.get("globalRelativeUrl") + "_sub/img/navi" + globalVars.get("NumberOfVideos") + "/navi-2-hvr2.jpg", globalVars.get("globalRelativeUrl") + "_sub/img/navi" + globalVars.get("NumberOfVideos") + "/navi-3-hvr2.jpg", globalVars.get("globalRelativeUrl") + "_sub/img/navi" + globalVars.get("NumberOfVideos") + "/subnaviBg.jpg");
        if (globalVars.get("NumberOfVideos") == 4) {
            img_preload(globalVars.get("globalRelativeUrl") + "_sub/img/navi" + globalVars.get("NumberOfVideos") + "/navi-4-hvr.jpg", globalVars.get("globalRelativeUrl") + "_sub/img/navi" + globalVars.get("NumberOfVideos") + "/navi-4-hvr2.jpg");
        }
        //WT
        var callcountSilverlightInstalled = new countSilverlightInstalled("silverlightInstalled", globalVars.get("globalCookieExpireDate"), globalVars.get("globalRelativeUrl") + "vistwithsilverlight", globalVars.get("visitWithSilverlightWtTitle"), globalVars.get("WebtrendsChannel"), 1);

        if ($("tellAFriend")) {
            $("tellAFriend").observe('click', function() {
                new wtTrack(window.location.pathname + "?tellafriend=true", globalVars.get("tellAFriendWtTitlePrefix") + document.title, globalVars.get("WebtrendsChannel"), 1);
            });
        }
        if ($("writeUs")) {
            $("writeUs").observe('click', function() {
                new wtTrack(window.location.pathname + "?writeus=true", globalVars.get("writeUsWtTitlePrefix") + document.title, globalVars.get("WebtrendsChannel"), 1);
            });
        }
        if ($("silverlightDownloadBtn")) {
            $("silverlightDownloadBtn").observe('click', function() { new wtTrack(globalVars.get("globalRelativeUrl") + "silverlightplugindownload", globalVars.get("silverlightPluginDownloadsWtTitle"), globalVars.get("WebtrendsChannel"), 1); });
        }

        //wmp
        //initialize WmpStatus Tracking
        if (!globalVars.get("silverlightInstalled") && -1 != navigator.userAgent.indexOf("MSIE")) {
            globalVars.set("startWmpStatusTracking", new wmpStatusWtTrack());
        }
        try {
            $("wmpPlayer").attachEvent("PlayStateChange", function(newState) {

                switch (newState) {
                    case 8:
                        for (i = 1; i < globalVars.get("NumberOfVideos") + 1; i++) {
                            if ("http://" + window.location.host + globalVars.get("vid" + i + "UrlWmp") == wmpPlayer.url) {
                                globalVars.set("activeVidId", "vid" + i);
                            }
                        }
                        Effect.Pulsate('overlayMoreLink', { pulses: 2, duration: 1, from: 0 });
                        if (globalVars.get("wmpCurrentPositionStatus100")) {
                            new wtTrack(globalVars.get(globalVars.get("activeVidId") + "UrlWmp")+globalVars.get("wmpVideoUrlSuffix100"), globalVars.get("wmpVideo100WtTitlePrefix") + globalVars.get(globalVars.get("activeVidId") + "Title"), globalVars.get("WebtrendsChannel"), 7);
                            globalVars.set("wmpCurrentPositionStatus100", false);
                        }
                        break;
                    case 3:
                        break;
                    default:
                        break;
                }

                if (newState == 3) {
                    globalVars.get("startWmpStatusTracking").startTimer();
                } else {
                    globalVars.get("startWmpStatusTracking").stopTimer();
                }


            } .bind(this));


        } catch (e) { }
    }
});

var wmpStatusWtTrack = Class.create({
    initialize: function() {
        this.wmpTimer;
    },
    startTimer: function() {
        this.wmpTimer = new PeriodicalExecuter(function(pe) {
            if (globalVars.get("wmpCurrentPositionStatus25") && ($("wmpPlayer").controls.currentPosition / $("wmpPlayer").currentMedia.duration) > 0.25) {
                globalVars.set("wmpCurrentPositionStatus25", false);
                new wtTrack(globalVars.get(globalVars.get("activeVidId") + "UrlWmp")+globalVars.get("wmpVideoUrlSuffix25"), globalVars.get('wmpVideo25WtTitlePrefix') + globalVars.get(globalVars.get("activeVidId") + "Title"), globalVars.get("WebtrendsChannel"), 7);
            }
            if (globalVars.get("wmpCurrentPositionStatus50") && ($("wmpPlayer").controls.currentPosition / $("wmpPlayer").currentMedia.duration) > 0.50) {
                globalVars.set("wmpCurrentPositionStatus50", false);
                new wtTrack(globalVars.get(globalVars.get("activeVidId") + "UrlWmp") + globalVars.get("wmpVideoUrlSuffix50"), globalVars.get('wmpVideo50WtTitlePrefix') + globalVars.get(globalVars.get("activeVidId") + "Title"), globalVars.get("WebtrendsChannel"), 7);
            }
            if (globalVars.get("wmpCurrentPositionStatus75") && ($("wmpPlayer").controls.currentPosition / $("wmpPlayer").currentMedia.duration) > 0.75) {
                globalVars.set("wmpCurrentPositionStatus75", false);
                new wtTrack(globalVars.get(globalVars.get("activeVidId") + "UrlWmp") + globalVars.get("wmpVideoUrlSuffix75"), globalVars.get('wmpVideo75WtTitlePrefix') + globalVars.get(globalVars.get("activeVidId") + "Title"), globalVars.get("WebtrendsChannel"), 7);
            }
        }, 5);
    },
    stopTimer: function() {
        try {
            this.wmpTimer.stop();

        } catch (e) {

        }
    }
});

var naviCore = Class.create({
    initialize: function() {
        this.allNavLinks = $$('#navi li a');
    },
    setNavi: function(event) {
        if (event == undefined) {

        } else {
            this.allNavLinks = event.element();
        }
        for (var i = 0; i < this.allNavLinks.size(); i++) {
            //navi
            if (window.location.pathname == this.allNavLinks[i].readAttribute('href')) {
                if (this.allNavLinks[i].id.startsWith("navi-")) {
                    this.allNavLinks[i].setStyle({ backgroundImage: "url(" + globalVars.get("globalRelativeUrl") + "_sub/img/navi" + globalVars.get("NumberOfVideos") + "/" + this.allNavLinks[i].id + "-hvr.jpg)" });
                }
                //subnavi
                if (this.allNavLinks[i].id == "") {
                    this.allNavLinks[i].up('li').up('li').down('a').setStyle({ backgroundImage: "url(" + globalVars.get("globalRelativeUrl") + "_sub/img/navi" + globalVars.get("NumberOfVideos") + "/" + this.allNavLinks[i].up('li').up('li').down('a').id + "-hvr.jpg)" });
                    this.allNavLinks[i].setStyle({ backgroundColor: "#dfe2e4", "borderTop": "solid 1px #626e76", "borderBottom": "solid 1px #626e76" });
                }
            } else {
                if (this.allNavLinks[i].id.length == 6) {
                    this.allNavLinks[i].observe('mouseover', this.setNaviHover);
                    this.allNavLinks[i].observe('mouseout', this.setNaviNormal);
                }
                if (this.allNavLinks[i].id.startsWith("navi-")) {
                    this.allNavLinks[i].setStyle({ backgroundImage: "url(" + globalVars.get("globalRelativeUrl") + "_sub/img/navi" + globalVars.get("NumberOfVideos") + "/" + this.allNavLinks[i].id + ".jpg)" });
                }
            }
        }
    },
    setNaviHover: function(event) {
        var element = event.element();
        if (element.id.startsWith("navi-")) {
            element.setStyle({ backgroundImage: "url(" + globalVars.get("globalRelativeUrl") + "_sub/img/navi" + globalVars.get("NumberOfVideos") + "/" + element.id + "-hvr.jpg)" });
        }
    },
    setNaviNormal: function(event) {
        var element = event.element();
        if (window.location.pathname == element.readAttribute('href')) {
            if (element.id.startsWith("navi-")) {
                element.setStyle({ backgroundImage: "url(" + globalVars.get("globalRelativeUrl") + "_sub/img/navi" + globalVars.get("NumberOfVideos") + "/" + element.id + "-hvr.jpg)" });
            }
        } else {
            flag = false;
            element.next('ul').childElements().each(function(s) {
                if (s.down('a').href == window.location.href) {
                    flag = true;
                }
            });
            if (flag) {
                element.setStyle({ backgroundImage: "url(" + globalVars.get("globalRelativeUrl") + "_sub/img/navi" + globalVars.get("NumberOfVideos") + "/" + element.id + "-hvr.jpg)" });
            } else {
            element.setStyle({ backgroundImage: "url(" + globalVars.get("globalRelativeUrl") + "_sub/img/navi" + globalVars.get("NumberOfVideos") + "/" + element.id + ".jpg)" });
            }
        }
    }
});
// Call Navigation Videos
var naviVideos = Class.create({
    initialize: function() {
        if (globalVars.get("silverlightInstalled")) {
            setLinkTargetToSelf("naviOverlay-vid");
            for (i = 1; i < globalVars.get("NumberOfVideos") + 1; i++) {

                $("naviOverlay-vid" + i).observe('click', this.openOverlaySl);
                $("naviOverlay-vid" + i).observe('mouseover', this.callVidSlAniMouseOver);
                $("naviOverlay-vid" + i).observe('mouseout', this.callVidSlAniMouseOut);
                //$("naviOverlay-vid" + i).down('b').observe('mouseout', this.callVidSlAniMouseOutB);
                $("naviOverlay-vid" + i).down('b').observe('mouseover', this.callVidSlAniMouseOverB);
            }
        } else {
            if (-1 != navigator.userAgent.indexOf("MSIE")) {
                setLinkTargetToSelf("naviOverlay-vid");
                for (i = 1; i < globalVars.get("NumberOfVideos") + 1; i++) {
                    $("naviOverlay-vid" + i).observe('click', this.openOverlayWmp);
                }
            } else {
                for (i = 1; i < globalVars.get("NumberOfVideos") + 1; i++) {
                    $("naviOverlay-vid" + i).observe('click', this.vidExtClick);
                }
            }
        }
    },
    callVidSlAniMouseOver: function(event) {
        var element = event.element();
        try {
            globalVars.get("callAniMouseEnter-" + element.id.split('-')[1])();
        } catch (e) { }
    },
    callVidSlAniMouseOut: function(event) {
        var element = event.element();
        try {
            globalVars.get("callAniMouseLeave-" + element.id.split('-')[1])();
        } catch (e) { }
    },
    callVidSlAniMouseOverB: function(event) {
        var element = event.element().up('a');
        try {
            globalVars.get("callAniMouseEnter-" + element.id.split('-')[1])();
        } catch (e) { }
    },
    callVidSlAniMouseOutB: function(event) {
        var element = event.element().up('a');
        try {
            globalVars.get("callAniMouseLeave-" + element.id.split('-')[1])();
        } catch (e) { }
    },
    openOverlaySl: function(event) {
        var element = event.element();
        var vidId = element.id.split("-")[1];
        $("mediaPlayerContainer").setStyle({ display: "none" });
        globalVars.get("createHtmlOverlay").show();
        globalVars.set("tmpOverlayVidSource", globalVars.get(vidId + "UrlSl"));
        $("SilverlightControlOverlay").content.findName("vidMedia").Source = globalVars.get(vidId + "UrlSl");
        globalVars.get("callOverlayVidPlay")();
        if (window.location.pathname == globalVars.get(vidId + "MoreBtnTopic")) {
            $("overlayMoreLink").writeAttribute("href", globalVars.get(vidId + "MoreBtnDetail"));
        } else {
            $("overlayMoreLink").writeAttribute("href", globalVars.get(vidId + "MoreBtnTopic"));
        }
        new wtTrack(globalVars.get(vidId + "UrlSl")+globalVars.get("slVideoUrlSuffix0"), globalVars.get("slVideoStartedWtTitlePrefix") + globalVars.get(vidId + "Title"), globalVars.get("WebtrendsChannel"), 7);
    },
    openOverlayWmp: function(event) {

        var element = event.element();
        vidId = element.id.split("-")[1];
        globalVars.get("createHtmlOverlay").show();
        $("overlayMoreLink").writeAttribute("href", globalVars.get(vidId + "MoreBtnTopic"));

        wmpPlayer.url = globalVars.get(vidId + "UrlWmp");
        wmpPlayer.controls.play();
        if (window.location.pathname == globalVars.get(vidId + "MoreBtnTopic")) {
            $("overlayMoreLink").writeAttribute("href", globalVars.get(vidId + "MoreBtnDetail"));
        } else {
            $("overlayMoreLink").writeAttribute("href", globalVars.get(vidId + "MoreBtnTopic"));
        }
        new wtTrack(globalVars.get(vidId + "UrlWmp") + globalVars.get("wmpVideoUrlSuffix0"), globalVars.get('wmpVideoStartedWtTitlePrefix') + globalVars.get(vidId + "Title"), globalVars.get("WebtrendsChannel"), 7);
    },
    vidExtClick: function(event) {
        var element = event.element();
        new wtTrack(globalVars.get(element.id.split("-")[1] + "UrlExt") + globalVars.get("extVideoUrlSuffix0"), globalVars.get('extVideoStartedWtTitlePrefix') + globalVars.get(element.id.split("-")[1] + "Title"), globalVars.get("WebtrendsChannel"), 7);
    }
});
var overlayClass = Class.create({
    initialize: function() {
        $("closeOverlayBtn").observe('click', this.close);
    },
    getTmpLeft: function() {
        return this.tmpLeft;
    },
    close: function() {
        $("overlayVideoPlayerContainer").setStyle({ "display": "none" });
        $("overlayVidPlayer").setStyle({ "left": "-9999px" });
        if (globalVars.get("silverlightInstalled")) {
            globalVars.get("callOverlayVidStop")();
        } else if (-1 != navigator.userAgent.indexOf("MSIE")) {
            wmpPlayer.controls.stop();
            globalVars.set("wmpCurrentPositionStatus25", true);
            globalVars.set("wmpCurrentPositionStatus50", true);
            globalVars.set("wmpCurrentPositionStatus75", true);
            globalVars.set("wmpCurrentPositionStatus100", true);
        }
    }
    ,
    show: function(vidId) {
        //set Size and position
        $("overlayVideoPlayerContainer").setStyle({ "width": ($("mainMiddleCont").getDimensions().width - 20) + "px", "height": ($("mainMiddleCont").getDimensions().height) + "px", "left": ($("mainMiddleCont").positionedOffset().left + 8) + "px", "top": $("mainMiddleCont").positionedOffset().top + "px", display: "block" });
        tmpWidth = document.viewport.getWidth() + "px";
        tmpHeight = new getDocumentSize().getHeight() + "px";
        tmpContainerWidth = parseInt($("overlayVidPlayer").getStyle('width').replace(/px/, "")) / 2;
        tmpContainerHeight = parseInt($("overlayVidPlayer").getStyle('height').replace(/px/, "")) / 1.5;
        this.tmpLeft = ((document.viewport.getWidth() / 2) - tmpContainerWidth);
        this.top = ((document.viewport.getHeight() / 2) + document.viewport.getScrollOffsets()[1] - tmpContainerHeight) + "px";
        this.left = this.tmpLeft + "px";
        $("overlayVidPlayer").setStyle({ display: "block", "left": this.left, "top": this.top });
    }
});

var getDocumentSize = Class.create({
    initialize: function() {
        if (window.innerHeight && window.scrollMaxY) // Firefox
        {
            pageWidth = window.innerWidth + window.scrollMaxX;
            pageHeight = window.innerHeight + window.scrollMaxY;
        }
        else if (document.body.scrollHeight > document.body.offsetHeight) // all but Explorer Mac
        {
            pageWidth = document.body.scrollWidth;
            pageHeight = document.body.scrollHeight;
        }
        else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
        { pageWidth = document.body.offsetWidth + document.body.offsetLeft; pageHeight = document.body.offsetHeight + document.body.offsetTop; }
        this.pageWidth = pageWidth;
        this.pageHeight = pageHeight;

    },
    getHeight: function() {
        return this.pageHeight;
    },
    getWidth: function() {
        return this.pageWidth;
    },
    getSize: function() {
        return { width: this.pageWidth, height: this.pageHeight };
    }
});

function setLinkTargetToSelf(id) {
    for (i = 1; i < globalVars.get("NumberOfVideos") + 1; i++) {
        $(id + i).writeAttribute("target", "_self");
        $(id + i).writeAttribute("href", "javascript:void(0);");
    }
}

Event.observe(window, 'load', function() {
    var applicationCoreCall = new applicationCore();
});



function img_preload() {
    document.PL = new Array();

    if (document.images) {
        for (var i = 0; i < img_preload.arguments.length; i++) {
            document.PL[i] = new Image();
            document.PL[i].src = img_preload.arguments[i];
        }
    }
    return true;
}

function createSilverlightHero() {
    var scene = new slmenu.Page();
    Silverlight.createObjectEx({
        source: globalVars.get("heroVidXamlUrl"),
        parentElement: document.getElementById("silverlightControlHost"),
        id: "SilverlightControl",
        properties: {
            width: "100%",
            height: "100%",
            version: "1.0",
            isWindowless: "true"

        },
        events: {
            onLoad: Silverlight.createDelegate(scene, scene.handleLoad),
            onError: function(sender, args) {
                var errorDiv = document.getElementById("errorLocation");
                if (errorDiv != null) {
                    var errorText = args.errorType + "- " + args.errorMessage;

                    if (args.ErrorType == "ParserError") {
                        errorText += "<br>File: " + args.xamlFile;
                        errorText += ", line " + args.lineNumber;
                        errorText += " character " + args.charPosition;
                    }
                    else if (args.ErrorType == "RuntimeError") {
                        errorText += "<br>line " + args.lineNumber;
                        errorText += " character " + args.charPosition;
                    }
                    errorDiv.innerHTML = errorText;
                }
            }
        }
    });
}

function createSilverlightMiniVid(vidId) {
    var scene = new miniplayer.Page();
    Silverlight.createObjectEx({
        source: globalVars.get("globalRelativeUrl") + "_global/component/miniplayer/Page.xaml",
        parentElement: document.getElementById("silverlightControlHostMini" + vidId),
        id: "SilverlightControl" + vidId,
        initParams: vidId,
        properties: {
            width: "100%",
            height: "100%",
            version: "1.0",
            isWindowless: "true"
        },

        events: {
            onLoad: Silverlight.createDelegate(scene, scene.handleLoad),
            onError: function(sender, args) {
                var errorDiv = document.getElementById("errorLocation");
                if (errorDiv != null) {
                    var errorText = args.errorType + "- " + args.errorMessage;

                    if (args.ErrorType == "ParserError") {
                        errorText += "<br>File: " + args.xamlFile;
                        errorText += ", line " + args.lineNumber;
                        errorText += " character " + args.charPosition;
                    }
                    else if (args.ErrorType == "RuntimeError") {
                        errorText += "<br>line " + args.lineNumber;
                        errorText += " character " + args.charPosition;
                    }
                    errorDiv.innerHTML = errorText;
                }
            }
        }
    });
}

function createSilverlightOverlay() {
    var sceneOverlay = new overlayVid.Page();
    Silverlight.createObjectEx({
        source: globalVars.get("globalRelativeUrl") + "_global/component/overlayVid/Page.xaml",
        parentElement: document.getElementById("silverlightControlHostOverlay"),
        id: "SilverlightControlOverlay",
        properties: {
            width: "100%",
            height: "100%",
            version: "1.0"
        },
        events: {
            onLoad: Silverlight.createDelegate(sceneOverlay, sceneOverlay.handleLoad),
            onError: function(sender, args) {
                var errorDiv = document.getElementById("errorLocation");
                if (errorDiv != null) {
                    var errorText = args.errorType + "- " + args.errorMessage;

                    if (args.ErrorType == "ParserError") {
                        errorText += "<br>File: " + args.xamlFile;
                        errorText += ", line " + args.lineNumber;
                        errorText += " character " + args.charPosition;
                    }
                    else if (args.ErrorType == "RuntimeError") {
                        errorText += "<br>line " + args.lineNumber;
                        errorText += " character " + args.charPosition;
                    }
                    errorDiv.innerHTML = errorText;
                }
            }
        }
    });
}

function getGETParameter(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
}

function Set_Cookie(name, value, expires, path, domain, secure) {
    var today = new Date();
    today.setTime(today.getTime());
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + escape(value) +
((expires) ? ";expires=" + expires_date.toGMTString() : "") +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
((secure) ? ";secure" : "");
}


function Get_Cookie(check_name) {
    var a_all_cookies = document.cookie.split(';');
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false;

    for (i = 0; i < a_all_cookies.length; i++) {
        a_temp_cookie = a_all_cookies[i].split('=');
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
        if (cookie_name == check_name) {
            b_cookie_found = true;
            if (a_temp_cookie.length > 1) {
                cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
            }
            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if (!b_cookie_found) {
        return null;
    }
}
function Delete_Cookie(name, path, domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


if (!window.Silverlight)
    Silverlight = {};

Silverlight.createDelegate = function(instance, method) {
    return function() {
        return method.apply(instance, arguments);
    }
}