
function clock() {
if (!document.layers && !document.all) return;
var digital = new Date();
var hours = digital.getHours();
var minutes = digital.getMinutes();
var seconds = digital.getSeconds();
var amOrPm = "AM";
if (hours > 11) amOrPm = "PM";
if (hours > 12) hours = hours - 12;
if (hours == 0) hours = 12;
if (minutes <= 9) minutes = "0" + minutes;
if (seconds <= 9) seconds = "0" + seconds;
dispTime = hours + ":" + minutes + ":" + seconds + " " + amOrPm;
if (document.layers) {
document.layers.pendule.document.write(dispTime);
document.layers.pendule.document.close();
}
else
if (document.all)
pendule.innerHTML = dispTime;
setTimeout("clock()", 1000);
}



function IsValidTime(field, timeStr) {
// Checks if time is in HH:MM:SS AM/PM format.
// The seconds and AM/PM are optional.

var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

var matchArray = timeStr.match(timePat);

if ((matchArray == null) && (timeStr != "")) {

	alert("Time is not in a valid format.");
	field.focus();

	return false;
}

if (timeStr == "") {

return false;

}


hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0  || hour > 23) {
alert("Hour must be between 0 and 23 for 24 Hour Time)");
field.focus();
return false;
}
if (hour <= 12 && ampm == null) {
if (false) {
alert("You must specify AM or PM.");
field.focus();
return false;
   }
}
if  (ampm != null) {
alert("You can't specify AM or PM for 24 Hour Time.");
field.focus();
return false;
}
if (minute<0 || minute > 59) {
alert ("Minute must be between 0 and 59.");
field.focus();
return false;
}
if (second != null && (second < 0 || second > 59)) {
alert ("Seconds must be between 0 and 59.");
field.focus();
return false;
}
return true;
}

function numvalidate(fieldName, fieldValue, decplaces) {

decallowed = decplaces;  // how many decimals are allowed?

if (isNaN(fieldValue) && fieldValue != "") {
alert("Value does not appear to be a valid number!");
fieldName.select();
fieldName.focus();
}
else {
if (fieldValue.indexOf('.') == -1) fieldValue += ".";
dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);

if (dectext.length > decallowed)
{
alert ("Please enter a number with up to " + decallowed + " decimal places!");
fieldName.select();
fieldName.focus();
      }
else {
 //successfully validated
return true;
      }
   }
}

function textvalidate(field, vtype) {

var nums = "0123456789";
var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
var valid = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ|,@.$£ ";
var curr = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ|£$ ";
var all = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ|£$-_+%.#[] ";
var ok = "yes";
var temp;


switch(vtype) {


//alphabetic
case 'a':

	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
	
			if (alpha.indexOf(temp) == "-1") ok = "no"; }

			if (ok == "no") {
					alert("Invalid entry!  Only letters are accepted!");
					field.focus();
					field.select();
					
   	}

	break;


//numbers
case 'n':


	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
	
			if (nums.indexOf(temp) == "-1") ok = "no"; }

			if (ok == "no") {
					alert("Invalid entry!  Only numbers are accepted!");
					field.focus();
					field.select();
   	}
	

	break;

//numbers
case 'c':

	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
	
			if (curr.indexOf(temp) == "-1") ok = "no"; }

			if (ok == "no") {
					alert("Invalid entry!  Only alphabetic plus dashes are accepted!");
					field.focus();
					field.select();
   	}
	break;

//numbers
case 'v':

	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
	
			if (all.indexOf(temp) == "-1") ok = "no"; }

			if (ok == "no") {
					alert("Invalid entry!  Only alphanumeric plus currency characters are accepted!");
					field.focus();
					field.select();
   	}
	break;

case 'd':

	//dates handled elsewhere
	break;

default:

	for (var i=0; i<field.value.length; i++) {
			temp = "" + field.value.substring(i, i+1);

			if (valid.indexOf(temp) == "-1") ok = "no"; }
		
			if (ok == "no") {
					alert("Invalid entry!  Only characters, numbers and comma are accepted!");
					field.focus();
					field.select();
   					}

	}

}


function ignoreSpaces(string) {
var temp = "";
string = '' + string;
splitstring = string.split(" ");
for(i = 0; i < splitstring.length; i++)
temp += splitstring[i];
return temp;
}

function validateForm(formobj) {

var req = "required";

	//-2 to remove the last two submit and reset buttons
	for(i=0; i < formobj.elements.length-2; i++) {


		if (formobj) {


			//var strname = 

			if (formobj.elements[i].name.match(/required/g) && formobj.elements[i].value == "") {


				alert("You have not filled in all the required fields! ");

				formobj.elements[i].focus();

				return false;

			}
			else
			{
				if (formobj.elements[i].name.match(/required/g) && formobj.elements[i].value != "") {

					var strname = formobj.elements[i].name;
													
					formobj.elements[i].name = strname.substring(0,strname.length-req.length);
					
				}
				else
				{

				}
				
			}	 

		}


	}


	return true;

}


function containvalidate(field, cword) {

	var re = new RegExp(cword,"g");

	if (field.value.match(re) || field.value == "") {

		

	}
	else {
		
		alert("Field must contain: " + cword);
		field.focus();
		
		

	}

}

function notcontain(field, cword) {

	var re = new RegExp(cword,"g");

	if (field.value.match(re) && field.value != "") {

		alert("Field must not contain: " + cword);
		field.focus();
		

	}
	else {
		
		
		

	}

}

function NewWindow(mypage, myname, w, h, scroll) {

	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;

	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'

	win = window.open(mypage, myname, winprops)


	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }

}

function replaceBR(fld, findText, replaceText) {

	var originalString = "";
	var pos = 0;
	var len = findText.length;
	
	originalString = fld.value;
	pos = originalString.indexOf(findText);
	
	
	while (pos != -1) {

		preString = originalString.substring(0,pos);
		postString = originalString.substring(pos+len, originalString.length);
		originalString = preString + replaceText + postString;
		pos = originalString.indexOf(findText);

	}


	fld.value = originalString;

	return originalString;

}