// Show & Hide layer for Video Testing
function setVisibility(id, visibility) {
	document.getElementById(id).style.display = visibility;
}


//BEGIN function for about bvs flash movie
function onVideoPlayerMoreClick(url) {
	//this function needs to be updated to do forward to the appropriate page based on uid
    location.href=url;
}
//END function for about bvs flash movie


//functions for tv episode hide/show details
function showFullDesc(whichEpisode) {
	setVisibility('episode' + whichEpisode + '_off', 'none');
	setVisibility('episode' + whichEpisode + '_more', 'none');
	setVisibility('episode' + whichEpisode + '_on', 'block');
	setVisibility('episode' + whichEpisode + '_close', 'block');
}
function hideFullDesc(whichEpisode) {
	setVisibility('episode' + whichEpisode + '_off', 'block');
	setVisibility('episode' + whichEpisode + '_more', 'block');
	setVisibility('episode' + whichEpisode + '_on', 'none');
	setVisibility('episode' + whichEpisode + '_close', 'none');
}
function showMoreInfoLink(whichRow) {
    var whichEpisode = whichRow.replace('seasonRow','');
	var isCollapsed = document.getElementById('episode' + whichEpisode + '_on').style.display != "block";
	if (isCollapsed == true) {
		setVisibility('episode' + whichEpisode + '_more', 'block');
	}
	
	$(whichRow).style.backgroundColor='#e2e2e2';
}
function hideMoreInfoLink(whichRow) {
    var whichEpisode = whichRow.replace('seasonRow','');
	var isCollapsed = document.getElementById('episode' + whichEpisode + '_on').style.display != "block";
	//alert("isCollapsed: " + isCollapsed);
	if (isCollapsed == true) {
		setVisibility('episode' + whichEpisode + '_more', 'none');
	}
	$(whichRow).style.backgroundColor='';
}
//end functions for tv episode hide/show details

//Popup Window
function popUpWindow(url) {
	newwindow=window.open(url,'name','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=628,height=500');
	if (window.focus) {
		newwindow.focus()
	}
}

//DropDown functions
var isIE = document.all ? true : false;
var isSafari = navigator.userAgent.indexOf("Safari") != -1;

//purchase option flyouts
window.flyoutKillWait = 1000; //milliseconds to wait before closing on mouseout
window.flyoutTimer = null;
window.activeFlyout = null;

function doPurchaseOver(whichTD, whichYOffset) {
	clearTimeout(flyoutTimer);
	if (activeFlyout != null) {
		activeFlyout.style.display = "none";
	//	hideAddToCart();
	}
	
	var curFlyout = document.getElementById(whichTD.id + "Flyout");
	if (curFlyout != undefined) {
		activeFlyout = curFlyout;
		placeFlyout(curFlyout, whichTD, whichYOffset);
	}
}

function placeFlyout(whichFlyout, whichAnchor, whichYOffset) {
	var anchorTop = getPageOffsetTop(whichAnchor);
	var anchorLeft = getPageOffsetLeft(whichAnchor);
	
	var anchorWidth = whichAnchor.offsetWidth - 12; //5 x 2 for padding; 2 for border
	if (whichYOffset != undefined) {
		anchorWidth += whichYOffset;
		anchorLeft -= whichYOffset;
	}
	
	whichFlyout.style.top = anchorTop + "px";
	whichFlyout.style.left = anchorLeft + "px";
	whichFlyout.style.width = anchorWidth + 18 + "px";//modify by tim	
	whichFlyout.style.display = "block";
}

function doPurchaseOut(e) {
	initKillFlyout();
}

function initKillFlyout() {
	clearTimeout(flyoutTimer);
	flyoutTimer = setTimeout(checkToHideFlyout, flyoutKillWait);
//	checkToHideFlyout();
}

function checkToHideFlyout() {
	clearTimeout(flyoutTimer);
	
	//if the mouse is over the current div, do nothing...
//	if (mouseIsInBounds(activeFlyout, e) == false) {
	try {
		if (mouseIsInBounds(activeFlyout) == false) {
			//alert("mouseIsInBounds = false");
			hideFlyout();
		} else {
			//alert("mouseIsInBounds = true");
		}
	} catch(e) {
		//do nothing
		//alert("error");
	}
}

function hideFlyout() {
	activeFlyout.style.display = "none";
	activeFlyout = null;
	
	//hideAddToCart();
}

//alternate flyout code for "wide" purchase options
function doPurchaseOverWide(whichTD) {
	clearTimeout(flyoutTimer);
	if (activeFlyout != null) {
		activeFlyout.style.display = "none";
	}
	
	var curFlyout = document.getElementById(whichTD.id + "Flyout");
	activeFlyout = curFlyout;
	activeFlyout.style.display = "block";
}

function doPurchaseOutWide() {
	initKillFlyoutWide();
}

function initKillFlyoutWide() {
	clearTimeout(flyoutTimer);
	flyoutTimer = setTimeout(checkToHideFlyoutWide, flyoutKillWait);
}

function checkToHideFlyoutWide() {
//if the mouse is over the current div, do nothing...
	try {
		if (mouseIsInBounds(activeFlyout) == false) {
			//alert("mouseIsInBounds = false");
			clearTimeout(flyoutTimer);
			hideFlyoutWide();
		} else {
			//alert("mouseIsInBounds = true");
		}
	} catch(e) {
		//do nothing
		//alert("error");
	}
}

function hideFlyoutWide() {
	activeFlyout.style.display = "none";
	activeFlyout = null;
}

// Temporary variables to hold mouse x-y <a href="http://www.ntsearch.com/search.php?q=pos&v=56">pos</a>.s
window.curMouseX = 0;
window.curMouseY = 0;
window.curMousePos = {x:curMouseX , y:curMouseY};
	
function setMouseXY(e) {
	if (isIE) {
		curMouseX = event.clientX + document.documentElement.scrollLeft;
		curMouseY = event.clientY + document.documentElement.scrollTop;
	} else {
		curMouseX = e.pageX;
		curMouseY = e.pageY;
	}
	curMousePos = {x:curMouseX , y:curMouseY};
	//doTrace("curMouseX/Y: " + curMouseX + ", " + curMouseY);
	return true;
}

function getMousePos() {
//	trace("curMouseX/Y: " + curMouseX + ", " + curMouseY);
	var curPos = {x:curMouseX , y:curMouseY};
	return curPos;
}

function getMousePosForEvent(e) {
	if (isIE) {
		curMouseX = event.clientX + document.documentElement.scrollLeft;
		curMouseY = event.clientY + document.documentElement.scrollTop;
	} else {
		curMouseX = e.pageX;
		curMouseY = e.pageY;
	}
	var curPos = {x:curMouseX , y:curMouseY};
	return curPos;
}

function trace(whichText) {
	window.status = whichText;
	return true;
}

function mouseIsInBounds(whichElement) {
//function mouseIsInBounds(whichElement, whichEvent) {
//	var curMousePos = getMousePosForEvent(whichEvent);
	//var curMousePos = curMousePos;
	
	var myLeftEdge = getPageOffsetLeft(whichElement);
	var myRightEdge = myLeftEdge + whichElement.offsetWidth;
	var myTopEdge = getPageOffsetTop(whichElement);
	var myBottomEdge = myTopEdge + whichElement.offsetHeight;
	
	var inXBounds = curMousePos.x > myLeftEdge && curMousePos.x < myRightEdge;
	var inYBounds = curMousePos.y > myTopEdge && curMousePos.y < myBottomEdge;
	var inBounds = inXBounds && inYBounds;
	//trace("X/Y: " + curMouseX + ", " + curMouseY + "; Top/Bottom: " + myTopEdge + " / " + myBottomEdge + "; inY: " + inYBounds + "; Left/Right: " + myLeftEdge + " / " + myRightEdge + "; inX: " + inXBounds + "; inBounds: " + inBounds);
	return inBounds;
}

//dropdown
function doDropDownMouseOver(e) {
	var srcDiv;
	if (isIE) {
		srcDiv = e.srcElement;
	} else {
		srcDiv = e.target;
	}
	
	if (srcDiv.nodeName != "SPAN") { //safari DOM exception
		srcDiv = srcDiv.parentNode;
	}
	
	if(top.strLang=="English")
	{
	    window.reportDropValues = [
	    [GetStr(2654), "/MyAccount/MyPage.aspx"],
	    [GetStr(2655), "/MyAccount/EditMyPage.aspx"],
	    ["----------------------", "javascript:void(0);"],
//	    [GetStr(2656), "/MyAccount/MyNotifications.aspx"],
	    [GetStr(2657), "/MyAccount/MyAccount.aspx"],
	    [GetStr(2658), "/MyAccount/MyMessages.aspx"]
        ];
    
	}else
	{
	    window.reportDropValues = [
	    [GetStr(2654), "/MyAccount/MyPage.aspx"],
	    [GetStr(2655), "/MyAccount/EditMyPage.aspx"],
	    ["----------------------", "javascript:void(0);"],
//	    [GetStr(2656), "/MyAccount/MyNotifications.aspx"],
	    [GetStr(2657), "/MyAccount/MyAccount.aspx"],
	    [GetStr(2658), "/MyAccount/MyMessages.aspx"]
        ];
	
	}
	
	var curDropDownList = reportDropValues;
	initDropDown(curDropDownList, srcDiv);
}

function doDropDownMouseOut() {	
	initKillDropDown();
}

function loadReport(e) {
	removeDropDown();
	
	var srcDiv = e ? e.target : event.srcElement;
	if (srcDiv.nodeName != "DIV") { //safari DOM exception
		srcDiv = srcDiv.parentNode;
	}
	
	var selectedRep = srcDiv.innerHTML;
	var targetURL;	
	for (var i=0; i<reportDropValues.length; i++) {
		var curRep = reportDropValues[i];
		if (curRep[0] == selectedRep) {
			targetURL = curRep[1];
			break;
		}
	}
	window.location.href = targetURL;
}


function DropDown (whichProps) {
	this.targetParentElement = document.body;

	this.listItems = whichProps.list;
	this.dropAnchor = whichProps.elem;
	
	//default fonts, and exceptions
	this._fontWeight = "normal";
	this._fontSize = "12px";
	this.forceWidth = false;
	this.listItemFunc = loadReport;
	
	this.yOffset = 4; //padding between target element and dropdown
	this.dropDownWidth = this.dropAnchor.offsetWidth + 10;
	
	this.listPadding = 5; //space around text
	
	
	this.listItemXPadding = 0; //space on left/right of text
	//see if the dropAnchor div has an image inside it. if so, we assume it's an arrow and offset text from the edges by that much
	var imgColl = this.dropAnchor.getElementsByTagName('img');
	if (imgColl.length > 0) {
		this.listItemXPadding = imgColl[0].offsetWidth;
	}
	
	this.listItemYPadding = 3; //space above/below text
	this.dropDownTextWidth = this.dropDownWidth - (this.listItemXPadding * 2) - (this.listPadding * 2);
	
	this.drawList();
	this.placeDropDown();
	
	return this;
}


DropDown.prototype.drawList = function() {
	var container = document.createElement('div');
	container.id = "dropDown";
	container.onmouseover = function () {
		clearTimeout(dropDownTimer);
	}
	container.onmouseout = function () {
		initKillDropDown();
	}
	with (container.style) {
		position = "absolute";
		top = "-300px";
		zIndex = "5000";
		display = "none";
		filter = "Alpha(Opacity=100)";
		opacity = "1.0";
	}
	this.dropDownDiv = container;
	
	this.listHolder = document.createElement('div');
	this.listHolder.id = "dropDownListHolder";
	with (this.listHolder.style) {
		position = "relative";
		zIndex = "100";
		backgroundColor = "#e2e2e2";
		padding = this.listPadding + "px";
	}
	
	for (var i=0; i<this.listItems.length; i++) {
		var curData = this.listItems[i];
		//use the first element of items when lists consist of arrays (e.g., report names)
		if (typeof(curData) != "string") {
			curData = curData[0];
		}
		var curItem = document.createElement('div');
		var curZIndex = 100 + i;
		with (curItem) {
			id = "indexItem" + curData;
			innerHTML = curData;
			with (style) {
				position = "relative";
				zIndex = curZIndex;
//				backgroundColor = "#FFFFFF";
				fontFamily = 'Arial, sans-serif';
				fontWeight = this._fontWeight;
				fontSize = this._fontSize;
				textAlign = "right";
				color = "#00446e";
				paddingLeft = paddingRight = this.listItemXPadding + "px";
				paddingTop = paddingBottom = this.listItemYPadding + "px";
				if (this.forceWidth == true) {
					width = this.dropDownTextWidth + "px";
				}
				cursor = "pointer";
			}
//			trace("offsetWidth: " + offsetWidth);
		}
		curItem.onclick = this.listItemFunc;
		curItem.onmouseover = function() {
			this.style.backgroundColor = "#fff";
		}
		curItem.onmouseout = function() {
			this.style.backgroundColor = "";
		}
		this.listHolder.appendChild(curItem);
	}
	
	container.appendChild(this.listHolder);
	this.targetParentElement.appendChild(container);
	
	container.style.display = "block";
}

DropDown.prototype.placeDropDown = function() {
	var anchorBottom = getPageOffsetTop(this.dropAnchor) + this.dropAnchor.offsetHeight;
	var anchorRight = getPageOffsetLeft(this.dropAnchor) + this.dropAnchor.offsetWidth;
	var targetTop = anchorBottom + this.yOffset;
	var targetLeft = anchorRight - this.listHolder.offsetWidth + 1;	
	this.dropDownDiv.style.top = targetTop + "px";
	this.dropDownDiv.style.left = targetLeft + "px";
}

DropDown.prototype.remove = function() {
	this.targetParentElement.removeChild(this.dropDownDiv);
}

window.dropDownWait = 0; //milliseconds to wait before showing
window.dropDownKillWait = 500; //milliseconds to wait before closing on mouseout
window.dropDownTimer = null;

function initKillDropDown() {
	clearTimeout(dropDownTimer);
	dropDownTimer = setTimeout(removeDropDown, dropDownKillWait);
}

function initDropDown(whichItems, whichElem) {
	clearTimeout(dropDownTimer);

	window.dropDownProps = {list: whichItems, elem: whichElem};
	dropDownTimer = setTimeout(showDropDown, dropDownWait);
}

function showDropDown() {
	removeDropDown();
	window.dropDown = new DropDown(dropDownProps);
}

function removeDropDown() {
	clearTimeout(dropDownTimer);
	if (window.dropDown != undefined) {
		window.dropDown.remove();
		window.dropDown = undefined;
	}
}

function getPageOffsetTop (whichElem) {
	var tOffsetTop = 0;
	var curCount = 0;
	var curElem = whichElem;
	//we cap the while loop to avoid any possible infinite loops
	try {
		while (curElem.offsetParent && curCount < 99) {
			tOffsetTop += curElem.offsetTop;
			curElem = curElem.offsetParent;
			curCount++;
		}
	} catch (e) {
		//do nothing
	}
	return tOffsetTop;
}

function getPageOffsetLeft (whichElem) {
	var tOffsetTop = 0;
	var curCount = 0;
	var curElem = whichElem;
	//we cap the while loop to avoid any possible infinite loops
	try {
		while (curElem.offsetParent && curCount < 99) {
			tOffsetTop += curElem.offsetLeft;
			curElem = curElem.offsetParent;
			curCount++;
		}
	} catch (e) {
		//do nothing
	}
	return tOffsetTop;
}

//DropDown functions
function buttonPush (buttonStatus) {
	if (buttonStatus == "depressed")
		document.getElementById("pseudobutton").style.borderStyle = "inset";
	else
		document.getElementById("pseudobutton").style.borderStyle = "outset";
}


//Table rows highlight
function highlightRow(row_id,check_id,default_color) {
	if (document.getElementById(check_id).checked) {
		document.getElementById(row_id).bgColor = '#f5f5f5';
	} else {
		document.getElementById(row_id).bgColor = default_color;
	}
}



