var curshow = 0;
var tooltipfix = false;


function hideall()
{
	topNode = null;
	if (document.all)
		topNode = document.all["colFaqStart"];
	else
		topNode = document.getElementById("colFaqStart");

	for (var i=0; i < topNode.childNodes.length; i++) 
	{
		var oNode = topNode.childNodes[i];
		if (oNode.id != null && oNode.id.indexOf("faqa") == 0)
			hideNode(oNode);
	}
}

function showmore(n,faqid)
{
	if (document.all)
	{
		if (curshow > 0)
		{
			hideNode(document.all["faqa"+curshow]);
			showNode(document.all["faq"+curshow]);
		}
		hideNode(document.all["faq"+n]);
		showNode(document.all["faqa"+n]);
		curshow = n;
	}	
	else
	{
		if (curshow > 0)
		{
			hideNode(document.getElementById("faqa"+curshow));
			showNode(document.getElementById("faq"+curshow));
		}
		hideNode(document.getElementById("faq"+n));
		showNode(document.getElementById("faqa"+n));
		curshow = n;
	}	

	AddVisitedFAQ(faqid);
	LogViewedFAQ(faqid);
}

function hideNode(topNode)
{
	if (topNode != null)
  	{
  		// First hide this node
  		if (topNode.style != null)
  			topNode.style.display = "none";
  		  			
  		// then look at all the children.
		for (var i=0; i < topNode.childNodes.length; i++) 
		{
			var oNode = topNode.childNodes[i];
			// hide this div
			if (oNode.style != null)
				oNode.style.display = "none";
			
			
			// untick the radio buttons
			if (oNode.type == "radio" || oNode.type == "checkbox")
				oNode.checked = false;

			// move to the next child
			hideNode(oNode, true);
		}     
  	}
}

function showNode(topNode)
{
	if (topNode != null)
  	{
  		// First show this node
  		if (topNode.style != null)
  			topNode.style.display = "";

  		// then look at all the children.
		for (var i=0; i < topNode.childNodes.length; i++) 
		{
			var oNode = topNode.childNodes[i];
			// show this element
			if (oNode.style != null)
				oNode.style.display = "";
			
			// untick the radio buttons
			if (oNode.type == "radio" || oNode.type == "checkbox")
				oNode.checked = false;

			// move to the next child
			showNode(oNode, true);
		}     
  	}
}

function useful(n)
{
	return;
}

function expandtt(num,id)
{
	document.getElementById("tooltip").innerHTML = tooltipdesc[num];
	document.getElementById("tooltip").style.visibility = 'visible';
	var obj = document.getElementById(id);
	if (!tooltipfix)
		document.getElementById("tooltip").style.left = (findPosX(obj) - 40) + 'px';
	else
		document.getElementById("tooltip").style.left = '10px';
	document.getElementById("tooltip").style.top = (findPosY(obj) + 26) + 'px';
}

function contracttt()
{
	document.getElementById("tooltip").style.visibility = 'hidden';
	document.getElementById("tooltip").innerHTML = '';
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function AddVisitedFAQ(id)
{
	cookiename = "contactX2FAQ";
	cookielen = cookiename.length + 1;
	faqlength = 6;
	c = document.cookie + ";";
	i = c.indexOf(cookiename);
		
	if (i >= 0)
	{
		j = c.indexOf(";", i);
		c = c.substr(i+cookielen, j-i-cookielen);
		i = c.indexOf("/" + id + "/");
		if (i >= 0) c = c.substr(0, i+1) + c.substr(i+id.length+2);
		j = 0;
		for (i=0 ; i < c.length ; i++) if (c[i] == '/') j++;
		if (j >= faqlength)
		{
			i = c.indexOf("/", 1);
			c = c.substr(i);
		}
	}
	else
		c = "/";
		
	c += id + "/";

	document.cookie = "contactX2FAQ=" + c + "; domain=open.ac.uk; path=/;";
}

function UsefulFAQ(id, code)
{
	var ans = "";
	if (document.getElementById("rad" + id + "a").checked == true) ans = "1";
	if (document.getElementById("rad" + id + "b").checked == true) ans = "2";
	if (document.getElementById("rad" + id + "c").checked == true) ans = "3";
	if (document.getElementById("rad" + id + "d").checked == true) ans = "4";
	document.getElementById("faqspan" + id).innerHTML = 'Thank you!';
	var img = new Image();
	img.src = p14url + "F01" + code + "+" + faqarea + "_" + ans + (new Date()).getTime() + "_";
}

function LogViewedFAQ(code)
{
	var img = new Image();
	img.src = p14url + "F02" + code + "+" + faqarea + "_" + (new Date()).getTime();
}
