var url = document.location.toString(); //website url
var url_http = '';
var http = 0; //http position
var endDomain = 0;//position 2
http = url.indexOf("//") ;
url_http = url.substring(http+2);
endDomain = url_http.indexOf("/");
var rootUrl = url.substring(0,http+endDomain+3);
//alert('root url '+rootUrl);

window.onload=function(){
	checkRightSize();
	getEpContent();
	getSeriesContent();
	ignoreDVD();
	luckDip();
	document.getElementsByTagName("body")[0].onclick = function () {
		var dynamicSearchWrapper = document.getElementById('dynamicSearchWrapper');
		if(dynamicSearchWrapper != null)
		{
			if(dynamicSearchWrapper.style.display == 'block')
			{
				dynamicSearchWrapper.style.display='none';
			}
		}
	};	
};

function luckDip()
{
	var span = document.getElementById('luckDip');
	if(span != null)
	{
		span.onclick = function () {
			//alert("Run Lucky Dip"+rootUrl+"lucky-dip/");
			window.location = rootUrl+"lucky-dip/";
		};
	}
};

function ignoreDVD()
{
	var nodes = document.getElementsByTagName('img');

	for(var i=0;i<nodes.length;i++)
	{
		//alert(nodes[i].getAttribute('id'));
		if(nodes[i].getAttribute('class') == 'ignoreDVD')
		{
			nodes[i].onclick = function()
			{
				//alert('Stop This DVD from showing. id ='+id);
				var id = parseInt(this.getAttribute('id').replace('ignoreDVD-',''));
				var img = this;
				//alert('Stop This DVD from showing. id ='+id);
				img.setAttribute('src', '/images/main/small-spinner.gif');
				
				var xmlHttp = GetXmlHttpObject();
				xmlHttp.onreadystatechange=function()
				{
					if(xmlHttp.readyState==4)
					{
						if(xmlHttp.status == 200)
						{
							if(xmlHttp.responseText != 'success')
							{
								img.setAttribute('src', '/images/main/action_delete.gif');
								alert("Failed "+xmlHttp.responseText);
							}
							else
							{
								img.setAttribute('src', '/images/main/action_check.gif');
							}
						}
					}
				};
				xmlHttp.open("post",rootUrl+'/includes/hideDVD.php', true);
				//Send the proper header information along with the request
				xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				var content = 'dvdId='+id;
				xmlHttp.setRequestHeader("Content-length", content.length);
				xmlHttp.setRequestHeader("Connection", "close");
				xmlHttp.send(content);
			};
		}
	}
};

function setAsTVName(tv)
{
	var tvNameInput = document.getElementById('tv');
	if(tvNameInput != null)
	{
		tvNameInput.value = tv;
		getSeriesList();
	}
};

function getSeriesList(tv)
{
	var series = document.getElementById('seriesSelect');
	series.innerHTML = '<img src="/images/main/ajax-loader.gif" alt="Loading Data.."/>';
	var xmlHttp = GetXmlHttpObject();	
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			if(xmlHttp.status == 200)
			{
				series.innerHTML = xmlHttp.responseText; 
			}
		}
	};
	xmlHttp.open("post",rootUrl+'/admin/getSeriesEpisode.php', true);
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	var content = 'tvId='+tv; 
	xmlHttp.setRequestHeader("Content-length", content.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(content);
};

function getEpisodesList(series)
{
	var episodes = document.getElementById('episodeSelect');
	episodes.innerHTML = '<img src="/images/main/ajax-loader.gif" alt="Loading Data.."/>';
	var xmlHttp = GetXmlHttpObject();	
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			if(xmlHttp.status == 200)
			{
				episodes.innerHTML = xmlHttp.responseText; 
			}
		}
	};
	xmlHttp.open("post",rootUrl+'/admin/getSeriesEpisode.php', true);
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	var content = 'seriesId='+series;
	xmlHttp.setRequestHeader("Content-length", content.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(content);
};

function adminTVSearch()
{
	var searchString = document.getElementById('tv').value;
	var searchBox = document.getElementById('adminSearch');
	var dynamicSearchWrapper = document.getElementById('adminDynamicSearchWrapper');
	dynamicSearchWrapper.innerHTML = 'Searching... <img src="/images/main/ajax-loader.gif" alt="Loading Data.."/>';
	searchString = searchString.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	//alert('--'+searchString+'--');
	if(searchString != '')
	{
		searchString = escape(searchString);
		var xmlHttp = GetXmlHttpObject();	
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				if(xmlHttp.status == 200)
				{
					dynamicSearchWrapper.innerHTML = xmlHttp.responseText; 
				}
			}
		};
		xmlHttp.open("post",rootUrl+'/admin/adminSearch.php', true);
		//Send the proper header information along with the request
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", searchString.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send('search='+searchString);
	}
};

function checkRightSize()
{
	var rightSide = document.getElementById('contentRight');
	var content = document.getElementById('content');
	if(content == null)
	{
		return;
	}
	var contentHeight = content.offsetHeight;
	//alert('The height of the content'+contentHeight);
	if(contentHeight > 1500)
	{
		var advert = document.createElement('div');
		advert.id= "skyscrapper";
		rightSide.appendChild(advert);
		processAjax('skyscrapper', '../includes/skyscrapper.php');
	}
}

function viewBiggerPicture(src, div)
{
	//<div id="shade"></div>
	document.getElementById(div).innerHTML = '<div id="biggerImage"><iframe id="frameImage" src="'+fileLocation+'main/popupImage.php?image='+src+'"></iframe></div>';
};

function editDiv(type)
{
	var div = document.getElementById('editDiv');
	var content = document.getElementById('editDivInnerMiddle');
	if(type == 'true')
	{
		div.style.display = 'block';
	}
	else
	{
		div.style.display = 'none';
		content.innerHTML = '';
	}
};

function deleteRecord(page, type, id)
{
	var result = confirm('Are you sure you want to delete '+type+' with id = '+id);
	if(result)
	{
		processAjaxPost('editOutput', '../admin/'+page, 'ajaxId='+id);
	}
};

function greyout(div, type)
{
	if(type == 'true')
	{
		var greyDiv = document.getElementById(div);
		//changed to handel the bloody flash
		//var shade = document.createElement('div');
		var shade = document.createElement('iframe');
		shade.style.backgroundColor = "#7A7A7A";
		
		//get the page width and height
	    	var width='100%';
	    	var height='100%';
		
		shade.style.height = width;
		shade.style.width = height;
  
		shade.style.opacity= .7;                      
		shade.style.MozOpacity= .7;                   
		shade.style.filter='alpha(opacity='+70+')';
		
		shade.style.zIndex = 99;
		shade.style.position = "fixed";
		shade.style.top = "0px";
		shade.style.left = "0px";
		shade.id= "shade";
		shade.style.display='block';
		greyDiv.appendChild(shade);
		//document.getElementById(div).innerHTML = '<div id="shade"></div>'
		
	}
	else
	{
		//jumps out of the iframe to the window then gets the parent and finds the div(that contains the iframe) to empty
		var iframe = window.parent.document.getElementById(div).innerHTML = '';
	}
};

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
};

function processAjax(div, page)
{
	page = page.replace("../", rootUrl+"/");
	var xmlHttp = GetXmlHttpObject();
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
	    {
			if(xmlHttp.status == 200)
			{
				document.getElementById(div).innerHTML = xmlHttp.responseText;
			}
		}
	};
	xmlHttp.open("get",page, true);
	xmlHttp.send(null);
};

function processAjaxAppened(div, page)
{
	page = page.replace("../", rootUrl+"/");
	var xmlHttp = GetXmlHttpObject();
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
	    {
			if(xmlHttp.status == 200)
			{
				var contents = document.getElementById(div).innerHTML;
				document.getElementById(div).innerHTML = contents + ' ' + xmlHttp.responseText; 
			}
		}
	};
	xmlHttp.open("get",page, true);
	xmlHttp.send(null);
};

function processAjaxPost(div, page, variables)
{
	page = page.replace("../", rootUrl+"/");
	//alert('div '+div+' page '+page+' var '+variables);
	var xmlHttp = GetXmlHttpObject();
	
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
	    {
			if(xmlHttp.status == 200)
			{
				if(div != 'updateViewed')
				{
					document.getElementById(div).innerHTML = xmlHttp.responseText;
					if(page.indexOf("changeTvDetails") > -1)
					{
						tinyMCE.execCommand('mceAddControl', false, 'addSummary');
					}
				}
			}
		}
	};
	xmlHttp.open("post",page, true);
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", variables.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(variables);
};

function processAjaxRedirect(div, page, target)
{
	page = page.replace("../", rootUrl+"/");
	var xmlHttp = GetXmlHttpObject();
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
	    {
			if(xmlHttp.status == 200)
			{
				if(xmlHttp.responseText != 'SUCCESS')
				{
					document.getElementById(div).innerHTML = xmlHttp.responseText; 
				}
				else
				{
					window.location = target;
				}
			}
		}
	};
	xmlHttp.open("get",page, true);
	xmlHttp.send(null);
}

function processAjaxPostRedirect(div, page, variables, target)
{
	page = page.replace("../", rootUrl+"/");
	var xmlHttp = GetXmlHttpObject();
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
	    {
			if(xmlHttp.status == 200)
			{
				if(xmlHttp.responseText != 'SUCCESS')
				{
					document.getElementById(div).innerHTML = xmlHttp.responseText; 
				}
				else
				{
					window.location.reload();
				}
			}
		}
	};
	xmlHttp.open("post",page, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", variables.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(variables);	
};

function loadEpisodeContent(tvid,seriesNum,episodeNum,ele)
{
	//only run if the episode element is empty
	var element = document.getElementById(ele);
	if(element.innerHTML == '')
	{
		//alert(tvid+seriesNum+episodeNum);
		processAjaxPost(ele, '../includes/episodeDetails.php', 'tvId='+tvid+'&series='+seriesNum+'&episode='+episodeNum);
	}
};

function numbers(e)
{
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	
	if((keynum < 58) && (keynum > 47) || (keynum == 13))
	{
		return true;
	}
	else if(keynum == 8)
	{
		return true;
	}
	else
	{
		return false;
	}
};

function postcode(e)
{
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	
	if((keynum < 58) && (keynum > 47))
	{
		return true;
	}
	else if((keynum < 123) && (keynum > 96) || (keynum < 91) && (keynum > 64) || (keynum == 8) || (keynum == 32) || (keynum == 13))
	{
		return true;
	}
	else
	{
		return false;
	}
};

function email(e)
{
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	
	if((keynum < 123) && (keynum > 96) || (keynum < 91) && (keynum > 64) || (keynum == 8) || (keynum == 64) || (keynum == 46) || (keynum == 13))
	{
		return true;
	}
	else if((keynum < 58) && (keynum > 47) || (keynum = 45) || (keynum == 95))
	{
		return true;
	}
	else
	{
		return false;
	}
};

function letter(e)
{
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	
	if((keynum < 123) && (keynum > 96) || (keynum < 91) && (keynum > 64) || (keynum == 8) || (keynum == 32) || (keynum == 13))
	{
		return true;
	}
	else
	{
		//alert(keynum);
		return false;
	}
};

function password(e)
{
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	
	// # " ' ; & 
	if((keynum == 35) || (keynum == 38) || (keynum == 34) || (keynum == 39) || (keynum == 59))
	{
		return false;
	}
	else if(keynum == 8)
	{
		return true;
	}
	else
	{
		return true;
	}
};

function passwordLogin(e)
{
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	
	// # " ' ; & 
	if((keynum == 35) || (keynum == 38) || (keynum == 34) || (keynum == 39) || (keynum == 59))
	{
		return false;
	}
	else if(keynum == 8)
	{
		return true;
	}
	else if(keynum == 13)
	{
		processAjaxPostRedirect('editDivInnerMiddle', rootUrl+'/register/login.php', 'usernameLogin='+document.getElementById('usernameLogin').value+'&passwordLogin='+document.getElementById('passwordLogin').value, '/');
	}
	else
	{
		return true;
	}
};


function ratingColour(number, type)
{
	var i = 1;
	var num = number;
	num++;
	
	if(type == 'in')
	{
		while(i < num)
		{
			document.getElementById('rate'+i).style.background = "url('"+rootUrl+"/images/main/starRating.png') 0 -2px no-repeat";
			i++;
		}
	}
	else
	{
		while(i < num)
		{
			document.getElementById('rate'+i).style.background = "url('"+rootUrl+"/images/main/starRating.png') 0 -25px no-repeat";
			i++;
		}
	}
};

function toggleEpisodes(div)
{
	var ele = document.getElementById(div);
	var link = document.getElementById('display'+div);
	
	if(ele)
	{
		if(ele.style.display == "block")
		{
			//then hide this div
			ele.style.display = "none";
			//alert("hide");
			link.innerHTML = '+';
		}
		else
		{
			//display this div
			//alert("show");
			ele.style.display = "block";
			link.innerHTML = '-';
		}		
	}
};

function ampersand(el)
{
	var ele = document.getElementById(el);
	if(ele)
	{
		var str = ele.value;
		//alert(str);
		var amper = /&/g;
		
		if(str.indexOf("&") != -1)
		{
			str = str.replace(amper, "-AMPERSAND-");
			//alert(str);
			ele.value = str;
		}
	}
};

function blankText(ele)
{
	var box = document.getElementById(ele);
	
	if(box)
	{
		if(box.value == "Enter your search term...")
		{
			box.value = "";
		}
	}
};

var bannerTimer;

function autoBanner(num, page)
{
	x = num;
	x++;
	//if(x > 10)
	if(x > 5)
	{
		x = 0;
	}
	
	//if(num == 10)
	if(num == 5)
	{
		num = 0;
		x = 1;
	}
	//bannerTimer = setTimeout("processAjaxPost('bannerContainer', '../includes/banner.php', 'bannerNum="+num+"&page="+page+"'); autoBanner("+x+", '"+page+"');" , 25000);
	//reduced from 25000 to 2000
	bannerTimer = setTimeout("processAjaxPost('bannerContainer', '"+rootUrl+"/includes/newsBanner.php', 'bannerNum="+num+"&page="+page+"'); autoBanner("+x+", '"+page+"');" , 15000);
};

function stopAutoBanner()
{
	clearTimeout(bannerTimer);
};

function schedView()
{	
	var div = document.getElementById('schedWrapperMain');
	var schedFull = document.getElementById('scheduleFull');
	var link = document.getElementById('shedView');
	var today = document.getElementById('today');	
	var rightFade = document.getElementById('rightFade');
	var leftFade = document.getElementById('leftFade');
	var uls = schedFull.childNodes;
	var ulLists = Array();
	
	for(var i=0;i<uls.length;i++)
	{
		if(uls[i].nodeName == 'UL')
		{
			var lis = uls[i].childNodes;
		}
	}
	
	
	//show full height
	if(link.innerHTML == 'View More')
	{
		div.style.minHeight='390px';
		today.style.minHeight='364px';
		today.style.height='100%';
		
		div.style.height='100%';
		rightFade.style.height='100%';
		leftFade.style.height='100%';
		link.innerHTML = 'View Less';
		for(var x=0;x<lis.length;x++)
		{
			if(lis[x].nodeName == 'LI')
			{
				ulLists = lis[x].childNodes;
				for(var y=0;y<ulLists.length;y++)
				{
					if(ulLists[y].nodeName == 'UL')
					{
						//alert("ulLists["+y+"] is =>"+ulLists[y]);
						ulLists[y].style.minHeight='360px';
						ulLists[y].style.height='100%';
					}
				}
			}
		}
		today.style.backgroundImage='url(/images/main/schedBackground.png)';
		today.style.backgroundRepeat='repeat-y';
	}
	else
	{
		div.style.height='360px';
		today.style.height='354px';
		today.style.minHeight='354px';
		rightFade.style.height='355px';
		leftFade.style.height='355px';
		link.innerHTML = 'View More';
		for(var x=0;x<lis.length;x++)
		{
			if(lis[x].nodeName == 'LI')
			{
				ulLists = lis[x].childNodes;
				for(var y=0;y<ulLists.length;y++)
				{
					if(ulLists[y].nodeName == 'UL')
					{
						ulLists[y].style.minHeight='340px';
						ulLists[y].style.height='340px';
					}
				}
			}
		}
	}
};

function futureSchedule()
{
	var div = document.getElementById('scheduleFull');
	var link = document.getElementById('futureSchedule');
	var linkOld = document.getElementById('olderSchedule');
	var rightFade = document.getElementById('rightFade');
	var leftFade = document.getElementById('leftFade');
	
	var left = '';
	if(div.style.left)
	{
		left = div.style.left;
	}
	left = left.replace("px", "");
	//alert(left);
	
	if(left == '')
	{
		//reduce to move one at a time
		div.style.left = '-1955px';
		//div.style.left = '-2400px';
	}
	else
	{
		left = parseFloat(left);
		//var val = left-600;
		//try to move just one at a time
		var val = left-230;
		div.style.left = val+'px';
		if(left < '-3300')
		{
			rightFade.removeAttribute('onclick');
			rightFade.style.cursor = 'auto';
			leftFade.setAttribute('onclick', 'olderSchedule()');
			leftFade.style.cursor = 'pointer';
			link.style.display = 'none';
			linkOld.style.display = 'inline';
		}
		else
		{	
			link.style.display = 'inline';
			linkOld.style.display = 'inline';
			leftFade.setAttribute('onclick', 'olderSchedule()');
			leftFade.style.cursor = 'pointer';
			rightFade.setAttribute('onclick', 'futureSchedule()');
			rightFade.style.cursor = 'pointer';
		}
	}
};

function olderSchedule()
{
	var div = document.getElementById('scheduleFull');
	var link = document.getElementById('futureSchedule');
	var linkOld = document.getElementById('olderSchedule');
	var rightFade = document.getElementById('rightFade');
	var leftFade = document.getElementById('leftFade');
	
	//total size 5000px
	//initial -1800px left
	
	var left = '';
	if(div.style.left)
	{
		left = div.style.left;
	}
	left = left.replace("px", "");
	//alert(left);
	
	if(left == '')
	{
		//reduce to move one at a time
		div.style.left = '-1500px';
		//div.style.left = '-1200px';
	}
	else
	{
		left = parseFloat(left);
		//var val = left+600;
		//try to move just one at a time
		var val = left+230;
		div.style.left = val+'px';
		if(val > '300')
		{
			rightFade.setAttribute('onclick', 'futureSchedule()');
			rightFade.style.cursor = 'pointer';
			leftFade.removeAttribute("onclick");
			leftFade.style.cursor = "auto";
			linkOld.style.display = 'none';
			link.style.display = 'inline';
		}
		else
		{	
			link.style.display = 'inline';
			linkOld.style.display = 'inline';
			leftFade.setAttribute('onclick', 'olderSchedule()');
			leftFade.style.cursor = 'pointer';
			rightFade.setAttribute('onclick', 'futureSchedule()');
			rightFade.style.cursor = 'pointer';
		}
	}
};

function getTvDbUpdate(tvdbid, tvName)
{
	greyout('greyOut', 'true'); 
	editDiv('true');
	document.getElementById('editDivInnerMiddle').innerHTML = 'Updating<br /><img src="/images/main/ajax-loader.gif" alt="Updating Data.."/>';
	var xmlHttp = GetXmlHttpObject();
	
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
	    {
			if(xmlHttp.status == 200)
			{
				document.getElementById('editDivInnerMiddle').innerHTML = xmlHttp.responseText; 
			}
		}
	};
	xmlHttp.open("post",rootUrl+'/includes/tvdbShowUpdate.php', true);
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", tvdbid.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send('tvdbid='+tvdbid+'&name='+tvName);
}

function dynamicSearch()
{
	displayDynamicSearch();
	var searchString = document.getElementById('searchBox').value;
	//alert(searchString);
	var searchBox = document.getElementById('search');
	var dynamicSearchWrapper = document.getElementById('dynamicSearchWrapper');
	dynamicSearchWrapper.innerHTML = 'Searching<br /><img src="/images/main/ajax-loader.gif" alt="Loading Data.."/>';
	searchString = searchString.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	if(searchString != '')
	{
		searchString = escape(searchString);
		var xmlHttp = GetXmlHttpObject();
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				if(xmlHttp.status == 200)
				{
					dynamicSearchWrapper.innerHTML = xmlHttp.responseText; 
				}
			}
		};
		xmlHttp.open("post",rootUrl+'/includes/dynamicSearch.php', true);
		//Send the proper header information along with the request
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", searchString.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send('search='+searchString);
	}
};

function displayDynamicSearch()
{
	var dynamicSearchWrapper = document.getElementById('dynamicSearchWrapper');
	if(dynamicSearchWrapper != null)
	{
		dynamicSearchWrapper.style.display='block';
	}
};

function openDic()
{
	var dic = new Array();
	//this would have to run an ajax call to server file
	return dic;
};
	
function passwordStrength(element, Div, pos)
{
	var password = document.getElementById(element).value;
	var c = password.length;
	var n = 0;
	var lL = 0;
	var lU = 0;
	var s = 0;
	var x;
	var y;
	//run the dictionary function to open a file and return the whole dictionary
	//var dic = openDic();
	var dic = new Array('the', 'and', 'password', 'testing', 'test', 'hello');
	var easy = new Array('qwerty', '12345678910');
	var lettersUp = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
	var lettersLow = new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
	var numbers = new Array('0','1','2','3','4','5','6','7','8','9');
	var specials = new Array(' ','!','£','$','%','^','&','*','(',')','-','_','+','=','[', ']', '{', '}','#','@','~',';',':',',','.','<','>','/','\\','?','|','`','¬','"','\'','');
	var passArray = new Array();
	
	passArray = password.split('');
	
	//check characters in password
	for(x in passArray)
	{
		//check against lettersLow
		for(y in lettersLow)
		{
			if(passArray[x] == lettersLow[y])
			{
				lL++;
			}
		}
		//check against lettersUp
		for(y in lettersUp)
		{
			if(passArray[x] == lettersUp[y])
			{
				lU++;
			}
		}
		//check against numbers
		for(y in numbers)
		{
			if(passArray[x] == numbers[y])
			{
				n++;
			}
		}
		//check against specials
		for(y in specials)
		{
			if(passArray[x] == specials[y])
			{
				s++;
			}
		}
	}
	
	//check for all characters no longer used can interfere with return
	//if((s + n + lL + lU) < c)
	//{
		//alert("ERROR " +); //please do not use spaces :" + s + " s " + n + " n " + lL + " lL " + lU + " lU " + c);
	//}
	
	//check for the password in the dictionary
	for(x in dic)
	{
		if(dic[x] == password)
		{
			c = 0;
		}
	}
	
	//check for the password in the easy list 
	for(x in easy)
	{
		if(easy[x] == password)
		{
			c = 0;
		}
	}
	
	if(c > 15)
	{
		//if they have used lL, lU, S and N green if three or two yellow if less then red
		if((lL != 0) && (lU != 0) && (n != 0) && (s != 0))
		{
			code = 100;
		}
		else if((((lL != 0) && (lU != 0)) && (n != 0)) || (((lL != 0) && (s != 0)) && (n != 0)) || (((lL != 0) && (lU != 0)) && (s != 0)) || ((n != 0) && ((s != 0) && (lU != 0))))
		{
		    code = 70;
		}
		else if(((lL != 0) && (lU != 0)) || ((n != 0) && (s != 0)) || ((lL != 0) && (s != 0)) || ((n != 0) && (lL != 0)) || ((n != 0) && (lU != 0)) || ((s != 0) && (lU != 0)))
		{
			code = 50;
		}
		else if((lL != 0) || (lU != 0) || (n != 0) || (s != 0))
		{
		    code = 30;
		}
		else
		{
			code = 10
		}
	}
	else if(c > 10)
	{
		//if they have used lL, lU, S and N green if three yellow or two orange if less then red
		if((lL != 0) && (lU != 0) && (n != 0) && (s != 0))
		{
			code = 70;
		}
		else if((((lL != 0) && (lU != 0)) && (n != 0)) || (((lL != 0) && (s != 0)) && (n != 0)) || (((lL != 0) && (lU != 0)) && (s != 0)) || ((n != 0) && ((s != 0) && (lU != 0))))
		{
		    code = 50;
		}
		else if(((lL != 0) && (lU != 0)) || ((n != 0) && (s != 0)) || ((lL != 0) && (s != 0)) || ((n != 0) && (lL != 0)) || ((n != 0) && (lU != 0)) || ((s != 0) && (lU != 0)))
		{
			code = 30;
		}
		else
		{
			code = 10;
		}
	}
	else if(c > 7)
	{
		//if they have used lL, lU, S and N green if three or two yellow if less then red
		if((lL != 0) && (lU != 0) && (n != 0) && (s != 0))
		{
			code = 50;
		}
		else if(((lL != 0) && (lU != 0)) || ((n != 0) && (s != 0)) || ((lL != 0) && (s != 0)) || ((n != 0) && (lL != 0)) || ((n != 0) && (lU != 0)) || ((s != 0) && (lU != 0)))
		{
			code = 30;
		}
		else
		{
			code = 10;
		}
	}
	else if(c == 0)
	{
	    code = 0;
	}
	else
	{
		code = c+5;
	}

	setDivColour(code, pos);
};

function setDivColour(code, pos)
{
	var divToStyleA = document.getElementById('passA'+pos);
	var divToStyleB = document.getElementById('passB'+pos);
	var divToStyleC = document.getElementById('passC'+pos);
	var divToStyleD = document.getElementById('passD'+pos);
	var divToStyleE = document.getElementById('passE'+pos);
	
	divToStyleE.style.backgroundColor = "#ffffff";
	divToStyleD.style.backgroundColor = "#ffffff";
	divToStyleC.style.backgroundColor = "#ffffff";
	divToStyleB.style.backgroundColor = "#ffffff";
	divToStyleA.style.backgroundColor = "#ffffff";
	
	//only for the best passwords create a red, orange, yellow, green and blue blocks
	if(code > 80)
	{
		document.getElementById('pStrength'+pos).style.display = "block";
		divToStyleE.style.backgroundColor = "#0080FF";
		divToStyleD.style.backgroundColor = "#00ff00";
		divToStyleC.style.backgroundColor = "#ffff00";
		divToStyleB.style.backgroundColor = "#ff8000";
		divToStyleA.style.backgroundColor = "#ff0000";
	}
	//create a red, orange, yellow and green blocks
	else if(code > 60)
	{
		document.getElementById('pStrength'+pos).style.display = "block";
		divToStyleD.style.backgroundColor = "#00ff00";
		divToStyleC.style.backgroundColor = "#ffff00";
		divToStyleB.style.backgroundColor = "#ff8000";
		divToStyleA.style.backgroundColor = "#ff0000";
	}
	//create a red, orange and yellow blocks
	else if(code > 40)
	{
		document.getElementById('pStrength'+pos).style.display = "block";
		divToStyleC.style.backgroundColor = "#ffff00";
		divToStyleB.style.backgroundColor = "#ff8000";
		divToStyleA.style.backgroundColor = "#ff0000";
	}
	//create a red and orange block
	else if(code > 20)
	{
		document.getElementById('pStrength'+pos).style.display = "block";
		divToStyleB.style.backgroundColor = "#ff8000";
		divToStyleA.style.backgroundColor = "#ff0000";
	}
	//remove the strength checker
	else if(code == 0)
	{
	    document.getElementById('pStrength'+pos).style.display = "none";
		divToStyleA.style.backgroundColor = "#ffffff";
	}
	//set the starting div to red
	else
	{
		document.getElementById('pStrength'+pos).style.display = "block";
		divToStyleA.style.backgroundColor = "#ff0000";
	}
};

//this functions checks that the passwords match
function passSame(first, second, pos)
{
	var password1 = document.getElementById(first).value;
	var password2 = document.getElementById(second).value;
	
	if((password1 == password2) && ((password1 != '') && (password2 != '')))
	{
		document.getElementById('passMatch'+pos).style.display = "inline";
		document.getElementById('passMatch'+pos).style.backgroundColor = "#ffffff";
		document.getElementById('passMatch'+pos).innerHTML = '<img width="15px height="15px" src="/images/main/tick.gif" alt="an image of a blue tick." title="Passwords match">';
	}
	else
	{
		document.getElementById('passMatch'+pos).style.display = "inline";
		document.getElementById('passMatch'+pos).style.backgroundColor = "#ffffff";
		document.getElementById('passMatch'+pos).innerHTML = '<img width="15px height="15px" "src="/images/main/cross.gif" alt="an image of a red x." title="Pbannerasswords do not match">';
	}
};

function watchLink(p, t, s, l)
{
	var currentPage = window.location+p;
	var type = t;
	var site = s;
	var link = l;
	var variables = "currentPage="+currentPage+"&type="+type+"&exitSite="+site+"&exitLink="+link;
	var xmlHttp = GetXmlHttpObject();	
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
	    {
			if(xmlHttp.status == 200)
			{
				if(xmlHttp.responseText == 'success')
				{
					return true;
				}
				else
				{
					return false;
				}
			}
		}
	};
	xmlHttp.open("post", rootUrl+'/includes/exitLinks.php', true);
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", variables.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(variables);	
};

function homeScroller(div)
{
	var current = document.getElementById('select'+div);
	var currentAnc = document.getElementById('anc'+div);
	var currentLi = document.getElementById('li'+div);
	var list = new Array("recomend","new","comedy","drama","documentary");
	if(current != null)
	{
		current.style.display = 'block';
		currentAnc.style.color = '#fff';
		currentAnc.style.backgroundImage = "url('/images/main/selectedBack.png')";
		
		for(ele in list)
		{
			var deselect = document.getElementById('select'+list[ele]);
			var deselectAnc = document.getElementById('anc'+list[ele]);
			var deselectLi = document.getElementById('li'+list[ele]);
			if(deselect != null)
			{
				if(deselect != current)
				{
					deselect.style.display = 'none';
					deselectAnc.style.backgroundImage = "url('/images/main/greyBack.png')";
					deselectAnc.style.color = '#6a89cc';
				}
			}
		}
	}
};

function showTvDetails(tvid)
{
	//only create the box if it does not exsist
	var shade = document.getElementById('showDetailFloat');
	if(shade == null)
	{
		shade = document.createElement('div');
		shade.id= "showDetailFloat";
		var editDiv = document.getElementById('topShows');
		editDiv.appendChild(shade);
	}
	
	var variables = "tvid="+tvid;
	var xmlHttp = GetXmlHttpObject();	
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
	    {
			if(xmlHttp.status == 200)
			{
				//put the outputin the div
				shade.innerHTML = xmlHttp.responseText;
			}
		}
	};
	xmlHttp.open("post", rootUrl+'/includes/findShowDetails.php', true);
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", variables.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(variables);
};

function closeShowDetails()
{
	var child = document.getElementById('showDetailFloat');
	var parentDiv = child.parentNode;
	parentDiv.removeChild(child);
	
};

function tourHover()
{
	var img  = document.getElementById('tourImage');
	if(img.getAttribute('src') == '/images/main/rightTour.png')
	{
		img.setAttribute('src', '/images/main/rightTourHover.png');
	}
	else
	{
		img.setAttribute('src', '/images/main/rightTour.png');
	}
};

function scrollHover(side)
{
	var img  = document.getElementById(side+'ChevronSlim');
	if(img.getAttribute('src') == '/images/main/'+side+'ChevronSlim.png')
	{
		img.setAttribute('src', '/images/main/'+side+'ChevronSlimHover.png');
	}
	else
	{
		img.setAttribute('src', '/images/main/'+side+'ChevronSlim.png');
	}
};

function registerHover()
{
	var img  = document.getElementById('rightRegister');
	var background = 'url("/images/main/rightRegisterTop.png")';
	if(img.style.backgroundImage != '')
	{	
		background = img.style.backgroundImage;
	}
	
	if(background == 'url("/images/main/rightRegisterTop.png")')
	{
		img.style.backgroundImage = "url('/images/main/rightRegisterTopHover.png')";
		img.style.color = '#fff';
	}
	else
	{
		img.style.backgroundImage = "url('/images/main/rightRegisterTop.png')";
		img.style.color = '#000';
	}
};

function showMoreLinks(tv)
{
	processAjaxPost('showLinksContent', '../includes/getMoreShowLinks.php', 'TvId='+tv);
	var div  = document.getElementById('showLinksContent');
	div.style.height = '100%';
};

function showDescription()
{
	var div  = document.getElementById('tvShowSummary');
	var par  = document.getElementById('tvSummaryShrunk');
	par.style.height = '100%';
	div.style.height = '100%';
};

function tvScroller(div)
{
	var current = document.getElementById('select'+div);
	var currentAnc = document.getElementById('anc'+div);
	var currentLi = document.getElementById('li'+div);
	var list = new Array("cast","comment","news","review");
	if(current != null)
	{
		current.style.display = 'block';
		currentAnc.style.color = '#fff';
		currentAnc.style.backgroundImage = "url('/images/main/selectedBack.png')";
		
		for(ele in list)
		{
			var deselect = document.getElementById('select'+list[ele]);
			var deselectAnc = document.getElementById('anc'+list[ele]);
			var deselectLi = document.getElementById('li'+list[ele]);
			if(deselect != null)
			{
				if(deselect != current)
				{
					deselect.style.display = 'none';
					deselectAnc.style.backgroundImage = "url('/images/main/greyBack.png')";
					deselectAnc.style.color = '#6a89cc';
				}
			}
		}
	}
};

function updateTVShow(id)
{
	processAjaxPost('editDivInnerMiddle', '../includes/changeTvDetails.php', 'tvId='+id);
	greyout('greyOut', 'true');
	editDiv('true');
};

function favouriteTV(id, add)
{
	var file = 'removeFavourite';
	if(add)
	{
		file = 'addFavourite';
	}
	processAjaxPost('addFavourite'+id, '../includes/'+file+'.php', 'tvId='+id);
};

function notLoggedIn()
{
	processAjax('editDivInnerMiddle', '../includes/editShow.php');
	greyout('greyOut', 'true');
	editDiv('true');
};

function rating(type, val, id)
{
	if(type == 'Tv')
	{
		processAjaxPost('tvRating', '../includes/rating.php', 'ratingType='+type+'&ratingValue='+val+'&ratingId='+id);
	}
	else
	{
		processAjaxPost('filmRating', '../includes/rating.php', 'ratingType='+type+'&ratingValue='+val+'&ratingId='+id);
	}
};

function pageVisit(id)
{
	processAjaxPost('updateViewed', '../includes/updateViewed.php', 'tvId='+id);
};

function feedback()
{
	processAjax('editDivInnerMiddle', '../includes/feedback.php');
	greyout('greyOut', 'true');
	editDiv('true');
};

function getUserLinks(epId)
{
	processAjax('userLinks'+epId, '../includes/getUserLinks.php?id='+epId);
};

function addLink(epId)
{
	processAjaxPost('editDivInnerMiddle', '../includes/addEpisodeLink.php', 'episode='+epId);
	greyout('greyOut', 'true');
	editDiv('true');
};

function logout(user)
{
	processAjaxPostRedirect('login', '../register/logout.php', 'user='+user, '/');
};

function login()
{
	processAjaxPost('editDivInnerMiddle', '../register/login.php', 'login=true');
	greyout('greyOut', 'true');
	editDiv('true');
};

function postComment(id, type)
{
	if(type == 'tv')
	{
		processAjaxPost('addComment', '../includes/addTvComment.php', 'tvId='+id+'&add=true');
	}
	else if(type == 'news')
	{
		processAjaxPost('addComment', '../includes/newsComment.php', 'newsComment='+id);
	}
	else if(type == 'review')
	{
		processAjaxPost('addComment', '../includes/reviewComment.php', 'reviewId='+id);
	}
};

function getEpContent()
{
	//alert('loading');
	var ele = document.getElementById("seriesEpisodeGuide");
	if(ele !== null)
	{
		var nodes = ele.getElementsByTagName('A');
		var data = new Array();
	
		for(var i=0;i<nodes.length;i++)
		{
			//alert(nodes[i].getAttribute('id'));
			if(nodes[i].getAttribute('class') == 'episodeLink')
			{
				var link = nodes[i].getAttribute('id');
				data = link.split('-');
				var tvid = data[0];
				var series = data[1];
				var episode = data[2];
				var divId = 'episodeContent'+series+episode;
		
				//create the div and append it
				var div = document.createElement('div');
				div.id= divId;
				div.className = 'individualEpisode';
				nodes[i].parentNode.appendChild(div);
				//alert(divId);

				//add a function to the link so that when it is clicked the link is not followed but the episode data is loaded.
				//alert('here'+tvid+series+episode+divId);
				nodes[i].onclick=function(e)
				{
					var link = this.getAttribute('id');
					data = link.split('-');
					var tvid = data[0];
					var series = data[1];
					var episode = data[2];
					var divId = 'episodeContent'+series+episode;
					//alert('here'+tvid+series+episode+divId);			
					loadEpisodeContent(tvid,series,episode,divId);			
					toggleEp(divId, link);
					if(!e)
					{
						var e = window.event
					}
					e.preventDefault();
				};
			}
		}
	}
};

function toggleEp(d, l)
{
	var ele = document.getElementById(d);
	var link = document.getElementById(l);
	
	if(ele)
	{
		if(ele.style.display == "block")
		{
			//then hide this div
			ele.style.display = "none";
			//alert("hide");
			link.innerHTML = link.innerHTML.replace('- ', '+ ');
		}
		else
		{
			//display this div
			//alert("show");
			ele.style.display = "block";
			link.innerHTML = link.innerHTML.replace('+ ', '- ');
		}		
	}
};

function getSeriesContent()
{
	var ele = document.getElementById("seriesEpisodeGuide");
	if(ele !== null)
	{
		var nodes = ele.getElementsByTagName('A');
		var data = new Array();
	
		for(var i=0;i<nodes.length;i++)
		{
			//alert(nodes[i].getAttribute('id'));
			if(nodes[i].getAttribute('class') == 'seriesLink')
			{
				var link = nodes[i].getAttribute('id');
				//alert(link);
				data = link.split('-');
				var tvid = data[1];
				var series = data[2];
				var divId = 'episodeDetails'+series;
		
				var episodeDetails = document.getElementById(divId);
				if(episodeDetails == null)
				{
					//create the div and append it
					var div = document.createElement('div');
					div.id= divId;
					div.className = 'episodeDetails';
					nodes[i].parentNode.parentNode.appendChild(div);
					//nodes[i].parentNode.appendChild(div);
					//alert(divId);
				}

				//add a function to the link so that when it is clicked the link is not followed but the episode data is loaded.
				//alert('here'+tvid+divId);
				nodes[i].onclick=function(e)
				{
					var link = this.getAttribute('id');
					data = link.split('-');
					var tvid = data[1];
					var series = data[2];
					var divId = 'episodeDetails'+series;
					//alert('linkClicked '+tvid+series+divId);
					loadSeriesContent(tvid,series,divId);			
					toggleEp(divId, link);
					//then run the function for the episodes that have been returned
					getEpContent();
					if(!e)
					{
						var e = window.event
					}
					e.preventDefault();
				};
			}
		}
	}
};

function loadSeriesContent(tvid,seriesNum,ele)
{
	//only run if the episode element is empty
	var element = document.getElementById(ele);
	if(element.innerHTML == '')
	{
		//alert(tvid+seriesNum+episodeNum);
		processAjaxPost(ele, '../includes/seriesDetails.php', 'tvId='+tvid+'&series='+seriesNum);
	}
};

function edit(type, page, id)
{
	greyout('greyOut', 'true');
	editDiv('true');
	
	var variables = "type="+type+"&page="+page+"&";
	if(id != 0)
	{
		variables += "add=false&id="+id;
	}
	else
	{
		variables += "add=true&id=0";
	}
	var div = document.getElementById('editDivInnerMiddle');
	
	var xmlHttp = GetXmlHttpObject();	
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
	    {
			if(xmlHttp.status == 200)
			{
				//put the outputin the div
				div.innerHTML = xmlHttp.responseText;
				if(type != 'delete')
				{
					tinyMCE.execCommand('mceAddControl', false, 'post');
				}
			}
		}
	};
	xmlHttp.open("get", rootUrl+'/tv-buzz/edit.php?'+variables, true);
	xmlHttp.send(null);
};

function sendEmails(type, id)
{
	var page = 'sendGeneralEmail.php';
	if(type == 'writers')
	{
		page = 'sendWritersEmail.php';
	}	
	greyout('greyOut', 'true');
	editDiv('true');
	var div = document.getElementById('editDivInnerMiddle');
	var variables = 'userId='+id;
	
	var xmlHttp = GetXmlHttpObject();	
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
	    {
			if(xmlHttp.status == 200)
			{
				//put the outputin the div
				div.innerHTML = xmlHttp.responseText;
				tinyMCE.execCommand('mceAddControl', false, 'message');
			}
		}
	};
	xmlHttp.open("post",rootUrl+'/admin/'+page, true);
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", variables.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(variables);
};

function hideImage(id)
{
	var result = confirm('Are you sure you want to delete the poster?');
	if(result)
	{
		processAjaxPost('deleteTvImage', '../includes/hideImage.php', 'id='+id);
	}
};

/*
	Show the global or local links depending on the current shown
	remove the current image from the link and add the opposite image, either global or flag.
*/
function showGlobal(link, ele)
{
	//get the elements that we need: links div, the link and the current img
	var div = document.getElementById('globalLink'+ele);
	var currentImg = link.getElementsByTagName('img');
	
	//create the new image element to append to the link
	var img = document.createElement('img');
    //display global
    if(currentImg[0].getAttribute('alt') == 'Worldwide links')
    {    
		img.setAttribute('src','/images/flags/'+userLocation.toLowerCase()+'.png');
		if(userLocation == 'GB')
		{
			img.setAttribute('alt', 'UK links');
			link.setAttribute('title','Display UK links');	
		}		
		else
		{
			img.setAttribute('alt', userLocation+' links');
			link.setAttribute('title','Display '+userLocation+' links');
		}
		img.style.height = '11px';
    	img.style.width = '16px';
    	//show the link block
		div.style.display = 'block';
    }
    else
    {
    	img.setAttribute('src','/images/main/global.png');
		img.setAttribute('alt','Worldwide links');
		link.setAttribute('title','Display Worldwide links');
		img.style.height = '15px';
    	img.style.width = '15px';
    	//show the link block
		div.style.display = 'none';
    }
    //clean the link before appending the new image
    link.innerHTML = '';
	link.appendChild(img);
	
};

//when anyone posts a comment using Facebook the response will be passed
//here then post the details back to the server and notify the author of the article
//and log the comment.
function logFbComment(response)
{	
	var page = 'facebookComment.php';	
	var variables = 'commentID='+response.commentID+'&href='+response.href.replace(rootUrl,'');
	//alert(variables);
	var xmlHttp = GetXmlHttpObject();
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
	    {
			if(xmlHttp.status == 200)
			{
				//alert('Done'+xmlHttp.responseText);
			}
		}
	};
	xmlHttp.open("post",rootUrl+'/includes/'+page, true);
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", variables.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(variables);
};

