var serverCall 		= "/ajaxHandler.php";
var webRoot			= "/";
var InternetPath	= "http://173.45.240.139/";
var imageCacheProc	= "/getOffsiteImage.php";
var defaultChannelImage = "defaultChannelImage_";
var popupDiv 		= document.getElementById("ajaxPopup");
var balloonDiv 		= document.getElementById("balloonPopup");
var sidebarDiv 		= "sidebar";
var filterbarDiv 	= "filterbar";
var headerDiv 		= "header";
var loginDiv		= "login_area";
var requestPending	= 0;
var reloadSideNavHtml = '<div id="my_stuff"><h3 class="trigger expanded">Reloading</h3><ul class="stripes"><li>Please wait while the navigation bar is customized...</li></ul></div>';
var currentMouseX 	= 0;
var currentMouseY 	= 0;
var hoverTimer= "";
var hideTimer= "";
var balloonTimer = "";
var autoSearchTimer = "";
var currentYOffset = 0; //used to memorize offset for html redraw scroll maintain
var lastAction		= 0;
var actionCount		= 0;
var doingNavAction	= 0;
var allowRollovers_info = 1;
var allowRollovers_help = 1;
var TIPS_UNSUBSCRIBE = "***TIPS_UNSUBSCRIBE***";
var TIPS_SUBSCRIBE = "***TIPS_SUBSCRIBE***";
var updateChannelImagesAfterNextAjaxReturn = 0;
var updateChannelImageAfterNextReturn = 0;

if (document.getElementById("ajaxPopup_iframe")) {
	var popupDiv_iframe		= document.getElementById("ajaxPopup_iframe");
	var balloonDiv_iframe	= document.getElementById("balloonPopup_iframe");
}

var ua = navigator.userAgent.toLowerCase();
if (!window.ActiveXObject) {
	IE = 0;
	ajaxRequest = new XMLHttpRequest();
	document.captureEvents(Event.MOUSEMOVE)
} else if (ua.indexOf('msie 5') == -1) {
	IE = 1;
	ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} else {
	IE = 1;
	ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}

var pageWidth =  window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
var pageHeight = window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;


// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {
	var tempX = 0
	var tempY = 0
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft
		tempY = event.clientY + document.body.scrollTop
	} else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX
		tempY = e.pageY
	}
	// catch possible negative values in NS4
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}
	// show the position values in the form named Show
	// in the text fields named MouseX and MouseY
	currentMouseX = tempX;
	currentMouseY = tempY;

	//drag processing
	if (isElementDragging) {
		var oldLeft = draggableDiv.style.left;
		var oldTop = draggableDiv.style.top;
		oldLeft = oldLeft.replace(/px/,"");
		oldTop = oldTop.replace(/px/,"");
		oldLeft = parseFloat(oldLeft);
		oldTop = parseFloat(oldTop);

		var newLeft = oldLeft + (currentMouseX-dragStartX);
		var newTop = oldTop + (currentMouseY-dragStartY);

		draggableDiv.style.left = newLeft+'px';
		draggableDiv.style.top = newTop+'px';
		dragStartX = currentMouseX;
		dragStartY = currentMouseY;

		processHover(currentMouseX,currentMouseY);
	}
}

function getCurrentYOffset()
{
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfY;
}


//Drag and drop stuff
var isElementDragging = 0;
var elementDragging;
var elementPreparedForDragging;
var elementDraggingDisplayStyle;
var dragStartX = 0;
var dragStartY = 0;
var draggableDiv;
var draggableDivName = 'draggableDiv1';
var preparedToDrag = 0;
var draggingDataId = "";
var draggingData = ""
var dropTargets=MultiDimensionalArray(20,3);
var dropTargetCount=0;
var reshowDragSourceAfterDrop=0;
var highlightedTarget;
var highlightedTargetOriginalBorder;

function prepareDrag(divElem)
{
	elementPreparedForDragging = document.getElementById(divElem);
	if (elementPreparedForDragging) {
		preparedToDrag = 1;
	}
}
function startDrag(divElem, dragText, dragDataId, dragData, takeOriginal, reshowOriginal, showDragBg)
{
	if (preparedToDrag == 1 && isElementDragging == 0) {
		if (elementPreparedForDragging) {
			if (divElem == elementPreparedForDragging.id) {
				elementDragging = document.getElementById(divElem);
				elementDraggingDisplayStyle = elementDragging.style.display;
				draggableDiv = makeDraggableElement(elementDragging,currentMouseX,currentMouseY,dragText);
				isElementDragging = 1;
				dragStartX = currentMouseX;
				dragStartY = currentMouseY;
				draggingDataId = dragDataId;
				draggingData = dragData;
				draggableDiv.innerHTML = elementDragging.innerHTML;
				if (showDragBg) {
					draggableDiv.style.backgroundColor = '#ffffff';
				} else {
					draggableDiv.style.backgroundColor = 'none';
				}
				if (takeOriginal == 1) {
					elementDragging.style.display = 'none';
				}
				if (reshowOriginal == 1) {
					reshowDragSourceAfterDrop = 1;
				} else {
					reshowDragSourceAfterDrop = 0;
				}
			}
		}
	}
}
function stopDrag()
{
	if (isElementDragging) {
		isElementDragging = 0;
		draggableDiv.style.border = 'none';
		draggableDiv.style.display = 'none';
		preparedToDrag = 0;
		var dropProcessed = processDrop(currentMouseX,currentMouseY);
		if (reshowDragSourceAfterDrop || dropProcessed == 0) {
			//if explicitly told to do so by the caller
			//or if the drop wasnt even on a valid target
			//then redisplay the original drag source
			elementDragging.style.display = elementDraggingDisplayStyle;
		}
		elementDragging = undefined;
		reshowDragSourceAfterDrop=0;
	} else if (preparedToDrag) {
		preparedToDrag = 0;
		elementPreparedForDragging = undefined;
	}
}
function makeDraggableElement(dragElement, startX, startY, dragText) {
	var newdiv = document.getElementById(draggableDivName)

	var sourceTop 	= getAbsoluteTop(dragElement.id);
	var sourceLeft 	= getAbsoluteLeft(dragElement.id);
	var sourceHeight = parseInt(dragElement.offsetHeight);
	var sourceWidth  = parseInt(dragElement.offsetWidth);

	//i had to do this for the thumbnails... lame workaround
	//I think it was because of the borders/margins/padding plus xlucent border in graphic
	sourceTop = sourceTop;// - 3;
	sourceLeft = sourceLeft;// - 3;
	sourceHeight = sourceHeight;// - 20;
	sourceWidth = sourceWidth;// - 20;

	newdiv.className = dragElement.className;
	newdiv.style.position = 'absolute';
	newdiv.style.display = 'block';

	newdiv.style.left = sourceLeft +'px';
	newdiv.style.top = sourceTop +'px';
	newdiv.style.width = sourceWidth + 'px';
	newdiv.style.height = sourceHeight + 'px';
	newdiv.innerHTML = '<p align="center">'+URLDecode(dragText)+'</p>';
	newdiv.style.zIndex = 999;
	newdiv.style.border = 'solid 3px #ffffff';

	if (IE) {
		newdiv.style.border = "none";
		newdiv.style.background = "none";
	} else {
		newdiv.style.border = "none";
		newdiv.style.background = "none";
	}
	//make sure the mouse is over the drag div just in case a border or something
	//knocked it off a bit
	return newdiv;
}

function addDropTarget(targetid,dropFunction,excludeids) {
//dropFunction can be any function in form:
//functionName (dropDataId as string, dropData as string){}
//only the functionName is passed here, so e.g.:
//addDropTarget('myDiv','myFunction');
	dropTargets[dropTargetCount][0] = targetid;
	dropTargets[dropTargetCount][1] = dropFunction;
	if (excludeids) {
		dropTargets[dropTargetCount][2] = excludeids;
	} else {
		dropTargets[dropTargetCount][2] = undefined;
	}
	dropTargetCount++;
}

function processDrop(x,y)
{
	//go through all targets and see if it is under the drop
	//if it is, then call its drop function with the drop data
	var dropTarget;
	var targetid;
	var targetFunction;
	var targetWidth;
	var targetHeight;
	var targetTop;
	var targetLeft;
	var excludeElem;
	var excludeIds;
	var excludeTop;
	var excludeLeft;
	var excludeBottom;
	var excludeRight;
	var isExcluded = 0;

	var dropProcessed=0;

	for (i=0; i < dropTargetCount; i++)
	{
		dropTarget = dropTargets[i];
		targetid = dropTarget[0];
		targetFunction = dropTarget[1];
		excludeIds = dropTarget[2];

		target = document.getElementById(targetid);
		if (target) {
			targetTop = getAbsoluteTop(target.id);
			targetLeft = getAbsoluteLeft(target.id);
			targetBottom = targetTop + parseInt(target.offsetHeight);
			targetRight  = targetLeft + parseInt(target.offsetWidth);
			if (excludeIds) {
				//check if it fell on an excluded target, of so do not process
				//TODO: add support for excludeIds to be an array of excluded elements
				excludeElem = document.getElementById(excludeIds);
				if (excludeElem) {
					excludeTop = getAbsoluteTop(excludeElem.id);
					excludeLeft = getAbsoluteLeft(excludeElem.id);
					excludeBottom = excludeTop + parseInt(excludeElem.offsetHeight);
					excludeRight  = excludeLeft + parseInt(excludeElem.offsetWidth);
					if (x >= excludeLeft && x <= excludeRight && y >= excludeTop && y <= excludeBottom) {
						//this drop target is exluded, do not process
						isExcluded = 1;
					}
				}
			}

			if (isExcluded == 0 && x >= targetLeft && x <= targetRight && y >= targetTop && y <= targetBottom) {
				//its in the target zone... call the target function
				dropProcessed = window[targetFunction](draggingDataId,draggingData);
			}
		}
	}
	return dropProcessed;
}

function processHover(x,y)
{
	//see if we are dragging a source over a potential target, if so highlight it
	//go through all targets and see if it is under the drop
	//if it is, then call its drop function with the drop data
	var dropTarget;
	var targetid;
	var targetFunction;
	var targetWidth;
	var targetHeight;
	var targetTop;
	var targetLeft;
	var excludeElem;
	var excludeIds;
	var excludeTop;
	var excludeLeft;
	var excludeBottom;
	var excludeRight;
	var isExcluded = 0;

	var hoverProcessed=0;
	var targetFound=0;

	for (i=0; i < dropTargetCount; i++)
	{
		dropTarget = dropTargets[i];
		targetid = dropTarget[0];
		targetFunction = dropTarget[1];
		excludeIds = dropTarget[2];

		target = document.getElementById(targetid);
		if (target) {
			targetTop = getAbsoluteTop(target.id);
			targetLeft = getAbsoluteLeft(target.id);
			targetBottom = targetTop + parseInt(target.offsetHeight);
			targetRight  = targetLeft + parseInt(target.offsetWidth);
			if (excludeIds) {
				//check if it fell on an excluded target, of so do not process
				//TODO: add support for excludeIds to be an array of excluded elements
				excludeElem = document.getElementById(excludeIds);
				if (excludeElem) {
					excludeTop = getAbsoluteTop(excludeElem.id);
					excludeLeft = getAbsoluteLeft(excludeElem.id);
					excludeBottom = excludeTop + parseInt(excludeElem.offsetHeight);
					excludeRight  = excludeLeft + parseInt(excludeElem.offsetWidth);
					if (x >= excludeLeft && x <= excludeRight && y >= excludeTop && y <= excludeBottom) {
						//this drop target is exluded, do not process
						isExcluded = 1;
					}
				}
			}

			if (x >= targetLeft && x <= targetRight && y >= targetTop && y <= targetBottom) {
				targetFound = 1;
				if (isExcluded == 0) {
					//its in the target zone... call the target function
					hoverProcessed = window[targetFunction](draggingDataId,draggingData,1);

					if (hoverProcessed) {
						if (!highlightedTarget || highlightedTarget != target) {
							highlightedTarget = target;
							highlightedTargetOriginalBorder = highlightedTarget.style.border;
							highlightedTarget.style.border = "solid 2px #ffffff";
						}
					} else {
						unHighlightTarget();
					}
				}
			}
		}
	}
	if (!targetFound) {
		unHighlightTarget();
	}
	return hoverProcessed;
}

function unHighlightTarget()
{
	if (highlightedTarget) {
		highlightedTarget.style.border = highlightedTargetOriginalBorder;
		highlightedTarget = undefined;
		highlightedTargetOriginalBorder = "";
	}
}
//this function can be anything as long as its name is set in addTarget
function processMyChannelsDrop(dataid, data, hoveringOver)
{
	if (hoveringOver==1) {
		if (dataid == "channelid") {
			//this is a good source, highlight myChannels div
			return 1;
		} else if (dataid == "channelgroup") {
			//this is a good source, highlight myChannels div
			return 1;
		} else {
			return 0;
		}

	} else {
		if (dataid == "channelid") {
			var subimage = 'subimage_'+data;
			ajax_subscribe_only(data,subimage);
			return 1;
		} else if (dataid == "channelgroup") {
			ajax_subscribe_group(data);
		} else {
			return 0;
		}
	}
}

function processMyFriendsDrop(dataid, data, hoveringOver)
{
	if (hoveringOver==1) {
		if (dataid == "friendid") {
			//this is a good source, highlight myFriends div
			return 1;
		} else {
			return 0;
		}
	} else {
		if (dataid == "friendid") {
			var addimage = "afimage_"+data;
			ajax_only_add_friend(data,addimage,"NO NOTE");
			return 1;
		} else {
			return 0;
		}
	}
}

function processUnhandledDroppings(dataid, data, hoveringOver)
{
	if (hoveringOver==1) {
		return 0; //do nothing on hovers
	} else {
		if (dataid == "unsubscribe_channel") {
			var subimage = 'subimage_'+data;
			ajax_unsubscribe_only(data,subimage);
			return 1;
		} else if (dataid == "remove_friend") {
			var subimage = 'afimage_'+data;
			ajax_only_remove_friend(data,subimage);
			return 1;
		} else {
			return 0;
		}
	}
}

function disabletext(e){
	if (isElementDragging || preparedToDrag){
		return false
	}
}

function reEnable(){
	if (isElementDragging || preparedToDrag){
		return true
	}
}

//if the browser is IE4+
document.onselectstart=new Function ("if (isElementDragging || preparedToDrag) return false")

//if the browser is NS6
if (window.sidebar){
	document.onmousedown=disabletext
	document.onclick=reEnable
}

function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	// Return left postion
	return oLeft
}

function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	// Return top position
	return oTop
}
function MultiDimensionalArray(iRows,iCols)
{
var i;
var j;
   var a = new Array(iRows);
   for (i=0; i < iRows; i++)
   {
       a[i] = new Array(iCols);
       for (j=0; j < iCols; j++)
       {
           a[i][j] = "";
       }
   }
   return(a);
}
//End Drag and drop stuff

function sendRequest(getvars,async,ispopup,ispage,width,height,x,y,divName)
{
	if ((ajaxRequest.readyState != 0 && ajaxRequest.readyState != 4) || requestPending==1) {
		setTimeout("sendRequest('"+getvars+"',"+async+","+ispopup+","+ispage+","+width+","+height+",'"+x+"','"+y+"','"+divName+"')",50);
	} else {
		requestPending = 1;
		var ua = navigator.userAgent.toLowerCase();
		if (!window.ActiveXObject) {
			IE = 0;
			ajaxRequest = new XMLHttpRequest();
			document.captureEvents(Event.MOUSEMOVE)
		} else if (ua.indexOf('msie 5') == -1) {
			IE = 1;
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} else {
			IE = 1;
			ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (!getvars) {
			getvars = null;
		}
		if (!async) {
			async = false;
		}
		if (ispopup==3) {
			ajaxRequest.onreadystatechange = function(){div_response(divName)};
		} else if (ispopup) {
			ajaxRequest.onreadystatechange = function(){popup_response(width,height,x,y)};
		} else if (ispage) {
			ajaxRequest.onreadystatechange = function(){page_response(divName)};
		} else {
			ajaxRequest.onreadystatechange = function(){};
		}
		ajaxRequest.open('GET', serverCall + "?" + getvars, async);
		ajaxRequest.send(null);
		if (!async) {
    		requestPending = 0;
		    return ajaxRequest.responseText;
		}
	}
}


function showLoadingPopup(msg,title,width,height,x,y)
{
	if (!msg) {
		msg = "Please wait.  Loading...";
	}
	if (!title) {
		title = "Loading...";
	}
	//first just show text in case it takes a second for actual feedback window to load
	showPopup(width,height,x,y,msg);

	//now show loading with formatting
	var getVars = "action=feedback&msg=" + msg + "&title=" + title;
	var feedbackForm = sendRequest(getVars);
	showPopup(width,height,x,y,feedbackForm);

}
function showPopup(width,height,x,y,html)
{
	currentYOffset = getCurrentYOffset();
	pageWidth =  window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
	pageHeight = window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;
	var isPercLoc = 0;
	width = width.toString();
	height = height.toString();
	x = x.toString();
	y = y.toString();

	popupDiv.innerHTML = html;
	if (x.indexOf('%') != -1) {
		isPercLoc = 1;
		//recalc the top based on screen height and passed percentage
		var percLoc = y.indexOf("%");
		var yNum = y.substring(0,percLoc);
		y = pageHeight * (yNum*.01);

		var percLoc = x.indexOf("%");
		var xNum = x.substring(0,percLoc);
		x = pageWidth * (xNum*.01);

		//need to add y offset for scroll position
    	y = y + currentYOffset;

		popupDiv.style.left 		= x+"px";
		popupDiv.style.top 			= y+"px";

		//dim the background, this giving focus to the popup
		//document.getElementById('container').className='dimmed';
	} else {
		x = Number(x);
		y = Number(y);
		if (IE > 0) {
			y = y + currentYOffset;
		}
		//if its gonna go off the right then pop left
		var popRight 	= x+Number(width);
		var popLeft 	= x;
		var popBottom 	= y+Number(height);
		x = x - 20;
		y = y - 20;
		if (popRight > pageWidth) {
			x = x - width+40;
		}

		//if its gonna go off the left then pop right
		if (popLeft < 50) {
			x = x + Number(width) -20;
		}

		//if its gonna go off the bottom then pop up
		if (popBottom > (pageHeight+currentYOffset)) {
			y = y - Number(height)+40;
		}

		//if its gonna go off the top then pop down
		if (y <= currentYOffset) {
			y = y + Number(height)-20;
		}

		//there are some cases where there just is not enough room to pop up/down/right/or left
		//in that case center it on the new x and/or y and hope for best
		var popRight 	= x+Number(width);
		var popLeft 	= x;
		var popBottom 	= y+Number(height);

		if (popRight > pageWidth) {
			x = x - (width/2);
		}
		//if its gonna go off the left then pop right
		if (popLeft < 50) {
			x = x + (width/2);
		}
		//if its gonna go off the bottom then pop up
		if (popBottom > (pageHeight+currentYOffset)) {
			y = y - (height/2);
		}
		//if its gonna go off the top then pop down
		if (y <= currentYOffset) {
			y = y + (height/2);
		}

		popupDiv.style.left 		= x+"px";
		popupDiv.style.top 			= y+"px";
	}
	if (width.indexOf('%') != -1) {
		popupDiv.style.width 		= width;
		popupDiv.style.height 		= height;
		popupDiv.style.marginLeft 	= "0px";
		popupDiv.style.marginTop 	= "0px";
	} else {
		popupDiv.style.width 		= width+"px";
		popupDiv.style.height 		= height+"px";
		//if x and y was a percentage then center div using margins
		if (isPercLoc == 1) {
			popupDiv.style.marginLeft 	= "-"+(width/2)+"px";
			popupDiv.style.marginTop 	= "-"+(height/2)+"px";
		} else {
			popupDiv.style.marginLeft 	= "0px";
			popupDiv.style.marginTop 	= "0px";
		}
	}

	if (popupDiv_iframe) {
		popupDiv_iframe.style.top 			= popupDiv.style.top;
		popupDiv_iframe.style.left 			= popupDiv.style.left;
		popupDiv_iframe.style.height 		= popupDiv.style.height;
		popupDiv_iframe.style.width 		= popupDiv.style.width;
		popupDiv_iframe.style.marginLeft 	= popupDiv.style.marginLeft;
		popupDiv_iframe.style.marginTop 	= popupDiv.style.marginTop;
		popupDiv_iframe.style.zIndex 		= 98;
		popupDiv_iframe.style.filter		='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
		popupDiv_iframe.style.display 		= "block";
	}
	popupDiv.zIndex = 99;
	popupDiv.style.display 				= "block";
}
function popup_response(width,height,x,y)
{
	if (ajaxRequest.readyState == 4) {
		var response = ajaxRequest.responseText;
		showPopup (width,height,x,y,response);
   		requestPending = 0;
   		if (updateChannelImagesAfterNextAjaxReturn!=0) {
			updateChannelImagesAfterNextAjaxReturn = 0;
			updateAllChannelImagesOnPage();
   		}
   		if (updateChannelImageAfterNextReturn!=0) {
   			image = document.getElementById(updateChannelImageAfterNextReturn);
   			if (image) {
   				if (image.src) {
					size = image.width;
					channelid = image.name;
					loadChannelImageFromCache(image,channelid,size);
   				}
   			}
   			updateChannelImageAfterNextReturn = 0;
   		}
	}
}

function page_response(divName)
{
	if (ajaxRequest.readyState == 4) {
		var response = ajaxRequest.responseText;
		redrawDiv (divName,response);
   		requestPending = 0;

   		redrawNavButtons();

		updateAllChannelImagesOnPage();
	}
	clearTimeout(hoverTimer); //clear out any pending popups
	if (!document.getElementById('DONT_EVER_FORCE_HIDE')) {
		hidePopup();  //hide any already visible popups
	}

	if (divName == sidebarDiv) {
		//make sure side nav is properly expanded/collapsed after redraw
		setLayersBasedOnCookies();
	}
}
function div_response(divName)
{
	if (ajaxRequest.readyState == 4) {
		var response = ajaxRequest.responseText;
		redrawDiv (divName,response);
   		requestPending = 0;
		updateAllChannelImagesOnPage();
	}
}

function fadeElement(elem,currentOpacity,endOpacity,increment)
{
	var obj = document.getElementById(elem);
	if (IE>0) {
		//fade doesnt work in IE for now
		setElemOpacity(obj,endOpacity);
	} else {
		setElemOpacity(obj,currentOpacity);
		if (currentOpacity < endOpacity) {
			setTimeout("fadeElement('"+elem+"',"+(currentOpacity+increment)+","+endOpacity+","+increment+")",5);
		}
	}
}

function setElemOpacity(obj,opacity)
{
//		obj.style.filter 		='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity='+opacity+')';
//		obj.style.MozOpacity 	=.01*opacity;
}

function showBalloon(width,height,x,y,html)
{
	currentYOffset = getCurrentYOffset();
	pageWidth =  window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
	pageHeight = window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;
	var isPercLoc = 0;
	width = width.toString();
	height = height.toString();
	x = x.toString();
	y = y.toString();
	balloonDiv.innerHTML = html;

	x = Number(x);
	y = Number(y)
	if (IE > 0) {
		y = y + currentYOffset;
	}

	//we want to generally popup from the mouseloc
	y = y - height - 5;
	x=x+5;

	balloonDiv.style.left 		= x+"px";
	balloonDiv.style.top 		= y+"px";

	balloonDiv.style.width 		= width+"px";
	balloonDiv.style.height 	= height+"px";
	balloonDiv.style.marginLeft = "0px";
	balloonDiv.style.marginTop 	= "0px";

	setElemOpacity(balloonDiv,0);

	balloonDiv.zIndex = 100;
	balloonDiv.style.display 	= "block";

	if (balloonDiv_iframe) {
		balloonDiv_iframe.style.left = balloonDiv.style.left;
		balloonDiv_iframe.style.top = balloonDiv.style.top;
		balloonDiv_iframe.style.width = balloonDiv.style.width;
		balloonDiv_iframe.style.marginLeft = balloonDiv.style.marginLeft;
		balloonDiv_iframe.style.marginTop = balloonDiv.style.marginTop;
		balloonDiv_iframe.zIndex = 99;
		balloonDiv_iframe.style.filter		='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
		balloonDiv_iframe.style.display 	= "block";
	}
	fadeElement(balloonDiv.id,0,100,8);
}

function hidePopup(hideDelay)
{
	if (popupDiv) {
	   	if (hideDelay) {
			hideTimer = setTimeout("hidePopup()",hideDelay);
		} else {
			if (popupDiv_iframe) {
				popupDiv_iframe.style.display = "none";
			}
			popupDiv.style.display = "none";
		}
	}
}
function hideBalloon()
{
	if (balloonDiv_iframe) {
		balloonDiv_iframe.style.display = "none";
	}
	balloonDiv.style.display = "none";
}
function redrawDiv(divName,html)
{
	oDiv = document.getElementById(divName);
	oDiv.innerHTML = html;
}

/*EVERYTHING BELOW is ajax stuff*/
function ajax_popup_channel(channelid, hoverReady, skipDelay)
{
	if (allowRollovers_info) {
		if (isElementDragging==0) { //no rollovers during drg and drp operation
			if (hoverReady) {
				if (skipDelay) {
					trackAction("channel_popup_viewed","");

					var getVars = "action=channelDetails&channelid=" + channelid;
					updateChannelImageAfterNextReturn = "popup_main_thumb_image";
					var channelData = sendRequest(getVars,true,true,false,460,365,currentMouseX,currentMouseY);
				} else {
					//showLoadingPopup("Loading channel information.  Please wait.","",460,365,currentMouseX,currentMouseY);
					setTimeout("ajax_popup_channel('"+channelid+"',1, 1)",250);
				}
			} else {
				//cancel any previous popus
				ajax_cancel_channel_popup();
				hoverTimer = setTimeout("ajax_popup_channel('"+channelid+"', 1,0)",300);
			}
		}
	}
}

function ajax_popup_flvPlayer(flvUrl,skipDelay,autoPlay)
{
	if (skipDelay) {
		if (!autoPlay || autoPlay == undefined || autoPlay == " undefined" || autoPlay == "") {
			autoPlay = "true";
		}
		var getVars = "action=flvPlayer&autoPlay=" + autoPlay + "&flvUrl=" + URLEncode(flvUrl);
		var flvPlayerData = sendRequest(getVars,true,true,false,460,365,'50%','50%');
	} else {
		setTimeout("ajax_popup_flvPlayer('"+flvUrl+"',1, '"+autoPlay+"')",250);
	}
}
function ajax_hide_flvPlayer(flvUrl,skipDelay,autoPlay)
{
	if (skipDelay) {
		if (!autoPlay || autoPlay == undefined || autoPlay == " undefined" || autoPlay == "") {
			autoPlay = "true";
		}
		var getVars = "action=flvPlayer&autoPlay=" + autoPlay + "&flvUrl=" + URLEncode(flvUrl);
		var flvPlayerData = sendRequest(getVars,true,true,false,460,365,'50%','50%');
		setTimeout("hidePopup()",100);
		setTimeout("hidePopup()",200);
		setTimeout("hidePopup()",300);
		setTimeout("hidePopup()",400);
		setTimeout("hidePopup()",500);
	} else {
		setTimeout("ajax_hide_flvPlayer('"+flvUrl+"',1, '"+autoPlay+"')",250);
	}
}

function ajax_popup_youTubeVideo(videoUrl,skipDelay)
{
	if (skipDelay) {
		var getVars = "action=youTubeVideo&videoUrl=" + URLEncode(videoUrl);
		var flvPlayerData = sendRequest(getVars,true,true,false,460,365,'50%','50%');
	} else {
		setTimeout("ajax_popup_youTubeVideo('"+videoUrl+"',1)",250);
	}
}
function ajax_hide_youTubeVideo(videoUrl,skipDelay)
{
	if (skipDelay) {
		var getVars = "action=youTubeVideo&videoUrl=" + URLEncode(videoUrl);
		var flvPlayerData = sendRequest(getVars,true,true,false,460,365,'50%','50%');
		setTimeout("hidePopup()",100);
		setTimeout("hidePopup()",200);
		setTimeout("hidePopup()",300);
		setTimeout("hidePopup()",400);
		setTimeout("hidePopup()",500);
	} else {
		setTimeout("ajax_hide_youTubeVideo('"+videoUrl+"',1)",250);
	}
}

function ajax_popup_user(userid, hoverReady, skipDelay)
{
	if (allowRollovers_info) {
		if (isElementDragging==0) { //no rollovers during drg and drp operation
			if (hoverReady) {
				if (skipDelay) {
					trackAction("user_popup_viewed","");
					var getVars = "action=userDetails&userid=" + userid;
					var userData = sendRequest(getVars,true,true,false,460,365,currentMouseX,currentMouseY);
				} else {
					//showLoadingPopup("Loading user information.  Please wait.","",460,365,currentMouseX,currentMouseY);
					setTimeout("ajax_popup_user('"+userid+"',1, 1)",20);
				}
			} else {
				//cancel any previous popus
				ajax_cancel_user_popup();
				hoverTimer = setTimeout("ajax_popup_user('"+userid+"', 1,0)",300);
			}
		}
	}
}

function ajax_cancel_channel_popup()
{
	clearTimeout(hoverTimer);
}

function ajax_cancel_user_popup()
{
	clearTimeout(hoverTimer);
}
function ajax_cancel_channel_popup_hide()
{
	clearTimeout(hideTimer);
}

function ajax_cancel_user_popup_hide()
{
	clearTimeout(hideTimer);
}

function ajax_popup_contact()
{
	showLoadingPopup("Loading contact information.  Please wait.","",460,365,"50%","50%");
	//show the contact us info
	var getVars = "action=contact";
	var contactForm = sendRequest(getVars,true,true,false,460,365,"50%","50%");

	// Google Analytics
	google_track("/info/contact");

}

function ajax_popup_avatars()
{
	showLoadingPopup("Loading contact information.  Please wait.","",460,365,"50%","50%");
	//show the contact us info
	var getVars = "action=avatar";
	var contactForm = sendRequest(getVars,true,true,false,460,365,"50%","50%");
}

function setUserStockAvatar(stockImageFilename)
{
	document.getElementById('currentAvatarImage').src = 'images/avatars/150/s/' + stockImageFilename;
	document.getElementById('customAvatar').value = stockImageFilename;
	setTimeout("document.getElementById('profileForm').submit()",250);
}

function ajax_popup_user_forget(userEmail)
{
	showLoadingPopup("Loading <em>forgot login</em> form information.  Please wait.","",460,365,"50%","50%");
	//show the contact us info
	var getVars = "action=forgotLogin&email="+userEmail;
	var contactForm = sendRequest(getVars,true,true,false,460,365,"50%","50%");

	// Google Analytics
	google_track("/user/forgot_login");
}

function ajax_popup_tip(helperid,popUpTitle)
{
	showLoadingPopup("Loading help system...  Please wait.","",460,365,"50%","50%");
	//show the contact us info
	var getVars = "action=helptip&helperid="+helperid+"&popUpTitle="+popUpTitle;
	var contactForm = sendRequest(getVars,true,true,false,460,365,"50%","50%");
}

function ajax_popup_episode(episodeid)
{
	showLoadingPopup("Loading episode information.  Please wait.","",460,365,currentMouseX,currentMouseY);

	var getVars = "action=episodeDetails&episodeid=" + episodeid;
	var channelData = sendRequest(getVars,true,true,false,460,365,currentMouseX,currentMouseY);

	// Google Analytics
	google_track("/episode/popup");
}

function ajax_popup_manual_add_channel(rssUrl, skipDelay)
{
	if (!rssUrl) {
		rssUrl = "";
	}
	if (skipDelay) {
		var getVars = "action=subscribeByUrl&rssUrl="+rssUrl;
		sendRequest(getVars,true,true,false,460,365,"50%","50%");

		if (rssUrl) {
			// Google Analytics
			google_track("/channel/subscribe_by_url");

			//redraw the sidebar since their "my channels" may have been changed
			var getVars = "action=sidebar_main";
			var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);
		}

	} else {
		if (rssUrl) {
			showLoadingPopup("Parsing the RSS feed... Please wait.","",460,365,"50%","50%");
		} else {
			showLoadingPopup("Loading subscription options... Please wait.","",460,365,"50%","50%");
		}
		setTimeout("ajax_popup_manual_add_channel('"+rssUrl+"',1)",250);
	}
}

function ajax_popup_manual_add_friend(friendName, note, skipDelay)
{
	if (!friendName) {
		friendName = "";
	}
	if (skipDelay) {
		var getVars = "action=addFriendByName&friendName="+friendName+"&msg="+note;
		sendRequest(getVars,true,true,false,460,365,"50%","50%");

		if (friendName) {
			// Google Analytics
			google_track("/friend/add");

			//redraw the sidebar since their "my channels" may have been changed
			var getVars = "action=sidebar_main";
			var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);
		}

	} else {
		if (friendName) {
			showLoadingPopup("Searching for friend... Please wait.","",460,365,"50%","50%");
		} else {
			showLoadingPopup("Loading friend options... Please wait.","",460,365,"50%","50%");
		}
		setTimeout("ajax_popup_manual_add_friend('"+friendName+"','"+note+"',1)",250);
	}
}

function ajax_popup_shareChannel(channelid, recipList, message, skipDelay)
{
	if (skipDelay) {
		if (recipList) {
			// Google Analytics
			google_track("/channel/share");

			var getVars = "action=shareChannel&channelid="+channelid+"&recipUsers="+recipList+"&msg="+message;
			var shareChannelData = sendRequest(getVars,true,true,false,460,365,"50%","50%");
		} else {
			var getVars = "action=isLoggedIn";
			var shareChannelData = sendRequest(getVars,false,false,false);
			if (shareChannelData == 1) {
				var getVars = "action=shareChannel&channelid="+channelid;
				var shareChannelData = sendRequest(getVars,true,true,false,460,365,"50%","50%");
			} else {
				//show them login form
				var reactionString = "ajax_popup_shareChannel('"+channelid+"', '','',1)";
				var getVars = "action=login&reaction=" + escape(reactionString) + "&feedback=You must sign-in or create an account to share podcast data with other users.";
				var loginResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
			}
		}
	} else {
		if (recipList) {
			showLoadingPopup("Sending message... Please wait.","",460,365,"50%","50%");
			ajax_popup_shareChannel(channelid, recipList, message, 1);
		} else {
			showLoadingPopup("Loading channel information...  Please wait.","",460,365,"50%","50%");
			setTimeout("ajax_popup_shareChannel('"+channelid+"', '','',1)",250);
		}
	}
}

function ajax_popup_shareEpisode(episodeid, recipList, message, skipDelay)
{
	if (skipDelay) {
		if (recipList) {
			var getVars = "action=shareEpisode&episodeid="+episodeid+"&recipUsers="+recipList+"&msg="+message;
			var shareChannelData = sendRequest(getVars,true,true,false,460,365,"50%","50%");

			//action tracking
			trackAction("episode_shared","",episodeid);

			// Google Analytics
			google_track("/episode/share");
		} else {
			var getVars = "action=isLoggedIn";
			var shareChannelData = sendRequest(getVars,false,false,false);

			if (shareChannelData == 1) {
				var getVars = "action=shareEpisode&episodeid="+episodeid;
				var shareChannelData = sendRequest(getVars,true,true,false,460,365,"50%","50%");
			} else {

				//show them login form
				var reactionString = "ajax_popup_shareEpisode('"+episodeid+"', '','',1)";
				var getVars = "action=login&reaction=" + escape(reactionString) + "&feedback=You must sign-in or create an account to share podcast data with other users.";
				var loginResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
			}
		}
	} else {
		if (recipList) {
			showLoadingPopup("Sending message... Please wait.","",460,365,"50%","50%");
			ajax_popup_shareEpisode(episodeid, recipList, message, 1);
		} else {
			showLoadingPopup("Loading episode information...  Please wait.","",460,365,"50%","50%");
			setTimeout("ajax_popup_shareEpisode('"+episodeid+"', '','',1)",250);
		}
	}
}

function ajax_popup_playEpisode(episodeid,action,skipDelay)
{
	if (skipDelay) {
		if (action == "PLAY") {
			window.open('playEpisode.php?episodeid='+episodeid,'MediaPlayer','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=728,height=450,left=20,top=20');
			hidePopup();

			// Google Analytics
			google_track("/episode/play");

			//track user action
			trackAction("episode_played","",episodeid);

		} else if (action == "PRIVATE_CHANNEL") {
			var getVars = "action=sendEpisodeToPrivateChannel&episodeid="+episodeid;
			var playResult = sendRequest(getVars,false,false,false);

			if (playResult == 1) {
				var getVars = "action=feedback&msg=This episode has been sent to your Private Channel.&title=Send Episode to Private Channel";
				var feedbackResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
			} else if (playResult == 0) {
				//they are not even logged in, we cant do anything until they login
				//show the login popup form
				var reactionString = "ajax_popup_playEpisode('"+episodeid+"','"+action+"',1)";
				var getVars = "action=login&reaction=" + escape(reactionString) + "&feedback=You must sign-in or create an account to save podcast data to your private channel.";
				var loginResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
			}
		} else {
			var getVars = "action=playEpisode&episodeid="+episodeid;
			var playResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
		}
		canel_baloon_popup();
	} else {
		showLoadingPopup("Playing episode...  Please wait.","",460,365,"50%","50%");
		//this delay is needed to make sure the aboive msgbox shows before synchronous action begins
		setTimeout("ajax_popup_playEpisode('"+episodeid+"','"+action+"',1)",250);
	}
}

function ajax_popup_playUserContent(episodeid,skipDelay)
{
	if (skipDelay) {
		window.open('playEpisode.php?episodeid='+episodeid,'MediaPlayer','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=450,height=325,left=20,top=20');
		hidePopup();

		// Google Analytics
		google_track("/episode/play");

		//track user action
		trackAction("episode_played","");

		canel_baloon_popup();
	} else {
		showLoadingPopup("Playing episode...  Please wait.","",460,365,"50%","50%");
		//this delay is needed to make sure the aboive msgbox shows before synchronous action begins
		setTimeout("ajax_popup_playUserContent('"+episodeid+"',1)",250);
	}
}


function ajax_popup_playEpisode_private(pchannelid,skipDelay)
{
	if (skipDelay) {
		window.open('playEpisode.php?pchannelid='+pchannelid,'MediaPlayer','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=450,height=325,left=20,top=20');
		hidePopup();

		// Google Analytics
		google_track("/episode/save_in_private_channel");

	} else {
		showLoadingPopup("Playing episode...  Please wait.","",460,365,"50%","50%");
		//this delay is needed to make sure the aboive msgbox shows before synchronous action begins
		setTimeout("ajax_popup_playEpisode_private('"+pchannelid+"',1)",250);
	}
/*
	if (skipDelay) {
		newWindow = window.open(webRoot+"playEpisode.php?pchannelid="+pchannelid,'Play Episode','left=20,top=20,width=450,height=325,toolbar=0,resizable=0');
		hidePopup();

		// Google Analytics
		google_track("/episode/save_in_private_channel");

	} else {
		showLoadingPopup("Playing episode...  Please wait.","",460,365,"50%","50%");
		//this delay is needed to make sure the aboive msgbox shows before synchronous action begins
		setTimeout("ajax_popup_playEpisode_private('"+pchannelid+"',1)",250);
	}
*/
}

function ajax_popup_playComment_private(commentid,skipDelay)
{
	if (skipDelay) {
		window.open('playComment.php?commentid='+commentid,'MediaPlayer','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=450,height=325,left=20,top=20');
		hidePopup();

		// Google Analytics
		google_track("/comments/play_comment");

	} else {
		showLoadingPopup("Playing comment...  Please wait.","",460,365,"50%","50%");
		//this delay is needed to make sure the aboive msgbox shows before synchronous action begins
		setTimeout("ajax_popup_playComment_private('"+commentid+"',1)",250);
	}
/*
	if (skipDelay) {
		newWindow = window.open(webRoot+"playEpisode.php?pchannelid="+pchannelid,'Play Episode','left=20,top=20,width=450,height=325,toolbar=0,resizable=0');
		hidePopup();

		// Google Analytics
		google_track("/episode/save_in_private_channel");

	} else {
		showLoadingPopup("Playing episode...  Please wait.","",460,365,"50%","50%");
		//this delay is needed to make sure the aboive msgbox shows before synchronous action begins
		setTimeout("ajax_popup_playEpisode_private('"+pchannelid+"',1)",250);
	}
*/
}

function ajax_removeEpisodeFromPrivateChannel(pchannelid,episodeCount,divName)
{
	var getVars = "action=removeEpisodeFromPrivateChannel&pchannelid="+pchannelid;
	var removeResult = sendRequest(getVars,false,false,false);

	// Google Analytics
	google_track("/episode/remove_from_private_channel");

	//redraw the private channel page
	ajax_page_private_channel(episodeCount,divName,0,"episodes");
}

function ajax_removeComment(commentid,episodeCount,divName)
{
	var getVars = "action=removeComment&commentid="+commentid;
	var removeResult = sendRequest(getVars,false,false,false);

	// Google Analytics
	google_track("/episode/remove_from_private_channel");

	//redraw the private channel page
	ajax_page_private_channel(episodeCount,divName,0,"feedback");
}

function ajax_removeBulletin(bulletinid,episodeCount,divName)
{
	var getVars = "action=removeBulletin&bulletinid="+bulletinid;
	var removeResult = sendRequest(getVars,false,false,false);

	// Google Analytics
	google_track("/episode/remove_from_private_channel");

	//redraw the private channel page
	ajax_page_private_channel(episodeCount,divName,0,"bulletins");
}

function ajax_popup_playChannel(channelid,skipDelay)
{
	if (skipDelay) {
		//first we need to get the episodeid of the first episode
		var getVars = "action=getFirstEpisodeId&channelid="+channelid;
		var firstEpisodeId = sendRequest(getVars,false,false,false);
		if (firstEpisodeId) {
			ajax_popup_playEpisode(firstEpisodeId);
		} else {
			var getVars = "action=feedback&msg=The selected channel does not have any episodes to play.";
			var loginResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
		}

		// Google Analytics
		google_track("/channel/play");

	} else {
		showLoadingPopup("Playing the channels latest episode...  Please wait.","",460,365,"50%","50%");
		//this delay is needed to make sure the aboive msgbox shows before synchronous action begins
		setTimeout("ajax_popup_playChannel('"+channelid+"',1)",250);
	}
}

function ajax_popup_userMessages(skipDelay)
{
	if (skipDelay) {
		var getVars = "action=userMessages";
		var userData = sendRequest(getVars,true,true,false,463,601,"50%","50%");

		// Google Analytics
		google_track("/user/messages");
	} else {
		showLoadingPopup("Loading messages.  Please wait.","",463,601,"50%","50%");
		setTimeout("ajax_popup_userMessages(1)",250);
	}
}

function ajax_page_user(userid,channelCount,divName,skipDelay,displayMode)
{
	if (displayMode == undefined || displayMode == "undefined") {
		displayMode = "";
	}
	hidePopup();
	ajax_cancel_user_popup();
	if (skipDelay) {
		//make sure the filter bar is correct in case we just came from a channel page
		if (!document.getElementById("fb_friends")) {
			var getVars = "action=filterbar_friends";
			filterBar = sendRequest(getVars,true,false,true,500,400,"50%","50%",filterbarDiv);
			setSelectedTab_mainNav('Friends');
		}

		history_set_action("ajax_page_user('"+userid+"',"+channelCount+",'"+divName+"',1,'"+displayMode+"')");

		var getVars = "action=user&userid="+userid+"&channelCount="+channelCount+"&displayMode="+displayMode;
		var channelsPage = sendRequest(getVars,true,false,true,460,365,"50%","50%",divName);

		// Google Analytics
		google_track('/view_user');

		setTimeout('scroll(0,0)', 500);;
	} else {
		//showLoadingPopup("Loading user data...  Please wait.","",460,365,"50%","50%");
		showLoadingDiv(divName);
		setTimeout("ajax_page_user('"+userid+"',"+channelCount+",'"+divName+"',1,'"+displayMode+"')",250);
	}
}

function ajax_page_profile(currentSection,selectedCategory,divName,skipDelay)
{
	if (skipDelay) {
		history_set_action("ajax_page_profile('"+currentSection+"','"+selectedCategory+"','"+divName+"',1)");

		var getVars = "action=profile&currentSection="+currentSection+"&categoryid="+selectedCategory;
		var channelsPage = sendRequest(getVars,true,false,true,460,365,"50%","50%",divName);

		// Google Analytics
		google_track('/user/profile');

		setTimeout('scroll(0,0)', 500);;

	} else {
		showLoadingDiv(divName);
		setTimeout("ajax_page_profile('"+currentSection+"','"+selectedCategory+"','"+divName+"',1)",250);
	}
}

//AJAX CHANNEL GUIDE
function ajax_channel_guide_episodes(categoryid, date, divName,skipDelay)
{
	if (skipDelay) {
		var getVars = "action=channelGuideEpisodes&categoryid="+categoryid+"&guideDate="+date;
		var channelGuideEp = sendRequest(getVars,true,3,true,460,365,"50%","50%",divName);
	} else {
		document.getElementById(divName).innerHTML = "LOADING SHOWS...";
		setTimeout("ajax_channel_guide_episodes('"+categoryid+"','"+date+"','"+divName+"',1)",25);
	}
}
function ajax_channel_guide_categoryList(categoryid, divName,skipDelay)
{
	if (skipDelay) {
		var getVars = "action=channelGuideCategoryList&categoryid="+categoryid;
		var channelGuideEp = sendRequest(getVars,true,false,true,460,365,"50%","50%",divName);
	} else {
		document.getElementById(divName).innerHTML = "Loading category show list...";
		setTimeout("ajax_channel_guide_categoryList('"+categoryid+"','"+divName+"',1)",25);
	}
}
function ajax_channel_guide_slotList(categoryid,slotDate,divName,skipDelay)
{
	if (skipDelay) {
		var getVars = "action=channelGuideSlotList&guideDate="+slotDate+"&categoryid="+categoryid;
		var channelGuideEp = sendRequest(getVars,true,false,true,460,365,"50%","50%",divName);
	} else {
		document.getElementById(divName).innerHTML = "Loading time slot show list...";
		setTimeout("ajax_channel_guide_slotList('"+categoryid+"','"+slotDate+"','"+divName+"',1)",25);
	}
}
function ajax_channel_guide_episode(episodeid,divName,skipDelay)
{
	if (skipDelay) {
		var getVars = "action=channelGuideEpisode&episodeid="+episodeid;
		var channelGuideEp = sendRequest(getVars,true,false,true,460,365,"50%","50%",divName);
	} else {
		document.getElementById(divName).innerHTML = "Loading selected show episode...";
		setTimeout("ajax_channel_guide_episode('"+episodeid+"','"+divName+"',1)",25);
	}
}
function ajax_channel_guide_PlayEpisode(episodeid,divName,skipDelay)
{
	if (skipDelay) {
		var getVars = "action=channelGuidePlayEpisode&episodeid="+episodeid;
		var channelGuideEp = sendRequest(getVars,true,false,true,460,365,"50%","50%",divName);
	} else {
		document.getElementById(divName).innerHTML = "Downloading selected show episode...";
		setTimeout("ajax_channel_guide_PlayEpisode('"+episodeid+"','"+divName+"',1)",25);
	}
}
function ajax_channel_guide_channel(feedid,divName,skipDelay)
{
	if (skipDelay) {
		var getVars = "action=channel&channelid="+feedid+"&episodeCount=10";
		var channelsPage = sendRequest(getVars,true,false,true,460,365,"50%","50%",divName);
		google_track("/channel");
		trackAction("view_feed",feedid);
		setTimeout('scroll(0,0)', 500);
	} else {
		showLoadingDiv(divName);
		setTimeout("ajax_channel_guide_channel('"+feedid+"','"+divName+"',1)",250);
	}
}
function ajax_channel_guide(divName,skipDelay)
{
	if (skipDelay) {
		var getVars = "action=channelGuide";
		var channelsPage = sendRequest(getVars,true,false,true,460,365,"50%","50%",divName);
		setTimeout('scroll(0,0)', 500);
	} else {
		showLoadingDiv(divName);
		setTimeout("ajax_channel_guide('"+divName+"',1)",250);
	}
}
//---END AJAX CHANNEL GUIDE

function ajax_page_channel(channelid,episodeCount,divName,skipDelay,source)
{
	if (!source || source==undefined || source == "undefined") {
		source = "";
	}
	hidePopup();
	ajax_cancel_channel_popup();
	if (skipDelay) {
		history_set_action("ajax_page_channel('"+channelid+"',"+episodeCount+",'"+divName+"',1)");

		var getVars = "action=channel&channelid="+channelid+"&episodeCount="+episodeCount;
		var channelsPage = sendRequest(getVars,true,false,true,460,365,"50%","50%",divName);

		//make sure the filter bar is correct in case we just came from a friends page
		if (!document.getElementById("fb_channels")) {
			var getVars = "action=filterbar_channels";
			filterBar = sendRequest(getVars,true,false,true,500,500,"50%","50%",filterbarDiv);
			setSelectedTab_mainNav('Podcasts');
		}

		// Google Analytics
		google_track("/channel");

		//action tracking
		trackAction("view_feed",channelid);
		if (source == "featured") {
			trackAction("view_featured_feed",channelid);
		} else if (source == "landing") {
			trackAction("view_landing_page_feed",channelid);
		}
		setTimeout('scroll(0,0)', 500);

	} else {
		//showLoadingPopup("Loading channel data...  Please wait.","",460,365,"50%","50%");
		showLoadingDiv(divName);
		setTimeout("ajax_page_channel('"+channelid+"',"+episodeCount+",'"+divName+"',1,'"+source+"')",250);
	}
}

function ajax_page_private_channel(episodeCount,divName, skipDelay, activeDisplay)
{
	if (activeDisplay == "undefined" || activeDisplay == undefined) {
		activeDisplay = "";
	}

	if (skipDelay) {
		history_set_action("ajax_page_private_channel("+episodeCount+",'"+divName+"',1,'"+activeDisplay+"')");

		var getVars = "action=privateChannel&activeDisplay="+activeDisplay+"&episodeCount="+episodeCount;
		var channelsPage = sendRequest(getVars,true,false,true,460,365,"50%","50%",divName);

		//make sure the filter bar is correct in case we just came from a friends page
		if (!document.getElementById("fb_channels")) {
			var getVars = "action=filterbar_channels";
			filterBar = sendRequest(getVars,true,false,true,500,500,"50%","50%",filterbarDiv);
			setSelectedTab_mainNav('Podcasts');
		}

		// Google Analytics
		google_track("/private_channel");

		setTimeout('scroll(0,0)', 500);;
	} else {
		//showLoadingPopup("Loading private channel data...  Please wait.","",460,365,"50%","50%");
		showLoadingDiv(divName);
		setTimeout("ajax_page_private_channel("+episodeCount+",'"+divName+"',1,'"+activeDisplay+"')",250);
	}
}

function ajax_page_home(divName,skipDelay)
{
	if (skipDelay) {
		history_set_action("ajax_page_home('"+divName+"',1)");

		var getVars = "action=home";
		var channelsPage = sendRequest(getVars,true,false,true,460,365,"50%","50%",divName);

		var getVars = "action=sidebar_home";
		var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);

		var getVars = "action=filterbar_channels&categoryid="+categoryid+"&orderBy="+orderBy+"&alpha="+alpha+"&subject="+subject+"&search="+search+"&page="+page+"&view="+view;
		var filterbarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",filterbarDiv);

		setSelectedTab_mainNav('Home');

		// Google Analytics
		google_track("/homepage");

		setTimeout('scroll(0,0)', 500);;
	} else {
		//showLoadingPopup("Loading home page...  Please wait.","",460,365,"50%","50%");
		showLoadingDiv(divName);
		setTimeout("ajax_page_home('"+divName+"',1)",250);
	}
}

function ajax_page_channels(categoryid,orderBy,alpha,subject,search,page,view,divName,skipDelay)
{
	if (skipDelay) {
		history_set_action("ajax_page_channels('"+categoryid+"','"+orderBy+"','"+alpha+"','"+subject+"','"+search+"','"+page+"','"+view+"','"+divName+"')");

		//if the filter bar is not set to channels then redraw that bitch
		if (!document.getElementById("fb_channels")) {
			var getVars = "action=filterbar_channels&categoryid="+categoryid+"&orderBy="+orderBy+"&alpha="+alpha+"&subject="+subject+"&search="+search+"&page="+page+"&view="+view;
			var filterbarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",filterbarDiv);
			setSelectedTab_mainNav('Podcasts');
		}

		//if the sidebar is not right then redraw it
		if (!document.getElementById('mypodcasts')) {
			var getVars = "action=sidebar_main";
			var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);
		}

		var getVars = "action=channels&categoryid="+categoryid+"&orderBy="+orderBy+"&alpha="+alpha+"&subject="+subject+"&search="+search+"&page="+page+"&view="+view;
		var channelsPage = sendRequest(getVars,true,false,true,460,365,"50%","50%",divName);

		// Google Analytics
		google_track("/channels");

		setTimeout('scroll(0,0)', 500);

		//if this is a nav action then redraw the filter bar
		//redraw the filter bar with appririate choices to match the search
		if (doingNavAction==1) {
			doingNavAction = 0;
			var getVars = "action=filterbar_channels&categoryid="+categoryid+"&orderBy="+orderBy+"&alpha="+alpha+"&subject="+subject+"&search="+search+"&page="+page+"&view="+view;
			var channelsPage = sendRequest(getVars,true,false,true,460,365,"50%","50%",filterbarDiv);
		}

		document.getElementById("search").focus();
	} else {
		//showLoadingPopup("Loading podcast data...  Please wait.","",460,365,"50%","50%");
		showLoadingDiv(divName);
		setTimeout("ajax_page_channels('"+categoryid+"','"+orderBy+"','"+alpha+"','"+subject+"','"+search+"','"+page+"','"+view+"','"+divName+"',1)",250);
	}
}

function ajax_page_reload_search(search,alpha, subject, categoryid, orderBy)
{
	if (subject == "channels" || subject == "episodes") {
		history_set_action("ajax_page_reload_search('"+search+"','"+alpha+"','"+subject+"','"+categoryid+"','"+orderBy+"')");
		ajax_page_channels(categoryid,orderBy,alpha,subject,search,1,"icon","contentBody");

		//redraw the filter bar with appririate choices to match the search
		if (!document.getElementById("fb_channels")) {
			var getVars = "action=filterbar_channels&categoryid="+categoryid+"&orderBy="+orderBy+"&alpha="+alpha+"&subject="+subject+"&search="+search+"&page="+1+"&view=icon";
			var channelsPage = sendRequest(getVars,true,false,true,460,365,"50%","50%",filterbarDiv);
			setSelectedTab_mainNav('Podcasts');
		}


		setTimeout('scroll(0,0)', 500);

	} else if (subject == "users") {
		ajax_page_friends(categoryid,alpha,search,1,"icon","contentBody");
		setTimeout('scroll(0,0)', 500);
	}

	// Google Analytics
	google_track("/saved_searches/load");
}

function ajax_page_download(divName)
{
	history_set_action("ajax_page_download('"+divName+"')");

	showLoadingPopup("Loading download page...  Please wait.","",460,365,"50%","50%");
	redrawDiv(divName,"Loading download data...  Please wait.");

	var getVars = "action=download";
	var downloadPage = sendRequest(getVars,true,false,true,460,365,"50%","50%",divName);

	// Google Analytics
	google_track("/download");

	setTimeout('scroll(0,0)', 200);
}

function ajax_page_friends(categoryid,alpha,search,page,view,divName)
{
	history_set_action("ajax_page_friends('"+categoryid+"','"+alpha+"','"+search+"','"+page+"','"+view+"','"+divName+"')");

	if (!document.getElementById("fb_friends")) {
		var getVars = "action=filterbar_friends&categoryid="+categoryid+"&alpha="+alpha+"&search="+search+"&page="+page+"&view="+view;
		var filterbarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",filterbarDiv);
		setSelectedTab_mainNav('Friends');
	}

	showLoadingPopup("Loading friend data...  Please wait.","",460,365,"50%","50%");
	showLoadingDiv(divName);

	var getVars = "action=friends&categoryid="+categoryid+"&alpha="+alpha+"&search="+search+"&page="+page+"&view="+view;
	var friendsPage = sendRequest(getVars,true,false,true,460,365,"50%","50%",divName);

	setSelectedTab_mainNav('Friends');

	// Google Analytics
	google_track("/friends");

//	scroll(0,0);
	setTimeout('scroll(0,0)', 200);
}

function ajax_page_info(sectionid,pageid,divName)
{
	history_set_action("ajax_page_info('"+sectionid+"','"+pageid+"','"+divName+"')");

	showLoadingPopup("Loading information page...  Please wait.","",500,500,"50%","50%");
	showLoadingDiv(divName);

	var getVars = "action=info&sectionid="+sectionid+"&pageid="+pageid;
	var downloadPage = sendRequest(getVars,true,false,true,500,500,"50%","50%",divName);

	// Google Analytics
	google_track("/info/pageid=" + pageid);

	setTimeout('scroll(0,0)', 200);
}

function ajax_save_search(search,orderBy,alpha,subject,categoryid,searchName)
{
	showLoadingPopup("Saving Search.  Please wait.","",460,365,"50%","50%");

	if (searchName) {
		// Google Analytics
		google_track("/saved_searches/save");

		var getVars = "action=saveSearch&search="+search+"&orderBy="+orderBy+"&alpha="+alpha+"&subject="+subject+"&categoryid="+categoryid+"&searchName="+searchName;
		var saveSearchResult = sendRequest(getVars,false,false,false);

		//redraw the sidebar since their "my saved searched" has been changed
		var getVars = "action=sidebar_main";
		var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);

		hidePopup();

	} else {
		var getVars = "action=saveSearch&search="+search+"&orderBy="+orderBy+"&alpha="+alpha+"&subject="+subject+"&categoryid="+categoryid;
		var shareSearchResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
	}
}

function ajax_unsave_search(searchid)
{
	// Google Analytics
	google_track("/saved_searches/remove");

	showLoadingPopup("Removing Saved Search.  Please wait.","",460,365,"50%","50%");

	var getVars = "action=unsaveSearch&searchid="+searchid;
	var saveSearchResult = sendRequest(getVars,false,false,false);

	//redraw the sidebar since their "my saved searched" has been changed
	var getVars = "action=sidebar_main";
	var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);
}

function ajax_add_user_interest(categoryid,selectedCategory)
{
	showLoadingPopup("Saving new interest.  Please wait.","",460,365,"50%","50%");

	var getVars = "action=addInterest&categoryid="+categoryid;
	var saveSearchResult = sendRequest(getVars,false,false,false);

	ajax_page_profile("interests",selectedCategory,"contentBody")
}

function ajax_remove_user_interest(categoryid,selectedCategory)
{
	showLoadingPopup("Saving new interest.  Please wait.","",460,365,"50%","50%");

	var getVars = "action=removeInterest&categoryid="+categoryid;
	var saveSearchResult = sendRequest(getVars,false,false,false);

	ajax_page_profile("interests",selectedCategory,"contentBody")
}

function ajax_remove_friend(friendid,friendActionClassElem)
{
	showLoadingPopup("Removing Friend.  Please wait.","",460,365,"50%","50%");
	//we wanna find all of the elements that match the subscribeClassElem pattern
	//so we can update all subscribe icons on the page
	var clsElems = new Array();
	if (friendActionClassElem != "" && friendActionClassElem != "undefined") {
		var clsElemsTemp = document.getElementsByTagName('*');
		for (elemIdx in clsElemsTemp)
		{
			if (clsElemsTemp[elemIdx]) {
				if (clsElemsTemp[elemIdx].id) {
					var elemId = clsElemsTemp[elemIdx].id;
					if (document.getElementById(elemId)) {
						if (elemId.substr(0,friendActionClassElem.length) == friendActionClassElem) {
							clsElems[elemIdx] = clsElemsTemp[elemIdx];
						}
					}
				}
			}
		}
	}

	var getVars = "action=removeFriend&friendid="+friendid;
	var removeFriendResult = sendRequest(getVars,false,false,false);

	for (elemIdx in clsElems)
	{
		clsElems[elemIdx].className = "plus";
	}

	//action tracking
	trackAction("remove_friend","");

	// Google Analytics
	google_track("/friend/remove");

	//redraw the sidebar since their "my friends" has been changed
	var getVars = "action=sidebar_main";
	var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);
}

function ajax_add_friend(friendid,friendActionClassElem,note)
{
	//we wanna find all of the elements that match the subscribeClassElem pattern
	//so we can update all subscribe icons on the page
	var clsElems = new Array();
	if (friendActionClassElem != "" && friendActionClassElem != "undefined") {
		var clsElemsTemp = document.getElementsByTagName('*');
		for (elemIdx in clsElemsTemp)
		{
			if (clsElemsTemp[elemIdx]) {
				if (clsElemsTemp[elemIdx].id) {
					var elemId = clsElemsTemp[elemIdx].id;
					if (document.getElementById(elemId)) {
						if (elemId.substr(0,friendActionClassElem.length) == friendActionClassElem) {
							clsElems[elemIdx] = clsElemsTemp[elemIdx];
						}
					}
				}
			}
		}
	}
	var getVars = "action=addFriend&friendid="+friendid+"&msg="+note;
	var addFriendResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");

	for (elemIdx in clsElems)
	{
		clsElems[elemIdx].className = "minus";
	}

	//action tracking
	trackAction("add_friend","");


	// Google Analytics
	google_track("/friend/add");

	//redraw the sidebar since their "my friends" has been changed
	var getVars = "action=sidebar_main";
	var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);
}

function ajax_send_fan_mail(recipientName,note)
{
	showLoadingPopup("Sending mail.  Please wait.","",460,365,"50%","50%");

	var getVars = "action=sendFanMail&friendName="+recipientName+"&msg="+note;
	var sendMailResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");

	// Google Analytics
	google_track("/friend/sendFanMail");
}

function ajax_toggle_friend(friendid,friendActionClassElem,note,skipDelay)
{
	try {
		if (note == undefined || note == "undefined") {
			note = "";
		}

		//we wanna find all of the elements that match the subscribeClassElem pattern
		//so we can update all subscribe icons on the page
		var clsElems = new Array();
		if (friendActionClassElem != "" && friendActionClassElem != "undefined") {
			var clsElemsTemp = document.getElementsByTagName('*');
			for (elemIdx in clsElemsTemp)
			{
				if (clsElemsTemp[elemIdx]) {
					if (clsElemsTemp[elemIdx].id) {
						var elemId = clsElemsTemp[elemIdx].id;
						if (document.getElementById(elemId)) {
							if (elemId.substr(0,friendActionClassElem.length) == friendActionClassElem) {
								clsElems[elemIdx] = clsElemsTemp[elemIdx];
							}
						}
					}
				}
			}
		}
		if (skipDelay) {

			//first lets go ahead and find out right now if theyre friends already
			var getVars = "action=isFriend&friendid="+friendid;
			var isFriendResult = sendRequest(getVars,false,false,false);
			if (isFriendResult == 1) {
				//they are already my friend
				ajax_remove_friend(friendid,friendActionClassElem);
			} else if (isFriendResult == 2) {
				//they are not my friend currently, add them.
				//was this call made after the user had a chance to enter a message or before?
				if (note) {
					ajax_add_friend(friendid,friendActionClassElem,note);
				} else {
					var getVars = "action=toggleFriend&friendid="+friendid+"&imageElem="+friendActionClassElem;
					var addFriendResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
				}
			} else if (isFriendResult == 0) {
				//they are not even logged in, we cant do anything until they login
				//show the login popup form
				var getVars = "action=login&feedback=You must sign-in or create an account to manage your friends.";
				var loginResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
			}
		} else {
			for (elemIdx in clsElems)
			{
				clsElems[elemIdx].className = "loading";
			}
			setTimeout("ajax_toggle_friend('"+friendid+"', '"+friendActionClassElem+"', '"+note+"',1)",250);
		}
	} catch (e) {
		setTimeout("ajax_toggle_friend('"+friendid+"', '"+friendActionClassElem+"', '"+note+"',0)",100);
	}
}

function ajax_only_add_friend(friendid,friendActionClassElem,note,skipDelay)
{
	try {
		if (note == undefined || note == "undefined") {
			note = "";
		}

		//we wanna find all of the elements that match the subscribeClassElem pattern
		//so we can update all subscribe icons on the page
		var clsElems = new Array();
		if (friendActionClassElem != "" && friendActionClassElem != "undefined") {
			var clsElemsTemp = document.getElementsByTagName('*');
			for (elemIdx in clsElemsTemp)
			{
				if (clsElemsTemp[elemIdx]) {
					if (clsElemsTemp[elemIdx].id) {
						var elemId = clsElemsTemp[elemIdx].id;
						if (document.getElementById(elemId)) {
							if (elemId.substr(0,friendActionClassElem.length) == friendActionClassElem) {
								clsElems[elemIdx] = clsElemsTemp[elemIdx];
							}
						}
					}
				}
			}
		}
		if (skipDelay) {

			//first lets go ahead and find out right now if theyre friends already
			var getVars = "action=isFriend&friendid="+friendid;
			var isFriendResult = sendRequest(getVars,false,false,false);
			if (isFriendResult == 1) {
				//they are already my friend, do nothing
				for (elemIdx in clsElems)
				{
					clsElems[elemIdx].className = "minus";
				}
			} else if (isFriendResult == 2) {
				//they are not my friend currently, add them.
				//was this call made after the user had a chance to enter a message or before?
				if (note) {
					ajax_add_friend(friendid,friendActionClassElem,note);
				} else {
					var getVars = "action=toggleFriend&friendid="+friendid+"&imageElem="+friendActionClassElem;
					var addFriendResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
				}
			} else if (isFriendResult == 0) {
				//they are not even logged in, we cant do anything until they login
				//show the login popup form
				var getVars = "action=login&feedback=You must sign-in or create an account to manage your friends.";
				var loginResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
			}
		} else {
			for (elemIdx in clsElems)
			{
				clsElems[elemIdx].className = "loading";
			}
			setTimeout("ajax_only_add_friend('"+friendid+"', '"+friendActionClassElem+"', '"+note+"',1)",250);
		}
	} catch (e) {
		setTimeout("ajax_only_add_friend('"+friendid+"', '"+friendActionClassElem+"', '"+note+"',0)",100);
	}
}

function ajax_only_remove_friend(friendid,friendActionClassElem,note,skipDelay)
{
	try {
		if (note == undefined || note == "undefined") {
			note = "";
		}

		//we wanna find all of the elements that match the subscribeClassElem pattern
		//so we can update all subscribe icons on the page
		var clsElems = new Array();
		if (friendActionClassElem != "" && friendActionClassElem != "undefined") {
			var clsElemsTemp = document.getElementsByTagName('*');
			for (elemIdx in clsElemsTemp)
			{
				if (clsElemsTemp[elemIdx]) {
					if (clsElemsTemp[elemIdx].id) {
						var elemId = clsElemsTemp[elemIdx].id;
						if (document.getElementById(elemId)) {
							if (elemId.substr(0,friendActionClassElem.length) == friendActionClassElem) {
								clsElems[elemIdx] = clsElemsTemp[elemIdx];
							}
						}
					}
				}
			}
		}
		if (skipDelay) {

			//first lets go ahead and find out right now if theyre friends already
			var getVars = "action=isFriend&friendid="+friendid;
			var isFriendResult = sendRequest(getVars,false,false,false);
			if (isFriendResult == 1) {
				//they are already my friend
				ajax_remove_friend(friendid,friendActionClassElem);
			} else if (isFriendResult == 2) {
				//they are not my friend currently, do nothing.
			} else if (isFriendResult == 0) {
				//they are not even logged in, we cant do anything until they login
				//show the login popup form
				var getVars = "action=login&feedback=You must sign-in or create an account to manage your friends.";
				var loginResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
			}
		} else {
			for (elemIdx in clsElems)
			{
				clsElems[elemIdx].className = "loading";
			}
			setTimeout("ajax_only_remove_friend('"+friendid+"', '"+friendActionClassElem+"', '"+note+"',1)",250);
		}
	} catch (e) {
		setTimeout("ajax_only_remove_friend('"+friendid+"', '"+friendActionClassElem+"', '"+note+"',0)",100);
	}
}

function ajax_get_channel_data_list(channelid, headDiveName, bodyDivName, whichList, episodeCount)
{

	var optionHtml = "";
	var optionType = "Episodes";

	showLoadingDiv(bodyDivName);
	if (whichList == "episodes") {
		optionType = "Episodes";
		response = '<b>Episodes</b>&nbsp;<a href="javascript: void(0)" onclick="ajax_get_channel_data_list(\''+channelid+'\',\''+headDiveName+'\',\''+bodyDivName+'\',\'otherListeners\',\''+episodeCount+'\');"><b style="font-weight: normal;">Other people who listen to this channel</b></a>&nbsp;<a href="javascript: void(0)" onclick="ajax_get_channel_data_list(\''+channelid+'\',\''+headDiveName+'\',\''+bodyDivName+'\',\'recommendedChannels\',\''+episodeCount+'\');"><b style="font-weight: normal;">People who like this channel also like</b></a>';
		redrawDiv (headDiveName,response);
	} else if (whichList == "otherListeners") {
		optionType = "Listeners";
		response = '<a href="javascript: void(0)" onclick="ajax_get_channel_data_list(\''+channelid+'\',\''+headDiveName+'\',\''+bodyDivName+'\',\'episodes\',\''+episodeCount+'\');"><b style="font-weight: normal;">Episodes</b></a>&nbsp;<b>Other people who listen to this channel</b>&nbsp;<a href="javascript: void(0)" onclick="ajax_get_channel_data_list(\''+channelid+'\',\''+headDiveName+'\',\''+bodyDivName+'\',\'recommendedChannels\',\''+episodeCount+'\');"><b style="font-weight: normal;">People who like this channel also like</b></a>';
		redrawDiv (headDiveName,response);
	} else if (whichList == "recommendedChannels") {
		optionType = "Recommended Channels";
		response = '<a href="javascript: void(0)" onclick="ajax_get_channel_data_list(\''+channelid+'\',\''+headDiveName+'\',\''+bodyDivName+'\',\'episodes\',\''+episodeCount+'\');"><b style="font-weight: normal;">Episodes</b></a>&nbsp;<a href="javascript: void(0)" onclick="ajax_get_channel_data_list(\''+channelid+'\',\''+headDiveName+'\',\''+bodyDivName+'\',\'otherListeners\',\''+episodeCount+'\');"><b style="font-weight: normal;">Other people who listen to this channel</b></a>&nbsp;<b>People who like this channel also like</b>';
		redrawDiv (headDiveName,response);
	}


	optionHtml = optionHtml + '<select name="episodeCount" id="episodeCount" onchange="ajax_get_channel_data_list(\''+channelid+'\',\''+headDiveName+'\',\''+bodyDivName+'\',\''+whichList+'\',document.getElementById(\'episodeCount\').value);">';
	optionHtml = optionHtml + '<option value="3"' + (episodeCount==3?'SELECTED':'') + '>3 '+optionType+'</option>';
	optionHtml = optionHtml + '<option value="10"' + (episodeCount==10?'SELECTED':'') + '>10 '+optionType+'</option>';
	optionHtml = optionHtml + '<option value="25"' + (episodeCount==25?'SELECTED':'') + '>25 '+optionType+'</option>';
	optionHtml = optionHtml + '<option value="50"' + (episodeCount==50?'SELECTED':'') + '>50 '+optionType+'</option>';
	optionHtml = optionHtml + '</select>';
	redrawDiv ('countSelector',optionHtml);

	var getVars = "action=getChannelDataList&episodeCount="+episodeCount+"&channelData="+whichList+"&channelid=" + channelid;
	var loginResult = sendRequest(getVars,1,3,0,0,0,0,0,bodyDivName)
}
function ajax_toggle_subscribe(userid, channelid, subscribeClassElem, skipDelay)
{
	try {
		//we wanna find all of the elements that match the subscribeClassElem pattern
		//so we can update all subscribe icons on the page
		var clsElems = new Array();
		if (subscribeClassElem != "" && subscribeClassElem != "undefined") {
			var clsElemsTemp = document.getElementsByTagName('*');
			if (clsElemsTemp) {
				for (elemIdx in clsElemsTemp)
				{
					if (clsElemsTemp[elemIdx]) {
						if (clsElemsTemp[elemIdx].id) {
							var elemId = clsElemsTemp[elemIdx].id;
							if (document.getElementById(elemId)) {
								if (elemId.substr(0,subscribeClassElem.length) == subscribeClassElem) {
									clsElems[elemIdx] = clsElemsTemp[elemIdx];
								}
							}
						}
					}
				}
			}
		}

		if (skipDelay) {
			var getVars = "action=subscribeChannelToggle&channelid="+channelid+"&userid="+userid;
			var subscribeToggleResult = sendRequest(getVars,false,false,false);

			if (subscribeToggleResult == 1) {
				//action tracking
				trackAction("subscribe",channelid);

				// Google Analytics
				google_track("/channel/subscribe");

				for (elemIdx in clsElems)
				{
					clsElems[elemIdx].className = "minus";
					clsElems[elemIdx].onMouseover = "popup_help_balloon('"+TIPS_UNSUBSCRIBE+"')";
				}
				//redraw the sidebar since their "my channels" has been changed (due to unsubscribing from a channel)
				var getVars = "action=sidebar_main";
				var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);

			} else if (subscribeToggleResult == 2) {
				//action tracking
				trackAction("unsubscribe",channelid);

				// Google Analytics
				google_track("/channel/unsubscribe");

				for (elemIdx in clsElems)
				{
					clsElems[elemIdx].className = "plus";
					clsElems[elemIdx].onMouseover = "popup_help_balloon('"+TIPS_SUBSCRIBE+"')";
				}
				//redraw the sidebar since their "my channels" has been changed (due to unsubscribing from a channel)
				var getVars = "action=sidebar_main";
				var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);

			} else if (subscribeToggleResult == 0) {
				//theyre not even logged in
				for (elemIdx in clsElems)
				{
					clsElems[elemIdx].className = "plus";
				}

				//show them login form
				var reactionString = "ajax_toggle_subscribe('"+userid+"', '"+channelid+"', '"+subscribeClassElem+"', 0)";
				var getVars = "action=login&reaction=" + escape(reactionString) + "&feedback=You must sign-in or create an account to subscribe to podcasts.";
				var loginResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
			} else if (subscribeToggleResult == -1) {
				//theyre user account has not yet been verified
				for (elemIdx in clsElems)
				{
					clsElems[elemIdx].className = "plus";
				}

				//show them account verify informayion
				var getVars = "action=feedback&msg=Your user account must first be verified before you can subscribe to Podcasts.  To verify your account, please follow the instructions in the email that was sent to you when you first signed up.  If you have lost the email, you can resend it to yourself by <a href=\"javascript: void(0)\" onclick=\"ajax_popup_resend_notification_email()\">clicking here</a>.&title=User Account Not Verified";
				var loginResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
			}

		} else {
			for (elemIdx in clsElems)
			{
				clsElems[elemIdx].className = "loading";
			}
			setTimeout("ajax_toggle_subscribe('"+userid+"', '"+channelid+"', '"+subscribeClassElem+"', 1)",250);
		}
	} catch (e) {
		//if there is an error it isprobably due to timing by overclicking or something
		//try again
		setTimeout("ajax_toggle_subscribe('"+userid+"', '"+channelid+"', '"+subscribeClassElem+"', 0)",25);
	}
}
function ajax_subscribe_only(channelid, subscribeClassElem, skipDelay)
{
	try {
		//we wanna find all of the elements that match the subscribeClassElem pattern
		//so we can update all subscribe icons on the page
		var clsElems = new Array();
		if (subscribeClassElem != "" && subscribeClassElem != "undefined") {
			var clsElemsTemp = document.getElementsByTagName('*');
			if (clsElemsTemp) {
				for (elemIdx in clsElemsTemp)
				{
					if (clsElemsTemp[elemIdx]) {
						if (clsElemsTemp[elemIdx].id) {
							var elemId = clsElemsTemp[elemIdx].id;
							if (document.getElementById(elemId)) {
								if (elemId.substr(0,subscribeClassElem.length) == subscribeClassElem) {
									clsElems[elemIdx] = clsElemsTemp[elemIdx];
								}
							}
						}
					}
				}
			}
		}

		if (skipDelay) {
			var getVars = "action=subscribeChannel&channelid="+channelid;
			var subscribeResult = sendRequest(getVars,false,false,false);

			if (subscribeResult == 1) {
				//action tracking
				trackAction("subscribe",channelid);

				// Google Analytics
				google_track("/channel/subscribe");

				for (elemIdx in clsElems)
				{
					clsElems[elemIdx].className = "minus";
					clsElems[elemIdx].onMouseover = "popup_help_balloon('"+TIPS_UNSUBSCRIBE+"')";
				}
				//redraw the sidebar since their "my channels" has been changed (due to unsubscribing from a channel)
				var getVars = "action=sidebar_main";
				var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);
			} else if (subscribeResult == 0) {
				//theyre not even logged in
				for (elemIdx in clsElems)
				{
					clsElems[elemIdx].className = "plus";
				}

				//show them login form
				var reactionString = "ajax_subscribe_only('"+channelid+"', '"+subscribeClassElem+"', 0)";
				var getVars = "action=login&reaction=" + escape(reactionString) + "&feedback=You must sign-in or create an account to subscribe to podcasts.";
				var loginResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
			} else if (subscribeResult == -1) {
				//theyre user account has not yet been verified
				for (elemIdx in clsElems)
				{
					clsElems[elemIdx].className = "plus";
				}

				//show them account verify informayion
				var getVars = "action=feedback&msg=Your user account must first be verified before you can subscribe to Podcasts.  To verify your account, please follow the instructions in the email that was sent to you when you first signed up.  If you have lost the email, you can resend it to yourself by <a href=\"javascript: void(0)\" onclick=\"ajax_popup_resend_notification_email()\">clicking here</a>.&title=User Account Not Verified";
				var loginResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
			}

		} else {
			for (elemIdx in clsElems)
			{
				clsElems[elemIdx].className = "loading";
			}
			setTimeout("ajax_subscribe_only('"+channelid+"', '"+subscribeClassElem+"', 1)",250);
		}
	} catch (e) {
		//if there is an error it isprobably due to timing by overclicking or something
		//try again
		setTimeout("ajax_subscribe_only('"+channelid+"', '"+subscribeClassElem+"', 0)",25);
	}
}

function ajax_unsubscribe_only(channelid, subscribeClassElem, skipDelay)
{
	try {
		//we wanna find all of the elements that match the subscribeClassElem pattern
		//so we can update all subscribe icons on the page
		var clsElems = new Array();
		if (subscribeClassElem != "" && subscribeClassElem != "undefined") {
			var clsElemsTemp = document.getElementsByTagName('*');
			if (clsElemsTemp) {
				for (elemIdx in clsElemsTemp)
				{
					if (clsElemsTemp[elemIdx]) {
						if (clsElemsTemp[elemIdx].id) {
							var elemId = clsElemsTemp[elemIdx].id;
							if (document.getElementById(elemId)) {
								if (elemId.substr(0,subscribeClassElem.length) == subscribeClassElem) {
									clsElems[elemIdx] = clsElemsTemp[elemIdx];
								}
							}
						}
					}
				}
			}
		}

		if (skipDelay) {
			var getVars = "action=unsubscribeChannel&channelid="+channelid;
			var subscribeResult = sendRequest(getVars,false,false,false);

			//action tracking
			trackAction("unsubscribe",channelid);

			// Google Analytics
			google_track("/channel/unsubscribe");

			for (elemIdx in clsElems)
			{
				clsElems[elemIdx].className = "plus";
				clsElems[elemIdx].onMouseover = "popup_help_balloon('"+TIPS_SUBSCRIBE+"')";
			}
			//redraw the sidebar since their "my channels" has been changed (due to unsubscribing from a channel)
			var getVars = "action=sidebar_main";
			var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);

		} else {
			for (elemIdx in clsElems)
			{
				clsElems[elemIdx].className = "loading";
			}
			setTimeout("ajax_unsubscribe_only('"+channelid+"', '"+subscribeClassElem+"', 1)",250);
		}
	} catch (e) {
		//if there is an error it isprobably due to timing by overclicking or something
		//try again
		setTimeout("ajax_unsubscribe_only('"+channelid+"', '"+subscribeClassElem+"', 0)",25);
	}
}
function ajax_subscribe_group(group, skipDelay)
{
	try {
		if (skipDelay) {
			var getVars = "action=subscribeChannelGroup&group="+group;
			var subscribeResult = sendRequest(getVars,false,false,false);
			if (subscribeResult == 1) {
				//action tracking
				trackAction("subscribeGroup"+group);

				// Google Analytics
				google_track("/channelgroup/mostpop_subscribe");

				//redraw the sidebar since their "my channels" has been changed (due to unsubscribing from a channel)
				var getVars = "action=sidebar_main";
				var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);

				//redraw the page since several of podcasts icons on landing page may have changed
				ajax_page_channels("","","","channels","",1,"","contentBody");
			} else if (subscribeResult == 0) {
				//show them login form
				var reactionString = "ajax_subscribe_only('"+channelid+"', '"+subscribeClassElem+"', 0)";
				var getVars = "action=login&reaction=" + escape(reactionString) + "&feedback=You must sign-in or create an account to subscribe to podcasts.";
				var loginResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
			} else if (subscribeResult == -1) {
				//show them account verify informayion
				var getVars = "action=feedback&msg=Your user account must first be verified before you can subscribe to Podcasts.  To verify your account, please follow the instructions in the email that was sent to you when you first signed up.  If you have lost the email, you can resend it to yourself by <a href=\"javascript: void(0)\" onclick=\"ajax_popup_resend_notification_email()\">clicking here</a>.&title=User Account Not Verified";
				var loginResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
			}
		} else {
			setTimeout("ajax_subscribe_group('"+group+"', 1)",250);
		}
	} catch (e) {
		//if there is an error it isprobably due to timing by overclicking or something
		//try again
		setTimeout("ajax_subscribe_group('"+group+"', 0)",25);
	}
}

function ajax_disable_info_rollovers(skipDelay)
{
	allowRollovers_info = false;
	if (skipDelay) {
		var getVars = "action=disableInfoRollovers";
		var disableRolloverReq = sendRequest(getVars,false,false,false);
		hidePopup();
	} else {
		showLoadingPopup("Disabling rollovers.  Please wait.","",460,365,currentMouseX,currentMouseY);
		setTimeout("ajax_disable_info_rollovers(1)",75);
	}
}


function ajax_subscribe(userid, channelid, subscribeImageElem)
{
	showLoadingPopup("Subscribing.  Please wait.","",460,365,currentMouseX,currentMouseY);

	var getVars = "action=subscribeChannel&channelid="+channelid+"&userid="+userid;
	var unsubscribeResult = sendRequest(getVars,false,false,false);

	if (unsubscribeResult == 1) {
		var imgElem = document.getElementById(subscribeImageElem);
		if (imgElem) {
			imgElem.src = webRoot+"/images/icon_remove.gif";
		}
	}

	//redraw the sidebar since their "my channels" has been changed (due to unsubscribing from a channel)
	var getVars = "action=sidebar_main";
	var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);

	// Google Analytics
	google_track("/channel/subscribe");

	//action tracking
	trackAction("subscribe",channelid);
}

function ajax_unsubscribe(userid, channelid, subscribeImageElem)
{
	showLoadingPopup("Unsubscribing.  Please wait.","",460,365,currentMouseX,currentMouseY);

	var getVars = "action=unsubscribeChannel&channelid="+channelid+"&userid="+userid;
	var unsubscribeResult = sendRequest(getVars,false,false,false);

	if (unsubscribeResult == 1) {
		var imgElem = document.getElementById(subscribeImageElem);
		if (imgElem) {
			imgElem.src = webRoot+"/images/icon_add.gif";
		}
	}

	//redraw the sidebar since their "my channels" has been changed (due to unsubscribing from a channel)
	var getVars = "action=sidebar_main";
	var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);

	// Google Analytics
	google_track("/channel/unsubscribe");

	//action tracking
	trackAction("unsubscribe",channelid);
}

function ajax_popup_login(redirect)
{
	if (!redirect) {
		redirect = "";
	}
	//show them login form
	var getVars = "action=login&feedback=Please login using this form.&redirect="+redirect;
	var loginResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");
}

function ajax_popup_resend_notification_email(skipDelay)
{
	if (skipDelay) {
		var getVars = "action=resendNotificationEmail";
		var resendResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");

		// Google Analytics
		google_track("/user/resend_confirmation");
	} else {
		showLoadingPopup("Resending confirmation email...  Please wait.","",460,365,"50%","50%");
		//this delay is needed to make sure the aboive msgbox shows before synchronous action begins
		setTimeout("ajax_popup_resend_notification_email(1)",250);
	}
}

function ajax_delete_message(userid,mailboxid,skipDelay)
{
	if (skipDelay) {
		var getVars = "action=deleteUserMessage&mailboxid="+mailboxid+"&userid="+userid;
		var unsubscribeResult = sendRequest(getVars,false,false,false);

		//now show messages with mailboxid deleted
		ajax_popup_userMessages();
	} else {
		showLoadingPopup("Deleting Message...  Please wait.","",460,365,"50%","50%");
		//this delay is needed to make sure the aboive msgbox shows before synchronous action begins
		setTimeout("ajax_delete_message('"+userid+"','"+mailboxid+"',1)",250);
		setTimeout("ajax_redraw_header()",250);
	}
}

function ajax_delete_all_messages(skipDelay)
{
	if (skipDelay) {
		var getVars = "action=deleteAllUserMessages";
		var unsubscribeResult = sendRequest(getVars,false,false,false);

		setTimeout("ajax_redraw_header()",250);

		//now show messages with mailboxid deleted
		ajax_popup_userMessages();
	} else {
		showLoadingPopup("Deleting Messages...  Please wait.","",460,365,"50%","50%");
		//this delay is needed to make sure the aboive msgbox shows before synchronous action begins
		setTimeout("ajax_delete_all_messages(1)",250);
	}
}

function ajax_email_message(userid,mailboxid,skipDelay)
{
	if (skipDelay) {
		var getVars = "action=emailUserMessage&mailboxid="+mailboxid+"&userid="+userid;
		var emailResult = sendRequest(getVars,false,false,false);

		//now re-show messages
		ajax_popup_userMessages();
	} else {
		showLoadingPopup("Emailing Message...  Please wait.","",460,365,"50%","50%");
		//this delay is needed to make sure the aboive msgbox shows before synchronous action begins
		setTimeout("ajax_email_message('"+userid+"','"+mailboxid+"',1)",750);
	}
}

function ajax_email_all_messages(skipDelay)
{
	if (skipDelay) {
		var getVars = "action=emailAllUserMessages";
		var emailResult = sendRequest(getVars,false,false,false);

		//now show messages
		ajax_popup_userMessages();
	} else {
		showLoadingPopup("Sending Messages...  Please wait.","",460,365,"50%","50%");
		//this delay is needed to make sure the aboive msgbox shows before synchronous action begins
		setTimeout("ajax_email_all_messages(1)",750);
	}
}
function ajax_redraw_header()
{
	var getVars = "action=header";
	var headerResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",headerDiv);
}

function ajax_redraw_custom_content_list(listDiv)
{
	var getVars = "action=customContentList";
	var headerResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",listDiv);
}

function ajax_update_feed_behoviors(channelid,syncOrder,syncCount,syncCleanupInterval,skipDelay)
{
	if (skipDelay) {
		var getVars = "action=updateSyncSettings&channelid="+channelid+"&syncOrder="+syncOrder+"&syncCount="+syncCount+"&syncCleanup="+syncCleanupInterval;
		var updateResult = sendRequest(getVars,false,false,false);
		hidePopup();
	} else {
		showLoadingPopup("Updating auto-sync settings...  Please wait.","",460,365,"50%","50%");
		//this delay is needed to make sure the aboive msgbox shows before synchronous action begins
		setTimeout("ajax_update_feed_behoviors('"+channelid+"','"+syncOrder+"','"+syncCount+"','"+syncCleanupInterval+"',1)",250);
	}
}

function ajax_update_feed_privacy(channelid,isPrivate,skipDelay)
{
	if (skipDelay) {
		var getVars = "action=updateSubscriptionPrivacy&channelid="+channelid+"&isPrivate="+isPrivate;
		var updateResult = sendRequest(getVars,false,false,false);
		hidePopup();
	} else {
		showLoadingPopup("Updating privacy settings...  Please wait.","",460,365,"50%","50%");
		//this delay is needed to make sure the aboive msgbox shows before synchronous action begins
		setTimeout("ajax_update_feed_privacy('"+channelid+"',"+isPrivate+",1)",250);
	}
}

function ajax_login(username,password,rememberMe,redirect,reaction, skipDelay)
{
    //rememberMe = 1;

	if (rememberMe == undefined || rememberMe == "undefined" ||
    !rememberMe) {
		rememberMe = 0;
	}
	if (redirect == undefined || redirect == "undefined") {
		redirect = "";
	}
	if (reaction == undefined || reaction == "undefined") {
		reaction = "";
	}

	reaction = unescape(reaction);
	if (skipDelay) {
		if (document.getElementById(sidebarDiv)) {
			redrawDiv(sidebarDiv,reloadSideNavHtml);
		}

		var getVars = "action=login&rememberMe="+rememberMe+"&username="+username+"&password="+URLEncode(password);
		var loginResult = sendRequest(getVars,false,false,false);

		if (loginResult == 1) {
			//done were logged in
			if (!redirect && !reaction) {
				//nowhere to go... just refresh the current page,
				//unless theyre currently at the new user page...
				//then send them to podcast landing page
				var sURL = unescape(window.location.pathname);
				if (sURL.indexOf("register.php") != -1) {
					window.location.replace(webRoot+"channels.php");
				} else {
					window.location.replace(sURL);
				}
			} else if (redirect) {
				//just in case the redirect is for a download lets redraw the header since there will be no page refreshes
				//redraw the header since their login state changed
				var getVars = "action=header";
				var headerResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",headerDiv);

				if (document.getElementById(sidebarDiv)) {
					var getVars = "action=sidebar_main";
					var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);
				}

				//hide any popups, again in case we stay oin same page (redirect is a download)
				hidePopup();

				//redirect them to the specified location
				setTimeout("window.location = '"+webRoot + redirect+"'",1000);
			} else {
				if (reaction) {
					eval(reaction);
				}

				//redraw the header since their login state changed
				var getVars = "action=header";
				var headerResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",headerDiv);

				//redraw the sidebar since their login state changed
				if (document.getElementById(sidebarDiv)) {
					var getVars = "action=sidebar_main";
					var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);
				}

				// Google Analytics
				google_track('/user/login');
			}
		} else {
			var getVars = "action=feedback&msg=There was an error logging you in.  Please try again.&title=Login Result";
			var feedbackResult = sendRequest(getVars,true,true,false,460,365,"50%","50%");

			//redraw the header, nothing has changed but we were in a "sigin in..." dialog
			if (document.getElementById(headerDiv)) {
				var getVars = "action=header";
				var headerResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",headerDiv);
			}

			if (document.getElementById(sidebarDiv)) {
				//redraw the sidebar, nothing has changed but we were in a "loading sidebar..." dialog
				var getVars = "action=sidebar_main";
				var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);
			}
		}

		return loginResult;

	} else {
		if (document.getElementById(loginDiv)) {
			redrawDiv(loginDiv,"Checking login information...  Please wait.");
		}
		showLoadingPopup("Checking login information...  Please wait.","",460,365,"50%","50%");
		setTimeout("ajax_login('"+username+"','"+password+"','"+rememberMe+"','"+redirect+"','"+escape(reaction)+"', 1)",250);
	}
}

function ajax_logout()
{
	showLoadingPopup("Logging out...  Please wait.","",460,365,"50%","50%");

	if (document.getElementById(sidebarDiv)) {
		redrawDiv(sidebarDiv,reloadSideNavHtml);
	}
	if (document.getElementById(loginDiv)) {
		redrawDiv(loginDiv,"Signing out.  Please wait...");
	}

	var getVars = "action=logout";
	var logoutResult = sendRequest(getVars,false,false,false);

	//redraw the header since their login state probably changed
	var getVars = "action=header";
	var headerResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",headerDiv);

	//redraw the sidebar since their login state probably changed
	if (document.getElementById(sidebarDiv)) {
		var getVars = "action=sidebar_main";
		var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);
	}

	//redraw the page since they may be on the preferences page or other user specific page
	ajax_page_channels("","","","channels","",1,"","contentBody");

	// Google Analytics
	google_track('/user/logout');
}

function ajax_ignore_device()
{
	var getVars = "action=ignoreDevice";
	var logoutResult = sendRequest(getVars,false,false,false);

	//redraw the page since they may be on the preferences page or other user specific page
	ajax_page_channels("","","","channels","",1,"","contentBody");
}

function ajax_change_user_device()
{
	var getVars = "action=changeUserDevice";
	var logoutResult = sendRequest(getVars,false,false,false);

	//redraw the page since they may be on the preferences page or other user specific page
	ajax_page_channels("","","","channels","",1,"","contentBody");

	//redraw the side nav since they may have imported subscriptions from another device
	var getVars = "action=sidebar_main";
	var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);
}

function ajax_change_user_device_with_subscriptions()
{
	var getVars = "action=changeUserDeviceWithSubscriptions";
	var logoutResult = sendRequest(getVars,false,false,false);

	//redraw the page since they may be on the preferences page or other user specific page
	ajax_page_channels("","","","channels","",1,"","contentBody");

	//redraw the side nav since they may have imported subscriptions from another device
	var getVars = "action=sidebar_main";
	var sidebarResult = sendRequest(getVars,true,false,true,460,365,"50%","50%",sidebarDiv);
}

function redrawNavButtons()
{
	//redraw the back button as needed
	backButton = document.getElementById('navButton_back');
	if (backButton) {
		if (lastAction > 1) {
			backButton.src = webRoot+"images/icons/nav_button_back-trans.png";
		} else {
			backButton.src = webRoot+"images/icons/nav_button_back_disabled-trans.png";
		}
	}

	//redraw the forward button as needed
	forwardButton = document.getElementById('navButton_forward');
	if (forwardButton) {
		if (lastAction < actionCount) {
			forwardButton.src = webRoot+"images/icons/nav_button_forward-trans.png";
		} else {
			forwardButton.src = webRoot+"images/icons/nav_button_forward_disabled-trans.png";
		}
	}
}
function history_back()
{
	//find out the last action id
	if (lastAction > 1) {
		lastAction = lastAction - 1;
		//get the action and resend it
		var getVars = "action=getHistoryActionBack";
		var newAction = sendRequest(getVars,false,false,false);

		if (newAction) {
			//store a cookie letting us know were in navigation mode so we dont overwrite ourself
			createCookie("navMode","1",1);
			doingNavAction = 1;
			eval(newAction);
		} else {
			//there are no back actions.. reset counters and disable the back button
			lastAction = 1;
			redrawNavButtons();
		}
	}
	return false;
}

function history_forward()
{
	if (lastAction < actionCount) {
		lastAction = lastAction + 1;
		//get the action and resend it
		var getVars = "action=getHistoryActionForward";
		var newAction = sendRequest(getVars,false,false,false);

		if (newAction) {
			//store a cookie letting us know were in navigation mode so we dont overwrite ourself
			createCookie("navMode","1",1);
			doingNavAction = 1;
			eval(newAction);
		} else {
			lastAction = lastAction - 1;
			actionCount = lastAction;
			redrawNavButtons();
		}
	}
	return false;
}

function history_set_action(action)
{
	//read the cookie to see if were in nav mode
	thisIsANavAction = readCookie("navMode");

	if (thisIsANavAction != "1") {
		actionCount = actionCount + 1;
		lastAction	= actionCount; //if were here to be setting this action then this must be the current action
		//send this to the database
		var getVars = "action=updateHistory&history_action="+escape(action);
		var sendResult = sendRequest(getVars,false,false,false);
	}
	//store a cookie letting us know were not in navigation mode anymore
	createCookie("navMode","0",1);
}

function ajax_scanUrlForPodcasts(url)
{
	var getVars = "action=scanUrlForPodcasts&rssUrl="+url;
	var friendsPage = sendRequest(getVars,true,false,true,460,365,"50%","50%","contentBody");
}

//*****THIS STUFF CAN BE CALLED FFROM THE CLIENT IF NEEDED
function updateChannels(view,page)
{
	if (!view) {
		var view = "icon";
	}
	if (!page) {
		var page = 1;
	}

	clearTimeout(hoverTimer); //clear out any pending popups
	hidePopup();  //hide any already visible popups

	var categoryid 	= document.getElementById("categoryid").value;
	var orderBy 	= document.getElementById("orderBy").value;
	var alpha 		= document.getElementById("alpha").value;
	var subject 	= document.getElementById("subject").value;
	var search	 	= document.getElementById("search").value;
	ajax_page_channels(categoryid,orderBy,alpha,subject,search,page,view,"contentBody");
}

function updateFriends(view,page)
{
	if (!view) {
		var view = "icon";
	}
	if (!page) {
		var page = 1;
	}

	clearTimeout(hoverTimer); //clear out any pending popups
	hidePopup();  //hide any already visible popups

	var categoryid 	= document.getElementById("categoryid").value;
	var alpha 		= document.getElementById("alpha").value;
	var search	 	= document.getElementById("search").value;
	ajax_page_friends(categoryid,alpha,search,page,view,"contentBody");
	document.getElementById("search").focus();
}

function searchFriends(search,categoryid,alpha,view,page)
{
	if (!view) {
		var view = "icon";
	}
	if (!page) {
		var page = 1;
	}

	clearTimeout(hoverTimer); //clear out any pending popups
	hidePopup();  //hide any already visible popups

	//redraw friends filter bar with serach choices
	var getVars = "action=filterbar_friends&categoryid="+categoryid+"&alpha="+alpha+"&search="+search+"&page="+page+"&view="+view;
	var filterbar = sendRequest(getVars,true,false,true,460,365,"50%","50%",filterbarDiv);
		setSelectedTab_mainNav('Friends');

	ajax_page_friends(categoryid,alpha,search,page,view,"contentBody");
}

function updateProfile()
{
	var profileSection = document.getElementById('profile_section').value;
	document.getElementById('currentProfileSection').value = profileSection;
	switch (profileSection)
	{
		case "public_profile":
			document.getElementById('public_profile').style.display='block';
			document.getElementById('account_info').style.display='none';
			document.getElementById('interests').style.display='none'
			break;
		case "account_info":
			document.getElementById('public_profile').style.display='none';
			document.getElementById('account_info').style.display='block';
			document.getElementById('interests').style.display='none'
			break;
		case "interests":
			document.getElementById('public_profile').style.display='none';
			document.getElementById('account_info').style.display='none';
			document.getElementById('interests').style.display='block'
			break;
	}
}

function updateInfo(section,page)
{
	if (!section) {
		var section = document.getElementById("section").value;
	}
	if (!page) {
		var page = document.getElementById("page").value;
	}
	ajax_page_info(section,page,"contentBody");
}

function searchChannels(orderBy,categoryid,alpha,subject,search,view,page)
{
	if (!view) {
		var view = "icon";
	}
	if (!page) {
		var page = 1;
	}

	clearTimeout(hoverTimer); //clear out any pending popups
	hidePopup();  //hide any already visible popups

	ajax_page_channels(categoryid,orderBy,alpha,subject,search,page,view,"contentBody");

	//redraw the filter bar with appririate choices to match the search
	var getVars = "action=filterbar_channels&categoryid="+categoryid+"&orderBy="+orderBy+"&alpha="+alpha+"&subject="+subject+"&search="+search+"&page="+page+"&view="+view;
	var channelsPage = sendRequest(getVars,true,false,true,460,365,"50%","50%",filterbarDiv);
	setSelectedTab_mainNav('Podcasts');
}

function doLogin(username, password, rememberMe, redirect, reaction)
{
	if (!username || !password) {
		var username = document.getElementById("head_username").value;
		var password = document.getElementById("head_password").value;
	}
	//if (rememberMe == undefined) {
		var rememberMe = document.getElementById('head_rememberMe').checked?1:0;
        //var rememberMe = 0;
	//}
	ajax_login(username,password,rememberMe,redirect,reaction);
}

function saveSearch()
{
	if (document.getElementById("categoryid")) {
		var categoryid 	= document.getElementById("categoryid").value;
	} else {
		var categoryid 	= 0;
	}
	if (document.getElementById("orderBy")) {
		var orderBy 	= document.getElementById("orderBy").value;
	} else {
		var orderBy 	= "";
	}
	if (document.getElementById("alpha")) {
		var alpha 		= document.getElementById("alpha").value;
	} else {
		var alpha 		= "";
	}
	if (document.getElementById("subject")) {
		var subject 	= document.getElementById("subject").value;
	} else {
		var subject 	= "users";
	}
	if (document.getElementById("search")) {
		var search	 	= document.getElementById("search").value;
	} else {
		var search	 	= "";
	}
	ajax_save_search(search,orderBy,alpha,subject,categoryid)
}

function addItemToList(item,listElem,displayElem)
{
	oTextArea = document.getElementById(listElem);
	oDisplay = document.getElementById(displayElem);
	oTextArea.value = oTextArea.value + item + ";\n";
	if (oDisplay) {
		oDisplay.innerHTML = oDisplay.innerHTML + item + "<br />";
	}
}

function addItemToSelect(item,selectElem)
{
	if (item != "") {
		oSelect = document.getElementById(selectElem);
		oSelect[oSelect.length] = new Option(item, item);
	}
}

function removeSelectedItemFromSelect(selectElem)
{
	oSelect = document.getElementById(selectElem);
	oSelect[oSelect.selectedIndex] = null;
}

function copySelectOptionsToElemValue(selectElem,newElem,delimiter)
{
	oSelect = document.getElementById(selectElem);
	oNew 	= document.getElementById(newElem);
	oNew.value="";
	var i=0;
	for (i=0; i<oSelect.length; i=i+1)
	{
		if (i>0) {
			oNew.value = oNew.value + ", " + oSelect[i].value;
		} else {
			oNew.value = oSelect[i].value;
		}
	}
}

function confirmUserLink(caption,link)
{
    if (confirm(caption)) {
		window.location = link;
    }
}
function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}

function URLDecode(encoded)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef";
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2)
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
}

function popup_help_balloon(msg,msgIE,skipDelay)
{
	if (allowRollovers_help) {
		if (isElementDragging==0) { //no rollovers during drg and drp operation
			if (!msgIE) {
				msgIE = msg;
			}
			if (skipDelay) {
				helpText = '<div class="hover_help_balloon"><div class="body_hover_help_balloon">';
				if (IE) {
					helpText = helpText + msgIE;
				} else {
					helpText = helpText + msg;
				}
				helpText = helpText + '</div></div>';
				showBalloon(196,59,currentMouseX,currentMouseY,helpText);
			} else {
				clearTimeout(balloonTimer);
				balloonTimer = setTimeout("popup_help_balloon('"+msg+"','"+msgIE+"',1);",350);
			}
		}
	}
}
function canel_baloon_popup()
{
	clearTimeout(balloonTimer);
	hideBalloon();
}
function google_track(full_action)
{
	urchinTracker(full_action);
}
function trackAction(actionType,feedid,episodeid)
{
	if (!feedid || feedid == undefined || feedid == "undefined") {
		feedid = "";
	}
	if (!episodeid || episodeid == undefined || episodeid == "undefined") {
		episodeid = "";
	}
	var getVars = "action=trackUserAction&actionType="+actionType+"&channelid="+feedid+"&episodeid="+episodeid;
	var loginResult = sendRequest(getVars,false,false,false);
}
function changeImage(imageId,newImage)
{
	document.getElementById(imageId).src = newImage;
}
function updateDownload(downloadVersion)
{
	switch (downloadVersion)
	{
		case "windows":
			document.getElementById('download_info').style.display='none';
			document.getElementById('windows').style.display='block';
			document.getElementById('mac').style.display='none';
			document.getElementById('u3').style.display='none'
			document.getElementById('windows_mobile').style.display='none'
			document.getElementById('linux').style.display='none'
			document.getElementById('combo').style.display='none'
			break;
		case "mac":
			document.getElementById('download_info').style.display='none';
			document.getElementById('windows').style.display='none';
			document.getElementById('mac').style.display='block';
			document.getElementById('u3').style.display='none'
			document.getElementById('windows_mobile').style.display='none'
			document.getElementById('linux').style.display='none'
			document.getElementById('combo').style.display='none'
			break;
		case "u3":
			document.getElementById('download_info').style.display='none';
			document.getElementById('windows').style.display='none';
			document.getElementById('mac').style.display='none';
			document.getElementById('u3').style.display='block'
			document.getElementById('windows_mobile').style.display='none'
			document.getElementById('linux').style.display='none'
			document.getElementById('combo').style.display='none'
			break;
		case "windows_mobile":
			document.getElementById('download_info').style.display='none';
			document.getElementById('windows').style.display='none';
			document.getElementById('mac').style.display='none';
			document.getElementById('u3').style.display='none'
			document.getElementById('windows_mobile').style.display='block'
			document.getElementById('linux').style.display='none'
			document.getElementById('combo').style.display='none'
			break;
		case "linux":
			document.getElementById('download_info').style.display='none';
			document.getElementById('windows').style.display='none';
			document.getElementById('mac').style.display='none';
			document.getElementById('u3').style.display='none'
			document.getElementById('windows_mobile').style.display='none'
			document.getElementById('linux').style.display='block'
			document.getElementById('combo').style.display='none'
			break;
		case "combo":
			document.getElementById('download_info').style.display='none';
			document.getElementById('windows').style.display='none';
			document.getElementById('mac').style.display='none';
			document.getElementById('u3').style.display='none'
			document.getElementById('windows_mobile').style.display='none'
			document.getElementById('linux').style.display='none'
			document.getElementById('combo').style.display='block'
			break;
	}
}
function downloadClient(userid,fileName)
{
	if (userid != "") {
		window.location = fileName;
	} else {
		ajax_popup_login(fileName);
	}
}
function eraseInputValue(inputElem)
{
	input = document.getElementById(inputElem);
	input.value = "";
}
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}
//disabled for the new theme
function setSelectedTab_mainNav(selectedTab)
{
    return true;
    /*
	document.getElementById('mainNavTab_Podcasts').className = '';
	document.getElementById('mainNavTab_Friends').className = '';
	document.getElementById('mainNavTab_Preferences').className = '';
	document.getElementById('mainNavTab_Downloads').className = '';
	document.getElementById('mainNavTab_Help').className = '';
	document.getElementById('mainNavTab_'+selectedTab).className = 'active';
    */
}

function trapKeyPresses(e)
{
	if (!e) e = window.event;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	if (e.keyCode == 27) {
		//escape ky should always close any open popups
		hidePopup();

		//also undim any lightboxes
		if (document.getElementById('dimoverlay')) {
			document.getElementById('dimoverlay').style.display = "none";
		}
	} else {
		switch (targ.id)
		{
			case "search":
//				clearTimeout(autoSearchTimer);
				if (e['keyCode'] == 13) {
					if (document.getElementById("orderBy")) {
						updateChannels();
					} else {
						updateFriends();
					}
//				} else if (!document.getElementById("orderBy")) {
//					autoSearchTimer = setTimeout("updateFriends();",200);
				}
				break;
			case "head_password":
				if (e['keyCode'] == 13) {
					doLogin();
				}
				break;
			case "pop_password":
				if (e['keyCode'] == 13) {
					doLogin(document.getElementById('pop_username').value,document.getElementById('pop_password').value,document.getElementById('pop_remember_me').value,document.getElementById('pop_redirect').value,document.getElementById('pop_reaction').value);
				}
				break;
			case "shareMessage":
				if (e['keyCode'] == 13) {
					if (document.getElementById('sharepop_channelid')) {
						ajax_popup_shareChannel(document.getElementById('sharepop_channelid').value,document.getElementById('recipientList').value, document.getElementById('shareMessage').value);
					} else if (document.getElementById('sharepop_episodeid')) {
						ajax_popup_shareEpisode(document.getElementById('sharepop_episodeid').value,document.getElementById('recipientList').value, document.getElementById('shareMessage').value);
					}
				}
				break;
			case "pop_email":
				if (e['keyCode'] == 13) {
					ajax_popup_user_forget(document.getElementById('pop_email').value);
				}
				break;
		}
	}
}
function showLoadingDiv(divName)
{
	redrawDiv(divName,"<img src='"+webRoot+"images/loading_text.gif' border='0' />");
}

function loadPageWithDelay(pageUrl,delayMs,showDivElem)
{
	if (showDivElem) {
		showLoadingDiv(showDivElem);
	}
	setTimeout("window.location = '"+pageUrl+"'",delayMs);
}

function loadNewPage(pageUrl)
{
	window.location.replace(pageUrl);
}

function updateAllChannelImagesOnPage()
{
	var image;
	var imageIdx;
	var size;
	var channelid;
	for (imageIdx in document.images)
	{
		image = document.images[imageIdx];
		if (image) {
			if (image.src) {
				if (image.src.indexOf(defaultChannelImage) > -1) {
					size = image.width;
					channelid = image.name;
					loadChannelImageFromCache(image,channelid,size);
				}
			}
		}
	}
}

function loadChannelImageFromCache(imageObject,channelid,size)
{
	if (imageObject) {
		window.setTimeout( function() { imageObject.src = imageCacheProc+"?feedid="+channelid+"&size="+size;},150);
	}
}
//HISTORY STUFF
//find out about our history
function updateHistoryData()
{

	//save this page as an action for forward/back buttons
	history_set_action("window.location.href='"+location.href+"'");

	var getVars = "action=getCurrentHistoryIndex";
	lastAction = sendRequest(getVars,false,false,false);

	var getVars = "action=getMaxHistoryIndex";
	actionCount = sendRequest(getVars,false,false,false);

	lastAction 	= parseInt(lastAction);
	actionCount = parseInt(actionCount);

	redrawNavButtons();
}

// Generate oneClick Promoter Code Snippet
function generateOneClickPromoterCode()
{
	var pcrButtonURL = document.getElementById('pcrButtonURL').value;
	var pcrButtonImage = document.getElementById('pcrButtonImage').value;
	document.getElementById('pcrButtonCode').value = "<a href=\"http://www.podcastready.com/oneclick_bookmark.php?url=" + pcrButtonURL + "\" target=\"_blank\" >  <img src=\"http://www.podcastready.com/images/" + pcrButtonImage + ".gif\" border=\"0\" />  </a>";
}
// Create Account - check that they have agreed to the terms and service
function createAccountTerms()
{
	if (document.getElementById('action').value=='register') {
		var agreedTerms = document.getElementById('terms').checked;
		if (agreedTerms){
			document.getElementById('action').value='register';
			return true;
		} else if (!agreedTerms) {
			alert("Please Read the Terms and Conditions, then check the box to accept them.")
			return false;
		}
	} else {
		return true;
	}
}
