﻿//Copyright 2008 Yontoo technology, Inc.

try
{
    var y2InstallBox =
    {
        debugMsg: function(msg) { /*alert(msg);*/ },
        
        isMac: function() {
            try {
                if (navigator.appVersion.toLowerCase().indexOf("mac") > 0) {
                    return true;
                }
            }
            catch (ex) {
            }
            return false;
        },

        isWin: function() {
            try {
                if (navigator.appVersion.toLowerCase().indexOf("windows") > 0) {
                    return true;
                }
            }
            catch (ex) {
            }
            return false;
        },

        isIE: function() {
            try {
                if (window.ActiveXObject)
                    return true;
                else
                    return false;
            }
            catch (ex) {
            }
            return false;
        },

        isIE6: function() {
            return false;
        },

        isFF: function() {
            try {
                var ua = navigator.userAgent.toLowerCase();
                if (ua.indexOf("firefox") != -1)
                    return true;
                else
                    return false;
            }
            catch (ex) {
            }
            return false;
        },

        isFF2: function() {
            try {
                var ua = navigator.userAgent.toLowerCase();
                if (ua.indexOf("firefox/2") != -1)
                    return true;
                else
                    return false;
            }
            catch (ex) {
            }
            return false;
        },

        isSafari: function() {
            try {
                var ua = navigator.userAgent.toLowerCase();
                if (ua.indexOf("safari") != -1)
                    return true;
                else
                    return false;
            }
            catch (ex) {
            }
            return false;
        },

        isChrome: function() {
            try {
                var ua = navigator.userAgent.toLowerCase();
                if (ua.indexOf("chrome") != -1)
                    return true;
                else
                    return false;
            }
            catch (ex) {
            }
            return false;
        },

        isOpera: function() {
            try {
                var ua = navigator.userAgent.toLowerCase();
                if (ua.indexOf("opera") != -1) {
                    return true;
                }
                else
                    return false;
            }
            catch (ex) {
            }
            return false;
        },

        isMSN: function() {
            try {
                var ua = navigator.userAgent.toLowerCase();
                if (ua.indexOf("msn optimized") != -1) {
                    return false;
                }
                if (ua.indexOf("msn") != -1)
                    return true;
                else
                    return false;
            }
            catch (ex) {
            }
            return false;
        },

        isAOL: function() {
            try {
                var ua = navigator.userAgent.toLowerCase();
                if (ua.indexOf("aol") != -1)
                    return true;
                else
                    return false;
            }
            catch (ex) {
            }
            return false;
        },

        isFacebook: function() {
            try {
                if (top.location.href.indexOf("facebook.com") != -1)
                    return true;
                else
                    return false;
            }
            catch (ex) {
                //y2InstallBox.debugMsg(ex);
            }
            return false;
        },

        getInstallId: function() {
            try {
                if (typeof (yontooAPI) == "undefined") {
                    try {
                        if (window.ActiveXObject) {
                            yontooAPI = new ActiveXObject("YontooIEClient.Api");
                        }
                    }
                    catch (ex) {
                    }
                }

                if (typeof (yontooAPI) != "undefined") {
                    var id = yontooAPI.getInstallId();
                    return id;
                }
                else {
                    var idElement = document.getElementById("YontooInstallID");
                    return idElement.textContent;
                }
            }
            catch (ex) {
            }
        },

        showInstallRequired: function() {
            var d2;
            if (y2InstallBox.isIE6()) {
                d2 = document.getElementById("failIE6");
                d2.style.display = "";
            }
            else if (y2InstallBox.isOpera()) {
                d2 = document.getElementById("failOpera");
                d2.style.display = "";
            }
            else if (y2InstallBox.isChrome()) {
                d2 = document.getElementById("failChrome");
                d2.style.display = "";
            }
            else if (y2InstallBox.isSafari()) {
                if (y2InstallBox.isMac()) {
                    d2 = document.getElementById("failSafariMac");
                    d2.style.display = "";
                }
                else if (y2InstallBox.isWin()) {
                    d2 = document.getElementById("failSafariWin");
                    d2.style.display = "";
                }
            }
            else if (y2InstallBox.isMSN()) {
                d2 = document.getElementById("failMSN");
                d2.style.display = "";
            }
            else if (y2InstallBox.isAOL()) {
                d2 = document.getElementById("failAOL");
                d2.style.display = "";
            }
            else if (y2InstallBox.isIE()) {
                d2 = document.getElementById("installRequiredIE");
                d2.style.display = "";
            }
            else if (y2InstallBox.isFF()) {
                d2 = document.getElementById("installRequiredFF");
                d2.style.display = "";
            }
            else {
            }
        },

        checkShowNeedInstall: function() {
            var installId = y2InstallBox.getInstallId();

            if ((installId == null) || (installId.length == 0)) {
                document.getElementById("detectingInstall").style.display = "none";
                y2InstallBox.showInstallRequired();
                document.getElementById("ieInstalled").style.display = "none";
                document.getElementById("ffInstalled").style.display = "none";
            }
            else if (y2InstallBox.isIE()) {
                document.getElementById("detectingInstall").style.display = "none";
                document.getElementById("installRequiredIE").style.display = "none";
                document.getElementById("ieInstalled").style.display = "";
                document.getElementById("ffInstalled").style.display = "none";
                document.getElementById("installRequiredFF").style.display = "none";
            }
            else if (y2InstallBox.isFF()) {
                document.getElementById("detectingInstall").style.display = "none";
                document.getElementById("installRequiredIE").style.display = "none";
                document.getElementById("ieInstalled").style.display = "none";
                document.getElementById("ffInstalled").style.display = "";
                document.getElementById("installRequiredFF").style.display = "none";
            }
        },

        showWhyDoINeedThis: function() {
            window.open("http://www.yontoo.com/WhyDoINeedThis.aspx", "HDIW", "width=400,height=400,toolbar=no,menubar=no,scrollbars=yes,resizable=yes");
        },

        showWhyDoTheyNeedThis: function() {
            window.open("http://www.yontoo.com/WhyDoTheyNeedThis.aspx", "HDIW", "width=400,height=400,toolbar=no,menubar=no,scrollbars=yes,resizable=yes");
        },

        showConfigure: function() {
            window.open("http://www.yontoo.com/EnableLayerApps.aspx", "HDIW", "width=650,height=400,toolbar=no,menubar=no,scrollbars=yes,resizable=yes");
        },

        showTOS: function() {
            window.open("http://www.yontoo.com/TermsOfService.aspx", "HDIW", "width=650,height=400,toolbar=no,menubar=no,scrollbars=yes,resizable=yes");
        },

        inviteFriends: function() {
            ShowInvite();
        },

        showMSNHelp: function() {
            window.open("http://www.yontoo.com/MSNHelp.aspx", "HDIW", "width=400,height=400,toolbar=no,menubar=no,scrollbars=no,resizable=no");
        },

        showAOLHelp: function() {
            window.open("http://www.yontoo.com/AOLHelp.aspx", "HDIW", "width=400,height=400,toolbar=no,menubar=no,scrollbars=no,resizable=no");
        },

        showSafariHelp: function() {
            window.open("http://www.yontoo.com/SafariHelp.aspx", "HDIW", "width=400,height=400,toolbar=no,menubar=no,scrollbars=no,resizable=no");
        },

        showOperaHelp: function() {
            window.open("http://www.yontoo.com/OperaHelp.aspx", "HDIW", "width=400,height=400,toolbar=no,menubar=no,scrollbars=no,resizable=no");
        },

        showChromeHelp: function() {
            window.open("http://www.yontoo.com/ChromeHelp.aspx", "HDIW", "width=400,height=400,toolbar=no,menubar=no,scrollbars=no,resizable=no");
        },

        showIE6Help: function() {
            window.open("http://www.yontoo.com/IE6Help.aspx", "HDIW", "width=400,height=400,toolbar=no,menubar=no,scrollbars=no,resizable=no");
        },

        getFirefox: function() {
            window.open("http://www.firefox.com", "HDIW", "width=400,height=400,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes");
        },

        getIE7: function() {
            window.open("http://www.microsoft.com", "HDIW", "width=400,height=400,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes");
        },

        getQSValue: function(strValue) {
            try {
                url = document.location.href;
                var urlSplit = url.split('/');
                var fileplus = urlSplit[3];
                var fileplusSplit = fileplus.split('?');

                var qs = fileplusSplit[1];
                var qsSplit = qs.split('&');
                for (var n = 0; n < qsSplit.length; n++) {
                    var qsPair = qsSplit[n];
                    var qsPairSplit = qsPair.split('=');
                    if (qsPairSplit[0] == strValue) {
                        return qsPairSplit[1];
                    }
                }
                return "";
            }
            catch (ex) {
                //y2InstallBox.debugMsg(ex);
            }
        },

        startInstall: function() {
            if (y2InstallBox.isWin()) {
                document.location.href = "http://download.yontoo.com/YontooClientSetup.exe", "InstallYontooLayers";
                if (y2InstallBox.isFF()) {
                    setTimeout("top.location.href = 'http://www.pagerage.com/InstallYontooPluginFF.aspx', 'InstallYontooLayers';", 100);
                }
                else {
                    setTimeout("top.location.href = 'http://www.pagerage.com/InstallYontooPluginIE.aspx', 'InstallYontooLayers';", 100);
                }
            }
            else {
                document.location.href = "http://download.yontoo.com/YontooFFClient.xpi", "InstallYontooLayers";
            }
        },

        handleWindowLoad: function() {
            setInterval("y2InstallBox.checkShowNeedInstall();", 2500);
        }
    }
    
    if (window.addEventListener)
        window.addEventListener('load', y2InstallBox.handleWindowLoad, false);
    else if (window.attachEvent)
        window.attachEvent('onload', y2InstallBox.handleWindowLoad);
}
catch(ex) {
    //y2InstallBox.debugMsg(ex);
}
