﻿var AdobeReaderCookieName = 'AdobeReaderCookie';

function AdobeReaderVersion() {

    var dontAsk = 'false';
    var nameEQ = AdobeReaderCookieName + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) {
            dontAsk = c.substring(nameEQ.length, c.length);
        }
    }

    if (dontAsk == 'true') {
        return;
    }

    var isInstalled = false;
    var version = null;
    if (window.ActiveXObject) {
        var control = null;
        try {
            // AcroPDF.PDF is used by version 7 and later
            control = new ActiveXObject('AcroPDF.PDF');
        } catch (e) {
            // Do nothing
        }
        if (!control) {
            try {
                // PDF.PdfCtrl is used by version 6 and earlier
                control = new ActiveXObject('PDF.PdfCtrl');
            } catch (e) {
                // Do nothing
            }
        }
        if (control) {
            isInstalled = true;
            version = control.GetVersions().split(',');
            version = version[0].split('=');
            version = parseFloat(version[1]);
        }
    } else {
        // Check navigator.plugins for "Adobe Acrobat" or "Adobe PDF Plug-in"*
    }

    return version;
}

function DisplayAlert(panClientID_, overrideClientID_, messageClientID_) {
    var pan = document.getElementById(panClientID_);
    var override = document.getElementById(overrideClientID_);
    var message = document.getElementById(messageClientID_);
    
    var dontAsk = 'false';

    override.style.display = 'none';
    if (AdobeReaderVersion() == null) {
        override.style.display = 'block';
        message.innerHTML = 'To view our site correctly you may need to download the latest version of Adobe Reader.';
    }
    
    try
    {
        var nameEQ = AdobeReaderCookieName + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) {
                dontAsk = c.substring(nameEQ.length, c.length);
            }
        }
        
        if (AdobeReaderVersion() >= 9.3) {
            pan.style.display = 'none';
            return;
        }

        if (dontAsk == 'true') {
            pan.style.display = 'none';
            return;
        }
        
        pan.style.display = 'block';
    }
    catch (err)
    {
        pan.style.display = 'block';
    }
}

function HideAlert() {
    var days = 100;
    var date = new Date();
    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
    var expires = "; expires=" + date.toGMTString();

    document.cookie = AdobeReaderCookieName + "=" + 'true' + expires + "; path=/";
    window.location = window.location;
}