// JavaScript Document

//Global variable changes the names of each hyperlink or button
var LessInfo = "Hide <<<"
var MORE = "Click to read more"
//////////////////////////////

//Global variable.  Set the number of news items there are.
var NEWSITEMCOUNT = 3
/////////////////////////

//Loads the news for a particular news section based on the cookies
//In this section you set the number of news items there are so that there can be a check on all news items
function loadNews()
{
	for (var i=1;i <=NEWSITEMCOUNT;i++)
	{
		var cookie;
		cookie = getCookie("Menu" + i);
		if (cookie)
		{
			
			//We then load news item again remembered from the last interaction.
			GetNews(i,"News" + i,"");
			//Quick fix - we want to make sure the buttons are changed to their appropriate text.
			//Normally we would tie this up and automate the process, but for swiftness I am just going to 
			//get the elements that display or hide the news items by using a prefix id.
			//IMPORTANT - THE PREFIX ID FOR EACH ELEMENT IS 'NewsButton' followed by the number of the news item.  Make sure the buttons always have this prefix id
			//Get the elements
			var newsbutton = document.getElementById("NewsButton" + i)
			//We know that the news item is appearing from the users last click so we set the button to HIDE text
			newsbutton.innerHTML = LessInfo;
		}	
	}

}

//Gets the content for the actual div id of the target location for the news story.
function GetNews(NewsID,divContainerID,obj)
{

//Firstly get the div thats going to hold it by instantiating the divContainerID.
var divContainer = "";
divContainer = document.getElementById(divContainerID);

//Then get the content of the news ID
var NewsContent = "";
NewsContent = document.getElementById(NewsID);


var NewsContentText = "";
NewsContentText = NewsContent.innerHTML;

//Find out if the divContainer has HTML contained.  If not then we populate
if (divContainer.innerHTML != "")
{

//And delete the cookie that was previously created
Delete_Cookie("Menu" + NewsID,"","");
divContainer.innerHTML = "";

if (obj)
{
//Then change the text of the object
obj.innerHTML = MORE
}

		
}
else
//We want to clear the information.
{


if (obj)
		{
		//Then change the text of the object
		obj.innerHTML = LessInfo
		}

//alert(NewsContent.innerHTML);
//Now get the innerHTML of the NewsContent and assign it to the divContainer
divContainer.innerHTML = NewsContentText;



//Now set the menu cookie for this
document.cookie = "Menu" + NewsID + "=yes";


}

}

//Remember what a user was reading in case a postback occurs
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return false;
}

//Delete a cookie when they hide information again.
function Delete_Cookie( name, path, domain ) {
if ( getCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

