
var pageGroupId = Math.floor(Math.random()*1000);
setCookie("pageGroup", pageGroupId);
//############################################################################
//###############Functions for more accessible cookies########################
//############################################################################
function setCookie(name, value, expires){
	var curCookie = name + "=" + escape(value) + ((expires)?"; expires="+expires.toGMTString():"");
	document.cookie = curCookie;
}
function getCookie(name){
	var allCookies = document.cookie.split(';');
	var lookFor = name+"=";
	for(var i=0; i<allCookies.length; i++){
		var cookie = allCookies[i];
		while (cookie.charAt(0)==' ') cookie = cookie.substring(1,cookie.length);
		if (cookie.indexOf(lookFor) == 0) return cookie.substring(lookFor.length,cookie.length);
	}
	return null;
}
//############################################################################
/////////////////////////////////////////////////////////////////////////////////////////\
// BROWSER DETECTION

var a = navigator.userAgent.toLowerCase();
var isSF = (a.indexOf("safari") > 0) ? true : false;
var xmlhttp = null;
//var isReady = false;

/////////////////////////////////////////////////////////////////////////////////////////
// WHEN THE PAGE LOADS
// 

window.onload = function() {
	
	//if (document.getElementById("timelinead")) {
  //		if (isReady!=true){
  //			document.getElementById("timelinead").style.display = "none";	
  //		} 
  //		document.getElementById("timelinead").style.left = "662px";
 	//}
	
	if (document.getElementById("lyr1")) {
		var wndo = new dw_scrollObj('wn', 'lyr1');
		wndo.setUpScrollbar("dragBar", "track", "v", 1, 1);
		dw_scrollObj.GeckoTableBugFix('wn');
		//alert("1 works");
	}
	if (document.getElementById("lyr2")) {
		var wndo2 = new dw_scrollObj('wn2', 'lyr2');
		wndo2.setUpScrollbar("dragBar2", "track2", "v", 1, 1);
		dw_scrollObj.GeckoTableBugFix('wn2');
		//alert("2 works");
	}
	if (document.getElementById("lyr3")) {
		var wndo3 = new dw_scrollObj('wn3', 'lyr3');
		wndo3.setUpScrollbar("dragBar3", "track3", "v", 1, 1);
		dw_scrollObj.GeckoTableBugFix('wn3');
		//alert("3 works");
	}
	domRollover();
}

/////////////////////////////////////////////////////////////////////////////////////////
// POLL SUBMISSION
//

function submitDHTML(baseURL) {
	var length = document.forms.pollForm.poll.length;
	var flag = false;
	var displayOrder = 0;
	// Handles the form validation for Viewers Choice Poll page
	if (document.getElementById("viewersChoicePoll")) {
		var itemsCount = 0;
		if(document.forms.pollForm.poll[0]) {
			for (var a = 0; a < length; a++) {
				if (document.forms.pollForm.poll[a].checked) {
					itemsCount++;
				}
			}
		}
		
		if (itemsCount !=8) {
			alert("Please select 8 shows.");
			return;
		}
	}
	// Handles the form validation for Home page poll
	if(document.forms.pollForm.poll[0]) {
		for (var a = 0; a < length; a++) {
			if (document.forms.pollForm.poll[a].checked) {
				flag = true;
				displayOrder += document.forms.pollForm.poll[a].value + ',';
			}
		}
	} else {
		if (document.forms.pollForm.poll.checked) {
			flag = true;
			displayOrder = document.forms.pollForm.poll.value;
		}
	}
	if (flag) {
		xmlhttp=GetXmlHttpObject();
		var url=baseURL;
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState == 4) {
		        if (xmlhttp.status == 200) {
		        	var pollResult = document.getElementById("pollResult");
		        	var pollEnded = document.getElementById("pollEnded");
		        	var xml = xmlhttp.responseXML;
		        	
		        	var isViewersChoiceEnded = false;
		        	if (xml.getElementsByTagName('viewersChoiceEnded')[0].firstChild) {
		        		isViewersChoiceEnded = xml.getElementsByTagName('viewersChoiceEnded')[0].firstChild.data;
		        	}
		        	
		        	var sumTotal = xml.getElementsByTagName('sumTotal')[0].firstChild.data;
		        	var answers = xml.getElementsByTagName('pollAnswer');
		        	for(var i=0;i<answers.length;i++) {
		        		var answer = answers[i];
		        		var total = answer.getElementsByTagName('total')[0].firstChild.data;
		        		var order = answer.getElementsByTagName('order')[0].firstChild.data;
		        		var barWidth = 100;
		        		if(sumTotal > 0) {
		        			barWidth = (100*total)/sumTotal;
		        		}
		        		var pollBar = document.getElementById("pollBar_" + order);
		        		var pollEndedBar = document.getElementById("pollEndedBar_" + order);
		        		pollBar.style.width = barWidth + "%";
		        		if (pollEndedBar) {
		        			pollEndedBar.style.width = barWidth + "%";
		        		}
		        		var pollLabel = document.getElementById("pollBarLabel_" + order);
		        		if (pollLabel) {
		        		  pollLabel.innerHTML = Math.round((total*100)/sumTotal) + "%";
		        		}
		        	}
		        	if (isViewersChoiceEnded == 'true') {
		        	  pollEnded.style.display = "block";
		        	} else {
		        	  pollResult.style.display = "block";
		        	}
		        } else {
		        	//Do something here?
		        }
		    }
		}
		xmlhttp.open('POST', url, true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.send("displayOrder="+ displayOrder);
		document.getElementById("pollTaker").style.display = "none";
	} else {
		alert ("Please select an option before submitting poll.");
	}
}

function GetXmlHttpObject(handler)
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
} 

function network() {
	box = document.dropdown.navi;
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = destination;
}


/////////////////////////////////////////////////////////////////////////////////////////
// IMAGE ROLLOVERS
// This script changes the image on rollover
// Usage: class="domroll [path and name of image]"

function domRollover() {
	if (navigator.userAgent.match(/Opera (\S+)/)) {
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	if (!document.getElementById||operaVersion <7) return;
	var imgarr=document.getElementsByTagName('img');
	var imgPreload=new Array();
	var imgSrc=new Array();
	var imgClass=new Array();
	for (i=0;i<imgarr.length;i++){
		if (imgarr[i].className.indexOf('domroll')!=-1){
			imgSrc[i]=imgarr[i].getAttribute('src');
			imgClass[i]=imgarr[i].className;
			imgPreload[i]=new Image();
			if (imgClass[i].match(/domroll (\S+)/)) {
				imgPreload[i].src = imgClass[i].match(/domroll (\S+)/)[1]
			}
			imgarr[i].setAttribute('xsrc', imgSrc[i]);
			imgarr[i].onmouseover=function(){
				this.setAttribute('src',this.className.match(/domroll (\S+)/)[1])
			}
			imgarr[i].onmouseout=function(){
				this.setAttribute('src',this.getAttribute('xsrc'))
			}
		}
	}
}


/////////////////////////////////////////////////////////////////////////////////////////
// DHTML MENU SWAP FIX
// This script solves the no-psuedo classes for IE problem with the dhtml menu

// Detect IE
var isIE = (navigator.userAgent.toLowerCase().indexOf("msie") > 0) ? true : false;

initNavBar = function() {
	// first we need to shorten the hgt of the bar itself
	var navContainer = document.getElementById('mainnav');
	if (navContainer) navContainer.style.height = "16px";
	
	// then we need to move items up to eliminate gaps
	var hasMenu = document.getElementById('mainnav');
	var menuBlocks = (hasMenu) ? document.getElementById('mainnav').getElementsByTagName('ul') : null;
	if (menuBlocks) {
		for (var i = 0; i < menuBlocks.length; i++) {
			var targElem = menuBlocks[i];
			var par = targElem.parentNode;
				var parpar = par.parentNode;
				var parparpar = parpar.parentNode;
			if (parparpar.id == 'mainnav') {
				targElem.style.top = "13px";
			}
		}
	}
}			
//if (isSF) window.addEventListener("load", initNavBar, true);


sfHover = function() {
	var hasMenu = document.getElementById('mainnav');
	var liElems = (hasMenu) ? document.getElementById('mainnav').getElementsByTagName('li') : null;
	if (liElems) {
		for (var i = 0; i < liElems.length; i++) {
			if (liElems[i]) {
				liElems[i].onmouseover = function() {
					this.className += " sfhover";
				/*************IFRAME is added to block SELECT elements to show through elements on top of them (IE6 zindex bug)****************************************/
					var ulElem = this.getElementsByTagName('ul');
					for (var j = 0; j < ulElem.length; j++) {
						var targUlElem = ulElem[j];
						var nextTag = targUlElem.firstChild;
						if (nextTag.nodeName != 'IFRAME') {
							var ulMat = document.createElement('iframe');
							ulMat.style.display = "block";
							ulMat.style.position = "absolute";
							ulMat.style.top = "0";
							ulMat.style.left = "0";
							ulMat.style.filter = "mask()";
							ulMat.style.width = "1000px";
							ulMat.style.height = "1000px";
							ulMat.style.zIndex = -1;
							targUlElem.insertBefore(ulMat, targUlElem.firstChild);
						}
					}
					/**************************************/
				}
			}
			liElems[i].onmouseout = function() {
				this.className = this.className.replace(' sfhover', '');
			}
		}
	}
}
if (window.attachEvent) window.attachEvent('onload', sfHover);

////////////////////////////////////////////////////////////////////
//  getElementsByClass(name of class)
//  Retrieves all classes on the page and extracts the desired class

function getElementsByClass(maClass) {
   	var tabRetour = new Array();
     	var tabTmp = new Array();
     	tabTmp = document.getElementsByTagName("*");
     	j=0;
      	for (i=0; i<tabTmp.length; i++) {
       	if (tabTmp[i].className==maClass) {
           	tabRetour[j]=tabTmp[i];
        		j++;						
        	} 
       }
      	return tabRetour;
}


///////////////////////////////////////////////////////////////////
//  DHTML Layer Tooltip rollover
//  Retrieves hidden layer and reveals it on a link

function getposOffset(overlay, offsettype, num) {
	if (num == 0) {
		num = (isIE)? 2 : 15;  
	}
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop + num;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function overlay(curobj, subobj, num) {
	if (document.getElementById) {
		var subobj=document.getElementById(subobj)
		subobj.style.left=getposOffset(curobj, "left", num)+"px";
		subobj.style.top=getposOffset(curobj, "top", num)+"px";
		subobj.style.display="block";
		//return false;		
	}
	//else return true;
}

function overlayclose(subobj) {
	document.getElementById(subobj).style.display="none";
}


/////////////////////////////////////////////////////////////////////////////////////////
// TAB ROLLOVERS
// Tabs are located in search results and in videos and speeches


function tabOnSelect (num, maxnum, imageName, flag, bannerloc) {	

	document.getElementById(bannerloc).src = "skyscraper.html";

	// checks to see if it's ontv and changes the toolbar accordingly
	if (flag == 1) {
		getElementsByClass('infobar')[0].style.display = "block";
		getElementsByClass('infoline')[0].style.display = "none";
		getElementsByClass('infobar')[1].style.display = "block";
		getElementsByClass('infoline')[1].style.display = "none";
	} else {
		getElementsByClass('infobar')[0].style.display = "none";
		getElementsByClass('infoline')[0].style.display = "block";
		getElementsByClass('infobar')[1].style.display = "none";
		getElementsByClass('infoline')[1].style.display = "block";
	}
	
	// changes the image to on and checks for on and changes it to off
	for (var i = 0; i < maxnum; ++i)  {
		image_obj = eval("document.img" + i);
		if (i == num) {		
			image_obj.src = imageName + "on.gif";
		} else {
			var imagesource = image_obj.src.indexOf("on.gif");
			if (imagesource != -1) {
				var temp = image_obj.src.slice(0, imagesource);
				temp = temp + "off.gif";
				image_obj.src = temp;
			}
		}
	}
	
	// changes the style of the text
	getElementsByClass('results')[num].style.paddingBottom = "15px";
	getElementsByClass('results')[num].style.backgroundColor = "#FFFFFF";
	getElementsByClass('results')[num].style.color = "#530000";	
	
		
	// display result of corresponding tab
	var display = eval ("document.getElementById('sr" + num + "')");
	display.style.display = "block";
	
	if (num < (maxnum - 1)) {
		getElementsByClass('tab')[num + 1].style.borderLeft = "none";	
	}
	getElementsByClass('tab')[num].style.borderRight = "1px solid #EAB452";
	
	// changes the style of the other tabs	
	for (var j = 0; j < maxnum; ++j) {
		if (j != num) {
			getElementsByClass('tab')[j].style.marginTop = "20px";
			getElementsByClass('results')[j].style.paddingBottom = "5px";
			getElementsByClass('results')[j].style.backgroundColor = "#530000";
			getElementsByClass('results')[j].style.color = "#FFFFFF";
			
			// kill other search results
			var display = eval ("document.getElementById('sr" + j + "')");
			display.style.display = "none";
			
			if (j < (maxnum - 1)) {
				getElementsByClass('tab')[j + 1].style.borderLeft = "1px solid #EAB452";
			}
			if (j != (maxnum - 1)) {
				getElementsByClass('tab')[j].style.borderRight = "none";
			}
		} else {
			getElementsByClass('tab')[j].style.marginTop = "10px";
		}
	}	
}


/////////////////////////////////////////////////////////////////////////////////////////
// FORM CHECK
// Check if required fields are filled


function formCheck (element1, element2, element3, element4) {
	var filled = true;
	
	if (document.forms[0][element1].value == '') {
		filled = false;
		document.getElementById('error').innerHTML = 'Please enter ' +  charReplace(element1);
	} else if (document.forms[0][element2].value == '') {
				filled = false;
				document.getElementById('error').innerHTML = 'Please enter ' +  charReplace(element2);
			} else 	if (document.forms[0][element3].value == '') {
						filled = false;
						document.getElementById('error').innerHTML = 'Please enter ' + charReplace(element3);
					} else 	if (document.forms[0][element4].value == '') {
								filled = false;
								document.getElementById('error').innerHTML = 'Please enter ' +  charReplace(element4);
							}
	if (filled) {
		document.forms[0].submit();
	}				
	
	function charReplace (elem) {
		return String(elem).replace(/_/,' ');
	}
		
}

/////////////////////////////////////////////////////////////////////////////////////////
// POP-UP
// Global pop ups

// set scrollbars to 1 to enable
function openwin (filename, w, h, scrollbars, winName) {
	if(!winName)
		{var winName='main';}
	
	var w = (w == null) ? "490" : w;
	var h = (h == null) ? "600" : h;
	var scrollbars = (scrollbars == null) ? 0 : scrollbars;
	var mainWin = window.open (filename, winName, 'width=' + w + ',height=' + h + ', scrollbars=' + scrollbars + ', resizeable=1, menubar=0');
	if(winName=='main' && !window.attachEvent){
		mainWin.resizeTo(w, h); // resize if already open
	}
	if (window.focus) {mainWin.focus()}
}

function openWinMyPlaylist(url, params) {
    var url = url + params; 
    window.open(url,'bbplaylistwin','width=800,height=500,scrollbars=1,resizeable=0');
}

function openWinMyPlaylistEmail(url) {
    window.open(url,'bbemailwin','width=490,height=600,scrollbars=1,resizeable=0,status=1');
}

function omniture_track_video_PLAY(network, channel_show, clip, player, format) {
		var s_wd=window,s_tm=new Date;
		var campaign=""; try {campaign = getCookie('CAMPAIGN')} catch (ex) {}

		if (campaign == null) campaign = '';

		document.getElementById("omniDiv").innerHTML =
			'<img src="http://aetv.112.2O7.net/b/ss/aebiographyvideo/1/H.2--NS/0' + s_tm.getTime()
			+'?pageName=' + network + ':' + channel_show + ':' + clip
			+'&c5=' + campaign
			+'&c6=' + player
			+'&c7=' + format
			+ '"'
			+' height="1" width="1" border="0" />';
	}

function trackVideo(suiteName, format, location, showTitle, clipTitle){
	var url = "http://"+suiteName+".112.2O7.net/b/ss/"+suiteName+"/1/H.2--NS/0?";
		
	var pageName = "THC:"+showTitle+":"+clipTitle;
	url += "pageName="+pageName;
	url += "&channel=" + location;
	url += "&c4="+showTitle;
	url += "&c7="+format;
	
	document.getElementById("omnidiv").innerHTML=
	'<img src="'+url+'" height="1" width="1" border="0"/>';
}


//***************************************************************
//setObjClass for left navigation on genericContent template

function setObjClass(objId, newClass){
	var obj;
	if(obj = document.getElementById(objId)){
		obj.className = newClass;
	}
}
//**************************************************
//Suckerfish hover fix for IE6 - input parameter, id of list element.
function sfHoverAnyList(listId) {
	var hasMenu = (listId) ? document.getElementById(listId) : null;
	var liElems = (hasMenu) ? document.getElementById(listId).getElementsByTagName('li') : null;
	if (liElems) {
		for (var i = 0; i < liElems.length; i++) {
			liElems[i].onmouseover = function() {
				this.className += " over";
			}
			liElems[i].onmouseout = function() {
				this.className = this.className.replace(new RegExp(" over\\b"), "");
			}
		}
	}
}
/*If IE - attach sfHoverGlobalNav function call to onload event*/
//if (window.attachEvent) window.attachEvent('onload', sfHoverGlobalNav);
//**************************************************

// super sleight script for IE 6 png transparency

var supersleight	= function() {
	
	var root = false;
	var applyPositioning = true;
	
	// Path to a transparent GIF image
	var shim			= '/images/global/x.gif';
	
	// RegExp to match above GIF image name
	var shim_pattern	= /x\.gif$/i;
	
	
	
	var fnLoadPngs = function() { 
		if (root) {
			root = document.getElementById(root);
		}else{
			root = document;
		}
		if(document.attachEvent){
			for (var i = root.all.length - 1, obj = null; (obj = root.all[i]); i--) {
				// background pngs
				if (obj.currentStyle.backgroundImage.match(/\.png/i) !== null) {
					bg_fnFixPng(obj);
				}
				// image elements
				if (obj.tagName=='IMG' && obj.src.match(/\.png$/i) !== null){
					el_fnFixPng(obj);
				}
				// apply position to 'active' elements
				if (applyPositioning && (obj.tagName=='A' || obj.tagName=='INPUT') && obj.style.position === ''){
					//position is applied here to give an element IE property hasLayout - this is IE bug fix
					//to avoid layout changes this might inflict instead of applying relative position, css property
					//zoom can be set to 1 - it has the same effect
					if(obj.parentNode.className.indexOf('extendedContainer') == -1){
						obj.style.position = 'relative';
					}
					//obj.style.zoom = '1';
					//obj.style.zIndex = "1";
				}
			}
		}
	};

	var bg_fnFixPng = function(obj) {
		var mode = 'scale';
		var bg	= obj.currentStyle.backgroundImage;
		var src = bg.substring(5,bg.length-2);
		if (obj.currentStyle.backgroundRepeat == 'no-repeat') {
			mode = 'crop';
		}
		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')";
		obj.style.backgroundImage = 'url('+shim+')';
	};

	var el_fnFixPng = function(img) {
		var src = img.src;
		img.style.width = img.width + "px";
		img.style.height = img.height + "px";
		img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
		img.src = shim;
	};
	
	var addLoadEvent = function(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			};
		}
	};
	
	return {
		init: function() { 
			addLoadEvent(fnLoadPngs);
		},
		
		limitTo: function(el) {
			root = el;
		},
		
		run: function() {
			fnLoadPngs();
		}
	};
}();

// limit to part of the page ... pass an ID to limitTo:
// supersleight.limitTo('header');

supersleight.init();



    //function for customization
/*    function cutomizeFontSize(inStyleSheetName,inSelectors,inOriginalSize,inCustomizedSize)
    {
        var theRules;
        var theRule;

        for (var i = 0; i < document.styleSheets.length; i++)
        {
            if (document.styleSheets[i].href.indexOf(inStyleSheetName) > -1)
            {
                if (document.styleSheets[i].cssRules)
                    theRules = document.styleSheets[i].cssRules;
                else if (document.styleSheets[i].rules)
                    theRules = document.styleSheets[i].rules;
                break;
            }
        }

        for (i = 0; theRules.length > i; i++)
        {
            for (var j = 0; j < inSelectors.length; j++)
            {
                if (theRules[i].selectorText == inSelectors[j])
                {
                    theRule = theRules[i];
                    if (theRule.style.fontSize == inOriginalSize)
                        theRule.style.fontSize = inCustomizedSize;
                    else if (theRule.style.fontSize == inCustomizedSize)
                        theRule.style.fontSize = inOriginalSize;
                }
            }
        }
    }
*/


