
function bringWindowInFocus()
{
	window.focus();
}

function checkDbfForm(frm)
{
	return true;
}

function checkEmailAddress(field)
{	
	if (field.value != '' && field.value.search(/^.+@.+\../) == -1)
	{
		alert('Please use {ie. username@claytablet.com} format for all email entries.');
		field.value = '';
	}
}

function checkPhoneNumber(field)
{
	if (field.value != "")
	{
		var sNumber = field.value.replace(/\D/g, "");
		if (sNumber.length != 10)
		{
			alert('Please use {ie. (555)555-5555} format for all phone number entries.');
			field.value = '';
		}
		else
		{
			field.value = "(" + sNumber.substr(0, 3) + ")" + sNumber.substr(3, 3) + "-" + sNumber.substr(6, 4);
		}
	}
}

function checkZipCode(field)
{
	if (field.value != '' && field.value.search(/^\d\d\d\d\d$/) == -1)
	{
		alert('Please use {ie. 97201} format for all zip code entries.');
		field.value = '';
	}
}

function collapseChildren(parentID, sImgRoot)
{
	var parentImage = document.getElementById(parentID);
	if (parentImage.alt.search(/collapse/gi) != -1)
	{
		parentImage.src = sImgRoot + "/expand.gif";
		parentImage.alt = "+ Expand this thread";
	}
	
	var aChildren = getSubElements(parentID);
	for (var i = 0; i < aChildren.length; i++)
	{
		collapseChildren("parent" + aChildren[i], sImgRoot);
		
		var childID = "child" + aChildren[i];
		var child = document.getElementById(childID + "_" + parentID);
		child.style.display = "none";
	}
}

function confirmDelete(toDelete)
{
	if (confirm('You are about to delete ' + toDelete + '. Are you positive you would like to continue?'))
		return true;
	return false;
}

function expandChildren(parentID, sImgRoot)
{
	var parentImage = document.getElementById(parentID);
	if (parentImage.alt.search(/collapse/gi) != -1)
	{
		parentImage.src = sImgRoot + "/collapse.gif";
		parentImage.alt = "- Collapse this thread";
	}
	
	var aChildren = getSubElements(parentID);
	for (var i = 0; i < aChildren.length; i++)
	{
		var childID = "child" + aChildren[i];
		var child = document.getElementById(childID + "_" + parentID);
		child.style.display = "block";
	}
}

function formatIbillDollarAmount(sAmount, sFallback)
{
	sAmount = sAmount.replace(/\D/gi, "");
	if (!isNaN(sAmount))
	{
		return '$' + sAmount.substring(0, sAmount.length - 2) + "." + sAmount.substr(sAmount.length - 2, 2);
	}
	return sFallback;
}

function getSubElements(parentID)
{
	return null;
}

function insertFormat(frmField, sTool)
{
	var aTools = new Array();
	var sCode = "";
	aTools["bold"] = "Enter the text to format bold:";
	aTools["italic"] = "Enter the text to italicize:";
	aTools["underline"] = "Enter the text to underline:";
	aTools["increase"] = "Enter the text to enlarge:";
	aTools["decrease"] = "Enter the text to reduce:";
	aTools["leftalign"] = "Enter the text to align left:";
	aTools["centeralign"] = "Enter the text to center:";
	aTools["rightalign"] = "Enter the text to align right:";
	
	if (aTools[sTool])
	{
		var sText = prompt(aTools[sTool], '');
		if (sText == null)
			return;
		if (sText.length)
			sCode = '[' + sTool + ']' + sText + '[/' + sTool + ']';
		else
			alert('You did not enter the text to be formatted.');
	}
	
	if (!sCode.length)
	{
		switch(sTool)
		{
			case "link":
				var sLink = prompt("Enter the URL of the link:", 'http://');
				if (sLink == null)
					return;
				var sText = prompt("Enter the text of the link:", '');
				if (sText == null)
					return;
				if (sLink.length && sText.length)
					sCode = '[link url="' + sLink + '"]' + sText + '[/link]';
				else
					alert('You did not enter the link URL and the link text.');
				break;
			case "line":
				sCode = '[line/]';
				break;
		}
	}
	
	if (sCode.length)
		frmField.value += sCode;
	frmField.focus();
	frmField.seelct();
	
}

function loadImage(strSrc)
{
	var img = new Image();
	img.src = String(strSrc);
	return img;
}

function selectRadio(field)
{
	field.checked = true;
}

function setCursor(objField)
{
	objField.focus();
	objField.select();
}

function swap(img, imgSwap)
{
	img.src = imgSwap.src;
}

function toggleState(parentID, sImgRoot)
{
	var parentImage = document.getElementById(parentID);
	if (parentImage.alt.search(/expand/gi) != -1)
	{
		parentImage.src = sImgRoot + "/collapse.gif";
		parentImage.alt = "- Collapse this thread";
		expandChildren(parentID, sImgRoot);
	}
	else
	{
		parentImage.src = sImgRoot + "/expand.gif";
		parentImage.alt = "+ Expand this thread";
		collapseChildren(parentID, sImgRoot);
	}
	return true;
}

function validate(field, sFieldString, bOverrideAlert)
{
	var sMessage = "";
	if (!field)
	{
		sMessage += " - ERROR: BAD FIELD\n";
		return sMessage;
	}
	
	var bIsError = false;
	var sErrorMessage = "";
	switch (String(field.type))
	{
		case "checkbox":
			bIsError = !field.checked;
			sErrorMessage += " - You must check the \'" + sFieldString + "\' field\n";
			break;
		case "select-one":
			bIsError = field.value.replace(/\s/g, '') == "";
			sErrorMessage += " - You must select a value from the \'" + sFieldString + "\' field\n";
			break;
		case "select-multiple":
			bIsError = field.value.replace(/\s/g, '') == "";
			sErrorMessage += " - You must select at least one value from the \'" + sFieldString + "\' field\n";
			break;
		case "file":
			bIsError = field.value.replace(/\s/g, '') == "";
			sErrorMessage += " - You must browse for a file in the \'" + sFieldString + "\' field\n";
			break;
		default:
			bIsError = field.value.replace(/\s/g, '') == "";
			sErrorMessage += " - You must enter a value in the \'" + sFieldString + "\' field\n";
			break
	}
	
	if (bIsError)
	{
		sMessage = !bOverrideAlert ? sErrorMessage : " - " + sFieldString + "\n";
	}
	return sMessage;
}

function verifyPasswordConstruction(p)
{
	p = String(p);
	if (p.length < 6)
	{
		return ' - Your password must be at least 6 characters in length\n';
	}
	if (p.search(/\W/gi) != -1)
	{
		return ' - Your password should not include any spaces or special characters\n';
	}
	return '';
}

