/**
 * SWFObject v1.4.1: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
 *   legal reasons.
 */
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, useExpressInstall, quality, xiRedirectUrl, redirectUrl, detectKey){
	if (!document.createElement || !document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion(this.getAttribute('version'), useExpressInstall);
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', useExpressInstall);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs.push(key +"="+ variables[key]);
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) this.addVariable("MMplayerType", "PlugIn");
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) this.addVariable("MMplayerType", "ActiveX");
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(reqVer, xiInstall){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else{
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			for (var i=3; axo!=null; i++) {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
				PlayerVersion = new deconcept.PlayerVersion([i,0,0]);
			}
		}catch(e){}
		if (reqVer && PlayerVersion.major > reqVer.major) return PlayerVersion; // version is ok, skip minor detection
		// this only does the minor rev lookup if the user's major version 
		// is not 6 or we are checking for a specific minor or revision number
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		if (!reqVer || ((reqVer.minor != 0 || reqVer.rev != 0) && PlayerVersion.major == reqVer.major) || PlayerVersion.major != 6 || xiInstall) {
			try{
				PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
			}catch(e){}
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = parseInt(arrVersion[0]) != null ? parseInt(arrVersion[0]) : 0;
	this.minor = parseInt(arrVersion[1]) || 0;
	this.rev = parseInt(arrVersion[2]) || 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param){
		var q = document.location.search || document.location.hash;
		if(q){
			var startIndex = q.indexOf(param +"=");
			var endIndex = (q.indexOf("&", startIndex) > -1) ? q.indexOf("&", startIndex) : q.length;
			if (q.length > 1 && startIndex > -1) {
				return q.substring(q.indexOf("=", startIndex)+1, endIndex);
			}
		}
		return "";
	}
}
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i=0; i < objects.length; i++) {
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = null;
			}
		}
	}
}
if (typeof window.onunload == 'function') {
	var oldunload = window.onunload;
		window.onunload = function() {
		deconcept.SWFObjectUtil.cleanupSWFs();
		oldunload();
	}
} else {
	window.onunload = deconcept.SWFObjectUtil.cleanupSWFs;
}
/* add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;

/* add Array.push if needed */
if(Array.prototype.push == null){
        Array.prototype.push = function(item) { this[this.length] = item; return this.length; }
}

Drawer.TOP = 0;
Drawer.RIGHT = 1;
Drawer.BOTTOM = 2;
Drawer.LEFT = 3;
Drawer.all = new Object();
Drawer.zIndex = 100;

function Drawer(id, speed, side, open, callback) {
    var outer = document.getElementById(id);

    this.id = id;
    this.speed = (speed % 100) / 100;
    this.side = side;
    this.open = open;
    this.callback = (typeof callback == "function") ? callback : function() {};
    this.moving = false;

    this.outer = outer;
    this.inner = outer.getElementsByTagName("div").item(0);
    this.width = outer.clientWidth || outer.offsetWidth;
    this.height = outer.clientHeight || outer.offsetHeight;

    switch (this.side) {
    case Drawer.TOP:
        this.clip = [this.height, this.width, this.height, 0];
        this.style = "top";
        this.start = 0;
        break;
    case Drawer.RIGHT:
        this.clip = [0, 0, this.height, 0];
        this.style = "left";
        this.start = -this.width;
        break;
    case Drawer.BOTTOM:
        this.clip = [0, this.width, 0, 0];
        this.style = "top";
        this.start = -this.height;
        break;
    case Drawer.LEFT:
        this.clip = [0, this.width, this.height, this.width];
        this.style = "left";
        this.start = 0;
        break;
    }

    this.inner.style.position = "relative";
    this.outer.style.visibility = this.open ? "visible" : "hidden";
    Drawer.all[id] = this;
}

Drawer.prototype.update = function() {
    var result, i = 0;
    var pattern = /\d+/g;

    this.width = this.outer.clientWidth || this.outer.offsetWidth;
    this.height = this.outer.clietHeight || this.outer.offsetHeight;

    while ((result = pattern.exec(this.outer.style.clip)) != null) {
        this.clip[i++] = Number(result[0]);
    }

    this.outer.style.visibility = "visible";
    if (!this.open) this.outer.style.zIndex = Drawer.zIndex++;
}

Drawer.prototype.activate = function() {
    this.update();
    this.move();
    this.moving = true;
}

Drawer.prototype.move = function() {
    var end;
    var dir;
    var i = this.side;

    switch (i) {
    case Drawer.TOP:
        end = this.open ? this.height : 0;
        dir = -1;
        break;
    case Drawer.RIGHT:
        end = this.open ? 0 : this.width;
        dir = 1;
        break;
    case Drawer.BOTTOM:
        end = this.open ? 0 : this.height;
        dir = 1;
        break;
    case Drawer.LEFT:
        end = this.open ? this.width : 0;
        dir = -1;
        break;
    }

    var by = Math.round((end - this.clip[i]) * this.speed) || 1;
    this.clip[i] += ((this.open ? -1 : 1) * Math.abs(by)) * dir;
    this.outer.style.clip = "rect(" + this.clip.join("px ") + "px)";
    this.inner.style[this.style] = (this.start + this.clip[i]) + "px";

    if (this.clip[i] == end) {
        this.open = !this.open;
        this.moving = false;
        this.callback(this);
        if (this.open == false) this.outer.style.visibility = "hidden";
        return;
    }

    setTimeout("Drawer.all['"+this.id+"'].move()", 10);
}

function getCookie(name) {
    if (new RegExp("\\b" + name + "=([^;]+)").test(document.cookie))
        return unescape(RegExp.$1);
    else
        return null;
}

function setCookie(name, value, days, path, domain, secure) {
    var c = name + "=" + escape(value);
    var expires = null;
    if (days)
        expires = new Date(new Date().getTime() + (days * 24 * 60 * 60 * 1000));
    if (expires)
        c += "; expires=" + expires.toUTCString();
    if (path)
        c += "; path=" + path;
    if (domain)
        c += "; domain=" + domain;
    if (secure)
        c += "; secure";
    document.cookie = c;
}

function addEvent(obj, evt, func) {
    if (obj.addEventListener)
        obj.addEventListener(evt, func, false);
    else if (obj.attachEvent)
        obj.attachEvent("on"+evt, func);
    else {
        var oldhandler = obj["on"+evt];
        obj["on"+evt] = (typeof oldhandler == "function")
            ? function() { oldhandler(); func(); } : func;
    }
}

function getElementsByTagNameFilter(root, tagName, filter) {
    var filtered = new Array();
    var elms = root.getElementsByTagName(tagName);
    for (var i = 0; i < elms.length; i++) {
        if (filter(elms[i])) {
            filtered[filtered.length] = elms[i];
        }
    }
    return filtered;
}

function hasClass(node, classname) {
    if (node) {
        var pattern = new RegExp("(?:^| )" + classname + "(?: |$)");
        return pattern.test(node.className);
    }
    return false;
}

function getParentByTagName(node, tagName) {
    var n = node;
    while (n && (n = n.parentNode) != null) {
        if (n.nodeType == 1 && n.tagName.toLowerCase() == tagName.toLowerCase())
            break;
    }
    return n;
}

function sethomepage(url) {
    window.open('http://static.viacomlocalnetworks.com/pages/sethomepage.html','sethomepage','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=562,height=550,left=100,top=100,screenX=100,screenY=100');
}

function setOpacity(obj, opacity) {
    opacity = (opacity == 100) ? 99.999 : opacity;
    // IE/Win
    obj.style.filter = "alpha(opacity:" + opacity + ")";
    // Safari<1.2, Konqueror
    obj.style.KHTMLOpacity = opacity / 100;
    // Older Mozilla and Firefox
    obj.style.MozOpacity = opacity / 100;
    // Safari 1.2, newer Firefox and Mozilla, CSS3
    obj.style.opacity = opacity / 100;
}

function fadeIn(id, opacity) {
    obj = document.getElementById(id);
    if (obj == null) return;
    if (opacity < 100) {
        setOpacity(obj, opacity);
        opacity += 5;
        obj.fadeInTimeout = window.setTimeout("fadeIn('" + id + "'," + opacity + ")", 30);
        return;
    }
    // fix for Safari

}

function fadeOut(id, opacity) {
    obj = document.getElementById(id);
    if (obj == null) return;
    if (opacity > 0) {
        setOpacity(obj, opacity);
        opacity -= 5;
        obj.fadeOutTimeout = window.setTimeout("fadeOut('" + id + "'," + opacity + ")", 30);
        return;
    }
    obj.style.visibility = "hidden";
}

function savezip(anchor) {
    var img = new Image();
    img.src = anchor.href;
    var message = document.getElementById("pop_saved_generic");
    setOpacity(message, 100);
    message.style.left = (getRealLeft(anchor) - (((message.clientWidth || message.offsetWidth) - (anchor.clientWidth || anchor.offsetWidth)) / 2)) + "px";
    message.style.top = (getRealTop(anchor) + 30) + "px";
    message.style.visibility = "visible";
    setTimeout("fadeOut('" + message.id + "', 95)", 15000);
    return false;
}

function showZip(linkid, boxid) {
    var ziplink = document.getElementById(linkid);
    var zipbox = document.getElementById(boxid);
    setOpacity(zipbox, 0);
    zipbox.style.display = "block";
    ziplink.style.display = "none";
    fadeIn(zipbox.getAttribute("id"), 5);
}

function isFirefoxPC() {
    var ua = navigator.userAgent;
    return (/Firefox/.test(ua) && /Windows/.test(ua));
}

function moveDrawer(id, actuator, direction) {
    if (actuator) actuator.blur();

    var drawer = Drawer.all[id];
    if (!drawer) {
        var speed = 50;
        if ((id == "popit" || id == "popit2") && isFirefoxPC()) {
            speed = 99.99; // fix for flickering iframe ads
        }
        drawer = new Drawer(id, speed, direction);
    }
    drawer.activate();

    var div = getParentByTagName(actuator, "div");
    if (hasClass(div, "pulldown")) {
        drawer.callback = function() {
            if (drawer.open) {
                actuator.parentNode.style.backgroundPosition = "left bottom";
                drawer.timeout = setTimeout("if (Drawer.all['" + drawer.id + "'].open) Drawer.all['" + drawer.id  + "'].activate()", 10000);
            } else {
                actuator.parentNode.style.backgroundPosition = "left top";
                clearTimeout(drawer.timeout);
            }
        }
    }

    if (id == "popit") {
        var other = Drawer.all["popit2"];
        if (other && other.open) other.activate();
    }
    if (drawer.id == "popit2") {
        var other = Drawer.all["popit"];
        if (other && other.open) other.activate();
    }
}

function setState(orig, dest, input) {
    var destEl = document.getElementById(dest);
    if (destEl) destEl.innerHTML = orig.innerHTML;
    var drawer = orig;
    while ((drawer = getParentByTagName(drawer, "div")) && !hasClass(drawer, "drawer-bottom"));
    moveDrawer(drawer.id);
    var hidden = document.getElementById(input);
    if (hidden) hidden.value = orig.innerHTML;
}

function selectTab(tabid, rest) {
    var tab = document.getElementById("tab" + tabid);
    var tabdata = document.getElementById("tab" + tabid + "data");
    if (tab && tabdata) {
        tab.className = "currenttab";
        tabdata.style.display = "block";
        for (var i = 1; i < arguments.length; i++) {
            var tab = document.getElementById("tab" + arguments[i]);
            var tabdata = document.getElementById("tab" + arguments[i] + "data");
            if (tab && tabdata) {
                tab.className = "";
                tabdata.style.display = "none"
            }
        }
    }
}

function selectCondition(anchor, max) {
    var id;
    var now = document.getElementById("now");
    if (anchor == null) {
        now.style.display = "block";
        id = 0;
    } else {
        id = anchor.getAttribute("id").substring(5) - 0;
        now.style.display = "none";
        anchor.className = "shown";
    }
    for (var i = 1; i <= max; i++) {
        var cond = document.getElementById("hr" + i);
        var anchor = document.getElementById("navhr" + i);
        if (i == id) {
            cond.style.display = "block";
        } else {
            cond.style.display = "none";
            anchor.className = "";
        }
    }
}

function showDetails(anchor, max) {
    var aid = anchor.getAttribute("id").substring(0,4);
    var detail = document.getElementById(aid + "detail");
    var display = detail.style.display;
    for (var i = 1; i <= max; i++) {
        var id = "day" + i;
        var trigger = document.getElementById(id + "trigger");
        var img = trigger.getElementsByTagName("img")[0];
        img.src = img.src.replace("_up_", "_down_");
        document.getElementById(id + "detail").style.display = "none";
    }
    if (display == "none" || display == "") {
        var trigger = document.getElementById(aid + "trigger");
        var img = trigger.getElementsByTagName("img")[0];
        img.src = img.src.replace("_down_", "_up_");
        detail.style.display = "block";
    }
}

function setDisplay(trigger, layerid, func) {
    var layer = document.getElementById(layerid);
    var display;
    if (layer) {
        display = layer.style.display;
        layer.style.display = (display == "block") ? "none" : "block";
    }
    if (typeof func == "function") {
        func(trigger, display);
    }
}

function setVisibility(trigger, layerid, func) {
    var layer = document.getElementById(layerid);
    var visibility;
    if (layer) {
        visibility = layer.style.visibility;
        layer.style.visibility = (visibility == "visible") ? "hidden" : "visible";
    }
    if (typeof func == "function") {
        func(trigger, visibility);
    }
}

function changeArrow(trigger, display) {
    if (trigger) {
        var id = trigger.getAttribute("id");
        var letter = id.substring(9);
        var arrow = document.getElementById("arrow_" + letter);
        if (arrow) {
            arrow.className = (display == "block") ? "showarrow" : "hidearrow";
            arrow.innerHTML = (display == "block") ? "Show" : "Hide";
        }
    }
}

function go(select) {
    if (select) {
        var index = select.selectedIndex;
        var value = select.options[index].value;
        if (value) {
            window.location = value;
        }
    }
}

function setFontSize(size) {
    var middle = document.getElementById("middle");
    var resultsbox = document.getElementById("resultsbox");
    var tdefault = document.getElementById("tdefault");
    var tmedium = document.getElementById("tmedium");
    var tlarge = document.getElementById("tlarge");
    switch (size) {
    case "medium":
        if (middle) middle.style.fontSize = "110%";
        if (resultsbox) resultsbox.style.fontSize = "110%";
        tdefault.style.backgroundPosition = "top left";
        tmedium.style.backgroundPosition = "bottom center";
        tlarge.style.backgroundPosition = "top right";
        setCookie("style", "medium", 365, "/");
        break;
    case "large":
        if (middle) middle.style.fontSize = "120%";
        if (resultsbox) resultsbox.style.fontSize = "120%";
        tdefault.style.backgroundPosition = "top left";
        tmedium.style.backgroundPosition = "top center";
        tlarge.style.backgroundPosition = "bottom right";
        setCookie("style", "large", 365, "/");
        break;
    default:
        if (middle) middle.style.fontSize = "100%";
        if (resultsbox) resultsbox.style.fontSize = "100%";
        tdefault.style.backgroundPosition = "bottom left";
        tmedium.style.backgroundPosition = "top center";
        tlarge.style.backgroundPosition = "top right";
        setCookie("style", "default", 365, "/");
        break;
    }
}

function hideShowDis(objOrId, hide) {
    var el = (typeof objOrId == "string")
        ? document.getElementById(id) : objOrId;
    if (el) {
        if (hide) el.style.display = "none";
        else el.style.display = (el.style.display == "none")
            ? "block" : "none";
    }
}

function hideShowVis(objOrId, hide) {
    var el = (typeof objOrId == "string")
        ? document.getElementById(id) : objOrId;
    if (el) {
        if (hide) el.style.visibility = "hidden";
        else el.style.visibility = (el.style.visibility == "hidden")
            ? "visible" : "hidden";
    }
}

function moveLoop(elementName, orgx, orgy, destx, desty, pct, destElementName) {
    var element = document.getElementById(elementName);
    var slope = -1 * (desty - orgy) / (destx - orgx);
    var dx = Math.round((desty - orgy) / slope * pct);
    var dy = Math.round(slope * (destx - orgx) * pct);

    element.style.left = (orgx - dx) + "px";
    element.style.top = (orgy - dy) + "px";

    if (pct >= 1.0) { motionFinished(elementName, destElementName, orgx, orgy); return; }

    var pct = pct + 0.05;
    setTimeout("moveLoop('" + elementName + "'," + orgx + "," + orgy + "," + destx + "," + desty + "," + pct + ",'" + destElementName + "')", 25);
}

function move(elementName, destx, desty, destElementName) {
    var element = document.getElementById(elementName);
    var currentX = element.offsetLeft;
    var currentY = element.offsetTop;
    moveLoop(elementName, currentX, currentY, destx, desty, 0.05, destElementName);
}

function moveToElement(elementName, destElementName) {
    var element = document.getElementById(destElementName);
    var currentX = getRealLeft(element);
    var currentY = getRealTop(element);
    move(elementName, currentX, currentY, destElementName);
}

function getRealLeft(element) {
    var xPos = element.offsetLeft;
    var tempElement = element.offsetParent;
    while (tempElement != null) {
        xPos += tempElement.offsetLeft;
        tempElement = tempElement.offsetParent;
    }
    return xPos;
}

function getRealTop(element) {
    var yPos = element.offsetTop;
    var tempElement = element.offsetParent;
    while (tempElement != null) {
        yPos += tempElement.offsetTop;
        tempElement = tempElement.offsetParent;
    }
    return yPos;
}

var readNews = getCookie("readnews");
var savedNews = getCookie("savednews");

if (readNews == null) readNews = "";
if (savedNews == null) savedNews = "";

// This function clears the read stories from the saved news
// HD 032706 - set readNews cookie blank when complete with this task
function clearRead() {
    var newsArray = readNews.split(",");
    var clipsArray = savedNews.split("|");

    for (var i = 0; i < clipsArray.length; i++) {
        var itemArray = clipsArray[i].split(";");
        for (var j = 0; j < newsArray.length; j++) {
            if (itemArray[1] == newsArray[j])
                deleteClipping(newsArray[j]);
        }
    }
    setCookie("savednews", savedNews, 365, "/");
    setCookie("readnews", "", 365, "/");
    element = document.getElementById("savedItems");
    element.innerHTML = clippingsHTML();
    resizeDrawer("saveit");
}

// This function deletes a specific story from read news
function deleteReadNews(url) {
    var newsArray = readNews.split(",");
    readNews = "";
    for (var i = 0; i < newsArray.length; i++) {
        if (url != newsArray[i]) {
            if (readNews != "") readNews += ",";
            readNews += newsArray[i];
        }
    }
    setCookie("readnews", readNews, 365, "/");
}

// This boolean function informs if address is in array
// Added by HD 032706
function urlIsInClipsArray(theURL, theList) {
		var clipsArray = theList.split("|");
		
    for (var i = 0; i < clipsArray.length; i++) {
      var itemArray = clipsArray[i].split(";");
	    if (theURL == itemArray[1]) {
        return true;
      }
    }
    return false;
}

function registerReadNews(url) {
// Added condition to make sure news was saved before added to read list

    var newsArray = readNews.split(",");
    for (var i = 0; i < newsArray.length; i++) {
        if (url == newsArray[i])
            return true;
    }
    
    if (urlIsInClipsArray(url,savedNews,"|")) {
	    if (readNews != "") readNews += ",";
	    readNews += url;
	    setCookie("readnews", readNews, 365, "/");
	  }
}

registerReadNews(window.location.href);

function deleteClipping(url) {
    var clipsArray = savedNews.split("|");
    savedNews = "";
    for (var i = 0; i < clipsArray.length; i++) {
        var itemArray = clipsArray[i].split(";");

        if (savedNews != "") savedNews += "|";
        if (itemArray[1] != url) {
            savedNews += clipsArray[i];
        } else {
            var element = document.getElementById(url2id(itemArray[1]));
            if (element) element.innerHTML = '<img src="http://static.viacomlocalnetworks.com/img/icon_plus_on.gif" />';
        }
    }
    setCookie("savednews", savedNews, 365, "/");
    element = document.getElementById("savedItems");
    element.innerHTML = clippingsHTML();
    resizeDrawer("saveit");
}

function clearClippings(){
    var clipsArray = savedNews.split("|");
    for (var i = 0; i < clipsArray.length; i++) {
        var itemArray = clipsArray[i].split(";");
        var element = document.getElementById(url2id(itemArray[1]));
        if (element) element.innerHTML = '<img src="http://static.viacomlocalnetworks.com/img/icon_plus_on.gif" />';
    }
    savedNews = "";
    setCookie("savednews", savedNews, 365, "/");
    element = document.getElementById("savedItems");
    element.innerHTML = clippingsHTML();
    resizeDrawer("saveit");
}

function motionFinished(elementName, destElementName, orgx, orgy) {
    var element = document.getElementById(elementName);
    element.style.visibility = "hidden";
    if (destElementName == "saveit") {
        element = document.getElementById("savedItems");
        element.innerHTML = clippingsHTML();
    }
    resizeDrawer(destElementName);
    showSuccess(orgx, orgy, destElementName);
}

var instructTimeout;

function showInstructions(element, clipType) {
    var xpos = getRealLeft(element);
    var ypos = getRealTop(element);
    var message = document.getElementById("pop_" + clipType);
    if (message == null) return;
    if (clipType == "saveit" && savedNews != "") return;
    if (instructTimeout) clearTimeout(instructTimeout);
    if (message.fadeOutTimeout) clearTimeout(message.fadeOutTimeout);
    setOpacity(message, 100);
    message.style.visibility = "hidden";
    message.style.left = xpos + "px";
    message.style.top = (ypos - (message.clientHeight || message.offsetHeight) - 5) + "px";
    instructTimeout = setTimeout("document.getElementById('pop_" + clipType + "').style.visibility = 'visible'", 500);
}

function hideInstructions(element, clipType) {
    var message = document.getElementById("pop_" + clipType);
    if (message == null) return;
    if (clipType == "saveit" && savedNews != "") return;
    if (instructTimeout) clearTimeout(instructTimeout);
    fadeOut("pop_" + clipType, 95);
}

function showSuccess(x, y, clipType) {
    if (clipType == "saveit") {
        var clipsArray = savedNews.split("|");
        var message = document.getElementById("pop_saved");
    }
    if (clipsArray.length > 1) return;
    var instruct = document.getElementById("pop_" + clipType);
    instruct.style.visibility = "hidden";
    if (message.fadeOutTimeout) clearTimeout(message.fadeOutTimeout);
    setOpacity(message, 100);
    message.style.left = x + "px";
    message.style.top = (y - (message.clientHeight || message.offsetHeight) - 5) + "px";
    message.style.visibility = "visible";
    setTimeout("fadeOut('" + message.id + "', 95)", 15000);
}

function resizeDrawer(destElementName) {
    if (destElementName == "saveit")
        var drawer = document.getElementById("popit");
    var list = drawer.getElementsByTagName("ul")[0];
    var css = drawer.style.clip || "rect(0px 0px 0px 0px)";
    var result;
    if (result = css.match(/rect\((\d+)px,? (\d+)px,? (\d+)px,? (\d+)px\)/)) {
        drawer.style.clip = "rect(" + result[1] + "px " + result[2] + "px " +
            (Number(result[3]) + (list.clientHeight || list.offsetHeight)) + "px " + result[4] + "px)";
    }
}

function clippingsHTML() {
    var markup = "";
    var clipsArray = savedNews.split("|");
    var counter = document.getElementById("savedCount");
    var count = clipsArray.length;
    if (count == 1 && clipsArray[0] == "") count = 0;
    counter.innerHTML = count;
    for (var i = 0; i < clipsArray.length; i++) {
        if (clipsArray[i] != "") {
            var itemArray = clipsArray[i].split(";");
            markup += '<li><a name="&amp;lid=saveit_story" href="' + itemArray[1] + '">' + itemArray[0] + '</a></li>';
        }
    }
    if (markup == "") {
        markup = '<li id="popnote" style="padding-left:10px;"><h3 style="color:#CC000C; font-size:1.4em;">Save It!</h3>' +
                 '<p><strong>Save stories here using <img src="http://static.viacomlocalnetworks.com/img/icon_plus_on.gif" width="10" height="10" alt="" /></strong></p>' +
                 '<p>Note: A maximum of 25 headlines can be saved. Headlines will be deleted if your CBS cookie is removed.</p></li>' +
                 '<li id="popclear"><a href="javascript:moveDrawer(\'popit\')" id="si_c">Close</a></li>';
    } else {
        markup += '<li id="popclear"><a href="javascript:moveDrawer(\'popit\')" id="si_c">Close</a><span> | </span><div id="popclearlinks"><a href="javascript:clearRead(\'saveit\')" id="si_cv">Clear Visited</a><span> | </span><a href="javascript:clearClippings()" id="si_ca">Clear All</a></div></li>'

    }
    return '<ul>' + markup + '</ul>';
}

function refreshSaved() {
    var element = document.getElementById("savedItems");
    if (element) element.innerHTML = clippingsHTML();
}

function clipExists(url) {
    var clipsArray = savedNews.split("|");
    for (var i = 0; i < clipsArray.length; i++) {
        var itemArray = clipsArray[i].split(";");
        if (itemArray[1] == url) {
            return true;
        }
    }
    return false;
}

function clipClick(element, headline, url, clipNum, clipType) {
    if (!clipExists(url)) {
        var xpos = getRealLeft(element);
        var ypos = getRealTop(element);

        clipElement = document.getElementById("fly");
        clipElement.style.left = xpos + "px";
        clipElement.style.top = ypos + "px";

        //destElement = document.getElementById("saveit");
        clipElement.style.visibility = "visible";

        if (clipType == "saveit") {
            if (savedNews != "") savedNews = "|" + savedNews;
            savedNews =  headline + ";" + url + savedNews;
            setCookie("savednews", savedNews, 365, "/");
        }

        deleteReadNews(url);

        element.innerHTML = '<img src="http://static.viacomlocalnetworks.com/img/icon_plus_off.gif" width="10" height="10" />';
        moveToElement("fly", clipType);
    }
}

function doClipClick(url) {
    var span = document.getElementById(url2id(url));
    if (span) span.onclick();
}

function url2id(url) { return url.replace(/%\/./g, "_"); }

var clipNum = 0;

function writeClipImg(headline, url, clipType) {
    var onover = 'onmouseover="showInstructions(this, \'' + clipType + '\')" onmouseout="hideInstructions(this, \'' + clipType + '\')"';
    var imageName = "http://static.viacomlocalnetworks.com/img/icon_plus_on.gif";
    if (clipExists(url)) {
        imageName = "http://static.viacomlocalnetworks.com/img/icon_plus_off.gif";
        onover = "";
    }
    document.write('<span class="clipicon" onclick="clipClick(this,\'' + headline.replace(/\'/g,"\\'") + '\',\'' + url + '\',' + clipNum + ',\'' + clipType + '\');" id="' + url2id(url) + '"><img src="' + imageName + '" width="10" height="10" ' + onover + ' /></span>');
    clipNum++;
}

function charStrip(a) {
    a = a.split("|").join("");
    a = a.split("&").join("");
    a = a.split("'").join("");
    a = a.split("#").join("");
    a = a.split("$").join("");
    a = a.split("%").join("");
    a = a.split("^").join("");
    a = a.split("*").join("");
    a = a.split(":").join("");
    a = a.split("~").join("");
    a = a.split(";").join("");
    a = a.split(" ").join("+");
    return a;
}

function hbxStrip(a) {
    a = a.split("|").join("");
    a = a.split("&").join("");
    a = a.split("'").join("");
    a = a.split("#").join("");
    a = a.split("$").join("");
    a = a.split("%").join("");
    a = a.split("^").join("");
    a = a.split("*").join("");
    a = a.split(":").join("");
    a = a.split("~").join("");
    a = a.split(";").join("");
    a = a.split(" ").join("+");
    return a;
}

function getParam(p) {
    var qstring = location.search.substring(1);
    var pattern = new RegExp("\\b" + p + "=([^&$]+)");
    var match = qstring.match(pattern);
    return match ? match[1] : "";
}

function getPic() {
    var path = unescape(getParam("gimg")).replace("+", " ");
    var title = unescape(getParam("gtitle")).replace("+", " ");
    showPicImpl(path, title);
}

function showPic(anchor) {
    var path = anchor.href;
    var title = anchor.title;
    showPicImpl(path, title);

    var advertframe =  document.getElementById("advertframe");
    if (advertframe) {
        advertframe.src = advertframe.src;
    }
    return false;
}

function showPicImpl(path, title) {
    if (path && title) {
        var gallerybigimage = document.getElementById("gallerybigimage");
        var emailimagelink =  document.getElementById("emailimagelink");
        var gallerytitle =  document.getElementById("gallerytitle");

        if (gallerybigimage && emailimagelink && gallerytitle) {
            gallerybigimage.src = path;
            gallerytitle.firstChild.data = title;
            emailimagelink.href = emailimagelink.href.replace(/\bgimg=([^%]+)%26/, "gimg=" + escape(path) + "%26").replace(/gtitle=(.*)/, "gtitle=" + title.replace(" ", "%2520"));
        }
    }
}

addEvent(window, "load", getPic);

var fsize = getCookie("style") || "default";
document.write('<link rel="stylesheet" type="text/css" href="http://static.viacomlocalnetworks.com/css/' + fsize + '.css"  />');


//New function added 1/12/06
function wipeInput(formName, inputField) {
	//alert(document.forms[formName][inputField].value);
	if (document.forms[formName][inputField].value == 'ZIP') {
		document.forms[formName][inputField].value = '';
	} else if (document.forms[formName][inputField].value == 'Quote') {
		document.forms[formName][inputField].value = '';
	}
}

//New functions added 1/26/06
function selectPartnerTab(tabid, rest) {
		var tab = document.getElementById("tab" + tabid);
		var tabdata = document.getElementById("newtab" + tabid + "data");
		if (tab && tabdata) {
				tab.className = "currenttab";
				tabdata.style.display = "block";
				for (var i = 1; i < arguments.length; i++) {
						var tab = document.getElementById("tab" + arguments[i]);
						var tabdata = document.getElementById("newtab" + arguments[i] + "data");
						if (tab && tabdata) {
								tab.className = "";
								tabdata.style.display = "none"
						}
				}
		}
}

function randomWeight() 
{
	var rNum=Math.floor(Math.random()*101);
	var domain = location.hostname

	/*if (domain == 'wcco.com')
	{
		if (rNum >= 0 && rNum <= 50) {selectPartnerTab('1','2','3','4','5','6','7');}
		if (rNum >= 51 && rNum <= 60) {selectPartnerTab('3','4','5','6','7','1','2');}
		if (rNum >= 61 && rNum <= 70) {selectPartnerTab('4','5','6','7','1','2','3');}
		if (rNum >= 71 && rNum <= 85) {selectPartnerTab('5','6','7','1','2','3','4');}
		if (rNum >= 86 && rNum <= 100) {selectPartnerTab('7','6','5','1','2','3','4');}
	}
	else
	{
		if (rNum >= 0 && rNum <= 50) {selectPartnerTab('1','2','3','4','5','6','7');}
		if (rNum >= 51 && rNum <= 60) {selectPartnerTab('2','1','3','4','5','6','7');}
		if (rNum >= 61 && rNum <= 70) {selectPartnerTab('3','4','5','6','7','1','2');}
		if (rNum >= 71 && rNum <= 80) {selectPartnerTab('4','5','6','7','1','2','3');}
		if (rNum >= 81 && rNum <= 90) {selectPartnerTab('5','6','7','1','2','3','4');}
		if (rNum >= 91 && rNum <= 100) {selectPartnerTab('7','6','5','1','2','3','4');}
	}*/
	
	// commented out random selector for partner tabs, always use coupons for now
	selectPartnerTab('1','2','3','4','5','6','7')
	
}

var sURL = unescape(window.location.pathname);

function doLoad()
{
    // the timeout value should be the same as in the "refresh" meta-tag
    setTimeout( "refresh()", 1000*1000 );
}

function refresh()
{
    //  This version of the refresh function will cause a new
    //  entry in the visitor's history.  It is provided for
    //  those browsers that only support JavaScript 1.0.
    //
    window.location.href = sURL;
}

function LaunchSyndicateArticle(ArtId,template,CustId,ContId,CatID)
{
  var SiteRegExp = new RegExp('@' + SiteName.replace(/\//g,"\\/"),"gi");
  var ArtString=ArtId.toString().replace(SiteRegExp,"");
  var Customer_ID="";
  var Contract_ID="";
  var Category_ID="";  
  var TemplateFile="";
  var URLstring="";

  kWidth = 764;
  kHeight = 449;
  var winName = "VideoViewer";
  var page;

URLstring = "&PreloadContract_DefID=1&Contract_DefID=2";

if ((template!= '') && (typeof template!= "undefined") && (template== "wjzviewer_noads.tpl")) {
	ContId="0";
	template="";
}

if ((template!= '') && (typeof template!= "undefined")) {
TemplateFile = '&tf='+template;
}else{
TemplateFile = '&tf=video_player.tpl';
}


if ((CatID != '') && (typeof CatID != "undefined")) {	
	switch(CatID) {
		case "0":
			URLstring = "&PreloadContract_DefID=1&Contract_DefID=3";
			break;		
		case "6":
			URLstring = "&PreloadContract_DefID=1&Contract_DefID=3";
			break;		
		default:
			URLstring = "&PreloadContract_DefID=1&Contract_DefID=2";
	} 
}


         if ((CustId != '') && (typeof CustId != "undefined"))
         {
           if (CustId.charAt(0) == "-")
             Customer_ID = '&ExCust='+CustId.slice(1);
           else      
             Customer_ID = '&Customer_ID='+CustId;
        }
  
	if ((ContId != '') && (typeof ContId != "undefined") && (ContId == "0"))
		Contract_ID = '&NoAds=true';
	else if ((ContId != '') && (typeof ContId != "undefined")) 
		Contract_ID = '&Contract_ID='+ContId;  	
	
	if ((CatID != '') && (typeof CatID != "undefined"))
		Category_ID = '&Category_ID='+CatID;
	else
		Category_ID = '&Category_ID=5';
	
	page = "http://"+SiteName+"/viewer/viewerpage.php?Art_ID=" + ArtString + TemplateFile + URLstring + Customer_ID + Contract_ID + Category_ID;

  var xPosition = screen.width/2-(kWidth/2);
  var yPosition = screen.height/2-(kHeight/2);
  var Params = "height=" + kHeight + ",width=" + kWidth + ",left=" + xPosition + ",top=" + yPosition + ",screenX=" + xPosition + ",screenY=" + yPosition;
  var kWin=window.open(page,winName,Params); 
  kWin.opener = self;
  kWin.focus();
}


