// script for page number & nav fwd/back
// created by P.Hobbs - EUdesign.com - April 2005
//
// Aug 2010 amended to declare all vars and avoid deprecated Fn.arguments
// Mar 2011 amended and enhanced for use with RASASC nav

function myArray(n) {		// define any array-object for browsers pre-3.0
	this.length = n;
	for (var h = 1; h <= n; h++){this[h] = 0}
	return this
}

var pList = new myArray(64)	// create object array in head, avoids reload problems
var tadr = pList.length;		// total array-data-rows
var tads,tal,tad
function item(pNr,pSec,pAdd) {	// create array of objects
	this.pNr=pNr;
	this.pSec=pSec;
	this.pAdd=pAdd;		// first define object type
}

/* Fn(n) to store args as array table-items in rows of n+1 items/row, n being first arg in list. */
// - fn upgraded Mar 2011 to use trim (regexp) subr.

function tdata(trecs) {
    tads = new myArray(trecs+1)			// create substr-arr
    tal = arguments.length			// get tot. of rows [Fn.arguments.length is deprecated]
//pList[0] = new item("No.","Section","Pathname")
    for (var i = 1; i < tal; i++) {		 	// for @new row
	tad = arguments[i]				// get argument-str  [Fn.args is deprecated]
	for (var j = 1; j < trecs; j++) {		// for @internal comma
	    var y = tad.indexOf(",")			// str into substrs
	    tads[j] = tad.substring(0, y)		// store
	    tad = tad.substring(y+1, tad.length)	// shorten arg-str			
	}
	tads[trecs] = tad				// store remain-str
	for (var j = 1; j <= trecs; j++) {		// for @stored string
	    tads[j]=trim(tads[j]);		// remove start/end blanks (incl.tabspace)
	}
	pList[i] = new item(i,tads[1],tads[2])
//alert('pList['+i+']='+pList[i].pNr+'_'+pList[i].pSec+'_'+pList[i].pAdd)
    }
}

function trim(str) {
	return str.replace(/^\s+|\t+|\n+|$\s+|\t+|\n+/g,'');
}

tdata(2,
"A,index.html",
"C,services/index.html",
"C,services/helpline.html",
"C,services/counselling.html",
"C,services/testimonies.html",
"C,services/presentations.html",
"C,services/pppscheme.html",
"D,adviceguides/index.html",
"E,aboutus/index.html",
"F,newsevents/index.html",
"G,supportus/index.html",
"H,downloads/index.html",
"A,contact.html",
"A,links.html",
"A,sitemap.html")

var pNo="x",pRev,pFwd,hComm		// global
function pNum(){
  for (var i=1;i<tal;i++) { 	// chk for match
    if (pList[i].pAdd==aTit) {
      pNo=i; i=tal;
    }
  }
  if (pNo=="x") return;		// stop if unlisted
  pRev=pNo-1,pFwd=pNo+1;	// calc. prev & next
  if (pRev=="") pRev=tal-1;
  if (pFwd==tal) pFwd=1;
//alert('pRev='+pRev+'\npNo='+pNo+'\npFwd='+pFwd)
  hComm=location.href.substr(0,location.href.length-aTit.length);
//alert('location.href='+location.href+'\nhComm='+hComm)
  tdir(hComm+pList[pRev].pAdd,hComm+pList[pFwd].pAdd);
}

//detect browser
var browserName=navigator.appName;
var browserVer=parseInt(navigator.appVersion);
if (browserName=='Netscape' && browserVer>=3) browserVer='1';
else if (browserName=='Microsoft Internet Explorer' && browserVer==4) browserVer='1';
else browserVer='2';
var t1=new Image(50,50);
var t2=new Image(50,50);
var t3=new Image(50,50);

function chktour() {
  if (pNo=="x") {

  var tfill=''
	+'<TABLE WIDTH="90" ALIGN="center">'
	+'<TD ALIGN="left">'
	+'&nbsp;</TD>'
	+'</TABLE>';
  document.writeln(tfill);
  return;
  }
  if (pNo!="x") {
	var tb=hComm+pList[pRev].pAdd, to=hComm+pList[pFwd].pAdd;	// Rev/Fwd addrs
	var tfill='Take a quick '+(tal-1)+'-page tour<BR>'
	+'\n<IMG SRC="'+iSrcAdd+'imgs/nav/olfamilytourgrey.png" VSPACE="10" HEIGHT="50" WIDTH="50" ALT="Click for Tour" BORDER="0"'
	+'USEMAP="#pt" NAME="t"><BR>';
	if (browserVer==1) {	//preload images:
	  t1.src=iSrcAdd+'imgs/nav/olfamilytourgrey.png';
	  t2.src=iSrcAdd+'imgs/nav/olfamilyrev.png';
	  t3.src=iSrcAdd+'imgs/nav/olfamilyfwd.png';
	  tfill+='\n<MAP NAME="pt">'
	  +'\n<AREA SHAPE="rect" COORDS="1,1,25,50" HREF="'+tb+'" ALT="Rev" onMouseOver="hiLite(\'t\',\'t2\',\'Rev\')" onMouseOut="hiLite(\'t\',\'t1\',\'Tour\')">'
	  +'\n<AREA SHAPE="rect" COORDS="26,1,50,50" HREF="'+to+'" ALT="Fwd" onMouseOver="hiLite(\'t\',\'t3\',\'Fwd\')" onMouseOut="hiLite(\'t\',\'t1\',\'Tour\')">'
	  +'\n</MAP>'
	}
	document.writeln(tfill+'\n<A HREF="'+tb+'">&lt;Previous</A> - '+pNo+' - <A HREF="'+to+'">Next&gt;</A>');
  }
}

//image swapping function:
function hiLite(imgDocID,imgObjName,comment) {
  if (browserVer==1) {
    document.images[imgDocID].src=eval(imgObjName+'.src');
//alert('img source = '+document.images[imgDocID].src)
    window.status=comment; return true;
  } return false;
}

var goNos="";
function tdir(tr,tf) { // write prev/no./next in 3-col table
	goNos='<DIV>\n<TABLE WIDTH="90%" ALIGN="center" CELLPADDING=0 CELLSPACING=0 BORDER=0>'
	+'\n<TH WIDTH="20%" ALIGN="left">'
	+'\n  <A HREF="'+tr+'">Tour back</A></TH>'
	+'\n<TH WIDTH="60%" ALIGN="center">'
	+'\n  Tour '+pNo+' of '+(tal-1)+'</TH>'
	+'\n<TH WIDTH="20%" ALIGN="right">'
	+'\n  <A HREF="'+tf+'">Tour forward</A></TH>'
	+'\n</TABLE>\n</DIV>';
}
