function show(what)
{
	var prefix = what.split('_')[0];
	var classNames;
	var obj;
	var maxTabs = 15;
	
	//Hide the other items	
	for (i=1;i<=maxTabs;i++)
	{
		obj=document.getElementById(prefix+"_"+i+"_tab");
		if (obj)
		{
			classNames = obj.className;
			classNames = classNames.split("active")[0];
			classNames = classNames.split("inactive")[0];
			obj.className = classNames + " inactive";
		}
		
		obj=document.getElementById(prefix+"_"+i);
		if (obj)
		{
			classNames = obj.className;
			classNames = classNames.split(" fold")[0];
			classNames = classNames.split(" unfold")[0];
			obj.className = classNames + " fold";
		}
		else
		{
			//break;		
		}
	}
	
	//Show the item
	obj=document.getElementById(what);
	if (obj)
	{
		classNames = obj.className;
		classNames = classNames.split(" fold")[0];
		classNames = classNames.split(" unfold")[0];
		obj.className = classNames + " unfold";
	}
	
	obj=document.getElementById(what+"_tab");
	if (obj)
	{	
		classNames = obj.className;
		classNames = classNames.split("active")[0];
		classNames = classNames.split("inactive")[0];
		obj.className = classNames + " active";
	}
}

function hide(what)
{
	obj=document.getElementById(what);
	if (obj)
	{
		classNames = obj.className;
		classNames = classNames.split(" fold")[0];
		classNames = classNames.split(" unfold")[0];
		obj.className = classNames + " fold";
	}
}

function deactivate(what, currentImage)
{
	var prefix = what
	var classNames;
	var obj;
	var maxItems = 30;

	//Hide the other items	
	for (i=1;i<=maxItems;i++)
	{
		obj=document.getElementById(prefix+"_"+i);
		if (obj)
		{
			//Leave the first few visible
			offsetFor=3-currentImage;
			if (offsetFor<0) {offsetFor=0;}
			if (i>currentImage-3 && i<currentImage+3+offsetFor)
			{
				obj.className="inactive";
			}
			else
			{
				obj.className="hidden";
			}
		}
		else
		{
			//Backtrack at the far end
			if (currentImage>i-3 && i>5)
			{
				for (j=i-1;j>=i-5;j--)
				{
					obj=document.getElementById(prefix+"_"+j);
					obj.className="inactive";
				}
			}
			break;	
		}
	}
}

function rigImage(smallUrl, bigUrl, alt, caption, copyright, passedItem)
{
	var prefix = passedItem.split('_')[0];
	var imageHolder = document.getElementById(prefix + "_" + "imageHolder");
	var imageCaption = document.getElementById(prefix + "_" + "imageCaption");
	var imageCopyright = document.getElementById(prefix + "_" + "imageCopyright");
	
	//Sort out the navigation items
	var theLink = document.getElementById(passedItem);
	if (theLink)
	{
		
		var currentImage = eval(passedItem.split('_')[1]);
		
		deactivate(prefix, currentImage);
		theLink.className = "active";
	
		//Next button
		nextLink = document.getElementById(prefix + "_" + (currentImage + 1));
		nextButton = document.getElementById(prefix + "_" +"nextImage");
		if (nextLink)
		{
			nextButton.href = nextLink.href;
			nextButton.className = "ends";
		}
		else
		{
			nextButton.href = "javascript:deadEnd();";
			nextButton.className = "ends dead";
		}
		
		//Prev button
		prevLink = document.getElementById(prefix + "_" + (eval(currentImage) - 1));
		prevButton = document.getElementById(prefix + "_" +"prevImage");
		if (prevLink)
		{
			prevButton.href = prevLink.href;
			prevButton.className = "ends";
		}
		else
		{
			prevButton.href = "javascript:deadEnd();";
			prevButton.className = "ends dead";
		}
	}
	
	var htmlOutput = '<img src="' + smallUrl + '" alt="' + alt + '"/>';
	if (imageHolder)
	{
		imageHolder.innerHTML = htmlOutput;
		imageCaption.innerHTML = caption;
		imageCopyright.innerHTML = copyright;
	}
	
	/*Update the link on the zoom button*/
	var zoomButton = document.getElementById(prefix + "_" + "zoomButton");
	
	if (zoomButton)
	{
		zoomButton.href = "javascript:zoom('" + bigUrl + "');";
	}
	
	/*Check for number of images and ahow pagination if required*/
	var imagePaginationLinks = document.getElementById(prefix + "_" + "imagePaginationLinks");
	var imagePagination = document.getElementById(prefix + "_" + "imagePagination");
	if (imagePaginationLinks)
	{
		if (imagePaginationLinks.innerHTML == "" || imagePaginationLinks.innerHTML == "{d069Repeater}")
		{
			/*Do nothing - this is disabled by default in CSS*/
		}
		else
		{
			imagePagination.style.display = "block";
		}
	}
}

var zoomed;
function zoom(url)
{
	newWindow = window.open(url,'TechRadar','width=748,height=760');
	newWindow.focus();
}

function deadEnd()
{
	/*Do nothing here - added to avoid IE displaying null*/
}

var xmlHttp = GetXmlHttpObject();
var returnedData = "waitState";

function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP.3.0");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
    if (xmlHttp==null)
    {
        alert ("Sorry, your browser does not appear to support AJAX.");
    } 
  return(xmlHttp);
}

function getData(url,what)
{
	what = escape(what);
	url = url + "?email=" + what;
	//var d = new Date();
	//url = url + "&nocache=" + d.getTime();
	
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged()
{ 
	if (xmlHttp.readyState==4)
	{ 
		returnedData = xmlHttp.responseText;
		updateDisplay();
		
		//Re-get a new object for IE 7
		xmlHttp=GetXmlHttpObject();
	}
}

function updateDisplay()
{
	switch(returnedData)
	{
		case "ok":
			show("forgotten_2");
			break;
		case "fail":
			show("forgottenEmailError");
			break;
		default:
			show("forgottenEmailError");
	}
}

function checkAvail(what)	
{
	var pane;
	var tab;
	var tabLink;
	var prefix = what;
	
	for (i=1;i<=6;i++)
	{
		pane = document.getElementById(prefix+"_"+i);
		if (pane)
		{
			if (pane.innerHTML.indexOf("<") < 0)
			{
				tab=document.getElementById(prefix+"_"+i+"_tab");
				if (tab)
				{
					tab.className = tab.className + " grey";
					//Hack to perminantly display tab for - requested by Future. Disabled.
					//if (i==1)
					//{
					//	show(prefix+"_4");	
					//}
				}
				tabLink=document.getElementById(prefix+"_"+i+"_link");
				if (tabLink)
				{
					tabLink.href = "javascript:void;";
				}
			}
		}
	}
}