// Set Global Variables
var theSpaces = / /g;
var theChars = /\D/g;
var theNums = /\d/g;
var newWindow;

// Show Layer
function showLayer(theLayer, thePositionX, thePositionY) {
if (document.getElementById || document.all) {
	eval(theLayer + ".style.left = thePositionX");
	eval(theLayer + ".style.top = thePositionY");
	eval(theLayer + ".style.visibility = 'visible'");
	}
}

// Hide Layer
function hideLayer(theLayer) {
if (document.getElementById || document.all) {
	eval(theLayer + ".style.visibility = 'hidden'");
	}
}

// Write Email
function writeEmail(theUser, theDomain) {
var theAddress = theUser + "@" + theDomain
	document.write("<A HREF=\"mailto:" + theAddress + "\">" + theAddress + "</A>");
}

// Make Remote
function makeRemote(theURL, Width, Height) {
if (!newWindow || newWindow.closed) {
	newWindow = window.open(theURL, "Remote", "Width=" + Width + ",Height=" + Height + ",ScrollBars=yes,Resizable=yes");
	newWindow.focus();
	}
else {
	newWindow.location.href = theURL;
	newWindow.focus();
	}
}

// Tool Action
function toolAction(theAction, theWidth, theHeight) {
var theURL = document.URL;
var theTitle = document.title;
if (theAction == "Print") {
	if (theURL.indexOf("?") < 0) {
		var thePrintURL = theURL + "?Print=Yes";
		}
	else {
		var thePrintURL = theURL + "&Print=Yes";
		}
	makeRemote(thePrintURL, theWidth, theHeight);
	}
else if (theAction == "Send") {
	var theSendURL = "/SendPage.cfm?URL=" + escape(theURL) + "&Title=" + escape(theTitle);
	makeRemote(theSendURL, theWidth, theHeight);
	}
else if (theAction == "Save") {
	if (window.external) {
		window.external.AddFavorite(document.URL, document.title);
		}
	else {
		alert("Press Ctrl-D to Bookmark in Netscape.\nPress Ctrl-T to Bookmark in Opera\nFor Others, See Browser Help.");
		}
	}
}

// Check Zip
function checkZip(theField) {
	theField.value = theField.value.replace(theChars, "");
var theLength = theField.value.length;
var theDash = theField.value.indexOf("-");
if (theLength == 5) {
	return true;
	}
if (theLength == 9) {
	var Part1 = theField.value.substr(0,5);
	var Part2 = theField.value.substr(5,4);
	theField.value = Part1 + "-" + Part2;
	return true;
	}
}

// Check Phone
function checkPhone(theField) {
	theField.value = theField.value.replace(theChars, "");
if (!isNaN(theField.value) && theField.value.length == 10) {
	var Part1 = theField.value.substr(0,3);
	var Part2 = theField.value.substr(3,3);
	var Part3 = theField.value.substr(6,4);
	theField.value = Part1 + "-" + Part2 + "-" + Part3;
	return true;
	}
}

// Check Email
function checkEmail(theField) {
var theInvalidChars = /[^A-Za-z0-9._@]/g;
	theField.value = theField.value.replace(theInvalidChars, "");
var theLength = theField.value.length;
var theAt = theField.value.indexOf("@");
var thePeriod = theField.value.lastIndexOf(".");
if (!(theLength < 8 || theAt < 2 || (thePeriod > theLength - 3 || thePeriod < theLength - 5) || theAt > thePeriod - 3)) {
	return true;
	}
}

// Check Password
function checkPassword(theField) {
if (theField.value.length >= 8 && theField.value.length <= 20) {
	for (i = 0; i <= 9; i++) {
		if (theField.value.indexOf(i) != -1) {
			return true;
			}
		}
	}
}

// Format Currency
function formatCurrency(theValue) {
var theValue = "" + Math.round(eval(theValue) * Math.pow(10,2))
while (theValue.length <= 2) {
	theValue = "0" + theValue;
	}
var theDecimal = theValue.length - 2;
var theDollars = theValue.substring(0,theDecimal)
var theCents = theValue.substring(theDecimal,theValue.length);
var theCommas = /(-?\d+)(\d{3})/
while (theCommas.test(theDollars)) {
	theDollars = theDollars.replace(theCommas,"$1,$2")
	}
return "$" + theDollars + "." + theCents;
}

// Confirm Delete
function confirmDelete(theURL) {
if (confirm("Are you sure you wish to delete this item?\nThis action cannot be undone.")) {
	location.href = theURL;
	}
}