var selectedTab = null;
var selectedDiv = null;
function turnTabsOnOff()
{
	var tabHeader = document.getElementById('header');
	var display = tabHeader.style.display;
	
	var resultsNoTab = document.getElementById('resultNoTab');
	var jResultNoTab = document.getElementById('jResultNoTab');
	var ytResultNoTab = document.getElementById('ytResultNoTab');
	var chResultNoTab = document.getElementById('chResultNoTab');
	var vimeoResultNoTab = document.getElementById('vimeoResultNoTab');
	
	var results = document.getElementById('result');
	var jResult = document.getElementById('jResult');
	var ytResult = document.getElementById('ytResult');
	var chResult = document.getElementById('chResult');
	var vimeoResult = document.getElementById('vimeoResult');
	
	var tabViewButton = document.getElementById('tabViewButton');
	
	if(display == 'none')
	{
		tabViewButton.innerHTML = 'Show All';
		//show tab
		tabHeader.style.display = 'block';
		tabHeader.style.visibility = 'visible';
		
		//hide rest
		resultsNoTab.style.display = 'none';
		resultsNoTab.style.visibility = 'hidden';
		jResultNoTab.style.display = 'none';
		jResultNoTab.style.visibility = 'hidden';
		ytResultNoTab.style.display = 'none';
		ytResultNoTab.style.visibility = 'hidden';
		chResultNoTab.style.display = 'none';
		chResultNoTab.style.visibility = 'hidden';
		vimeoResultNoTab.style.display = 'none';
		vimeoResultNoTab.style.visibility = 'hidden';
		
		//hide rest
		results.style.display = 'none';
		results.style.visibility = 'hidden';
		jResult.style.display = 'none';
		jResult.style.visibility = 'hidden';
		ytResult.style.display = 'none';
		ytResult.style.visibility = 'hidden';
		chResult.style.display = 'none';
		chResult.style.visibility = 'hidden';
		vimeoResult.style.display = 'none';
		vimeoResult.style.visibility = 'hidden';
		
		selectedDiv.style.display = 'block';
		selectedDiv.style.visibility = 'visible';
	}
	else
	{
		tabViewButton.innerHTML = 'Tab View';
		
		//show tab
		tabHeader.style.display = 'none';
		tabHeader.style.visibility = 'hidden';
		
		//hide rest
		resultsNoTab.style.display = 'block';
		resultsNoTab.style.visibility = 'visible';
		jResultNoTab.style.display = 'block';
		jResultNoTab.style.visibility = 'visible';
		ytResultNoTab.style.display = 'block';
		ytResultNoTab.style.visibility = 'visible';
		chResultNoTab.style.display = 'block';
		chResultNoTab.style.visibility = 'visible';
		vimeoResultNoTab.style.display = 'block';
		vimeoResultNoTab.style.visibility = 'visible';
		
		//hide rest
		results.style.display = 'block';
		results.style.visibility = 'visible';
		jResult.style.display = 'block';
		jResult.style.visibility = 'visible';
		ytResult.style.display = 'block';
		ytResult.style.visibility = 'visible';
		chResult.style.display = 'block';
		chResult.style.visibility = 'visible';
		vimeoResult.style.display = 'block';
		vimeoResult.style.visibility = 'visible';
	}
}
function openCloseTB(elem)
{
	var tb = document.getElementById('toolbar');
	var display = tb.style.display;
	if(display == 'none')
	{	
		tb.style.display='block';
		tb.style.visibility='visible';
		elem.innerHTML='[-]&nbsp;toolbar';
	}
    else
	{
		tb.style.display='none';
		tb.style.visibility='hidden';
		elem.innerHTML='[+]&nbsp;toolbar';
	}
}

function setSelected(elem,showDiv)
{
	selectedTab.className = 'clear';
	elem.className='selected';
	
	selectedDiv.style.display = 'none';
	selectedDiv.style.visibility = 'hidden';
	
	showDiv.style.display = 'block';
	showDiv.style.visibility = 'visible';
	
	selectedTab = elem;
	selectedDiv = showDiv;
}

function displayHulu(param)
{
	var oDiv = document.getElementById("result");
	oDiv.innerHTML = "<br/><br/>Loading...<br/><br/><br/>";
	if(param.value.items[0] != undefined ) //&& param.value.items[0].title != "" )
	{
		var total = param.value.items.length;
		var table = document.createElement("table");
		table.border = "0";
		table.style.marginTop = "2px";
		table.cellpadding = "3";
		table.cellspacing = "3";
		var tr;
		
		for (var i = 0; i < total; i++)
		{
			if(i == 5 && i==-1)
			{
				// place comission junction add here:
				//var cjAd = "<a href=\"http://www.jdoqocy.com/p1115nmvsmu9DBBGBEJ9BAFGCCAC\" target=\"_blank\"><img src=\"http://www.tqlkg.com/3977snrflj4866B69E465AB7757\" alt=\"Get All 5 Cinemax Channels for a Penny\" border=\"0\"/></a>";
				
				var cjAd = "<a href=\"http://www.anrdoezrs.net/2f81xdmjdl0422725A021695979\" target=\"_blank\"><img src=\"http://www.tqlkg.com/pf65m-3sywHLJJOJMRHJINQMQOQ\" alt=\"Free 3 Months of TIVO\" border=\"0\"/></a>";
				tr=table.insertRow(-1);
				var adTD = tr.insertCell(-1);
				adTD.colSpan = "5";
				adTD.align = "center";
				adTD.innerHTML = cjAd;
			}
			if(i%5 == 0)
			{
				tr=table.insertRow(-1);
			}
			if(tr != null)
			{
				var td = tr.insertCell(-1);
				var image = document.createElement("img");
				
				var myForm = document.createElement("form");
				myForm.id = "videoForm" + i;
				myForm.name = "videoForm" + i;
				myForm.action = "http://www.tvharddrive.com/videolink.php";
				myForm.style.margin = "0px";
				td.appendChild(myForm);
				
				var item = param.value.items[i];
				
				var videoURLInput = document.createElement("input");
				
				videoURLInput.type = "hidden";
				videoURLInput.name = "url";
				videoURLInput.id   = "url";
				videoURLInput.value = encodeURIComponent(item.myurl);
				
				myForm.appendChild(videoURLInput);
				
				var videoTitleInput	= document.createElement("input");
				videoTitleInput.type = "hidden";
				videoTitleInput.name = "title";
				videoTitleInput.id   = "title";
				videoTitleInput.value = encodeURIComponent(item.title);
				
				myForm.appendChild(videoTitleInput);
				
				var videoInput	= document.createElement("input");
				videoInput.type = "hidden";
				videoInput.name = "desc";
				videoInput.id   = "desc";
				videoInput.value = encodeURIComponent(item.mydesc);
				
				myForm.appendChild(videoInput);
				
				image.border = "0";
				image.src = item.thumb;
				image.style.width = "145px";
				image.style.height = "80px";
				image.title = item.title;
				image.style.cursor = "pointer";
				
				if(item.myurl == "")
				{
					videoURLInput.value = encodeURIComponent(item.link);
					image.title = image.title + " [ ~ EXTERNAL SITE ~ ]";
					videoTitleInput.value = encodeURIComponent(image.title);
				}

				var awrap = document.createElement("a");
				awrap.href = "javascript:setVideo(\"videoForm" + i + "\");";
				awrap.appendChild(image);
				
				if(item.title)
				{
					awrap.appendChild(document.createElement("br"));
					var tSpan = document.createElement("div");
					tSpan.innerHTML = item.title.length > 75 ? item.title.substring(0,72) + "..." : item.title;
					tSpan.style.width = "145px";
					tSpan.style.fontSize = "9px";
					tSpan.style.overflow = "hidden";
					tSpan.style.marginTop = "2px";
					awrap.appendChild(tSpan);
					awrap.style.color = "#C0C0C0";
				}
				
				td.vAlign = "top";
				td.appendChild(awrap);				
			}
			
		}
		oDiv.innerHTML = "";
		oDiv.appendChild(table);
	}
	else
	{
		oDiv.innerHTML = "<br/><br/>No Hulu Results Found. Please Try Again.<br/><br/><br/>";
	}
}

function displayYT(param)
{
	var oDiv = document.getElementById("ytResult");
	if(oDiv)
	{
		oDiv.innerHTML = "<br/><br/>Loading...<br/><br/><br/>";
		if(param.value.items[0] != undefined ) //&& param.value.items[0].title != "" )
		{
			var total = param.value.items.length;
			var table = document.createElement("table");
			table.border = "0";
			table.style.marginTop = "2px";
			table.cellpadding = "3";
			table.cellspacing = "3";
			var tr;
			
			for (var i = 0; i < total; i++)
			{
				if(i == 5 && i==-1)
				{
					// place comission junction add here:
					var cjAd = "<a href=\"http://www.jdoqocy.com/p1115nmvsmu9DBBGBEJ9BAFGCCAC\" target=\"_blank\"><img src=\"http://www.tqlkg.com/3977snrflj4866B69E465AB7757\" alt=\"Get All 5 Cinemax Channels for a Penny\" border=\"0\"/></a>";
					//var cjAd = "<a href=\"http://www.anrdoezrs.net/2f81xdmjdl0422725A021695979\" target=\"_blank\"><img src=\"http://www.tqlkg.com/pf65m-3sywHLJJOJMRHJINQMQOQ\" alt=\"Free 3 Months of TIVO\" border=\"0\"/></a>";
					tr=table.insertRow(-1);
					var adTD = tr.insertCell(-1);
					adTD.colSpan = "5";
					adTD.align = "center";
					adTD.innerHTML = cjAd;
				}
				if(i%5 == 0)
				{
					tr=table.insertRow(-1);
				}
				if(tr != null)
				{
					var td = tr.insertCell(-1);
					var image = document.createElement("img");
					
					var myForm = document.createElement("form");
					myForm.id = "videoForm" + (i+50);
					myForm.name = "videoForm" + (i+50);
					myForm.action = "http://www.tvharddrive.com/videolink.php";
					myForm.style.margin = "0px";
					td.appendChild(myForm);
					
					var item = param.value.items[i];
					
					var videoURLInput = document.createElement("input");
					
					videoURLInput.type = "hidden";
					videoURLInput.name = "url";
					videoURLInput.id   = "url";
					videoURLInput.value = encodeURIComponent(item.link);
					
					myForm.appendChild(videoURLInput);
					
					var videoTitleInput	= document.createElement("input");
					videoTitleInput.type = "hidden";
					videoTitleInput.name = "title";
					videoTitleInput.id   = "title";
					videoTitleInput.value = encodeURIComponent(item.title);
					
					myForm.appendChild(videoTitleInput);
					
					var videoID	= document.createElement("input");
					videoID.type = "hidden";
					videoID.name = "v";
					videoID.id   = "v";
					videoID.value = encodeURIComponent(item.videoID);
					
					myForm.appendChild(videoID);
					
					var videoInput	= document.createElement("input");
					videoInput.type = "hidden";
					videoInput.name = "desc";
					videoInput.id   = "desc";
					videoInput.value = encodeURIComponent(item.mydesc);
					
					myForm.appendChild(videoInput);
					
					image.border = "0";
					image.src = item.thumb;
					image.style.width = "145px";
					image.style.height = "80px";
					image.title = item.title;
					image.style.cursor = "pointer";
					
					/*if(item.myurl == "")
					{
						videoURLInput.value = encodeURIComponent(item.link);
						image.title = image.title + " [ ~ EXTERNAL SITE ~ ]";
						videoTitleInput.value = encodeURIComponent(image.title);
					}
					*/
					var awrap = document.createElement("a");
					awrap.href = "javascript:setVideo(\"videoForm" + (i+50) + "\");";
					awrap.appendChild(image);
					
					if(item.title)
					{
						awrap.appendChild(document.createElement("br"));
						var tSpan = document.createElement("div");
						tSpan.innerHTML = item.title.length > 75 ? item.title.substring(0,72) + "..." : item.title;
						tSpan.style.width = "145px";
						tSpan.style.fontSize = "9px";
						tSpan.style.overflow = "hidden";
						tSpan.style.marginTop = "2px";
						awrap.appendChild(tSpan);
						awrap.style.color = "#C0C0C0";
					}	
					
					td.vAlign = "top";
					td.appendChild(awrap);			
				}
				
			}
			oDiv.innerHTML = "";
			oDiv.appendChild(table);
		}
		else
		{
			oDiv.innerHTML = "<br/><br/>No YouTube Results Found. Please Try Again.<br/><br/><br/>";
		}
	}
}


function displayJ(param)
{
	var oDiv = document.getElementById("jResult");
	if(oDiv)
	{
		oDiv.innerHTML = "<br/><br/>Loading...<br/><br/><br/>";
		if(param.value.items[0] != undefined ) //&& param.value.items[0].title != "" )
		{
			var total = param.value.items.length;
			var table = document.createElement("table");
			table.border = "0";
			table.style.marginTop = "2px";
			table.cellpadding = "3";
			table.cellspacing = "3";
			var tr;
			
			for (var i = 0; i < total; i++)
			{
				if(i == 5 && i == -1)
				{
					// place comission junction add here:
					var cjAd = "<a href=\"http://www.jdoqocy.com/p1115nmvsmu9DBBGBEJ9BAFGCCAC\" target=\"_blank\"><img src=\"http://www.tqlkg.com/3977snrflj4866B69E465AB7757\" alt=\"Get All 5 Cinemax Channels for a Penny\" border=\"0\"/></a>";
					//var cjAd = "<a href=\"http://www.anrdoezrs.net/2f81xdmjdl0422725A021695979\" target=\"_blank\"><img src=\"http://www.tqlkg.com/pf65m-3sywHLJJOJMRHJINQMQOQ\" alt=\"Free 3 Months of TIVO\" border=\"0\"/></a>";
					tr=table.insertRow(-1);
					var adTD = tr.insertCell(-1);
					adTD.colSpan = "5";
					adTD.align = "center";
					adTD.innerHTML = cjAd;
				}
				if(i%5 == 0)
				{
					tr=table.insertRow(-1);
				}
				if(tr != null)
				{
					var td = tr.insertCell(-1);
					var image = document.createElement("img");
					
					var myForm = document.createElement("form");
					myForm.id = "videoForm" + (i+2050);
					myForm.name = "videoForm" + (i+2050);
					myForm.action = "http://www.tvharddrive.com/videolink.php";
					myForm.style.margin = "0px";
					td.appendChild(myForm);
					
					var item = param.value.items[i];
					
					var videoURLInput = document.createElement("input");
					
					videoURLInput.type = "hidden";
					videoURLInput.name = "url";
					videoURLInput.id   = "url";
					videoURLInput.value = encodeURIComponent(item.link);
					
					myForm.appendChild(videoURLInput);
					
					var videoTitleInput	= document.createElement("input");
					videoTitleInput.type = "hidden";
					videoTitleInput.name = "title";
					videoTitleInput.id   = "title";
					videoTitleInput.value = encodeURIComponent(item.title);
					
					myForm.appendChild(videoTitleInput);
					
					var videoID	= document.createElement("input");
					videoID.type = "hidden";
					videoID.name = "j";
					videoID.id   = "j";
					videoID.value = encodeURIComponent(item.videoID);
					
					myForm.appendChild(videoID);
					
					var videoInput	= document.createElement("input");
					videoInput.type = "hidden";
					videoInput.name = "desc";
					videoInput.id   = "desc";
					videoInput.value = encodeURIComponent(item.mydesc);
					
					myForm.appendChild(videoInput);
					
					image.border = "0";
					image.src = item.thumb != null && item.thumb != undefined && item.thumb.length > 0 ? item.thumb : item.thumb2;
					image.style.width = "145px";
					image.style.height = "80px";
					image.title = item.title;
					image.style.cursor = "pointer";
					
					/*if(item.myurl == "")
					{
						videoURLInput.value = encodeURIComponent(item.link);
						image.title = image.title + " [ ~ EXTERNAL SITE ~ ]";
						videoTitleInput.value = encodeURIComponent(image.title);
					}
					*/
					var awrap = document.createElement("a");
					awrap.href = "javascript:setVideo(\"videoForm" + (i+2050) + "\");";
					awrap.appendChild(image);
					
					if(item.title)
					{
						awrap.appendChild(document.createElement("br"));
						var tSpan = document.createElement("div");
						tSpan.innerHTML = item.title.length > 75 ? item.title.substring(0,72) + "..." : item.title;
						tSpan.style.width = "145px";
						tSpan.style.fontSize = "9px";
						tSpan.style.overflow = "hidden";
						tSpan.style.marginTop = "2px";
						awrap.appendChild(tSpan);
						awrap.style.color = "#C0C0C0";
					}	
					
					td.vAlign = "top";
					td.appendChild(awrap);			
				}
				
			}
			oDiv.innerHTML = "";
			oDiv.appendChild(table);
		}
		else
		{
			oDiv.innerHTML = "<br/><br/>No Joost Results Found. Please Try Again.<br/><br/><br/>";
		}
	}
}


function displayVimeo(param)
{
	var oDiv = document.getElementById("vimeoResult");
	if(oDiv)
	{
		oDiv.innerHTML = "<br/><br/>Loading...<br/><br/><br/>";
		if(param.value.items[0] != undefined ) //&& param.value.items[0].title != "" )
		{
			var total = param.value.items.length;
			var table = document.createElement("table");
			table.border = "0";
			table.style.marginTop = "2px";
			table.cellpadding = "3";
			table.cellspacing = "3";
			var tr;
			
			for (var i = 0; i < total; i++)
			{
				if(i%5 == 0)
				{
					tr=table.insertRow(-1);
				}
				if(tr != null)
				{
					var td = tr.insertCell(-1);
					var image = document.createElement("img");
					
					var myForm = document.createElement("form");
					myForm.id = "videoForm" + (i+1050);
					myForm.name = "videoForm" + (i+1050);
					myForm.action = "http://www.tvharddrive.com/videolink.php";
					myForm.style.margin = "0px";
					td.appendChild(myForm);
					
					var item = param.value.items[i];
					
					var videoURLInput = document.createElement("input");
					
					videoURLInput.type = "hidden";
					videoURLInput.name = "url";
					videoURLInput.id   = "url";
					videoURLInput.value = encodeURIComponent(item.link);
					
					myForm.appendChild(videoURLInput);
					
					var videoTitleInput	= document.createElement("input");
					videoTitleInput.type = "hidden";
					videoTitleInput.name = "title";
					videoTitleInput.id   = "title";
					videoTitleInput.value = encodeURIComponent(item.title);
					
					myForm.appendChild(videoTitleInput);
					
					var videoID	= document.createElement("input");
					videoID.type = "hidden";
					videoID.name = "vi";
					videoID.id   = "vi";
					videoID.value = encodeURIComponent(item.videoID);
					
					myForm.appendChild(videoID);
					
					var videoInput	= document.createElement("input");
					videoInput.type = "hidden";
					videoInput.name = "desc";
					videoInput.id   = "desc";
					videoInput.value = encodeURIComponent(item.mydesc);
					
					myForm.appendChild(videoInput);
					
					image.border = "0";
					image.src = item.thumb;
					image.style.width = "145px";
					image.style.height = "80px";
					image.title = item.title;
					image.style.cursor = "pointer";
					
					var awrap = document.createElement("a");
					awrap.href = "javascript:setVideo(\"videoForm" + (i+1050) + "\");";
					awrap.appendChild(image);
					
					if(item.title)
					{
						awrap.appendChild(document.createElement("br"));
						var tSpan = document.createElement("div");
						tSpan.innerHTML = item.title.length > 75 ? item.title.substring(0,72) + "..." : item.title;
						tSpan.style.width = "145px";
						tSpan.style.fontSize = "9px";
						tSpan.style.overflow = "hidden";
						tSpan.style.marginTop = "2px";
						awrap.appendChild(tSpan);
						awrap.style.color = "#C0C0C0";
					}	
					
					td.vAlign = "top";
					td.appendChild(awrap);			
				}
				
			}
			oDiv.innerHTML = "<br/>We Currently Only Support Recent Videos From Vimeo Videos<br/><br/>";
			oDiv.appendChild(table);
		}
		else
		{
			oDiv.innerHTML = "<br/><br/>No Vimeo Results At This Time. Please Try Again.<br/><br/><br/>";
		}
	}
}

function displayCH(param)
{
	var oDiv = document.getElementById("chResult");
	if(oDiv)
	{
		oDiv.innerHTML = "<br/><br/>Loading...<br/><br/><br/>";
		if(param.value.items[0] != undefined )
		{
			var total = param.value.items.length;
			var table = document.createElement("table");
			table.border = "0";
			table.cellpadding = "3";
			table.cellspacing = "3";
			var tr;
			
			for (var i = 0; i < total; i++)
			{
				if(i%5 == 0)
				{
					tr=table.insertRow(-1);
				}
				if(tr != null)
				{
					var td = tr.insertCell(-1);
					var image = document.createElement("img");
					
					var myForm = document.createElement("form");
					myForm.id = "videoForm" + (i+150);
					myForm.name = "videoForm" + (i+150);
					myForm.action = "http://www.tvharddrive.com/videolink.php";
					myForm.style.margin = "0px";
					td.appendChild(myForm);
					
					var item = param.value.items[i];
					
					var videoURLInput = document.createElement("input");
					
					videoURLInput.type = "hidden";
					videoURLInput.name = "url";
					videoURLInput.id   = "url";
					videoURLInput.value = encodeURIComponent(item.link);
					
					myForm.appendChild(videoURLInput);
					
					var videoTitleInput	= document.createElement("input");
					videoTitleInput.type = "hidden";
					videoTitleInput.name = "title";
					videoTitleInput.id   = "title";
					videoTitleInput.value = encodeURIComponent(item.title);
					
					myForm.appendChild(videoTitleInput);
					
					var videoID	= document.createElement("input");
					videoID.type = "hidden";
					videoID.name = "c";
					videoID.id   = "c";
					videoID.value = encodeURIComponent(item.videoID);
					
					myForm.appendChild(videoID);
					
					var videoInput	= document.createElement("input");
					videoInput.type = "hidden";
					videoInput.name = "desc";
					videoInput.id   = "desc";
					videoInput.value = encodeURIComponent(item.mydesc);
					
					myForm.appendChild(videoInput);
					
					image.border = "0";
					image.src = item.thumb;
					image.style.width = "145px";
					image.style.height = "80px";
					image.title = item.title;
					image.style.cursor = "pointer";
					
					/*if(item.myurl == "")
					{
						videoURLInput.value = encodeURIComponent(item.link);
						image.title = image.title + " [ ~ EXTERNAL SITE ~ ]";
						videoTitleInput.value = encodeURIComponent(image.title);
					}
					*/
					var awrap = document.createElement("a");
					awrap.href = "javascript:setVideo(\"videoForm" + (i+150) + "\");";
					awrap.appendChild(image);
					
					if(item.title)
					{
						awrap.appendChild(document.createElement("br"));
						var tSpan = document.createElement("div");
						tSpan.innerHTML = item.title.length > 75 ? item.title.substring(0,72) + "..." : item.title;
						tSpan.style.width = "145px";
						tSpan.style.fontSize = "9px";
						tSpan.style.overflow = "hidden";
						tSpan.style.marginTop = "2px";
						awrap.appendChild(tSpan);
						awrap.style.color = "#C0C0C0";
					}	
					
					td.vAlign = "top";
					td.appendChild(awrap);			
				}
				
			}
			oDiv.innerHTML = "<br/>We Currently Only Support Recent Videos From College Humor<br/><br/>";
			oDiv.appendChild(table);
		}
		else
		{
			oDiv.innerHTML = "<br/><br/>No College Humor Results Found. Please Try Again.<br/><br/><br/>";
		}
	}
}

var titleType = 0;
function doTitle(type)
{
    titleType = type;
    var elem = document.getElementById('jsondiv');
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = "http://pipes.yahoo.com/pipes/pipe.run?_id=7hXfR4ah3RGv4ntMBRNMsA&_render=json&_callback=displayTitles";
    elem.appendChild(script);
}

function displayTitles(param)
{
	var oDiv = document.getElementById("titlesresult");
	oDiv.innerHTML = "<br/><br/><span style='font-size:20px'>Loading...</span><br/><br/><br/>";
	if(param.value.items[0] != undefined ) 
	{
		var total = param.value.items.length;
		var table = document.createElement("table");
		table.border = "0";
		table.cellpadding = "5";
		table.cellspacing = "5";
		var tr;
		
		tr=table.insertRow(-1);
		var td = tr.insertCell(-1);
		td.colSpan = "5";
		td.align = "center";
		td.style.fontSize = "17px";
		td.style.fontWeight = "bold";
		td.innerHTML = "Available Titles" + (titleType == 1 ? " - All TV Shows" : titleType == 2 ? " - All Movies" : titleType == 3 ? " - Full Movies Only" : titleType == 4 ? " - Full TV Shows Only" : "");
		

		tr=table.insertRow(-1);
		var td = tr.insertCell(-1);
		td.colSpan = "5";
		td.align = "center";
		var anchors = document.createElement('div');
		anchors.id = 'anchors';
		td.appendChild(anchors);
		td.style.fontSize = "11px";
		
		
		tr=table.insertRow(-1);
		td = tr.insertCell(-1);
		td.align = "center";
		td.colSpan = "5";
		td.style.fontSize = "12px";
		td.innerHTML = "<div class='bar' style='color:black'>Filters:&nbsp;&nbsp;<a href=\"javascript:doTitle('0')\">ALL</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"javascript:doTitle('1')\">ALL TV SHOWS</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"javascript:doTitle('2')\">ALL MOVIES</a></div>"; //&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"javascript:doTitle('4')\">FULL TV SHOWS ONLY</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"javascript:doTitle('3')\">FULL MOVIES ONLY</a></div>";
		
		var count = 0;
		var firstLetter = null;
		for (var i = 0; i < total; i++)
		{
			var item = param.value.items[i];
			
			var isFull = false;
			isFull = (item.full != null && item.full == "FULL");
			
			if(count%5 == 0)
			{
				tr=table.insertRow(-1);
			}
			
			count++;
			if (titleType == 1 && item.type == 'MOVIE')
			{
				count--;
				continue;
			}
			else if (titleType == 2 && item.type == 'TV')
			{
				count--;
				continue;
			}
			else if (titleType == 3 && (item.type == 'TV' || !isFull))
			{
				count--;
				continue;
			}
			else if (titleType == 4 && (item.type == 'MOVIE' || !isFull))
			{
				count--;
				continue;
			}
			var myTitle = "";
			if(item.title == undefined || item.title == null || item.title == "")
			{
			   // try to set title from content
			   myTitle = item.content;
			}
			else
			{
				myTitle = item.title;
			}
			var tempF = myTitle.replace(/^[tT]he\s+/,"").replace(/^'/,"").substring(0,1);
			if(firstLetter == null || firstLetter != tempF.toUpperCase())
			{
				var doFirst = firstLetter;
				if((count-1)%5 != 0)
				{
					tr = table.insertRow(-1);
					count = 1;
				}
				td = tr.insertCell(-1);
				td.colSpan = "5";
				td.align = "center";
				td.style.fontSize = "12px";
				td.style.marginTop = "10px";
				firstLetter = tempF;
				td.innerHTML = "<a name='" + firstLetter + "' id='" + firstLetter + "' style='font-weight:bold'>" + firstLetter + "</a>&nbsp;&nbsp;<a style='color:#6C6CFF' href='#top'>(top)</a>";
				td.style.borderBottom = "1px solid #C0C0C0";
				anchors.innerHTML = anchors.innerHTML + (doFirst == null ? "" : " | ") + "<a style='color:#6C6CFF;font-weight:bold' href='#" + firstLetter + "'>" + firstLetter + "</a>"
				
				tr = table.insertRow(-1);
			}

			if(tr != null)
			{
				var td = tr.insertCell(-1);
				var awrap = document.createElement("a");
				var div = document.createElement("div");
				var item = param.value.items[i];
				
				awrap.innerHTML = myTitle + " <span style='font-size:9px'>(" + (isFull ? "<span style='color:red'>FULL</span> " : "") +  item.type + ")</span>";
				awrap.style.width = "155px";
				awrap.style.fontSize = "11px";
				awrap.style.color = "#C0C0C0";
				div.style.width = "156px";
				div.style.marginTop = "3px";
				awrap.href = "http://tvharddrive.com/?search=" + encodeURIComponent(myTitle);
				//awrap.appendChild(div);
				
				td.vAlign = "top";
				div.appendChild(awrap);
				td.appendChild(div);				
			}
			
		}
		oDiv.innerHTML = "&nbsp;";
		oDiv.appendChild(table);
	}
	else
	{
		oDiv.innerHTML = "<br/><br/>Titles are not currently available to view at this time.<br/><br/><br/>";
	}
}


function continueOn(queryA)
{
	if(decodeURIComponent(queryA.title).indexOf("[ ~ EXTERNAL SITE ~ ]") == -1)
	{
		document.getElementById('videoForm').submit();
	}
	else
	{
		window.open(decodeURIComponent(queryA.url),'newWindow','width=600,height=400');
	}
	
}
function setVideo(formId)
{
	var theForm = document.getElementById(formId);
	theForm.submit();
}
function doCall(type)
{
	var titleResult = document.getElementById('titlesresult');
	if(titleResult)
	{
		titleResult.style.display='none';
	}
	document.getElementById('result').innerHTML = '<br/><br/>Loading...<br/><br/><br/>';
	document.getElementById('ytResult').innerHTML = '<br/><br/>Loading...<br/><br/><br/>';
	document.getElementById('jResult').innerHTML = '<br/><br/>Loading...<br/><br/><br/>';
	var search = document.getElementById("search").value;
	
	//SEARCH BY KEYWORD
	var huluBaseURL =    "http://pipes.yahoo.com/pipes/pipe.run?_id=2b5732c75d62768a80d9d058c85101f3&_render=json&_callback=displayHulu";	
	var youtubeBaseURL = "http://pipes.yahoo.com/pipes/pipe.run?_id=f34c22225f6433f439f8c79886c51ac4&_render=json&_callback=displayYT&url=";
	var joostBaseURL =   "http://pipes.yahoo.com/pipes/pipe.run?_id=c041e0533830c45e72cd5347b7b045f0&_render=json&_callback=displayJ&url=";
	if(type == 1)
	{
	    huluBaseURL += "&SearchString=" + search;
		joostBaseURL = "";
		document.getElementById('jResult').innerHTML = '<br/><br/>Search not currently supported for Joost...<br/><br/><br/>';
		youtubeBaseURL += encodeURIComponent("http://video.google.com/videosearch?q=" + search.replace(/\s+/g,"+") + "+site:youtube.com&__q=" + search.replace(/\s+/g,"+") + "&btnG=Google+Search&so=0&num=25&output=rss");
	}
	else if(type == 2)
	{
		//FAVORITES OF ALL TIME
		huluBaseURL = "http://pipes.yahoo.com/pipes/pipe.run?_id=673fa5e47ad06ef938cb70ad508fd88d&_render=json&_callback=displayHulu";
		//currently doing EVENTS... not really all time favorites for joost...		
		joostBaseURL += encodeURIComponent("http://www.joost.com/api/events/getrecent?fmt=atom&count=25");
		youtubeBaseURL += encodeURIComponent("http://video.google.com/videosearch?q=site:youtube.com&__q=site:youtube.com&btnG=Google+Search&lr=&dur=&so=4&num=25&output=rss");
	}
	else if (type == 3)
	{
		//TODAY's FAVORITES
		joostBaseURL += "http%3A%2F%2Fwww.joost.com%2Fapi%2Fpopular%2Fvideos%3Ffmt%3Datom%26count%3D25";
		huluBaseURL = "http://pipes.yahoo.com/pipes/pipe.run?_id=jGfOif9X3RGjFRjgjUnRlg&_render=json&_callback=displayHulu";
		youtubeBaseURL = "http://pipes.yahoo.com/pipes/pipe.run?_id=25bb5d1e04646172caef6b2c602b5b0e&_render=json&_callback=displayYT&url=http%3A%2F%2Fgdata.youtube.com%2Ffeeds%2Fbase%2Fstandardfeeds%2Fmost_viewed";
	}
	else if (type == 4)
	{
		//Recently Added Movies
		joostBaseURL += encodeURIComponent("http://www.joost.com/epg/us/film/?fmt=atom&count=25");
		huluBaseURL = "http://pipes.yahoo.com/pipes/pipe.run?_id=358de09df572ef6f124a0ba334d3068b&_render=json&_callback=displayHulu&url=" + encodeURIComponent("http://rss.hulu.com/HuluRecentlyAddedMovies");
		youtubeBaseURL += encodeURIComponent("http://video.google.com/videosearch?q=recent+movies+site:youtube.com&__q=recent+movies&btnG=Google+Search&so=0&num=25&output=rss");
	}
	else if (type == 5)
	{
		
		//Recently Added Videos
		huluBaseURL = "http://pipes.yahoo.com/pipes/pipe.run?_id=358de09df572ef6f124a0ba334d3068b&_render=json&_callback=displayHulu&url=" + encodeURIComponent("http://rss.hulu.com/HuluRecentlyAddedVideos");
		youtubeBaseURL += encodeURIComponent("http://video.google.com/videosearch?q=tv+video+clips+site:youtube.com&__q=tv+video+clips&btnG=Google+Search&so=0&num=25&output=rss");
		joostBaseURL += "http%3A%2F%2Fwww.joost.com%2Fapi%2Frecent%2Fvideos%3Ffmt%3Datom%26count%3D25";
	}
	
	
	var huluURL = huluBaseURL;

    var elem = document.getElementById('jsondiv');
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = huluURL;
    elem.appendChild(script);
  
    if(joostBaseURL != null && joostBaseURL.length > 0)
    {
	   var jURL = joostBaseURL;

	   var script = document.createElement('script');
	   script.type = 'text/javascript';
	   script.src = jURL;
	   elem.appendChild(script);
    }  
   
    if(youtubeBaseURL != null)
    {
	   var ytURL = youtubeBaseURL;

	   var script = document.createElement('script');
	   script.type = 'text/javascript';
	   script.src = ytURL;
	   elem.appendChild(script);
    }
}
