//Global Functions & settings version=2.6

/*******************
* global variables *
********************/

currentLink = 0;		//current highlighted link
currentPage = 0;		//current page


/************
* constants *
*************/

//date constants
var MINUTE = 60 * 1000
var HOUR = MINUTE * 60
var DAY = HOUR * 24
var WEEK = DAY * 7


/****************************
* general browser functions *
*****************************/

function checkFrame(page) {
	if (window.top == self) {
		this.location="../main.asp?page=" + page;
	} else {
		return true;
	}
}

function newWindow(url,inName,w,h) {
	if (inName == '') {
		winName = 'info';
	} else {
		winName = inName;
	}
	window.open(url,winName,'width=' + w + ',height=' + h + ',menubar=no,directories=no,toolbar=no,location=no,status=0,resizable=yes,scrollbars=yes');
}

function newWindowF(url,inName,w,h) {
	if (inName == '') {
		winName = 'info';
	} else {
		winName = inName;
	}
	window.open(url,winName,'width=' + w + ',height=' + h + ',menubar=no,directories=no,toolbar=no,location=no,status=0,resizable=no,scrollbars=no');
}

//as newWindow but without scroller
function newWin(url,inName,w,h) {
	if (inName == '') {
		winName = 'info';
	} else {
		winName = inName;
	}
	window.open(url,winName,'width=' + w + ',height=' + h + ',menubar=no,directories=no,toolbar=no,location=no,status=0,resizable=no,scrollbars=no');
}

function focusWindow() {
	this.window.focus();
}

function closeWindow() {
	this.window.close();
}

function on(image) {
	if(currentLink != 0) document['link' + currentLink].src = eval('img' + currentLink + "_off.src");
	document['link' + image].src = eval('img' + image + '_on.src');
}

function off(image) {
	if(currentLink != 0) document['link' + currentLink ].src = eval('img' + currentLink + "_on.src");
	if(currentLink == 0 || currentLink != image) document['link' + image].src = eval('img' + image + "_off.src");
}

function linkOn(linkNum) {
	off(currentPage);
	on(linkNum);
}

function linkOff(linkNum) {
	off(linkNum);
	on(currentPage);
}

function backPage() {
	this.window.history.back();
}

function printPage(){
	this.focus();
	if (window.print) {
	    window.print();  
	}
}

function bookmark(url, name) {
	if (navigator.appName == 'Microsoft Internet Explorer') {
		window.external.AddFavorite(url, name);
	} else {
		alert('Sorry, this feature is only available on Microsoft Internet Explorer');
	}
}


/*******************
* string & numeric *
********************/

//return a string comprising a repeated substring 
function makeString(strLen,strText) {
	var outText = '';
	for(n=1; n<=strLen; n++) outText += strText;
	return outText;
}

//return number or string with specified leading 0's
function pad(inNum,padLen) {
	outText = inNum.toString();
	padLen -= outText.length;
	if(padLen > 0) outText = makeString(padLen,'0') + outText;
	return outText;
}

//validate email address
function validateEmail(email) {
	if (email != '') {
		return email.search(/.+@.+\..+/);
	} else {
		return -1;
	}
}


//check if number is numeric
function isInt(num) {
	if (num == '' || num.search(/\D+/) >= 0) {
		return false;
	} else {
		return true;
	}
}


/*****************
* date functions *
******************/

//builds date string from date part fields
function buildDate(fieldName,formName) {
	dateDay = eval('document.' + formName + '.p_d_' + fieldName + '.value');
	dateMonth = eval('document.' + formName + '.p_m_' + fieldName + '.value');
	dateYear = eval('document.' + formName + '.p_y_' + fieldName + '.value');

	if(typeof eval('document.' + formName + '.p_h_' + fieldName) == 'object') {
		dateHour = pad(eval('document.' + formName + '.p_h_' + fieldName + '.value'),2);
		dateMin = pad(eval('document.' + formName + '.p_mm_' + fieldName + '.value'),2);
		timeStr = ' ' + dateHour + ':' + dateMin;
	} else {
		timeStr = '';
	}
	
	formField = eval('document.' + formName + '.' + fieldName);
	formField.value = pad(dateDay,2) + '/' + pad(dateMonth,2) + '/' + pad(dateYear,2) + timeStr;
	if(formField.value == '00/00/00') formField.value = '';
}

//put day, month & year in respective form fields
function setDate(fieldName,formName,dayVal,monthVal,yearVal) {
	eval('document.' + formName + '.p_d_' + fieldName + '.value = ' + pad(dayVal,2));
	eval('document.' + formName + '.p_m_' + fieldName + '.value = ' + pad(monthVal,2));
	eval('document.' + formName + '.p_y_' + fieldName + '.value = ' + pad(yearVal,2));

	buildDate(fieldName,formName);
}

//convert dd/mm/yy string & return millisecs
function getUKDate(inDate) {
	dayVal		= inDate.substr(0,2);
	monthVal	= inDate.substr(3,2);
	yearVal		= inDate.substr(6,2);

	var newDate = new Date();

	newDate.setDate(dayVal);
	newDate.setMonth(monthVal - 1);
	newDate.setFullYear(yearVal);

	return newDate.valueOf();

}


/**************
* right click *
***************/
function clickIE() {
	if (document.all) {
		return false;
	}
}

function clickNS(e) {
	if (document.layers||(document.getElementById&&!document.all)) {
		if (e.which==2||e.which==3) {
			return false;
		}
	}
}

