﻿//<script>
function ad_click(id, url, target, spaceid, ext) {
    if (url != '' && url != 'none') {
        if (url.indexOf('mailto:') != -1) {	// email link?
            document.location.href = url;
        } else {	// normal link
            if (target == '_blank') {
                window.open('adjump.asp?id=' + id + '&url=' + url + '&spaceid=' + spaceid, 'adjump');
            } else {
                document.location.href = 'adjump.asp?id=' + id + '&url=' + url + '&spaceid=' + spaceid;
            }
        }
    }
}
var now = new Date();
fixDate(now);
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);

//***************** survey functions ******************
function _vote(fid) {
    var frm = document.forms("survey" + fid);
    var voteid = null;
    for (var i = 0; i < frm.item("vote").length; i++) {
        if (frm.item("vote").item(i).checked) {
            voteid = frm.item("vote").item(i).value;
        }
    }
    if (voteid == null) {
        alert("please choose a voting option");
        return (false)
    } else {
        if (getCookie('v' + fid) == 1) {
            alert('Voting is only allowed once');
            return (false)
        }
        setCookie('v' + fid, 1, now);
        var mywin = window.open('dynamic/survey/survey_results.asp?sid=' + fid + '&vid=' + voteid, 'vote', 'width=490,height=300,status=no,toolbar=no,menubar=no,location=no');
        mywin.focus();
    }
}

function _vote_results(fid) {
    var mywin = window.open('dynamic/survey/survey_results.asp?sid=' + fid, 'vote', 'width=490,height=300,status=no,toolbar=no,menubar=no,location=no');
}

//***************** cookie functions ******************
function setCookie(name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
    document.cookie = curCookie;
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else
        begin += 2;
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
        end = dc.length;
    return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function fixDate(date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}

function _preview(img, alt) {
    var x = window.open('preview_image.aspx?img=' + img + '&alt=' + alt, 'imgPreview', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, copyhistory=no');
}

// open talkback pannel
function openTB(oLink, tbId) {
    var tbDiv = document.getElementById('divTB' + tbId);
    if (tbDiv) {
        if (tbDiv.style.display == 'none') {
            tbDiv.style.display = '';
        } else {
            tbDiv.style.display = 'none';
        }
    }
}

// post talkback
function postTB(id) {
    if (document.getElementById("articleid")) {
        var aId = document.getElementById("articleid").value;
    } else {
        aId = 0;
    }
    window.open('talkback_post.asp?id=' + aId, 'postTB', 'width=350,height=260,toolbar=no, location=no, directories=no, status=yes, scrollbars=no');
}

function checkTB(frm) {
    if (frm.username.value == '' || frm.title.value == '') {
        alert("please enter name and title");
        return (false);
    }
    if (frm.user_email_display.checked) {
        if (frm.email.value == '') {
            alert("please enter a valid email address");
            return (false);
        }
    }
    return (true);
}

// Disable right click script on images - by Darren Mackintosh
function disableclick(e) {
    if (document.all) {
        if (event.button == 2 || event.button == 3) {
            if (event.srcElement.tagName == "IMG") {
                alert(clickmessage);
                return false;
            }
        }
    }
    else if (document.layers) {
        if (e.which == 3) {
            alert(clickmessage);
            return false;
        }
    }
    else if (document.getElementById) {
        if (e.which == 3 && e.target.tagName == "IMG") {
            alert(clickmessage)
            return false
        }
    }
}

function associateimages() {
    for (i = 0; i < document.images.length; i++)
        document.images[i].onmousedown = disableclick;
}

function popup_open(url, title, width, height, centered) {
    if (typeof (centered) == 'undefined') centered = false;
    if (typeof (title) == 'undefined') title = 'popup';
    var x;
    if (centered == true) {
        x = window.open(url, title, 'status=no,toolbar=no,menubar=no,location=no, scrollbars=yes,top=' + ((screen.height - height) / 2) + ',left=' + ((screen.width - width) / 2) + ', width=' + width + ', height=' + height,false);
    }
    else {
        x = window.open(url, title, 'status=no,toolbar=no,menubar=no,location=no, scrollbars=yes, width=' + width + ', height=' + height, false);
    }
    if (x == null) {
        alert('You must disable your popup blocker to use that function');
    }
    return false;
}

// ----------------------------------------------------------------------
// language selection
// this function will add setLanguage=x to the url, removing any previous
// params of this kind.
// ----------------------------------------------------------------------
function user_setLanguage(lang) {
    setCookie('user_language', lang, now);
    var sHref = document.location.href;
    if (sHref.indexOf("?") > -1) {
        var sQueryString = sHref.substr(sHref.indexOf("?")).toLowerCase();
        sHref = sHref.substring(0, sHref.indexOf("?"));
        sQueryString = sQueryString.replace(/[?|&]setlanguage=[0-9a-zA-Z][0-9a-zA-Z]/g, "")

        if (sQueryString.indexOf('?') > -1)
            var sNewRef = sHref + sQueryString + "&setlanguage=" + lang;
        else
            var sNewRef = sHref + "?setlanguage=" + lang;

    } else {
        var sNewRef = "?setlanguage=" + lang;
    }
    document.location.href = sNewRef;
    return;
}

// get the body content before posting
function copyEditorText(target) {
    var editorText = '';
    if (document.frames["editor"].document.getElementById("Content")) {
        var editorText = document.frames["editor"].document.getElementById("Content").innerText;
        document.getElementById(target).value = editorText;
    }
    return;
}