//*** TACIT DESIGN JAVASCRIPT FUNCTION LIBRARY **********************************************************************
//
//	  Version 0.6 (18 May 2002)
//
//    COPYRIGHT 2002. ALL RIGHTS RESERVED 
//
//    All original work including code, content and artwork remains the property of its author
//	  and/or creator and must not be reproduced, modified, disassembled, transmitted, stored or translated
//	  in anyway, or used for any other purpose without prior written concent from its owner.
//	  Infringement of copyright is a civil and criminal offence which can result in heavy fines
//
//********************************************************************************************************************

// *** Library constants (MS-10.03.02) ***

var MSIE = "Microsoft Internet Explorer";
var NETSCAPE = "Netscape";

var PAGE_TITLE = "pageTitle";
var DATA_RECOG_ID = "dataID";

// *** A function to load a page depending on a condition (MS-18.05.02) ***

function conditionallyLoadPage(theCondition,thePage)
{
	if((theCondition == true) || (theCondition == 1))
	{
		window.location.href = thePage;
	}
}

// *** A function to determine screen size(MS-10.03.02) ***

function getScreenSize()
{
	return "Screen"+screen.width+"x"+screen.height;
}

// *** A function to determine browser and version (MS-10.03.02) ***

function getBrowserVrs()
{
	var thisBrowser = navigator.appName.substring(0,8);
	var thisVersion = navigator.appVersion.substring(0,1);

	return "Browser"+thisBrowser+thisVersion;
}

// *** A function to determine if browser is IE version 4 or above (MS-10.03.02) ***

function isIE4plus()
{
	var rc = false;

	if((navigator.appName == MSIE) && (parseInt(navigator.appVersion) >= 4))
	{
		rc = true;
	}
	return rc;
}

// *** A function to determine if browser is Netscape (MS-10.03.02) ***

function isNetscape()
{
	var rc = false;

	if(navigator.appName == NETSCAPE)
	{
		rc = true;
	}
	return rc;
}

// *** A function to add a favourite to your browser (MS-10.03.02) ***

function addFavourite(siteUrl, siteName)
{
	if(isIE4plus())
	{
		window.external.AddFavorite(siteUrl, siteName);
	}
	else if(isNetscape)
	{
		var msg = "To bookmark this site on Nescape press Ctrl and D";
	}
}

//***  A function to determine if a date is in a specified range (MS-30.03.02) ***

function isInDateRange(dateToCheck ,fromDate, toDate)
{
	var rc = false;

	if( (dateToCheck.valueOf() > fromDate.valueOf()) && (dateToCheck.valueOf() < toDate.valueOf()) )
	{rc = true;}

	return rc;
}//isDateValid

//***  A function to determine of a date is valid (MS-30.03.02) ***

function isDateValid(fromDate, toDate)
{
	var now = new Date;
	var rc = false;

//	if( (now.valueOf() > fromDate.valueOf()) && (now.valueOf() < toDate.valueOf()) )
	if((now ,fromDate, toDate))
	{rc = true;}

	return rc;
}//isDateValid

// *** A function to post a rotating set of banners (MS-23.02.02) ***

function circulateBanners(bannersArray,locRef,userViews,height,width)
{
	//BUILD ARRAY OF VALID OBJECTS

	var filteredBannersArray = new Array();
	var i;
	var sizeOfLocationArray;
	var validPost;
	var ad2 = 0;

	for(var ad1=0; ad1 < (bannersArray.length); ad1++)
	{
		validPost = false;
		i = 0;

		sizeOfLocationArray = bannersArray[ad1].locations.length;
	
		while((i < sizeOfLocationArray) && !validPost )
		{
			if( locRef == bannersArray[ad1].locations[i] )
			{
				validPost = true;
				var displayItToday = isDateValid(bannersArray[ad1].validFrom, bannersArray[ad1].validTo)

				if(displayItToday)
				{
					filteredBannersArray[ad2] = new Object();
					filteredBannersArray[ad2] = bannersArray[ad1];
					ad2++;
				}
			}
			i++;
		}
	}

	// POST BANNERS

	var bannerToPost = userViews%filteredBannersArray.length;

	document.write("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=1 WIDTH=125>")

	for(var y = 0;y < height;y++)
	{
		document.write("<TR>")

		for(var x = 0;x < width;x++)
		{
			document.write("<TD>")

				document.write("&nbsp<BR>")
				document.write(filteredBannersArray[bannerToPost].linkText);
				bannerToPost++;

				if(bannerToPost == (filteredBannersArray.length)) {bannerToPost = 0}

			document.write("</TD>")
		}
		document.write("</TR>")
	}
	document.write("</TABLE>")

}//circulateBanners

// *** A function to strip unwanted characters from a string (MS-17.11.01) ***

function removeCharacters(aString, unwantedChar)
{
	var thisChar;
	var newString = "";

	for(var pos = 0; pos < aString.length; pos++)
	{
		thisChar = aString.substr(pos,1);

		if(thisChar != unwantedChar)
		{
			newString = newString + thisChar;	
		}
	}

	return newString;
}

// *** A function to format the date as DD/MM/YY (MS-14.9.01) ***

function formatToDateDDMMYY(thisDateObj)
{
	var thisDate = thisDateObj.getDate();
	var thisMonth = thisDateObj.getMonth()+1;
	var thisYear = thisDateObj.getYear();

	thisYear = thisYear.toString();

	thisYear = thisYear.substring(2,5);

	return thisDate +"/"+ thisMonth +"/"+ thisYear;
}

// *** A function to load a web page into a frame of a frame set (MS-14.9.01) ***

function loadStaticPage(pageURL, frameName)
{
	parent.frames[frameName].location.href = pageURL;
}

// ***  A function to store a value in a cookie (MS-14.9.01) ***

function setCookieValue(cookieName,cookieValue,lifeSpanDays)
{
	// Declare and initialise variables 

	expiryDate = new Date
	expiryDate.setDate(expiryDate.getDate()+lifeSpanDays)

	// Save data to cookie

	document.cookie = cookieName + "=" + cookieValue + "; expires=" + expiryDate.toGMTString();
}

// *** A function to retrieve a value stored in a cookie (MS-14.9.01) ***

function getCookieValue(cookieName)
{
	// Declare and initialise variables

	var cookieValue = -1;		// return value. -1 if cookie not found
	var cookieFound = false;	// flag set to true if cookie found
	var cookieNum = 0; 			// index used when cookie is split into array

	// Split multiple cookies into an array "thisCookie"

	var thisCookie = document.cookie.split("; ");

	// Increment through array searching for the requested cookie
	
	while ((cookieNum < thisCookie.length) && (cookieFound == false)) 
	{
		// If the cookie is found store its value in "cookieValue"

		if (cookieName == thisCookie[cookieNum].split("=")[0])
		{
			cookieValue = thisCookie[cookieNum].split("=")[1];
 			cookieFound = true;
		}
		cookieNum++;
	}

	// Return the cookieValue to the caller

	return cookieValue; 
}

// *** A function to determine how many time a user has visited a web page (MS-14.9.01) ***

function recordUserHits(cookieName, lifeSpanDays)
{
	// Declare and initialise variables
    
	var userHits;

	// Get previous hits or initialise hits to zero

	userHits = eval(getCookieValue(cookieName));

	if (userHits == -1)
	{
    	userHits = 0;	
	}

	// Increment visit count

	userHits++;

	// Save data to cookie

	setCookieValue(cookieName,userHits,lifeSpanDays);
}

// *** A function to load two pages into a frameset (MS-14.9.01) ***

function loadTwoPages(firstURL, firstFrameName, secondURL, secondFrameName)
{
	parent.frames[firstFrameName].location.href = firstURL;
	parent.frames[secondFrameName].location.href = secondURL;
}
