// Set Global Variables
var theSpaces = / /g;
var theChars = /\D/g;
var theNums = /\d/g;
var newWindow;

// Swap Image
function swapImage(theAction, theImage, theOriginalImage) {
if (theAction == 1) {
	document[theImage].src = eval(theImage + "_On.src");
	}
if (theAction == 0) {
	document[theImage].src = eval(theImage + "_Off.src");
	}
if (theOriginalImage) {
	document[theOriginalImage].src = eval(theOriginalImage + "_On.src");
	}
}

// Swap Style
function swapStyle(theID, theClass) {
	theID.className = theClass;
}

// Give Focus
function giveFocus(theForm, theField) {
	eval("document.forms[" + theForm + "]." + theField + ".focus()");
}

// Write Email
function writeEmail(theUser, theDomain, theText) {
var theAddress = theUser + "@" + theDomain;
if (!theText) {
	document.write("<A HREF=\"mailto:" + theAddress + "\">" + theAddress + "</A>");
	}
else {
	document.write("<A HREF=\"mailto:" + theAddress + "\">" + theText + "</A>");
	}
}

// Make Remote
function makeRemote(theURL, theWidth, theHeight, theOptions) {
var theCenterWidth = (window.screen.width - theWidth) / 2;
var theCenterHeight = (window.screen.height - theHeight) / 2;
if (newWindow) {
	newWindow.close();
	}
	newWindow = window.open(theURL, "Remote", "Width=" + theWidth + ",Height=" + theHeight + "," + theOptions);
	newWindow.moveTo(theCenterWidth, theCenterHeight - 50);
	newWindow.focus();
}

// 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 theLastAt = theField.value.lastIndexOf("@");
var thePeriod = theField.value.lastIndexOf(".");
var theDoublePeriod = theField.value.indexOf("..");
if (!(theLength < 7 || theAt < 2 || (thePeriod > theLength - 2 || thePeriod < theLength - 4) || theAt > thePeriod - 2 || theAt < theLastAt || theDoublePeriod > -1)) {
	return true;
	}
}

// Left Trim
function leftTrim(theString) {
	return theString.replace(/^\s*/, "");
}

// Right Trim
function rightTrim(theString) {
	return theString.replace(/\s*$/, "");
}

// Confirm Delete
function confirmDelete(theURL) {
if (confirm("Are you sure you wish to delete this item?\nThis action cannot be undone.")) {
	location.href = theURL;
	}
}
