﻿var live_domains = ['www.healthforceminnesota.org', 'healthforceminnesota.org'];

addLoadEvent(checkForPoundAnchors);
addLoadEvent(checkForDev);

//DEV only, disables empty hyperlinks and puts up a message box if clicked
function checkForPoundAnchors() {
    if (!live_domains || live_domains.length <= 0) return;
    for (var i = 0; i < live_domains.length; i++) {
        if (live_domains[i] == window.location.host) return;
    }
    //Grab all hyperlinks
    var AS = document.getElementsByTagName('a');
    for (var i = 0; i < AS.length; i++) {
        //If they don't have a hyperlink set or its just a pound
        if (!AS[i].href || (AS[i].href == '#' || AS[i].href.indexOf('#') == AS[i].href.length - 1) || AS[i].href == '') {
            //See if they already have on onclick handler wired
            if (typeof AS[i].onclick != 'function') {
                //If not, wire an alert message in
                //If the link is text-only send a message about where it will eventually go
                if (AS[i].innerHTML && AS[i].innerHTML.length > 0 && AS[i].innerHTML.indexOf('<') < 0) {
                    eval("AS[i].onclick = function() { sendPoungMsg('" + AS[i].innerHTML + "'); return false; };");
                } else {
                    AS[i].onclick = function() { sendPoungMsg(null); return false; };
                }
            }
        }
    }
}
function sendPoungMsg(msg) {
    if (msg) {
        alert('This link doesn\'t go anywhere yet but will eventually go to:\n\n' + msg);
    } else {
        alert('This link doesn\'t go anywhere yet.');
    }
}
function checkForDev() {
    if (!live_domains || live_domains.length <= 0) return;
    for (var i = 0; i < live_domains.length; i++) {
        if (live_domains[i] == window.location.host) return;
    }
    if (readCookie('no-show-dev') == 'true') return;

    var div = document.createElement('div');
    div.id = 'dev-site';
    div.innerHTML = 'Warning: You are on the development site, click <a href="http://' + live_domains[0] + '" target="_blank" style="color:#FFFFFF;text-decoration:underline !IMPORTANT;font-style:italic;">here</a> to visit the live site';
    setCss(div, 'position:absolute;top:0;left:0;z-index:1000;width:100%;height:35px;text-align:center;color:#FFFFFF;font-family:Arial, Sans-Serif;font-size:20px;padding-top:5px;background-repeat:repeat;background-image:url(data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%01%00%00%00%01%08%06%00%00%00%1F%15%C4%89%00%00%00%19tEXtSoftware%00Adobe%20ImageReadyq%C9e%3C%00%00%00%0FIDATx%DAb%F8%CF%C0%B0%1F%20%C0%00%04%C0%01%BF%88%16%A6%F6%00%00%00%00IEND%AEB%60%82);');
    var div_close = document.createElement('div');
    div_close.id = 'dev-site-close';
    setCss(div_close, 'float:right;margin-right:20px;cursor:pointer;');
    div_close.innerHTML = String.fromCharCode(9746);
    div_close.onclick = function() { document.getElementById('dev-site').style.display = 'none'; if (document.getElementById('dev-site-check').checked) { createCookie('no-show-dev', 'true', 1); } };
    var div_check = document.createElement('div');
    div_check.id = 'dev-site-check-cont';
    setCss(div_check, 'float:right;margin-right:30px;font-size:16px;padding-top:4px;');
    div_check.innerHTML = '<span>Do not show again</span><input type="checkbox" id="dev-site-check" />';
    div.appendChild(div_close);
    div.appendChild(div_check);
    document.getElementsByTagName('body')[0].appendChild(div);
}
function setCss(obj, css) {
    //Most browsers
    obj.setAttribute('style', css);
    //IE7
    if (obj.style.setAttribute) {
        obj.style.setAttribute('cssText', css);
    }
}