﻿/////////////////////////////////////////
//  adm player support

var bPlayer = 0;
var sAdmServer = '';
var diagIframe = null;
var UpdateBannerCount = 0;

function SbtvPageContext(
       sSbtvSid,
       sQueryString,
       sJsideBside,
       sIpAddress,
       sIpStatus,
       sIp2LocationMessage,
       sZipCode,
       sDmaStatus,
       sCity,
       sState,
       sDMA,
       sMachineName,
       sSiteDomainRoot,
       sCS_Server,
       sWebSqlServer,
       sWebDatabase,
       sWwwSqlServer,
       sWwwDatabase,
       sContentServer,
       sAspxPage,
       nodePage,
       nodeContent,
       sAncestor,
       sRequestUrl,
       sPlaylistGuid
) {
    this.sid = sSbtvSid;
    this.sQueryString = sQueryString;
    this.sJsideBside = sJsideBside;
    this.sIpAddress = sIpAddress;
    this.sIpStatus = sIpStatus;
    this.sIp2LocationMessage = sIp2LocationMessage;
    this.sZipCode = sZipCode;
    this.sDmaStatus = sDmaStatus;
    this.sCity = sCity;
    this.sState = sState;
    this.sDMA = sDMA;
    this.sMachineName = sMachineName;
    this.sSiteDomainRoot = sSiteDomainRoot;
    this.sCS_Server = sCS_Server;
    this.sWebSqlServer = sWebSqlServer;
    this.sWebDatabase = sWebDatabase;
    this.sWwwSqlServer = sWwwSqlServer;
    this.sWwwDatabase = sWwwDatabase;
    this.sContentServer = sContentServer;
    this.sAspxPage = sAspxPage;
    this.nodePage = nodePage;
    this.nodeContent = nodeContent;
    this.sAncestor = sAncestor;
    this.sRequestUrl = sRequestUrl;
    this.sPlaylistGuid = sPlaylistGuid;
}

function RawContent(
    clip_id,
    clip_type,
    bIsAd,
    sTitle,
    clusterkey,
    contentPath,
    default_id
) {
    this.clip_id = clip_id;
    this.clip_type = clip_type;
    this.bAd = bIsAd;
    this.sTitle = sTitle;
    this.clusterkey = clusterkey;
    this.contentPath = contentPath;
    this.default_id = default_id;
}

function VideoAd(
    clip_id,
    clusterkey,
    admOverrideContext,
    contentPath,
    videoClickTag,
    videoStartTag,
    videoMiddleTag,
    videoFinishTag,
    duration,
    title,
    description,
    StartDate,
    EndDate,
    PI,
    PI_Total,
    GoalDaily,
    GoalPI,
    Archive,
    sAdmRemark,
    cap,
    cap_hours
) {
    this.clip_id = clip_id;
    this.clusterkey = clusterkey;
    this.admOverrideContext = admOverrideContext;
    this.contentPath = contentPath;
    this.videoClickTag = videoClickTag;
    this.videoStartTag = videoStartTag;
    this.videoMiddleTag = videoMiddleTag;
    this.videoFinishTag = videoFinishTag;
    this.duration = duration;
    this.title = title;
    this.description = description;
    this.StartDate = StartDate;
    this.EndDate = EndDate;
    this.PI = PI;
    this.PI_Total = PI_Total;
    this.GoalDaily = GoalDaily;
    this.GoalPI = GoalPI;
    this.Archive = Archive;
    this.sAdmRemark = sAdmRemark;
    this.cap = cap;
    this.cap_hours = cap_hours;
}

function BannerAd(
    uid,
    zone,
    AdUnitSize,
    clusterkey,
    duration,
    title,
    StartDate,
    EndDate,
    PI,
    PI_Total,
    GoalDaily,
    GoalPI,
    Archive,
    sAdmRemark,
    list_order,
    cap,
    cap_hours
) {
    this.uid = uid;
    this.zone = zone;
    this.AdUnitSize = AdUnitSize;
    this.clusterkey = clusterkey;
    this.duration = duration;
    this.title = title;
    this.StartDate = StartDate;
    this.EndDate = EndDate;
    this.PI = PI;
    this.PI_Total = PI_Total;
    this.GoalDaily = GoalDaily;
    this.GoalPI = GoalPI;
    this.Archive = Archive;
    this.sAdmRemark = sAdmRemark;
    this.list_order = list_order;
    this.cap = cap;
    this.cap_hours = cap_hours;
}

function Clip(
    clip_id,
    clip_type,
    clusterkey,
    contentPath,
    videoClickTag,
    videoStartTag,
    videoMiddleTag,
    videoFinishTag,
    duration,
    title,
    description,
    suppress_skip_controls,
    sCueList,
    playerMode,
    sImageCueList
) {
    this.clip_id = clip_id;
    this.clip_type = clip_type;
    this.clusterkey = clusterkey;
    this.contentPath = contentPath;
    this.videoClickTag = videoClickTag;
    this.videoStartTag = videoStartTag;
    this.videoMiddleTag = videoMiddleTag;
    this.videoFinishTag = videoFinishTag;
    this.duration = duration;
    this.title = title;
    this.description = description;
    this.sCueList = sCueList;
    this.suppress_skip_controls = suppress_skip_controls;
    this.playerMode = playerMode;
    this.sImageCueList = sImageCueList;
}

function AdCap(
    ad_id_uid,
    delivered_count,
    cookie_expires
) {
    this.AdIdUid = ad_id_uid;
    this.DeliveredCount = delivered_count;
    this.CookieExpires = cookie_expires;
}


function setPlayerClip(ixSetClip) {
    theVideo("SBTVPlayer").setClip(ixSetClip);
}

function getCurrentClipIndex() {
    return ixCurrentClip;
}

function theVideo(movieName) {
    var vid;

    vid = document.getElementsByName("SBTVPlayer")[0];
    /*
    if (navigator.appName.indexOf("Microsoft") != -1) {
    vid = window[movieName];
    }
    else {
    vid= document[movieName];
    }
    */
    return vid;
}

function getClips() {
    //    document.getElementById('sbtv_main_menu').innerHTML = 'getClips  aClip[0].clip_id=' + aClip[0].clip_id;
    if (typeof (override_playlist) != 'undefined') {
        override_playlist();
    }
    var sClips = '';
    var iCounter;
    for (iCounter = 0; iCounter < aClip.length; iCounter++) {
        if (iCounter != 0) {
            sClips += '}';
        }
        else {
            setTimeout(InitialBanners, 100);
        }
        sClips += aClip[iCounter].title + '|'
        + aClip[iCounter].contentPath + '|'
        + aClip[iCounter].duration + '|'
        + aClip[iCounter].suppress_skip_controls + '|'
        + aClip[iCounter].sCueList + '|'
        + aClip[iCounter].playerMode + '|'
        + aClip[iCounter].sImageCueList
        ;
    }
    createTrackingFrame();
    return sClips;
}

function createTrackingFrame() {
    var sTrackingSrc = sbtv_page_context.sRequestUrl
    + ((sbtv_page_context.sRequestUrl.indexOf('?')!=-1)?'&':'?')
    + 'tracking_tags=1'
     + '&cb=' + new Date().valueOf();
     
    document.getElementById("tracking-tag-frame").innerHTML = '<iframe src="'
    + sTrackingSrc
    + '"></iframe>';
}

function getClipArray() {
    return aClip;
}

function InitialBanners() {
    var sClipCue = aClip[0].sCueList;
    if (sClipCue.indexOf(',') != -1) {
        sClipCue = aClip[0].sCueList.split(',')[0];
    }
    ixCurrentClip = 0;
    sCueTime = 0;
    sUpdateBannersString = sClipCue.split('@')[0];
    UpdateBanners();
}


function getClickTag(ixClip) {
    return aClip[ixClip].videoClickTag;
}

function getStartTag(ixClip) {
    return aClip[ixClip].videoStartTag;
}

function getMiddleTag(ixClip) {
    return aClip[ixClip].videoMiddleTag;
}

function getFinishTag(ixClip) {
    return aClip[ixClip].videoFinishTag;
}

var ixCurrentClip;
var admCurrentClipType = '';
var admCurrentPostId = 0;
var admCurrentPostTitle = '';

var sVideoEvent = '';
var sCueTime = '';
var sUpdateBannersString = '';

function VideoEvent(ixClip, event_type) {
    var sEventUrl = '';
    var zone_id = "4";

    var zone_sequence = "";
    var zone_total = "";
    var event_position = "";
    var ad_duration = "0";

    var sTable = "";

    var clip = aClip[ixClip];
    var bHitTag = true;

    ixCurrentClip = ixClip;
    var admCurrentClip = aClip[ixCurrentClip];
    admCurrentClipType = admCurrentClip.clip_type;
    admCurrentPostId = admCurrentClip.clip_id;
    admCurrentPostTitle = admCurrentClip.title;

    var bUpdatePI = false;
    switch (event_type) {
        case "click":
            sEventUrl = clip.videoClickTag;
            if (sEventUrl != "") {
                window.open(sEventUrl, "_blank");
            }
            bHitTag = false;
            break;
        case "VideoStart":
            sEventUrl = clip.videoStartTag;
            updateACTbar();
            bUpdatePI = true;
            break;
        case "VideoMiddle":
            sEventUrl = clip.videoMiddleTag;
            break;
        case "VideoFinish":
            sEventUrl = clip.videoFinishTag;
            break;
        default:
            sDiagMsg += "\n" + 'unrecognized event_type >' + event_type + '<';
            break;
    }
    if ((sEventUrl != '') && (bHitTag == true)) {
        hitTag(sEventUrl, ixClip, event_type);
    }
    if (bUpdatePI == true) {
        UpdatePI(clip.clip_type, event_type, clip.clip_id);
    }
}

function LogVideoSegEvent(segid, event_type) {
    sUpdatePI_params = 'tbl=SBTVContent' +
        '&evt=' + event_type +
        '&data=' + segid +
        '&sip=' + sbtv_client_context.sIpAddress +
        '&sid=' + sbtv_client_context.sSbtvSid;

    sbtvAjax.Post('/UpdatePI.aspx',
        sUpdatePI_params,
        UpdatePIResponseHandler
        );
}

function hitTag(sUrl, ixClip, event_type) {
    document.getElementById('hit-frame').innerHTML = '<iframe src="' + sUrl + '"></iframe>';
}

function VideoCueEvent(clip_index, cue_position, cue_name) {
    switch (cue_name) {
        case 'VideoStart':
            VideoEvent(clip_index, cue_name);
            break;
        case 'VideoMiddle':
            VideoEvent(clip_index, cue_name);
            break;
        case 'VideoFinish':
            VideoEvent(clip_index, cue_name);
            break;
        default:
            break;
    }
}

var InitialBannersDisplayed = false;

function cueUpdateBanners(ixClip, cue_time, cue_name, caller) {
    if ((ixClip == 0)
        && (cue_time == 0)
        ) {
        InitialBannersDisplayed = true;
        if (bPlayer == 1) {
            return;
        }
    }

    if (UpdateBannerCount == 1) {
        UpdateBannerCount++;
    }
    else {
        ixCurrentClip = ixClip;
        sCueTime = cue_time;
        sUpdateBannersString = cue_name;
        setTimeout("UpdateBanners()", 100);
    }
}

function displayBanner(banner) {
    var aIdZone = banner.split('_');
    var BannerId = aIdZone[0];
    if (CheckAdCap(BannerId) == false) {
        return false;
    }

    var sSrc = sAdmServer + '/Banner.aspx?id=' + BannerId
        + '&sid=' + sbtv_page_context.sid
        + '&cb=' + new Date().valueOf();
    var sZoneId = 'ad-zone-' + aIdZone[1];
    var bBannerDisplayed = false;
    try {
        document.getElementById(sZoneId).src = sSrc;
        bBannerDisplayed = true;
    }
    catch (err) {
    }
    return bBannerDisplayed;
}

function UpdateBanners() {
    var aBanner = new Array();
    var aIdZone = new Array();
    var ixBanner;

    var sSrc;

    aBanner = sUpdateBannersString.split("/");
    var sBannersDisplayed = '';
    for (ixBanner = 0; ixBanner < aBanner.length; ixBanner++) {
        if (displayBanner(aBanner[ixBanner]) == true) {
            if (sBannersDisplayed != '') {
                sBannersDisplayed += '/';
            }
            sBannersDisplayed += aBanner[ixBanner];
        }
    }
    updateDiag();
    // Banner.aspx handles updating PI and dtLastViewed,
    // so a discrete UpdatePI() call is not required
    //    if (sBannersDisplayed == '') {
    //        UpdatePI('AdContent', 'Banner', '(empty sBannersDisplayed)');
    //    }
    //    else {
    //        UpdatePI('AdContent', 'Banner', sBannersDisplayed);
    //    }
    //    UpdateBannerCount++;
}



var sUpdatePI_params = '';
function UpdatePI(sTableName, sEventType, sData) {
    sUpdatePI_params = 'tbl=' + sTableName +
        '&evt=' + sEventType +
        '&data=' + sData +
        '&sip=' + sbtv_page_context.sIpAddress +
        '&sid=' + sbtv_page_context.sid;
    sbtvAjax.Post('/UpdatePI.aspx',
        sUpdatePI_params,
        UpdatePIResponseHandler
        );
}


function UpdatePIResponseHandler(sResponse) {
    var sMarker = '<!-' + '-CONTENTMARKER-' + '->';
    var aSeg = sResponse.split(sMarker);
    var sMessage = '<div style="margin-left: 5px;background-color: white;font: normal 10px verdana;">' +
    sUpdatePI_params +
    '<br>' +
    "\n" +
    aSeg[1] +
    '</div>';
}

function SetDiagIframe(frame) {
    diagIframe = frame;
    document.getElementById('diag-loading').style.backgroundImage = "";
}

var jadmClipTimeout = null;
var jadmCueTimeout = null;
var aJadmCue = new Array();
var ixNextJadmCue;

function JadmCue(
    sCueTarget,
    msClipCueTime,
    msTimeout) {
    this.sCueTarget = sCueTarget;
    this.msClipCueTime = msClipCueTime
    this.msTimeout = msTimeout;
}

function jadmNextCue() {
    clearTimeout(jadmCueTimeout);
    var cue = aJadmCue[ixNextJadmCue];
    cueUpdateBanners(ixCurrentClip, cue.msClipCueTime / 1000, cue.sCueTarget, 'jadmNextCue()');
    ixNextJadmCue++;
    if (ixNextJadmCue < aJadmCue.length) {
        jadmCueTimeout = setTimeout(
            'jadmNextCue',
            aJadmCue[ixNextJadmCue].msTimeout
            );
    }
}

var bAutoOpenAdmConsole = false;

function jadm() {
    create_banner_frame('az1', '01', 728, 90);
    create_banner_frame('az2', '02', 160, 600);
    create_banner_frame('az3', '03', 300, 250);

    if (document.cookie.indexOf('adm_console=') != -1) {
        bAutoOpenAdmConsole = true;
    }

    if (bPlayer == 1) {
        try {
            document.getElementById('sbtv-flash-player').src = sVideoPlayerPath + '?cb=' + new Date().valueOf();

        }
        catch (err) {
            ixCurrentClip = aClip.length - 1;
            UpdateBannerCount = 2; // skip over "Suppress Clip 0, Cue 0" state
            jadmNextClip();
        }
    }
    else {
        ixCurrentClip = aClip.length - 1;
        UpdateBannerCount = 2; // skip over "Suppress Clip 0, Cue 0" state
        createTrackingFrame();
        jadmNextClip();
    }

}

function create_banner_frame(parent_div_id, zone_number, width, height) {

    var divParent;
    divParent = document.getElementById(parent_div_id);
    if (divParent == null) {
        return;
    }
    var divZone = document.createElement('IFRAME');
    divZone.id = 'ad-zone-' + zone_number;
    divZone.width = width;
    divZone.height = height;
    divZone.frameBorder = 0;
    divZone.scrolling = 'no';
    divParent.appendChild(divZone);
}

function jadmNextClip() {
    ixCurrentClip++;
    if (ixCurrentClip == aClip.length) {
        ixCurrentClip = 0;
    }
    jadmSetClip(ixCurrentClip);
}

function jadmSetClip(ixNewClip) {
    clearTimeout(jadmCueTimeout);
    clearTimeout(jadmClipTimeout);
    var clip = aClip[ixNewClip];
    var aCue = clip.sCueList.split(',');
    var ixCue;
    var ixNextCue;
    var aCueTargetAndDuration;
    var offset;
    var this_cue_time;
    var next_cue_time;
    var sTarget;

    aJadmCue.length = 0;
    ixNextJadmCue = 0;
    for (ixCue in aCue) {
        aCueTargetAndDuration = aCue[ixCue].split('@');
        sTarget = aCueTargetAndDuration[0];
        if (sTarget != '') {
            this_cue_time = parseFloat(aCueTargetAndDuration[1]) * 1000;
            if (ixCue < (aCue.length - 1)) {
                ixNextCue = parseInt(ixCue) + 1;
                next_cue_time = parseFloat(aCue[ixNextCue].split('@')[1]) * 1000;
                aJadmCue.push(new JadmCue(sTarget, this_cue_time, next_cue_time - this_cue_time));
            }
            else {
                aJadmCue.push(new JadmCue(sTarget, 0, 0));
            }
        }
    }
    if (clip.clip_id != 0) {
        jadmClipTimeout = setTimeout('jadmNextClip()', parseFloat(clip.duration) * 1000);
    }
    if (aJadmCue.length != 0) {
        jadmNextCue();
    }
}

var bAudioStreamPlayerDisplayed = false;

function toggle_AudioStreamPlayer(audio_player_url, audio_player_width) {
    var divButton = document.getElementById('toggle-radio-button');

    if (bPlayer) {
        if (bAudioStreamPlayerDisplayed == true) {
            document.getElementById('sbtv-flash-player').src = sVideoPlayerPath;
            divButton.className = "sbctrl-radio-listen-now";
            bAudioStreamPlayerDisplayed = false;
        }
        else {
            document.getElementById('sbtv-flash-player').src = audio_player_url;
            divButton.className = "sbctrl-radio-now-playing";
            bAudioStreamPlayerDisplayed = true;
        }
    }

}

function updateDiag() {
    if (bDiagMonitor == true) {
        try {
            diagIframe.updateDiagFrame();
        }
        catch (err) {
        }

    }
}

function log(div_id, sMessage) {
    var sContent = document.getElementById('diag_output').innerHTML;
    document.getElementById(div_id).innerHTML = sMessage + '<hr>' + sContent;
}

function log_reset(div_id, sMessage) {
    document.getElementById(div_id).innerHTML = sMessage;
}

function SearchSbtv(search_div_id) {
    var fldSearchSbtv = document.getElementById(search_div_id);
    var sSearchSbtv = fldSearchSbtv.value;
    if (sSearchSbtv != '') {

        var sParams = 'search-text=' + sSearchSbtv;
        window.location.href = ('/SearchSbtv/?' + sParams);
    }
    else {
        alert('Please enter a word or phrase, then click Search SBTV.com');
    }
}

function search_key_down(evt) {
    evt = (evt) ? evt : ((window.event) ? window.event : "");
    var elem = (evt.target) ? evt.target : evt.srcElement;

    var key_code;
    if (window.event) // Internet Explorer
    {
        key_code = evt.keyCode
    }
    else if (evt.which) // Netscape/Opera/FireFox
    {
        key_code = evt.which
    }
    switch (key_code) {
        case 13:
            SearchSbtv(elem.id);
            break;
        default:
            break;
    }
}

function SearchResponseHandler() {
    var sResponse;
    var sContent;
    var sMarker = '<!-' + '-CONTENTMARKER-' + '->';
    var bNoContent;
    var aSeg;
    var divTarget = document.getElementById('main-col');

    if (oXmlHttp.readyState == 4 || oXmlHttp.readyState == 'complete') {
        sResponse = oXmlHttp.responseText;
        aSeg = sResponse.split(sMarker);
        sContent = aSeg[1];
        if (sContent == '(no items)') {
            $(sListId).innerHTML = sContent;
        }
        else {
            divTarget.innerHTML = sContent;
        }
    }
}

var oXmlHttp;
var AjaxResponseStringHandler;

function PagePI() {
    UpdatePI('PI', 'Page', window.location);
}

function getPlayerContext() {
    return sContextString = sbtv_client_context.sSbtvSid + '|' + sbtv_client_context.sIpAddress;
}

function handlePollResponse(sResponse) {
    poll_box.innerHTML = sResponse.split('</h3>')[1];
    document.getElementById('poll-header').innerHTML = "SBTV.com Quick Poll Response";
}

function get_poll_results(poll_id, response_value) {
    poll_box = document.getElementById('poll-box');
    var poll_result_source = '/_modules/right_col_poll_result.asp';
    var poll_params = 'poll_id=' + poll_id + '&resp=' + response_value;

    var poll_string = '<iframe id="poll-iframe" name="poll-iframe" frameborder="0" src="' + poll_result_source + '" scrolling=no style="height: 300px;"></iframe>';

    sbtvAjax.Post(poll_result_source, poll_params, handlePollResponse);
}

function sbtv_sc(ContentSourceId, RecordId) {

    var sUrl;
    switch (ContentSourceId) {
        case 1:
            sUrl = classic_path + '/default.asp?segid=' + RecordId;
            break;
        case 2:
            sUrl = classic_path + '/default.asp?segid=' + RecordId;   // needs to be modified to bring up Audio
            break;
        case 3:
            sUrl = classic_path + '/default.asp?cid=27&uid=' + RecordId;
            break;
        case 4:
            sUrl = cs_path + '/blogs/' + RecordId + '.aspx';
            break;
    }
    window.open(sUrl, '_blank');
}


var FlashPlayer;

function SetClip(ixClip) {
    ixCurrentClip = ixClip;
    FlashPlayer.SetClip(ixCurrentClip);
}

function SbtvAdCap(cookie_name, cookie_value_string) {
    var aCookieSeg = cookie_value_string.split('|');
    var sCookieSeg;
    var sDiag = cookie_name + "\n";
    for (var ixSeg in aCookieSeg) {
        sCookieSeg = aCookieSeg[ixSeg];
        sDiag += ixSeg + ': ' + sCookieSeg + "\n";
    }
    this.name = cookie_name;
    this.cap_count = aCookieSeg[0];
    this.cap_limit = aCookieSeg[1];
    this.cap_dt = new Date(aCookieSeg[2]);
    this.sInfo = SbtvCookieInfo;
}

function SbtvCookieInfo() {
    return 'name=' + this.name + "\n" +
            'cap=' + this.cap_count + ' of ' + this.cap_limit + "\n" +
            'cap_dt=' + this.cap_dt;
}

var sAdCapPrefix = 'sbtv_ad_cap_';

function SbtvGetAdCap(banner_id) {
    var Name = sAdCapPrefix + banner_id;
    var search = Name + "="
    var returnvalue = null;
    var offset;
    var end;
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) { // if cookie exists
            offset += search.length
            end = document.cookie.indexOf(";", offset);
            if (end == -1)
                end = document.cookie.length;
            returnvalue = new SbtvAdCap(Name, unescape(document.cookie.substring(offset, end)))
        }
    }
    return returnvalue;
}


function CheckAdCap(banner_id) {
    var banner = aBannerAd[banner_id];
    if (banner.cap == 0) {
        return true;
    }
    var bDisplay = false;
    var cookie_name = sAdCapPrefix + banner_id;
    var ad_cap = SbtvGetAdCap(banner_id);
    if (ad_cap == null) {
        var cap_ms = parseFloat(banner.cap_hours) * 3600000;
        var dtNow = new Date();

        var cap_dt = new Date(dtNow.getTime() + cap_ms);
        ad_cap = new SbtvAdCap(
            cookie_name,
            '1|' +
            banner.cap + '|' +
            cap_dt.toUTCString()
            );
        bDisplay = true;
    }
    else {
        if (ad_cap.cap_count >= ad_cap.cap_limit) {
            return false;
        }
        ad_cap.cap_count++;
    }

    document.cookie = cookie_name + '=' +
        ad_cap.cap_count + '|' + ad_cap.cap_limit + '|' + ad_cap.cap_dt.toUTCString() +
        ';path=/;expires=' + ad_cap.cap_dt.toUTCString();
    return bDisplay;
}

function SbtvCookie(cookie_name, cookie_val, dt_expires) {
    this.cookie_name = cookie_name;
    var cookie_value = cookie_val;
    if (cookie_value.indexOf('=') != -1) {
        cookie_value = cookie_val.split('=')[1];
    }
    this.cookie_value = cookie_value;
    this.dt_expires = dt_expires;
}

function SbtvSetCookie(cookie_name, cookie_val, dt_expires) {
    document.cookie = cookie_name + '=' +
        cookie_val +
        ';path=/;expires=' + dt_expires.toUTCString();
}

function SbtvGetCookie(cookie_name) {
    var returnvalue = null;
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(cookie_name)
        if (offset != -1) { // if cookie exists
            offset += cookie_name.length
            end = document.cookie.indexOf(";", offset);
            if (end == -1)
                end = document.cookie.length;
            returnvalue = new SbtvCookie(cookie_name, unescape(document.cookie.substring(offset, end)), 0);
        }
    }
    return returnvalue;
}

function SbtvGetCookieValue(cookie_name) {
    var returnvalue = null;
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(cookie_name)
        if (offset != -1) { // if cookie exists
            offset += cookie_name.length
            end = document.cookie.indexOf(";", offset);
            if (end == -1)
                end = document.cookie.length;
            returnvalue = unescape(document.cookie.substring(offset + 1, end));
        }
    }
    return returnvalue;
}

function NewWindow(url) {
    window.open(url);
}

var ae_url = document.location.href;

function set_ae(html_content) {
    var div_ae = document.getElementById('sbtv_ae');
    div_ae.innerHTML = html_content;
    div_ae.style.display = 'block';
}

function refresh_ae(refresh_url) {
    document.location.href = ae_url;
}

function sbtv_upload_thumb(post_id) {
    set_ae('<iframe'
        + ' src="/admin/utilities/Post/UploadThumb.aspx?post_id=' + post_id + '"'
        + ' frameborder="0"'
        + ' style="'
        + 'width:800px;'
        + 'height: 190px;'
        + '"'
        + '></iframe>'
        );
}

function sbtv_toggle(element_id) {
    var el = document.getElementById(element_id);
    if (el.style.display == 'none') {
        el.style.display = 'block';
    }
    else {
        el.style.display = 'none';
    }
}

// Begin Bio Functions for About Us

function toggle_watch() {
    var obj;
    obj = document.getElementById('watchpop');
    if (obj.style.display == 'none') {
        obj.style.display = 'block';
    }
    else {
        obj.style.display = 'none';
    }
}

function watch(watch_id) {

    var obj = document.getElementById(watch_id);
    var obj_watch = document.getElementById('watch-content');
    obj_watch.innerHTML = obj.innerHTML;
    toggle_watch();
}

function toggle_pop() {
    var obj;
    obj = document.getElementById('biopop');
    if (obj.style.display == 'none') {
        obj.style.display = 'block';
    }
    else {
        obj.style.display = 'none';
    }
}

function set_pop(bio_id) {

    var obj = document.getElementById(bio_id);
    var obj_pop = document.getElementById('biopop-content');
    obj_pop.innerHTML = obj.innerHTML;
    toggle_pop();
}

// End Bio Functions for About Us



// Download Tracking and Link

function downloadLink(parent_id, download_type) {
    var sParams = 'op=download'
            + '&pid='
            + parent_id
            + '&dtype='
            + download_type;

    sbtvAjax.Post('/ajax/DownloadLink.aspx', sParams, handleDownloadResponse);

}

function handleDownloadResponse(sResponse) {
    window.open(sResponse);
}

// End Download Tracking and Link