var domain = "http://www.comcast.net";
var sessiondomain = ".comcast.net";
var loggedin = false;
var haspreferences = false;
var isPrimary = false;
var firstName = "";
var greeting = "";
var zipCode = "";
var areaCode = "";
var user = "";
var pollPath = "";
var param = "";

if (document.location.href.indexOf("http://comcast.net") != -1) {
	document.location.href = "http://www.comcast.net";
}

if ((loggedin) && ((document.location.href.indexOf("home.html") != -1) || (document.location.href.indexOf("comcast.html") != -1))) {
	document.location.href = "http://www.comcast.net";
}

if (document.location.href.indexOf("sports") != -1) {
	pollPath = "classic/poll/sports"; // needed for missing variable on Sports JSP pages
}
else {
	pollPath = "classic/poll/news"; // needed for missing variable on News JSP pages
}

// for backward comp.
var yhmcount = -1;


/* Global array provides data for tab system */
var tabData = {
    active:[],
    types:{
        dvd:[0,31,66],
        movies:[0,80],
        playgames:[0,87,218]
    }
};

function displayLoginLogoutButton() {
    if (loggedin) {
		return "<a href=\"" + domain + "/signout.jsp\">Sign Out</a>";
    } else {
		if ((document.location.href.indexOf("home.html") != -1) || (document.location.href.indexOf("comcast.html") != -1)) {
			return"<a href=\"" + domain + "/signin.jsp\">Sign In</a>";
		}
		else {
			return"<a href=\"" + domain + "/signin.jsp?redirectUrl=" + document.location + "\">Sign In</a>";			
		}
    }
}

function displaySwitchButton() {
	return "<div><a href=\"" + domain + "/express\" title=\"Switch to the Express View. Requires the Flash 7 plugin.\"><img src=\"/images/buttons/express.gif\" alt=\"Go to express\" border=\"0\" onclick=\"setSessionCookie('SESSIONHOME', 'forcedexpress', '/', '" + sessiondomain + "', false);document.location.href='" + domain + "/';return false;\" /></a></div>";
}

function displayModifyButton() {
	return "<div><a href=\"#\"><img src=\"/images/buttons/modifythispage.gif\" alt=\"Modify This Page\" border=\"0\" onclick=\"modify(); return false;\" /></a></div>";
}

function displayGreetingYHM() {
    var tmp = "<span>Welcome, Guest!</span>";
    if (loggedin) {
        tmp = getGreeting();
        if (greeting.length >= 1) {
            tmp += ", " + "<a href=\"" + domain + "/providers/greeting/\" title=\"Modify your greeting name\" class=\"greet\" onclick=\"window.open(this.href, 'greeting', 'scrollbars=no,status=no,location=no,toolbar=no,favorites=no,address=no,menubar=no,resizable=yes,width=335,height=205'); return false;\">" + greeting + "</a>!</span>";
        }
    }
    return tmp;
}

function searchTheWeb(form) {
	var searchTerm = document.getElementById('search-field').value;
	if ((searchTerm == "search the web") || (searchTerm == "")) {
		document.location.href = "/search";
		return false;
	}
	else {
		return true;
	}
}


function getGreeting() {
    var now = new Date();
    var hour = now.getHours();
    var greeting = "<span>";
    if (hour < 12) {
        greeting += "Good Morning";
    } else if (hour < 17) {
        greeting += "Good Afternoon";
    } else {
        greeting += "Good Evening";
    }

    return greeting;
}


// Used to calculate time elapse in AP articles
// milliseconds in each
var mn = 60000;
var hr = 3600000;
var dy = hr * 6;

var months = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var days = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');


// expects date/time in GMT
function getElapsed(dtIn) {
	var now = (new Date()).getTime();
  var dt = makeDate(dtIn);
	var then = dt.getTime();
	var diff = now - then;
  var unit = "";
	if (diff > dy) {
		unit = days[dt.getDay()] + " ";
		unit += months[dt.getMonth()] + " ";
		unit += dt.getDate() + ", ";
		min = dt.getMinutes();
		if (min < 10) {
			min = "0" + min;
		}
		if (dt.getHours() > 12) {
		   unit += (dt.getHours() - 12) + ":" + min + " ";
		   unit += "PM";
		} else {
		   unit += dt.getHours() + ":" + min + " ";
		   unit += "AM";
		}
	} else if (diff > hr) {
		var tm = Math.round(diff/hr);
		var s = (tm > 1) ? "s" : "";
		unit = tm+" hour"+s+" ago";
	} else if (diff > mn) {
		var tm = Math.round(diff/mn);
		var s = (tm > 1) ? "s" : "";
		unit = tm+" minute"+s+" ago";
	}

	return unit;
}

function makeDate(dtIn) {

  var year = dtIn.substr(0,4);
  var month = dtIn.substr(4,2) - 1;
  var day = dtIn.substr(6,2);

  var hour = dtIn.substr(9,2);
  var minute = dtIn.substr(11,2);

  var dt = new Date();
  dt.setUTCFullYear(year);
  dt.setUTCMonth(month);
  dt.setUTCDate(day);
  dt.setUTCHours(hour);
  dt.setUTCMinutes(minute);

	return dt;
}


function getArgs() {
    var args = new Object();
    var query = top.location.search.substring(1);   //get querystring
    var pairs = query.split("&");                   //break on each &
    for(var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('=');            //look for name=value
        if (pos == -1) continue;                    //if not found, skip
        var argname = pairs[i].substring(0, pos);   //extract name
        var value = pairs[i].substring(pos+1);      //extract value
        args[argname] = unescape(value);            //store as a property
    }
    return args;                                    //return object
}

function getParam(parameter) {
    var allTheValues = getArgs();                   //get hashmap object
    var theValue = allTheValues[parameter];
    if (typeof theValue == "undefined") {
        theValue = "";
    }
    return theValue;                                //return value
}

function isProduction() {
    var dom = new String(location.hostname);
    if (dom.indexOf("comcast.net") >= 0 || dom.indexOf("attbi.com") >= 0) {
        return true;
    } else {
        return false;
    }
}

function stringReplace(theString, replaceMe, withMe) {
    var rExp;
    var temp = "";
    var newReplaceMe = "";
    for (var x = 0 ; x < replaceMe.length ; x++) {
        temp = replaceMe.substr(x, 1);
        if (
            temp == "$" ||
            temp == "^" ||
            temp == "*" ||
            temp == "(" ||
            temp == ")" ||
            temp == "+" ||
            temp == "?" ||
            temp == "\\"
           ) {
           temp = "\\" + temp;
        }
        newReplaceMe += temp
    }
    rExp = new RegExp(newReplaceMe, "gi");
    results = theString.replace(rExp, withMe);
    return results;
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
}

function getCookieVal (offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            return getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) {
            break;
        }
    }
    return '';
}
function setCookie(name, value, days, path, domain, secure) {
    if (isNaN(days)) {
        days = 1;
    }
    var offset = days * 24 * 60 * 60 * 1000;
    var now = new Date();
    var d;
    if (!isNaN(now.valueOf())) {
        var then = now.valueOf() + offset;
        d = new Date(then);
    } else {
        d = now;
    }
    var curCookie = name + "=" + escape(value) + "; expires=" + d.toGMTString() +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
    document.cookie = curCookie;
}
function getCrumbVal (crumb, offset) {
    var endstr = crumb.indexOf("&", offset);
    if (endstr == -1) {
        endstr = crumb.length;
    }
    var temp = crumb.substring(offset, endstr);
    temp = stringReplace(temp, "+", " ");
    return unescape(temp);
}
function GetCrumb (crumb, name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = crumb.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (crumb.substring(i, j) == arg) {
            return getCrumbVal(crumb,j);
        }
        i = crumb.indexOf("&", i) + 1;
        if (i == 0) {
            break;
        }
    }
    return '';
}



//writes a 120x600 banner to the document
function writeBannerSkyScraper(category) {
    var minNum = 10000000;
    var maxNum = 99999999;
    var randomNumber = Math.round(Math.random() * (maxNum - minNum)) + minNum;
    var status = ((loggedin) ? "logged" : "anon");
    var term = getParam("query");
    /*if (is_js < 1.1) {
        document.write('<a href="http://oascentralnx.comcast.net/RealMedia/ads/click_nx.ads/comcast.net/searchresults/1' + randomNumber + '@Right?c=' + status + '&query=' + term + '"><img src="http://oascentralnx.comcast.net/RealMedia/ads/adstream_nx.ads/comcast.net/searchresults/1' + randomNumber + '@Right?c=' + status + '&query=' + term + '"></a>');
    	//alert("Term = " + term + "\nRandom Number = " + randomNumber + "\nStatus = " + status);
    } else {*/
        document.write('<script language="JavaScript1.1" src="http://oascentral.comcast.net/RealMedia/ads/adstream_jx.ads/comcast.net/searchresults/1' + randomNumber + '@Right?c=' + status + '&query=' + term + '">');
        document.write('</script>');
        //alert("Term = " + term + "\nRandom Number = " + randomNumber + "\nStatus = " + status);
    //}
}

function getFirstFolder() { 
  var path = new String(window.location.pathname); 
  var firstFolder = path.split("/"); 
  //return the second item in the array; first item is blank 
  return firstFolder[1]; 
 } 
//document.writeln(getFirstFolder());

function writeSkyBan(position) {
	var minNum = 10000000;
    var maxNum = 99999999;
    var randomNumber = Math.round(Math.random() * (maxNum - minNum)) + minNum;
    var status = ((loggedin) ? "logged" : "anon");
    var term = getParam("query");
    var pagename = getFirstFolder();
    var placement = "";
    if ((pagename == "comcast.html") || (pagename == "home.html") || (pagename == "explore.html")) { pagename = "home"; }
    if (position == "navbar") {
    	placement = "Left";
    }
    else {
    	placement = "Right";
    }
	if ((position == "navbar" && loggedin) || (position == "assistant" && !loggedin)) {
		document.write('<div id="asst-ad-wrapper"><div id="asst-ad">');
		document.write('<iframe width="120" height="600" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" src="http://oascentral.comcast.net/RealMedia/ads/adstream_sx.cgi/comcast.net/' + pagename + '/1' + randomNumber + '@' + placement + '?c=' + status + '&query=' + term + '"></iframe>');
		document.write("</div></div>");
	}
}



// Writes links in the Search subnav bar
function searchQry(type) {
	if (type != "videosearch") {
		document.location.href = "/qry/" + type + "?query=" + getParam('query');
	}
	else {
		document.location.href = "http://videosearch.comcast.net/ss-query/videosearch.jsp?query=" + getParam('query');
	}
}


function submitAskComcast(frm) {
    if(frm.q.value == '') return false;
    var defaultFeatures = 'scrollbars=no,status=no,location=no,toolbar=no,favorites=no,address=no,menubar=no,resizable=yes';
    var askFeatures     = defaultFeatures + ',width=500,height=435';
    var tmpQuery        = new String(frm.q.value).split(' ');
    var tmpQueryStr     = frm.action + '?q=' + tmpQuery.join('+');
    window.open(tmpQueryStr, "ask", askFeatures);
    return false;
}


// Provides an accessible, standards-compliant method of handling popup windows that also degrades gracefully in the absense of JavaScript
function externalLinks() {

	// detect modern, DOM-compliant browsers
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");

	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];

		// window chrome features
		var defaultFeatures = 'scrollbars=no,status=no,location=no,toolbar=no,favorites=no,address=no,menubar=no,resizable=yes';
		var comicFeatures = defaultFeatures + ',width=650,height=320';
		var fanFeatures = defaultFeatures + ',width=560,height=625';
		var slideshowFeatures = defaultFeatures + ',width=560,height=625';
		var askFeatures = defaultFeatures + ',width=500,height=435';
		var newWinMsg = ". This link will open in a new window.";
		var fanMsg = ". This link will open in a new window.";
		var ssMsg = "View a photo slideshow starting with this picture. This link will open in a new window.";

		// test for anchors that contain hyperlinks, exclude named page anchors
		//if (!anchor.getAttribute("href")) return;

		// test for anchors that contain the REL attribute
		if (anchor.getAttribute("rel")) {

			// for links that should open a fully-chromed, full-sized browser window
			//if (anchor.getAttribute("rel") == "external") {
			if (anchor.getAttribute("rel").indexOf("external") != -1) {
				//anchor.title += newWinMsg;
				anchor.target = "_blank";
			}

			// for links that should open with specific chrome features and preset sizes
			if (anchor.getAttribute("rel").indexOf("popup") != -1) {
				anchor.onclick = function() {
				    var anchorFeat = (this.href.indexOf("Comic") != -1 || this.href.indexOf("comic") != -1) ? comicFeatures : defaultFeatures;
					window.open(this.href, this.rel, anchorFeat);
					return false;
				}
			}

			// for links to Fan videos
			if (anchor.getAttribute("rel") == "fan") {
				//anchor.title += fanMsg;
				anchor.onclick = function() {
					window.open(this.href, "fan", fanFeatures);
					return false;
				}
			}

			// for links to Ask Comcast
			if (anchor.getAttribute("rel") == "ask") {
				//anchor.title += newWinMsg;
				anchor.onclick = function() {
					window.open(this.href, "ask", askFeatures);
					return false;
				}
			}

			// for links to AP Photo Slideshow
			/*if (anchor.getAttribute("rel") == "slideshow") {
				//anchor.title += ssMsg;
				anchor.onclick = function() {
					window.open(this.href, "slideshow", slideshowFeatures);
					return false;
				}
			}*/

			// symbol lookup
			if (anchor.getAttribute("rel").indexOf("symbollookup") != -1) {
				anchor.onclick = function() {
                    var tmpURL       = this.href;
                    var tmpSymbolObj = document.getElementById('searchfor');
                    if(tmpSymbolObj != null) tmpURL += "?searchfor=" + tmpSymbolObj.value;
                    window.open(tmpURL, this.rel, askFeatures);
					return false;
				}
			}

			// used for links in leftnav
			if (anchor.className && anchor.className.indexOf("channel") != -1) {
				anchor.onclick = function() {
					subnav(this.getAttribute("rel"), this);
					return false;
				}
			}

			// used for closing popup window and loading document in the opener
			if (anchor.getAttribute("rel") == "opener") {
				anchor.onclick = function() {
					opener.document.location.href = this.getAttribute("href");
					self.close();
					return false;
				}
			}

			}
	}
}


// Hides and shows submenus and highlights appropriate button
function subnav(menuName, buttonName) {

// detect modern, DOM-compliant browsers
if (!document.getElementById) return;

	var menuName = document.getElementById(menuName);

	if (menuName.style.display == "none") {
		menuName.style.display = "";

		if (buttonName.className.indexOf("selected") == -1) {
			if (buttonName.className.indexOf("sub") == -1) {
				buttonName.className = stringReplace(buttonName.className, "channel-menu", "channel-menu-s");
			}
			else {
				buttonName.className = stringReplace(buttonName.className, "subchannel-menu", "subchannel-menu-s");
			}
		}
	}

	else {

		if (buttonName.className.indexOf("selected") == -1) {
			menuName.style.display = "none";

			if (buttonName.className.indexOf("sub") == -1) {
				buttonName.className = stringReplace(buttonName.className, "channel-menu-s", "channel-menu");
			}
			else {
				buttonName.className = stringReplace(buttonName.className, "subchannel-menu-s", "subchannel-menu");
			}
		}
	}
}


// Writes Flash navbar, shifts HTML navbar off screen. When Flash is disabled, replaces Flash navbar with HTML navbar. HTML navbar shows in absence of JavaScript.
// Writes HTML navbar IFRAME for third parties
function writeNav() {
	document.write('<iframe src="http://www.comcast.net/includes/layout/inav.html" id="navframe" frameborder="0" scrolling="no"><\/iframe>');
}

function writeNavBody() {
	if (top.document.location.href.indexOf("finance.comcast.net") != -1) {
		if (top.document.location.href.indexOf("/rich/us_markets") != -1) {
			document.write('<body id="comcastnet" class="finance markets rich standard">');
		}
		else {
			document.write('<body id="comcastnet" class="finance main rich standard">');
		}
	}
}

function writeNavHStart() { }
function writeNavHEnd() { }


// Writes Assistant sidebar when authenticated. When Flash is disabled, nothing shows. When JavaScript is disabled, nothing shows.
function writeAssistant(teaser) {

    if ((hasRightVersion) && (loggedin)) {
    	var queryStr = "?is=common/assistant";
		queryStr += "&un="+user;
		
		document.write('<div id="assistant">');
		document.write(teaser);
		document.write('<a href="#" onclick="popAssistant(); return false;"><img src="/images/global/assistant2.gif" width="200" height="39" alt="Comcast Assistant" border="0" title="Launch the Popup Assistant. This link will open in a new window." id="assistant2" /></a>');
		document.write('<div class="skip"><a href="#a-assistant">Skip this Flash Movie</a><br /></div>');
       	writeFlash("assistantFlash","/Canvas.swf"+queryStr,200,1900,"#19314B"); 
		document.write('<a name="a-assistant"></a>');
		document.write('<div class="skip"><a href="#a-pagetop">Back to Top</a><br /></div>');
		document.write('</div>');
	}
	else if ((hasRightVersion) && (isInNetwork)) {
		document.write('<div id="assistant">');
		document.write(teaser);
		document.write('<a href="#" onclick="popAssistant(); return false;"><img src="/images/global/assistant2.gif" width="200" height="39" alt="Comcast Assistant" border="0" title="Launch the Popup Assistant. This link will open in a new window." id="assistant2" />');
		document.write('<a href="/signin.jsp" title="Access the Assistant by signing in to Comcast.net"><img src="/images/global/assistant.gif" alt="Comcast Assistant" /></a>');
		document.write('<div class="skip"><a href="#a-pagetop">Back to Top</a><br /></div>');
		writeSkyBan("assistant");
		document.write('</div>');
	}
	else if ((hasRightVersion) && ((!isInNetwork) && (!loggedin))) {
		document.write('<div id="assistant">');
		document.write(teaser);
		document.write('<a href="#" onclick="popAssistant(); return false;"><img src="/images/global/assistant2.gif" width="200" height="39" alt="Comcast Assistant" border="0" title="Launch the Popup Assistant. This link will open in a new window." id="assistant2" /></a>');
		document.write('<a href="/signin.jsp"><img src="/images/global/teaser.jpg" alt="Sign in to: create and send multimedia photo shows; send free video emails to your friends and family; watch thousands of free videos from music to movie trailers to news; customize scores stock and bookmarks." /></a>');
		document.write('<div class="skip"><a href="#a-pagetop">Back to Top</a><br /></div>');
		writeSkyBan("assistant");
		document.write('</div>');
	}
}

function writePopupAssistant() {
    if ((hasRightVersion) && (loggedin)) {
	    self.focus();
        var queryStr = "?is=common/assistant";
        queryStr += "&un="+user;
        var winH = 600;
        if( typeof( window.innerWidth ) == 'number' ) { //Non-IE
            winH = window.innerHeight;
        } else if( document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight) ) { //IE 6+ in 'standards compliant mode'
            winH = document.documentElement.clientHeight;
        } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible
            winH = document.body.clientHeight;
        }
        writeFlash("assistantFlash","/Canvas.swf"+queryStr,200,1300,"#19314B");
	} else {
	    self.close();
	}
}

function popAssistant() {
	if ((hasRightVersion) && (loggedin)) {
		var h = (eval((screen.height) - 100));
		window.open('/providers/assistant/popup.html','popup_assistant','scrollbars=yes,status=no,location=no,toolbar=no,favorites=no,address=no,menubar=no,resizable=yes,width=220,height=' + h + ',top=10,left=10');
	}
	else {
		document.location.href = "/signin.jsp?redirectUrl=" + document.location;
	}
}

function writeCover(path) {
    if (hasRightVersion) {
    	var queryStr="?";
        var h = 246;
        if (loggedin||isInNetwork) {
        	queryStr += "isLoggedIn="+loggedin;	
	   if(path != "classic/cover/music") {
            		h = 466;
          }
        }
        document.write('<div id="cover">');
        writeFlash("coverFlash","/swf/classic/cover/CoverSA.swf"+queryStr,592,h);
        document.write('</div>');
	}
   
}

function writePoll(path) {
/*    if (hasRightVersion) {
    
    	if (document.location.href.indexOf("playgames") != -1) {
    		path = "classic/poll/gamesplay";
    	}
    	
    	var queryStr = "?is="+path;
        if (loggedin) {
            queryStr += "&un="+user;
        }
        document.write('<div class="module wide">');
    	document.write('<h3 id="h-poll">Poll</h3>');
    	document.write('<div class="skip"><a href="#a-poll">Skip this Flash Movie</a><br /></div>');
        writeFlash("pollFlash","/Canvas.swf"+queryStr,180,250);
        document.write('<a name="a-poll"></a>');
        document.write('</div>');
        document.write('<div class="module-divider"></div>');
	}*/
}

function writeScores() {
    if (hasRightVersion) {
    	document.write('<div class="module wide scores">');
    	document.write('<h3 id="h-scores">Scoreboard</h3>');
        document.write('<div class="skip"><a href="#a-scores">Skip this Flash Movie</a><br /></div>');
		writeFlash("scoresFlash","/swf/common/module/scores/scores.swf?backgroundColor=FFFFFF&islgin="+loggedin,200,420);
        document.write('<a name="a-scores"></a>');
        document.write('</div>');
        document.write('<div class="module-divider"></div>');
    }
}

function writeFlashHome() {
		var usrname= GetCrumb(myportal, "em");
		document.write('<div id="flashhome-wrapper">');
		document.write('<div id="flashhome">');
		document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="592" height="2000" id="site" align="middle">');
		document.write('  <param name="allowScriptAccess" value="sameDomain" />');
		document.write('  <param name="movie" value="Canvas.swf" />');
		document.write('  <param name="FlashVars" value="is=classic&loggedin=true&ion=true&un='+usrname+'" />');
		document.write('  <param name="quality" value="high" />');
		document.write('  <param name="menu" value="false" />');
		document.write('  <param name="salign" value="lt" />');
		document.write('  <param name="bgcolor" value="#EBEDEF" />');
		document.write('  <embed src="Canvas.swf" quality="high" FlashVars="is=classic&loggedin=true&ion=true&un='+usrname+'" salign="lt" bgcolor="#19314B" width="592" height="2000" name="site" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
		document.write('</object>');
		//document.write('<iframe id="page" name="page" src="page.html?section=0&content=0&name=HOME - Comcast.net" noresize="noresize" width="400" height="0" frameborder="0" scrolling="no"><\/iframe>');
}

var sessionHomeCookie=GetCookie("SESSIONHOME");

function homeRedirect() {
		var queryStr = new String(window.location.search);
		var sessionHomeCookie=GetCookie("SESSIONHOME");
		var skinChoice = sessionHomeCookie;
		var myportal = GetCookie("MYPORTAL");
		var loggedin = false;
		var upgradePage = "/flashUpgrade.html";
		var exploreAuth = "/explore.html";
		var exploreSemi = "/home.html";
		var exploreAnon = "/comcast.html";
		var litePage = "/lite";
		
		// Inits the game variables for real.com's code
		if (document.getElementById) { initGameScript("comcast_"); }
	// No Flash
	if (!hasRightVersion) {
		// Auth
		if (myportal != "") {
			if ((sessionHomeCookie == "express") || (sessionHomeCookie == "forcedexpress")) {
				setSessionCookie('SESSIONHOME', 'express', '/', '" + sessiondomain + "', false);
				document.location.href = upgradePage;
				
			}
			else if (sessionHomeCookie == "lite") {
				document.location.href = litePage;
			}
			else {
				document.location.href = exploreSemi;
			}
		}
		// Anon
		else  {
			if ((sessionHomeCookie == "express") || (sessionHomeCookie == "forcedexpress")) {
				setSessionCookie('SESSIONHOME', 'express', '/', '" + sessiondomain + "', false);
				document.location.href = upgradePage;
			}
			else if (sessionHomeCookie == "lite") {
				document.location.href = litePage;
			}
			else if (isInNetwork) {
				document.location.href = exploreSemi;
			}
			else {
				document.location.href = exploreAnon;
			}
		}
	}
	
	// Flash
	else {
		// Auth
		if (myportal != "") {
			if((queryStr.indexOf("section")!=-1)||(queryStr.indexOf("content")!=-1)){
				writeExpress();
			}
			else if(sessionHomeCookie == "forcedexpress") {
				setSessionCookie('SESSIONHOME', 'express', '/', '" + sessiondomain + "', false);
				writeExpress();
			}
			else if(myportal.indexOf("&v=&")==-1){
				var skin = GetCrumb(myportal, "v");
				if (skin=="express"){
					writeExpress();
				}
				else {
					document.location.href = exploreAuth;
				}	
			}
			else{
				document.location.href = exploreAuth;
			}
		}
		// Anon
		else {
			if ((sessionHomeCookie == "express") || (sessionHomeCookie == "forcedexpress")) {
				setSessionCookie('SESSIONHOME', 'express', '/', '" + sessiondomain + "', false);
				writeExpress();
			}
			else if ((sessionHomeCookie == "home") || (sessionHomeCookie == "explore") || (sessionHomeCookie == "forcedexplore") || (sessionHomeCookie == "")) {
				if (isInNetwork) {
					document.location.href = exploreSemi;
				}
				else {
					document.location.href = exploreAnon;
				}
			}
			else if (sessionHomeCookie == "lite") {
				document.location.href = litePage;
			}
			else {
				document.location.href = exploreAnon;
			}
		}	
	}
}

function writeExpress() {
	var queryStr = new String(window.location.search);
	queryStr = queryStr.substr(1);
	if (queryStr.length > 0) queryStr += "&";
	queryStr += "un="+GetCrumb(myportal, "em")+"&";
	queryStr += "&is=express&";
	queryStr += "ion="+isInNetwork+"&";
	queryStr += stamp;
	
	var w = "100%";
	if (isIE) w = "995";
	
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+w+'" height="2000" id="site" align="middle">');
	document.write('  <param name="allowScriptAccess" value="sameDomain" />');
	document.write('  <param name="movie" value="Canvas.swf" />');
	document.write('  <param name="FlashVars" value="'+queryStr+'" />');
	document.write('  <param name="quality" value="high" />');
	document.write('  <param name="menu" value="false" />');
	document.write('  <param name="salign" value="lt" />');
	document.write('  <param name="bgcolor" value="#19314B" />');
	document.write('  <embed src="Canvas.swf" quality="high" FlashVars="'+queryStr+'" salign="lt" bgcolor="#19314B" width="'+w+'" height="2000" name="site" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('<\/object>');
	document.write('<iframe id="page" name="page" src="page.html?section=0&content=0&name=HOME - Comcast.net" noresize="noresize" width="400" height="0" frameborder="0" scrolling="no"><\/iframe>');
}

function metaBypass() {
	if ((sessionHomeCookie == "express") || (sessionHomeCookie == "forcedexpress")) {
	} 
	else { 
		if (loggedin) {
			document.write('<meta http-equiv="refresh" content="5; URL=/explore.html" />');
		}
		else {
			
		}
	}
}

function writeEmbeddedFan() {
}


function viewTheFan(source) {
}

function hideTheFan() {
	var vlyr = document.getElementById("fanLayer");
	vlyr.style.left = -2500;
	vlyr.style.display = "none";
}

function popTheFan(vid,conf) {
	window.open("/providers/fan/popup.html?"+vid+"&config="+conf,'thefan',"width=560,height=625");
}




/*
 * Tab Initialization
 */
function initTabs() {
	if (document.getElementsByTagName) {
    var tmpTags = document.getElementsByTagName('dl');
    // Loop through all 'dl' tags, look for 'tab-set' class

    for(i = 0; i < tmpTags.length; i++) {
        if(!tmpTags[i].className || tmpTags[i].className != 'tab-set') continue;
        var tabSetType  = new String(tmpTags[i].id).split('-')[2];
        var tabSetID    = new String(tmpTags[i].id).split('-')[3];
        var tabSplitID  = new String(tmpTags[i].id).split('-');
        var tabSetWidth = (tabSplitID[4] != null) ? tabSplitID[4] : 160;
        tabData.active[tabSetID] = {tabRefs:[],contentRefs:[],currTab:null,type:tabSetType};
        
        var tmpDate = new Date();
        var dotw = tmpDate.getDay();
        var isWeekend = (dotw == 0 || dotw > 4);
        var selectSecondTab = ((tabSetID == 'intheaters') && isWeekend);
        
        var tabCount  = 0;
        var tabOffset = 0;
        var tabToActivate  = null;
        for(var o = 0; o < tmpTags[i].childNodes.length; o++) {
            if(tmpTags[i].childNodes[o].nodeType == 1) {
                var tagType = new String(tmpTags[i].childNodes[o].nodeName).toLowerCase();
                if(tagType == 'dt') {
                    tabData.active[tabSetID].tabRefs[tabCount] = tmpTags[i].childNodes[o];
                    
                    // Determine tab to be selected
                    if((selectSecondTab && tabCount == 1) || tabToActivate == null) {
                        tabToActivate = tmpTags[i].childNodes[o];
                    }
                    
                    var currOffset = tabData.types[tabSetType][tabCount];
                    var nextOffset = (tabData.types[tabSetType][tabCount+1] != null) ? tabData.types[tabSetType][tabCount+1] : null;
                    var currWidth  = (nextOffset != null ? nextOffset : tabSetWidth) - currOffset;
                    tabOffset     += tabData.types[tabSetType][tabCount];

                    tmpTags[i].childNodes[o].id = 'tab-set-hdr-' + tabSetID + '-' + tabCount;
                    tmpTags[i].childNodes[o].style.backgroundImage = "url(/images/headings/tabs-" + tabSetType + ".gif)";
                    tmpTags[i].childNodes[o].style.backgroundPosition = '-' + currOffset + 'px 0px';
                    tmpTags[i].childNodes[o].style.marginLeft = (currOffset + 'px');
                    tmpTags[i].childNodes[o].style.width = (currWidth + 'px');
                    tmpTags[i].childNodes[o].onclick = function() { activateTab(this); };

                } else if(tagType == 'dd') {
                    tabData.active[tabSetID].contentRefs[tabCount] = tmpTags[i].childNodes[o];
                    if(!tabCount++) tmpTags[i].childNodes[o].style.visiblity = 'visible';
                }

            } else {
                lastTag = null;
            }

        }
        if(tabToActivate != null) activateTab(tabToActivate);
    }
    }
}


/*
 * Tab activation
 */
function activateTab(tabObj) {
    var idData      = new String(tabObj.id).split('-');
    var tabSetID    = idData[3];
    var tabSetType  = tabData.active[tabSetID].type;
    var clickTabID  = idData[4];

    // Clear active tab
    if(tabData.active[tabSetID].currTab != null) {
        var currTabID  = tabData.active[tabSetID].currTab;
        var currOffset = tabData.types[tabSetType][currTabID];
        tabData.active[tabSetID].tabRefs[currTabID].style.backgroundPosition = '-' + currOffset + 'px 0px';
        tabData.active[tabSetID].contentRefs[currTabID].style.display = 'none';
    }

    // Activate new tab
    var clickOffset = tabData.types[tabSetType][clickTabID];
    tabData.active[tabSetID].tabRefs[clickTabID].style.backgroundPosition = '-' + clickOffset + 'px -18px';
    tabData.active[tabSetID].contentRefs[clickTabID].style.display = 'block';

    tabData.active[tabSetID].currTab = clickTabID;
}


var myportal = "";
myportal = GetCookie("MYPORTAL");
if (myportal != '') {
	user = GetCrumb(myportal, "em");
	if (user != '') {
		loggedin = true;
	}
	greeting = GetCrumb(myportal, "gt");
	zipCode  = GetCrumb(myportal, "zip");
	areaCode = GetCrumb(myportal, "npa");
	isPrimary = (GetCrumb(myportal, "ipr") == 'y')?true:false;
	var p = GetCrumb(myportal, "p");
	if (p != '') haspreferences = true;
}

function getZipCode() {
    return zipCode;
}


function fanPopup(url) {
	if (hasRightVersion) { 
		window.open(url, "thefan", "scrollbars=no,status=no,location=no,toolbar=no,favorites=no,address=no,menubar=no,resizable=yes,width=560,height=625");
	}
	else {
		document.location.href = "/flashUpgrade.html";
	}
}

function slidePopup(url) {
	window.open(url, "slideshow", "scrollbars=auto,status=no,location=no,toolbar=no,favorites=no,address=no,menubar=no,resizable=yes,width=600,height=650");
}

function slideClose(url) {
	opener.document.location.href = url;
	self.close();
	return false;
}

function pageLoad() {
	externalLinks();
	if(typeof(initTabs) != 'undefined') initTabs();
	//alert("page loaded");
}

/*
 * URL Randomizer
 *
 * Returns original URL with a random integer appended as an argument, prevents caching
 */
function randomizeURL(url) {
    return url + ((url.indexOf('?') != -1) ? '&random=' : '?random=') + Math.floor(Math.random() * 999999);
}



function disneyConnection(url) {
var title = "Welcome to Disney Connection!";
var myname = "disneyConnectionAuth"; 
var width = "800"; 
var height = "500"; 
var winl = (screen.width - width) / 2;
var wint = (screen.height - height) / 2;
features = 'toolbar=yes,height='+height+',width='+width+',top='+wint+',left='+winl+',scrollbars=yes,';

if(self.SymRealWinOpen) {
	window.open=SymRealWinOpen; 
} 
 
	var uri = '/kids/';
	var referrer = "";
	var extra = "";
	var internal = false;
	if (uri.indexOf(".exlink") == -1) {
		if (internal) {
			uri += ".inlink";
		} else {
		uri += ".exlink";
		}
	}
	setTitle(title);
	DCS = new Object();
	DCS.dcsuri = uri;
	DCS.dcspro = window.location.protocol;
	DCS.dcssip = window.location.hostname;
	var dCurrent = new Date();
	DCS.dcsdat = dCurrent.getTime();
	
	if (referrer.length == 0) {
		referrer = window.location.href;
	}
	
	DCS.dcsref = referrer;
	var query = getTitle() + dcsDCS() + extra + ((url.length > 0) ? "&CM.url=" + url : "");
	dcsTrack(query);
	
	if (url.length > 0) {
		if (internal) {
			window.location = url;
		} else {
			width = castInt(width);
			height = castInt(height);
			var params = "";
				if (width > 0) {
					params += (params != null && params.length > 0) ? "," : "";
					params += "width=" + width;
				}
				if (height > 0) {
					params += (params != null && params.length > 0) ? "," : "";
					params += "height=" + height;
				}
				if (features != null && features.length > 0) {
					params += (params != null && params.length > 0) ? "," : "";
					params += features;
				}
			window.open(url, "tracking", params);
			}
		}
}


window.onload = pageLoad;


// To preload images in javascript
function cacheImage(tmpSrc) {
    var tmpImg = new Image();
    tmpImg.src = tmpSrc;
    return tmpImg;
}


function appendBreadcrumbList(crumbs) {
if (document.getElementById('breadcrumb2')) {
 for (x=0; x<crumbs.length; x++) {
 appendBreadcrumb(crumbs[x]);
		}
	}
}

function appendBreadcrumb(crumbObj) {
 if (typeof(crumbObj) != 'object'
 || crumbObj.text == null
 || crumbObj.href == null) return false;

 // Identify last dd tag in breadcrumb
 var breadBox = document.getElementById('breadcrumb');
 var breadLoaf = breadBox.getElementsByTagName('dd')[0];
 var newLink = '&#160;<span>&gt;</span>&#160'
 +'<a href="' + crumbObj.href + '">' + crumbObj.text +
'</a>';
 breadLoaf.innerHTML += newLink;
}

function removeFaqCrumbs() {
if (document.getElementById('breadcrumb2')) {
 var refContent = document.getElementById('content');
 var topModule = refContent.getElementsByTagName('div')[0];
 var breadBox = topModule.getElementsByTagName('h4')[0];
 var crumbs = breadBox.getElementsByTagName('a');

 // Ignore first crumb ('FAQ')
 var crumbReturn = [];
 for(x=1; x<crumbs.length; x++) {
 var rawLink = new String(crumbs[x].href);
 var outLink = rawLink.substr(rawLink.indexOf('.com/') + 4);
 crumbReturn[crumbReturn.length] = {text:crumbs[x].innerHTML,
href:outLink};
 }

 breadBox.style.display = 'none';
 breadBox.style.visibility = 'hidden';
 return crumbReturn;
}
}


function photoPopup() {
var width='533';
if(width != null && width.length != 0) width = parseInt(width) + 32;
else width = 600;

var height='400';
if(height != null && height.length != 0) height = parseInt(height) + 148;
else height = 700;

window.open(''.concat('/data/home/photopopup.html?random=',Math.random()), 'Photo', 'width=' + width + ',height=' + height + ',hotkeys=no,status=no,resizable=yes,scrollbars=no');
}

/******** start page scrolling *********/
function ScrollProps() {
    this.begin;
    this.end;
    this.start;
    this.change;
    this.dur = 1000;
}

var xScroll = new ScrollProps();
var yScroll = new ScrollProps();
var psintv;

function easeOut(t, b, c, d) {
    return -c *(t/=d)*(t-2) + b;
}

function pageScroll() {
    var elapsed = (new Date()).getTime() - yScroll.start;
    //alert(elapsed+" : "+yScroll.dur);
    if (elapsed < yScroll.dur) {
        scrollTo(
            easeOut(elapsed, xScroll.begin, xScroll.change, xScroll.dur),
            easeOut(elapsed, yScroll.begin, yScroll.change, yScroll.dur)
        );
    } else {
        scrollTo(xScroll.end,yScroll.end);
        clearInterval(psintv);
    }
}

function jumpTo(x,y) {
    yScroll.begin = getWindowYOffset();
    yScroll.end = y;
    yScroll.start = (new Date()).getTime();
    yScroll.change = yScroll.end - yScroll.begin;

    xScroll.begin = getWindowXOffset();
    xScroll.end = x;
    xScroll.start = yScroll.start;
    xScroll.change = xScroll.end - xScroll.begin;

    clearInterval(psintv);
    psintv = setInterval("pageScroll()",10);
    //alert(getWindowXOffset()+" : "+getWindowYOffset());
}

var d = document;
var checkObj = d.all?(d.getElementById?3:2):(d.getElementById?4:(d.layers?1:0));

function getWindowXOffset(){
    if(checkObj == 2 || checkObj == 3){
        if (document.documentElement && document.documentElement.scrollTop) {
            return document.documentElement.scrollLeft;
        } else {
            return d.body.scrollLeft;
        }
    }else if(checkObj == 1 || checkObj == 4){
        return window.pageXOffset;
    }
}

function getWindowYOffset(){
    if(checkObj == 2 || checkObj == 3){
        if (document.documentElement && document.documentElement.scrollTop) {
            return document.documentElement.scrollTop;
        } else {
            return document.body.scrollTop;
        }
    } else if(checkObj == 1 || checkObj == 4){
        return window.pageYOffset;
    }
}
/******** end page scrolling *********/
