﻿var AARF_PDX = window.AARF_PDX || {};

AARF_PDX.nav = {

    init: function() {
        var links = document.getElementsByTagName('a');
        for (var i = 0; i < links.length; i++) {
            if (links[i].className == "downloadLink") {
                links[i].onclick = AARF_PDX.download.open;
            }
        }
    }
}

AARF_PDX.download = {

    so: {},

    NoThanksNormal: function(e) {
        if (e == undefined) {
            e = window.event;
        }
        try {
            if (e) {
                e.srcElement.style.backgroundImage = "url(/Images/download/disagree_btn.png)";
            }
        } catch (ex) { }
    },

    NoThanksHover: function(e) {
        if (e == undefined) {
            e = window.event;
        }
        try {
            if (e) {
                e.srcElement.style.backgroundImage = "url(/Images/download/disagree_btn_hvr.png)";
            }
        } catch (ex) {
        }
    },

    ContinueNormal: function(e) {
        if (e == undefined) {
            e = window.event;
        }
        try {
            if (e) {
                e.srcElement.style.backgroundImage = "url(/Images/download/agree_btn.png)";
            }
        } catch (ex) { }
    },

    ContinueHover: function(e) {
        if (e == undefined) {
            e = window.event;
        }
        try {
            if (e) {
                e.srcElement.style.backgroundImage = "url(/Images/download/agree_hvr.png)";
            }
        } catch (ex) { }
    },

    init: function() {

        AARF_PDX.download.so = new AARF_PDX.screen.screenout('000000', .30, function() { AARF_PDX.download.close(); });
        var download = document.createElement('div');
        download.id = "downloadConfirm";

        //close button
        var closeButton = document.createElement('a');
        closeButton.id = "btnClose";
        closeButton.className = "btnClose";
        closeButton.href = '#';
        closeButton.appendChild(document.createTextNode("close"));
        closeButton.onclick = AARF_PDX.download.close;
        download.appendChild(closeButton);

        //headline
        var headline = document.createElement('h1');
        headline.id = "mainHeadline";
        headline.innerHTML = "Download Microsoft Recite";
        download.appendChild(headline);

        //copy
        var confirmContent = document.createElement('div');
        confirmContent.id = "downloadConfirmContent";
        var p1 = document.createElement('p');
        var p2 = document.createElement('p');
        p1.innerHTML = 'By clicking on "I agree," you agree to the <a href="termsofuse.aspx" target="_blank">Terms of Use</a> and <a href="AppPrivacy.aspx" target="_blank">Privacy Statement</a> governing this service.  This service collects information on a weekly basis about your use of the service as well as the version of the service that you are using and sends that information to Microsoft. Also, Microsoft will notify you when a new version is available. You may incur carrier charges when this information is sent between your device and Microsoft.';
        p2.innerHTML = 'Acceptance of these terms is required to download and use Microsoft Recite';
        confirmContent.appendChild(p1);

        //buttons container
        var buttons = document.createElement('div');
        buttons.id = "downloadConfirmButtons";

        //agree button 
        var agree = document.createElement('a');
        agree.href = '../Base/DownloadAgent.ashx?msi';
        agree.id = 'btnAgree'
        agree.appendChild(document.createTextNode('I agree'));
        agree.onclick = AARF_PDX.download.confirm;
        agree.onmouseover = AARF_PDX.download.ContinueHover;
        agree.onmouseout = AARF_PDX.download.ContinueNormal;
        buttons.appendChild(agree);

        //disagree button
        var disagree = document.createElement('a');
        disagree.href = '#';
        disagree.id = 'btnDisagree'
        disagree.appendChild(document.createTextNode('I disagree'));
        disagree.onclick = AARF_PDX.download.close;
        disagree.onmouseover = AARF_PDX.download.NoThanksHover;
        disagree.onmouseout = AARF_PDX.download.NoThanksNormal;
        buttons.appendChild(disagree);

        //add content
        confirmContent.appendChild(buttons);
        confirmContent.appendChild(p2);
        download.appendChild(confirmContent);
        document.body.appendChild(download);

        //hide carrier select for ie6
        if (AARF_PDX.dom.$('selectCarrier')) {
            AARF_PDX.dom.$('selectCarrier').style.marginLeft = "-9000px";
        }

        AARF_PDX.screen.centerElement('downloadConfirm');
        AARF_PDX.download.so.show();
    },

    open: function(e) {
        AARF_PDX.download.init();
        AARF_PDX.dom.preventReturn(e);
    },

    confirm: function(e) {
        AARF_PDX.dom.$('btnAgree').onclick = null;
        AARF_PDX.dom.$('btnDisagree').onclick = null;
        AARF_PDX.dom.$('downloadConfirmContent').innerHTML = '<h1>Your download will begin shortly.</h1><p><ol><li>Connect your Windows Mobile&reg; phone to your computer using the appropriate cable for your device.</li><li>To start the installation immediately, click Open or Run this program from its current location. In some cases, you may need to save this file to your computer before running it.</li><li>Once the installation begins, follow the instructions provided to install the application to your mobile device.</li><li>Once the installation is complete, the application will start automatically. If the application does not start, go to the Start menu and click on the Microsoft Recite shortcut to start the application.</li><li>The application requires that Microsoft .NET Compact Framework 2.0 or higher is installed on your mobile device.</li></ol></p>';
        SetEvent('download');
    },

    close: function(e) {
        var download = AARF_PDX.dom.$('downloadConfirm');
        if (AARF_PDX.dom.$('btnClose')) AARF_PDX.dom.$('btnClose').onclick = null;
        if (AARF_PDX.dom.$('btnAgree')) AARF_PDX.dom.$('btnAgree').onclick = null;
        if (AARF_PDX.dom.$('btnDisagree')) AARF_PDX.dom.$('btnDisagree').onclick = null;
        document.body.removeChild(download);
        AARF_PDX.download.so.hide();

        //show carrier select for ie6
        if (AARF_PDX.dom.$('selectCarrier')) {
            AARF_PDX.dom.$('selectCarrier').style.marginLeft = "0";
        }

        //prevent jumping to top of page on click
        if (window.event) window.event.returnValue = false;
        if (e) AARF_PDX.dom.preventReturn(e);

    }
}

AARF_PDX.dom.addEventListener(window, 'load', AARF_PDX.nav.init);

