//Global Functions & settings version=2.34

/*******************
* global variables *
********************/

currentLink = 0;		//current highlighted link


/************
* 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');
}

//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 backPage() {
	this.window.history.back();
}

function printPage(){
	this.focus();
	if (window.print) {
	    window.print();  
	}
}


/**********************
* string manipulation *
***********************/

//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;
}


/*****************
* 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');

	formField = eval('document.' + formName + '.' + fieldName);
	formField.value = pad(dateDay,2) + '/' + pad(dateMonth,2) + '/' + pad(dateYear,2);
	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;
		}
	}
}
