/*
A collection of standard functions
for use on the new Herald site
*/

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



function setHeadlines (theSection, theFirstHeadline) {
	var theDiv = theSection + "MenuMaster";
	var theEnd = false;
	var headlinesPerPage = 20;
	var totalPages = Math.ceil(eval(theSection + "IdArray").length / headlinesPerPage);
	var thisPage = Math.floor(theFirstHeadline / headlinesPerPage) + 1;

	myLastHeadline = 0;
	if ((theFirstHeadline + headlinesPerPage) >= eval(theSection + "IdArray").length) {
		myLastHeadline = eval(theSection + "IdArray").length;
		theEnd = true;
	} else {
		myLastHeadline = theFirstHeadline + headlinesPerPage;
		theEnd = false;
	}

	myString = "";
	for (x=theFirstHeadline; x<myLastHeadline; x++) {
		myString += "<a href='/" + theSection + "/" + eval(theSection + 'IdArray[x]') + ".html' class=menuLink>" + eval(theSection + 'HeadlinesArray[x]') + "</a><br>";
	}
	if (theEnd) myLastHeadline = 0;
	myString += "<br><img src=/images/menuFgdots.gif width=260 height=5><br>";
	if (eval(theSection + 'IdArray.length') > headlinesPerPage)
	myString += "<a href='#' onClick=\"setHeadlines('" + theSection + "'," + myLastHeadline + ");\" class=menuLink>MORE HEADLINES...</a>";
	else myString += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	myString += " <img src=/images/menuFgdotsVert.gif width=7 height=15 hspace=15> <span class=menuPages> [page " + thisPage + " of " + totalPages + "] </span>";

	if(document.layers) { //Netscape 4 code
		theDiv = document.layers[theDiv];
		theDiv.document.open();
		theDiv.document.write(myString);
		theDiv.document.close();
	}
  
	if(document.all) { //Internet Explorer code
		theDiv = document.all[theDiv];
		theDiv.innerHTML = myString;
	}

	if(!document.all && document.getElementById) { //Netscape 6 code
		theDiv = document.getElementById(theDiv);
		theDiv.innerHTML = myString;
	}
}

var menuStart = "<table width=310 border=0 cellspacing=0 cellpadding=0><tr><td bgcolor=#BA0304>";
var menuMid1 = "";
var menuMid2 = "<span class=menuPages>(";
var menuEnd = ")</span></td></tr></table>";




function readCookie(name) 
{ 
  var cookieValue = ""; 
  var search = name + "="; 
  if(document.cookie.length > 0) 
  { 
    offset = document.cookie.indexOf(search); 
    if (offset != -1) 
    { 
      offset += search.length; 
      end = document.cookie.indexOf(";", offset); 
      if (end == -1) end = document.cookie.length; 
      cookieValue = unescape(document.cookie.substring(offset, end)) 
    } 
  } 
  return cookieValue; 
}

function writeCookie(name, value, hours) 
{ 
  var expire = ""; 
  if(hours != null) 
  { 
    expire = new Date((new Date()).getTime() + hours * 3600000); 
    expire = "; expires=" + expire.toGMTString(); 
  } 
  document.cookie = name + "=" + escape(value) + expire; 
} 


function articlePrint()	{
	if (window.print) {
		window.print();
	} else {
		alert("Your web browser does not support standard web printing.\n\nPlease print the page using your browsers print command.");
	}
}

function largePic(picID) {
  var thePage = "/news/storypic.html?id=" + picID;
  window.open(thePage,"","width=200,height=200,resizable=yes,screenX=150,screenY=150,top=150,left=150");
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

var doc, sty;
var n4 = false;
var n6 = false;
var ie = false;
var activeMenu = "";

if (document.layers) {
  doc = "document.";
  sty = "";
  n4 = true;
  } 
else if (document.all) {
  doc = "document.all.";
  sty = ".style";
  ie = true;
  }
else if (document.getElementById) {
  doc = "document.getElementById('";
  sty = "').style";
  n6 = true;
}

function showhideMenu(elem,state) { 
  // generic function for showing/hiding layers using a cross-browser DOM
  docObj = eval (doc + elem + sty);
  docObj.visibility = state;
}

function closeAllMenus() {
  // checks for any active menus and closes them
  if (activeMenu != "") {
    showhideMenu(activeMenu, "hidden");
    activeMenu = "";
    document.onclick = null; 
  }
}

function handleMenuClick(theMenu) {
  // opens the clicked menu and closes all others
  closeAllMenus();
  showhideMenu(theMenu, "visible");
  activeMenu = theMenu;
}

function menuOut() {
  // sets the default mouse button click to close all open menus
  if (activeMenu != "") {
    document.onclick = closeAllMenus;
  }
}

function menuIn() {
  // sets the default mouse button click to have no javascript action
  document.onclick = null;
}

function doAddFavourites() {
  // bookmarking function for browsers which support it
  if (window && window.external) {
    window.external.addFavorite("http://www.theherald.co.uk/", "The Herald");
  } else {
    alert ("Sorry, your browser doesn't support automatic bookmarking.\nPlease add this bookmark manually.");
  }
}