// this file contains the common functions that various other functions/scripts call

function txtstrip(text) // strip off the leading 'C' off the identifier
{
	var newtxt=''; // stripped off identifier
	
	for(charitr=1;charitr<text.length;charitr++){
		newtxt=newtxt.concat(text.charAt(charitr)); // create new txt minus the leading 'C'
	}

	return(newtxt);
}

function lowerCase(text) // make the string lower case
{
	return(text.toLowerCase());
}

function init(){ // function initialises various javascript routines on start up
	positionInit(); // calculate variables needed to dynamically position elements
	createMainLayers(); // create main layers used for displays
	showHome();
}

function doNothing() {} //function is a placeholder

function show(name) { // shows the layer
	name.style.visibility='visible';
}

function hide(name) { // hides the layer
	name.style.visibility='hidden';
}

function isVisible(name) // return a bolean indicating if the layer is visible
{
	if(name.style.visibility == 'visible') return true; // return true if the layer is visible
	else return false; // return false if the layer is hidden
}

function left() { // returns the left position of the element
  return parseInt(this.element.left);
}

function top() { // returns the top position of the element
  return parseInt(this.element.top);
}

function element(){ // returns the reference to the current layer 
	return GetObject(this.name);
}

function elementStyle(){ // returns the style reference for the current layer
	return GetStyleObject(this.name);
}

function lyrRef(layer){ // returns the reference to the current layer
	return GetObject(layer);
}

function writeInfo(id,txt) // dynamically write info that supports ns4 and other browsers
{
	if(!document.layers) id.innerHTML=txt; // not ns4 browser
}

function GetObject(id) // return object 'id' assuming browser is dhtml compliant
{
	if(document.getElementById) return document.getElementById(id); // new browsers net v6 > and ie
}

function GetStyleObject(id) // return object 'id' style assuming browswer is dhtml compliant
{
	if(document.getElementById) return document.getElementById(id).style; // new browsers net v6 > and ie
}

function imgInc(index,maxImg)
{
	if(index>=0 && index<maxImg) return(index);
	else if(index<0) return(maxImg-1);
	else return(0);
}


function NewWindow(mypage,myname,w,h,scroll,pos) // opens a subwindow with a predefined web page
{
	LeftPosition=0;
	TopPosition=20;
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
}

function getParams() // gets the parameters from a page with parameters in the address
{
	var params = new Array(); // array to elements obtained from the URL

	var idx = document.location.href; // holds the url of the page

	// strips of the information of interest off the URL of the page
	pairs = (idx.substring(idx.lastIndexOf('?')+1,idx.length)).split('&');
	
	for(i=0;i<pairs.length;i++) // goes through and splits apart the variable name and value from the URL info
	{
		nameVal = pairs[i].split('=');
		params[2*i]=nameVal[0];
		params[(2*i)+1]=nameVal[1];
	}

	return params;
}

function clearScreen() // clear the screen
{
	clearMain(); // clear the main screen
}

function displayExtPage(location) // display the guestbook in a seperate window
{
	NewWindow(location,'slideshow','600','400','yes','center');
}


function stripPx(string) // strip the px off the size
{
	tempVal=eval(string.substring(0,string.indexOf('p'))); 
	return(tempVal); // return the value
}

function getCurrMonth() // find the current month
{
	timeNow = new Date(); // set timeNow to the current date
	
	currMonth=timeNow.getMonth(); // get the current month
	
	return(currMonth);
}

function dynamicLoadScript(url) // dynamically locad a javascript file into the page
{
	var e=document.createElement("script"); // create a script object
	e.src=url; // set the source to the url of the javascript files
	e.type="text/javascript"; // set type to a javascript files
	document.getElementsByTagName("head")[0].appendChild(e); // append the loaded file into the page
}


function findScreenSize() // find the size of the web page window
{
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		WebWidth = window.innerWidth;
		WebHeight = window.innerHeight;
	} else if( document.documentElement &&
		( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		WebWidth = document.documentElement.clientWidth;
		WebHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		WebWidth = document.body.clientWidth;
		WebHeight = document.body.clientHeight;
	}
}

