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');
	if(type == 'true')
	{
		div.style.display = 'block';
	}
	else
	{
		div.style.display = 'none';
		div.innerHTML = '';
	}
}

function greyout(div, type)
{
	if(type == 'true')
	{
		var greyDiv = document.getElementById(div);
		var shade = document.createElement('div');
		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 = "absolute";
		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)
{
	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)
{
	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)
{
	//alert('div '+div+' page '+page+' var '+variables);
	var xmlHttp = GetXmlHttpObject();
	
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
	    {
			if(xmlHttp.status == 200)
			{
				document.getElementById(div).innerHTML = xmlHttp.responseText; 
			}
		}
	}
	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)
{
	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)
{
	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("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 handleHistory()
{
  /*if ( window.location.hash != '')
  {
    var expectedHash = window.location.hash;
    var hashVal = expectedHash.substring(1);
	if(hasVal = 'double')
	{
		processAjax('contentInfo', 'beds.php?bed=double');
	}
	alert(hashVal);
  }
  return true;*/
}

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 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('login', '../register/login.php', 'usernameLogin='+document.getElementById('usernameLogin').value+'&passwordLogin='+document.getElementById('passwordLogin').value, 'index.php');
	}
	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('../images/main/starRating.gif') 0 -2px no-repeat";
			i++;
		}
	}
	else
	{
		while(i < num)
		{
			document.getElementById('rate'+i).style.background = "url('../images/main/starRating.gif') 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)
{
	x = num;
	x++;
	if(x > 4)
	{
		x = 1;
	}
	
	if(num > 4)
	{
		num = 1;
		x = 2;
	}
	bannerTimer = setTimeout("processAjaxPost('bannerMain', '../includes/indexBanner.php', 'bannerNum="+num+"'); autoBanner("+x+");" , 5000);
}

function stopAutoBanner()
{
	clearTimeout(bannerTimer);
}

function countDown(end)
{
	var endDate = new Date(end);
	var now = new Date();
	//if it is an old date do nothing
	if(now>endDate)
	{
		document.getElementById("countDown").innerHTML = "The next show date is TBA.";
		return;
	}
	else
	{
		diff = new Date(endDate-now);
		secs = Math.floor(diff.valueOf()/1000);
		countBack(secs);
		setTimeout("countDown('" + (end) + "')", 1000);
	}
}

function calcage(secs, num1, num2) 
{
	s = ((Math.floor(secs/num1))%num2).toString();
	if(s.length < 2)
	{
		s = "0" + s;
	}
	return s;
}

function countBack(secs) 
{
	//alert(secs);
	if (secs < 46800) 
	{
		document.getElementById("countDown").innerHTML = "Today is show day";
		return;
	}
	else
	{
		display = '<b>Only '+calcage(secs,86400,100000)+' Days To Go</b>';
		//display =  display + calcage(secs,3600,24)+' Hours ';
		//display =  display + calcage(secs,60,60)+' Minutes ';
		//display =  display + calcage(secs,1,60)+' Seconds';
		
		document.getElementById("countDown").innerHTML = display;		
	}
}

function setImage(img, ele)
{
	var div = document.getElementById(ele);
	div.innerHTML = '<img src="'+img+'" alt="Competition image"/>';
}

function displayBlock(d)
{
	var div = document.getElementById(d);
	div.style.display = 'block';
}

function hideBlock(d)
{
	var div = document.getElementById(d);
	div.style.display = 'none';
}

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 toggleEleDisplay(e)
{
	ele = document.getElementById(e);
	if(ele)
	{
		if(ele.style.display == "block")
		{
			//then hide this div
			ele.style.display = "none";
		}
		else
		{
			//display this div
			ele.style.display = "block";
		}		
	}
}