﻿function doPostBackAsync(eventName, eventArgs) {
    var prm = Sys.WebForms.PageRequestManager.getInstance();

    if (!Array.contains(prm._asyncPostBackControlIDs, eventName)) {
        prm._asyncPostBackControlIDs.push(eventName);
    }

    if (!Array.contains(prm._asyncPostBackControlClientIDs, eventName)) {
        prm._asyncPostBackControlClientIDs.push(eventName);
    }

    __doPostBack(eventName, eventArgs);
}

function hideFlashBanner() {
    document.getElementById("headeranim3").style.visibility = "hidden";
}

function showFlashBanner() {
    var headeranim3 = self.parent.document.getElementById("headeranim3");

    if (headeranim3 != null) {
        if (headeranim3.style.visiblity != "visible") {
            headeranim3.style.visibility = "visible";
        }
    }
}

function thumbUploadRefresh() {
    var ifr = $get("ifrUploadThumbnailImage");
    ifr.contentWindow.doRefreshUpdatePanel = function() {
        __doPostBack('ctl00$ctl00$cphSiteContent$cphOnlineContent$Test', '')
    }
}

function generatePostSlug() {
    var txtNewsHeadline = document.getElementById("ctl00_ctl00_ctl00_cphSiteContent_cphOnlineContent_cphOnlineContent_txtNewsHeadline");
    var lblSlugSuffix = document.getElementById("ctl00_ctl00_ctl00_cphSiteContent_cphOnlineContent_cphOnlineContent_lblSlugSuffix");
    var hdfSlugSuffix = document.getElementById("ctl00_ctl00_ctl00_cphSiteContent_cphOnlineContent_cphOnlineContent_hdfSlugSuffix");

    if (!txtNewsHeadline.value == "") {
        var strSlugSuffix = txtNewsHeadline.value;
        strSlugSuffix = strSlugSuffix.toLowerCase();
        strSlugSuffix = strSlugSuffix.replace(/[^a-zA-Z 0-9]+/g, "");
        strSlugSuffix = strSlugSuffix.replace(/ /g, "-");
        lblSlugSuffix.innerHTML = strSlugSuffix;
        hdfSlugSuffix.value = strSlugSuffix;
    }
}

function generatePageSlug() {
    var txtShortTitle = document.getElementById("ctl00_ctl00_ctl00_cphSiteContent_cphOnlineContent_cphOnlineContent_txtShortTitle");
    var txtSlugSuffix = document.getElementById("ctl00_ctl00_ctl00_cphSiteContent_cphOnlineContent_cphOnlineContent_txtSlugSuffix");
    var hdfSlugSuffix = document.getElementById("ctl00_ctl00_ctl00_cphSiteContent_cphOnlineContent_cphOnlineContent_hdfSlugSuffix");

    if (!txtShortTitle.value == "") {
        var strSlugSuffix = txtShortTitle.value;
        strSlugSuffix = strSlugSuffix.toLowerCase();
        strSlugSuffix = strSlugSuffix.replace(/[^a-zA-Z 0-9]+/g, "");
        strSlugSuffix = strSlugSuffix.replace(/ /g, "-");
        txtSlugSuffix.value = strSlugSuffix;
        hdfSlugSuffix.value = strSlugSuffix;
    }
}

function showpdfoutputtext(id, icon) {
    switch (icon) {
        case 'player':
            document.getElementById(id).innerHTML = "View this PDF in our Media Player";
            break;
        case 'download':
            document.getElementById(id).innerHTML = "Download PDF";
            break;
        case 'scribd':
            document.getElementById(id).innerHTML = "View on Scribd";
            break;
    }     
}

function hidepdfoutputtext(id) {
    document.getElementById(id).innerHTML = "View or download this PDF";
}

function showvideooptionstext(id, icon) {
    switch (icon) {
        case 'player':
            document.getElementById(id).innerHTML = "View in Media Player";
            break;
        case 'youtube':
            document.getElementById(id).innerHTML = "View on YouTube";
            break;
        case 'viddler':
            document.getElementById(id).innerHTML = "View on Viddler";
            break;
    }
}

function hidevideooptionstext(id, icon) {
    document.getElementById(id).innerHTML = "View this video";
}

function showSCSHover(id) {
    var img = document.getElementById("scsDiagram");

    img.src = "/images/content/pages/scs_diagram_sel" + id + ".png";
}

function hideSCSHover() {
    var img = document.getElementById("scsDiagram");

    img.src = "/images/content/pages/scs_diagram.png";
}

function showMeasurementsInfo() {
    var div = document.getElementById("measurementsInfo");
    var a = document.getElementById("measurementsInfoLink");

    if (div.style.display == "none") {
        div.style.display = "block";
        a.innerHTML = "Hide information";
    }
    else {
        div.style.display = "none";
        a.innerHTML = "More information";
    }
}

function checkifPasswordChanged() {
    var txtUsername = document.getElementById("ctl00_ctl00_ctl00_cphSiteContent_cphOnlineContent_cphOnlineContent_txtUserName")
    var lblConfirmUsername = document.getElementById("ctl00_ctl00_ctl00_cphSiteContent_cphOnlineContent_cphOnlineContent_lblCurrentUserName")

    if (txtUsername.value != lblConfirmUsername.innerHTML) {
        alert("Due to the password salting methods used in Servo Online, changing a username's login username requires that their password must also be changed. Please ensure that you enter a new password for this user below.");
    }
}

/* Code taken from http://ilovethecode.com/Javascript/Javascript-Tutorials-How_To-Easy/Get_Query_String_Using_Javascript.shtml */
function parseQueryString(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}

