
	var n = 0;
	var ns4 = false;
	var ie = false;
	var ns6 = false;



//Adapted from Source code from www.open.ac.uk
function BrowserDetect()
{
	var browserInfo;

	if (document.layers) {
		ns4 = true;
	}
	if (document.all && (navigator.appVersion.indexOf("MSIE") != -1)) {
		ie = true;
	}
	ns6 = (!document.all && !document.layers && navigator.appName == "Netscape" && parseInt(navigator.appVersion) >=5)? true : false;

	if (ie) {
		browserInfo = navigator.appName + " version " + ((navigator.appVersion.split("; ")[1]).split(" ")[1]) + " detected";
	}
	else if (navigator.vendorSub) {
		browserInfo = navigator.appName + " version " + navigator.vendorSub + " detected";
	}	
	else {
		browserInfo = navigator.appName + " version " + (navigator.appVersion.split(" ")[0]) + " detected";
	}

	return browserInfo;

}

function FindObject(objName, doc)
{
	var p;
	var i;
	var x;
	
	if (!doc) {
		doc = document;
	}
	if ((p = objName.indexOf("?")) > 0 && parent.frames.length) {
		doc = parent.frames[objName.substring(p+1)].document;
		objName = objName.substring(0,p);
	}
	if (!(x = doc[objName]) && doc.all) {
		x = doc.all[objName];
	}
	for (i=0;!x && i < doc.forms.length;i++) {
		x = doc.forms[i][objName];
	}
	for (i=0;!x && doc.layers && i < doc.layers.length;i++) {
		x = FindObject(objName, doc.layers[i].document);
	}
	if (!x && doc.getElementById) {
		x = doc.getElementById(objName);
	}
	return x;
}

function SelectGoMenu(selName, selTarget, restore)
{
	var selObject = FindObject(selName);
	if (selObject) {
		JumpTo(selTarget,selObject,restore);
	}	
}

function JumpTo(selTarget,selObject,restore)
{
	eval(selTarget + ".location='" + selObject.options[selObject.selectedIndex].value + "'");
	if (restore) {
		selObject.selectedIndex = 0;
	}
}


function GetCookieVal(cookieName)
{
	thisCookie = document.cookie.split("; ");
	
	for (i=0; i<thisCookie.length; i++) {
		if (cookieName == thisCookie[i].split("=")[0]) {
			return thisCookie[i].split("=")[1];
		}
		else {
			return 0;
		}
	}
}
	
function chgImg(imgID,newImg)
{		
	if (document.getElementById){
		document.getElementById(imgID).src= newImg.src;
	}
	else if (document.images) {
		document[imgID].src= newImg.src;
	}
}
function drawChart(cookieName, chartWidth)
{
	if (document.cookie) {
			if(chartWidth < 200) {
				chartWidth = 200; 
			}
			re=/^(\S)(\S+)$/;
			re.exec(cookieName);
			chartHead = RegExp.$1.toUpperCase() + RegExp.$2.toLowerCase();
			chartData = GetCookieVal(cookieName);
			arrayVals = EscapeCookieVals(chartData);
			arrayLength = arrayVals.length/2;
			barWidth = (chartWidth - 47)/arrayLength;
		
			document.write("<table class='chart'><tbody><tr><td class='chartarea'>" + chartHead);
			document.write("<table class='grapharea' cellspacing='0' width='" + barWidth * arrayLength + "'><tbody><tr>");
		
			//loop here for td's
			for (i=0;i<arrayLength;i++) {
				document.write("<td class='chartvalues' width='" + barWidth + "'>");
				document.write(arrayVals[(i * 2) + 1] + "<br><img border='0' src='images\/blue_bar.gif' width='" + (barWidth/4) + "' height='" + arrayVals[(i * 2) + 1] + "'><\/td>");
			}
		
			document.write("<\/tr><\/tbody><\/table><table cellspacing='0' width='" + barWidth * arrayLength + "'><tbody><tr>");
		
			//loop here for categories
			for (i=0;i<arrayLength;i++) {
				document.write("<td class='chartcat'>" + arrayVals[i * 2] + "<\/td>");
			}
		
			document.write("<\/tr><\/tbody><\/table><\/td><\/tr><\/tbody><\/table>");
	}
	else {
		document.write("No chart data available");
	}
}
function EscapeCookieVals(cookieValue)
{
	namedVals = new Array;
	splitVals = cookieValue.split("%2C");
	for (i=0; i<splitVals.length; i++) {
		namedVals[i * 2] = (splitVals[i].split("%3D")[0]);
		namedVals[(i * 2) + 1] = (splitVals[i].split("%3D")[1]);
	}
	return namedVals;
}
function MonthSelected(fieldName,fieldSize)
{
	now = new Date;
	nowMonth = now.getMonth();
	
	document.write("<select name='" + fieldName + "' size='" + fieldSize + "' id='" + fieldName + "' class='textbox'>");
	
	for (i=0;i<12;i++) {
		if (i == nowMonth) {
			sel = " selected";
		}
		else {
			sel = "";
		}
		
		tmpMonth = i + 1
		if (tmpMonth < 10) {
			document.write("<option" + sel + " value='" + tmpMonth + "'>0" + tmpMonth + "<\/option>");
		}
		else {
			document.write("<option" + sel + " value='" + tmpMonth + "'>" + tmpMonth + "<\/option>");
		}
	}	
	
	document.write("<\/select>");
}
function YearSelected(fieldName, fieldSize, minusYrs, plusYrs)
{
	now = new Date;
	nowYear = now.getFullYear();
	startYr = nowYear - minusYrs;
	endYr = nowYear + plusYrs;
	if (endYr < startYr) {return false}
	document.write("<select name='" + fieldName + "' size='" + fieldSize  + "' id='" + fieldName + "' class='textbox'>");
	for (i=startYr;i<endYr;i++) {
		if (i == nowYear) {
			sel = " selected";
		}
		else {
			sel = "";
		}
		document.write("<option" + sel + " value='" + i + "'>" + i + "<\/option>");
	}
	document.write("<\/select>");
}

function validateFirst(fName) {
	if (fName.value != "") {
	
		re=/^[a-zA-z]+$/;
		valid = re.test(fName.value);
		if (!valid) {
			alert("One word only for First Name please and only letters!");
			fName.focus();
			fName.select();
		}
		return valid;
	}
}
function validateLast(lName) {
	if (lName.value != "") {
	
		re=/^[a-zA-z]+[-]?\s?[a-zA-z]*$/;
		valid = re.test(lName.value);
		if (!valid) {
			alert("Last Name should only consist of letters,\rwith an optional dash or space\rfor double barrelled names!");
			lName.focus();
			lName.select();
		}
		return valid
	}
}
function validatePhone(phone) 
    {
	if (phone.value != "") {
	    re=/^\+?\d{1,3}?\s?\(?\d{4,5}\)?\s?\d{4,8}(\s*x\d+)?$/i;
	    valid = re.test(phone.value);
	    if (!valid) {
		alert("Valid Telephone number formats:\n\n(NNNNn) NNNNnnnn (Minimum requirement (n,brackets and spaces optional))" + "\n\n+Nnn(NNNNn) NNNNnnnn (Including Country Code)\r\rExtension numbers (if applicable) should be prefixed with x eg." + "\n(NNNNn)NNNNnnnn  xNn...\n\nN = Required digit 0-9, n = Optional digit 0-9");
		phone.focus();
		phone.select();
	    }
	    return valid;
	}
    }
function validateCC(ccNo) 
{
	if (ccNo.value != "") {
	
		re=/^(\d{4})\s?(\d{4})\s?(\d{4})\s?(\d{4})$/;
		valid = re.test(ccNo.value);
		if (!valid) {
			alert("Credit Card Number must be 16 digits!");
			ccNo.focus();
			ccNo.select();
		}
		return valid;
	}
}
function validateEMail(email) 
{
	if (email.value != "") {
		re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
		valid = re.test(email.value);
		if (!valid) {
			alert("Invalid email address!");
			email.focus();
			email.select();
		}
		return valid;
	}
}

function validateExpDate(expmonth,expyr)
{
	now = new Date;
	nowYr = now.getFullYear();
	nowMonth = now.getMonth();
	valid = true;
	if (!((expyr>nowYr + 1) || (expyr>nowYr && expmonth > 1))) { // Card well in date
		if (expyr>nowYr) { // Card Expires next year
			expmonth =+ 12;
		}
		if ((expmonth - nowMonth) < 4) { //Credit card expires soon
			if ((expmonth - (nowMonth + 1)) < 0) { //CardExpired
				alert("Your credit card has expired!");
				valid = false;
			}
			else {
				 alert("Your credit card expires in " + (expmonth - nowMonth) + " months!");
			} 
		}
	}
	return valid;
}

function clearInitial(textField,initialValue)
{
	if (textField.value == initialValue) {
		 textField.value = '';
	}
}

function FormatDateAndTime()
{
	now = new Date;
	nowDay = now.getDay();
	nowDays = now.getDate();
	nowMonth = now.getMonth();
	nowYear = now.getFullYear();
	dayArray = new Array('Sunday, ','Monday, ','Tuesday, ','Wednesday, ','Thursday, ','Friday, ','Saturday, ');
	monthArray = new Array('January ','February ','March ','April ','May ','June ','July ','August ','September ','October ','November ','December');
	nthArray = new Array('th','st','nd','rd');
	dayNth = nthArray[0];
	
	if(!(nowDays > 3 && nowDays < 21)) {
		dayLast = nowDays % 10;
		if (dayLast < 4) {
			dayNth = nthArray[dayLast];
		}
	}

	return (dayArray[nowDay] + nowDays + dayNth + ' ' + monthArray[nowMonth] + ' ' + nowYear);
}

function WelcomeMsg()
{
	now = new Date;
	nowHours = now.getHours();
	msgArray = new Array('Good morning, ','Good afternoon, ','Good evening, ','Wow! You\'re up early, ','When do you sleep? Anyway ');
	
	if (nowHours > 22 || nowHours < 3) {
		returnIndex = 4;
	}
	else if (nowHours > 2 && nowHours < 7) {
		returnIndex = 3;
	}
	else if (nowHours > 6 && nowHours < 12) {
		returnIndex = 0;
	}
	else if (nowHours > 11 && nowHours < 18) {
		returnIndex = 1;
	}
	else {
		returnIndex = 2;
	}
	
	return msgArray[returnIndex];
}

