// GLOBAL VARIABLES				// USED BY FUNCTION
var submitCount = 0;			// SubmitFormOnlyOnce


/************************************************************************
* changeImage
*	changes out images during rollovers 
************************************************************************/
function changeImage(imgName,imgObj,layer) {
	/*
		function to do rollovers of images
	*/
	if (document.images) {
		if (document.layers) {
			if (layer!=null){
				eval('document.layers.'+layer+'.document.images["'+imgName+'"].src = '+imgObj+'.src');
			} else {
				document.images[imgName].src = eval(imgObj+".src");
			}
		} else {
			document.images[imgName].src = eval(imgObj+".src");
		}
	}
}


/************************************************************************
* CharacterLimiterCounter
*	limits character count and shows dynamic count of characters as user 
*   is typing them in the text area
************************************************************************/
function CharacterLimiterCounter(field, maxlimit, cntfield) 
{
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else
		cntfield.value = maxlimit - field.value.length;
}


/************************************************************************
* EmailAddressValidation
*	shows a message (alertText) and returns false if no e-mail address 
*	has been specified in the input text box (entered) or if the
*	address appears invalid due to a number of conditions checked
************************************************************************/
function EmailAddressValidation(entered, alertText)
{
	with (entered)
	{
		var len=value.length
		var apos=value.indexOf("@");
		var dotpos=value.lastIndexOf(".");
		var lastpos=value.length-1;
		// if length = 0
		// or "@" is the first character or doesn't exist
		// or "." doesn't follow "@" with at least 2 spaces between them
		// or there are more than 3 characters following the "."
		// or there are less than 2 characters following the "."
		if (len==0 || apos<1 || dotpos-apos<2 || lastpos-dotpos>4 || lastpos-dotpos<2) 
		{
			if (alertText) 
				alert(alertText);
			entered.focus();
			return false;
		}
		else 
			return true;
	}
}


/************************************************************************
* EmptyValidation
*	shows a message (alertText) and returns false if no data has been 
*	entered in the input text box (entered)
************************************************************************/
function EmptyValidation(entered, alertText)
{
	var strValue = Trim(entered.value);
	if (strValue == null || strValue == "" || strValue == "undefined")
	{
		if (alertText)
		{
			alert(alertText);
		} 
		entered.focus();
		entered.select();
		return false;
	}
	else 
		return true;
}


/************************************************************************
* popupWindow
*	opens url in a new window
************************************************************************/
function popupWindow(sURL, sWindowName) 
{ 
	var pwWidth = 400;
	var pwHeight = 200;
	var posLeft = (screen.width - pwWidth) / 2;
	var posTop = (screen.height - pwHeight) / 2;
	newWindow = window.open(sURL, sWindowName,'width=' + pwWidth + ',height=' + pwHeight +',resizable=no,scrollbars=no,status=no,toolbar=no,location=no,menubar=no,directories=no,top=' + posTop + ',left=' + posLeft); 
	newWindow.focus();
}


/************************************************************************
* popupWindowSizeable
*	opens url in a new window
************************************************************************/
function popupWindowSizeable(sURL, sWindowName, iWidth, iHeight) 
{ 
	var pwWidth = iWidth;
	var pwHeight = iHeight;
	var posLeft = (screen.width - pwWidth) / 2;
	var posTop = (screen.height - pwHeight) / 2;
	newWindow = window.open(sURL, sWindowName,'width=' + pwWidth + ',height=' + pwHeight +',resizable=no,scrollbars=no,status=no,toolbar=no,location=no,menubar=no,directories=no,top=' + posTop + ',left=' + posLeft); 
	newWindow.focus();
}


/************************************************************************
* preload
*	image preloader
************************************************************************/
function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()');
		eval(imgObj+'.src = "'+imgSrc+'"');
	}
}


/************************************************************************
* SelectValidation
*	shows a message (alertText) and returns false if no data has been 
*	selected in the dropdown list (entered)
************************************************************************/
function SelectValidation(entered, alertText)
{
	var idx = entered.selectedIndex;

	with (entered.options[idx])
		{
		if ( (value == 0) || (value == "") || (value == null) )
		{
			if (alertText) 
			{
				alert(alertText);
			}
			entered.focus();
			return false;
		}
		else 
			return true;
	}
}


/************************************************************************
* SubmitFormOnlyOnce
*	once the form's submit button is clicked, prevents the form from 
*   being submitted more than once.  
*   NOTE: Make sure to call this function AFTER all validation functions
************************************************************************/
function SubmitFormOnlyOnce()
{
   if (submitCount == 0)
   {
      submitCount++;
      return true;
   }
   else 
   {
      alert("This form has already been submitted.  Thanks!");
      return false;
   }
}


/************************************************************************
* Trim
*	Trims leading and trailing spaces and tabs. 
************************************************************************/
function Trim(sData) 
{
	var sTrimmed = String(sData);
	sTrimmed = sTrimmed.replace(/(^[ |\t]+)|([ |\t]+$)/g, '');
	return sTrimmed;
}
