function enlarge(target){
	var width="280", height="520";
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;	
	var styleStr = 'fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=yes,directories=no,location=no,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;	
	window.open(target, "Enlarge", styleStr)
}

function info(page, width, height){
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	var styleStr = 'fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=yes,directories=no,location=no,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	window.open(page,"INFO", styleStr);
}
/******************************************************************************
** This function trims the leading and trailing blanks from a string object.
******************************************************************************/
function Trim(sText)
{
	var iStart, iEnd;
	var sTrimmed;
	var cChar;

	iEnd = sText.length - 1;
	iStart = 0;
	bLoop = true;

	cChar = sText.charAt(iStart);
	while ((iStart < iEnd) && ((cChar == "\n") || (cChar == "\r") || (cChar == "\t") || (cChar == " ")))
	{
		iStart ++;
		cChar = sText.charAt(iStart);
	}

	cChar = sText.charAt(iEnd);
	while ((iEnd >= 0) && ((cChar == "\n") || (cChar == "\r") || (cChar == "\t") || (cChar == " ")))
	{
		iEnd --;
		cChar = sText.charAt(iEnd);
	}

	if (iStart <= iEnd)
	{
		sTrimmed = sText.substring(iStart, iEnd + 1);
	} else {
		sTrimmed = "";
	}

	return sTrimmed;
}

/******************************************************************************
** This function takes a form field as a passed parameter.
** It replaces the value with a trimmed version of the value
** and returns the length.
******************************************************************************/
function TrimField(fldObject)
{
	var S = Trim(fldObject.value);
	fldObject.value = S;
	return S.length;
}

/******************************************************************************
** This function returns 'true' if the passed field object contains a
** valid date in the form of "mm/dd/yy" or "mm/dd/yyyy".  The month
** and day can be either one or two digits, and the year can be two or four.
******************************************************************************/
function checkdate(fldObject)
{
	var a = fldObject.value;

	if (a.substring(1,2) == "/") 
	{
		a = "0" + a;
	}
	
	if (a.substring(4,5) == "/") 
	{
		a = a.substring(0,3) + "0" + a.substring(3,a.length);
	}

	var ln = a.length;

	if ((ln != 8) && (ln != 10))
	{
		return false;
	}
	
	b = a.substring(0, 2); // month
	c = a.substring(2, 3); // '/'
	d = a.substring(3, 5); // day
	e = a.substring(5, 6); // '/'

	if (ln == 8)
	{
		f = a.substring(6, 8); // year (2-digit)
	}
	else
	{
		f = a.substring(6, 10); // year (4-digit)
	}

	if (b < 1 || b > 12) 
	{
		return false;
	}
	
	if (c != '/' || e != '/')
	{
		return false;
	}
	
	if (d < 1 || d > 31)
	{
		return false;
	}
	
	if (((ln == 8) && (f < 0 || f > 99)) || ((ln == 10) && (f < 1900 || f > 2100)))
	{
		return false;
	}

	if (b == 4 || b == 6 || b == 9 || b == 11)
	{
  		if (d == 31)
  		{
  			return false;
  		}
	}

	if (b == 2)
	{
		var g = parseInt(f/4);

  		if (isNaN(g))
  		{
  			return false;
  		}

  		if (d > 29)
  		{
  			return false;
  		}
  		
  		if (d == 29 && ((f/4) != parseInt(f/4)))
  		{
  			return false;
  		}
	}

	return true;
}

/******************************************************************************
** This function pulls out all numberic characters from a text string
** (as well as the sign and decimal).  The return value is then suitable
** for use in the "parseInt" and "parseFloat" functions.
** The function STOPS parsing once a non-numeric character is found
** (with the exceptions of the dollar sign, plus sign, comma, and space)
******************************************************************************/
function ToNumeric(sText)
{
	var i, iStart, iEnd, iSign;
	var cChar, sNumbers;

	iEnd = sText.length - 1;
	iSign = 1;
	sNumbers = '';

	if (iEnd == -1)
	{
		return '0';
	}

	for (i=0; i<=iEnd; i++)
	{
		cChar = sText.charAt(i);

		switch (cChar)
		{
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
			case '.':
				sNumbers += cChar;
				break;

			case '$':
			case ',':
			case '+':
			case ' ':
				break;

			case '-':
				iSign *= -1;
				break;

			default:
				i = iEnd;
				break;
		}
	}

	if (sNumbers == '') sNumbers = '0';

	return (iSign == -1 ? "-" : "") + sNumbers;
}

/******************************************************************************
** A simple function to encapsulate the parseInt/ToNumeric functions.
******************************************************************************/
function CInt(sText)
{
	return parseInt(ToNumeric(sText));
}

/******************************************************************************
** A simple function to encapsulate the parseFloat/ToNumeric functions.
******************************************************************************/
function CSng(sText)
{
	return parseFloat(ToNumeric(sText));
}

/******************************************************************************
** Performs a close approximation to the VB "IsNumeric" function.
******************************************************************************/
function IsNumeric(sValue)
{
	var i, x, sgn = 0, InDigits = false;
	var sPattern = " 0123456789.,$+-";
	var sText = Trim(sValue);
	var iEnd = sText.length - 1;

	// Empty strings are not numeric.
	if (iEnd == -1) return false;

	for (i=0; i<=iEnd; i++)
	{
		x = sPattern.indexOf(sText.charAt(i));

		// If it's not in the pattern, we're done.
		if (x == -1) return false;

		// Set a flag the first time we encounter a digit.
		if (x > 0 && x < 11) InDigits = true;

		// If we find a space after the numbers, then we quit.
		if (x == 0 && InDigits) return false;

		// We're done if we find more than one "-" or "+".
		if (x > 13)
		{
			sgn++;
			if (sgn > 1) return false;
		}
	}

	return true;
}

/******************************************************************************
** This has the same functionality as the VB "Replace" function.
******************************************************************************/
function ReplaceText(szText, szFind, szReplace)
{
	var pos=szText.indexOf(szFind);
	var len=szFind.length;

	while (pos != -1)
	{
		szPre = szText.substring(0, pos);
		szPost = szText.substring(pos + len, szText.length);
		szText = szPre + szReplace + szPost;
		pos=szText.indexOf(szFind, pos + szReplace.length);
	}

	return szText;
}

/******************************************************************************
** Here's a simple function to extract the value of a 'checked' radio button.
******************************************************************************/
function RadioValue(rdoObject)
{
	var value = null;
	
	for (var i = 0; i < rdoObject.length; i++)
	{
		if (rdoObject[i].checked) 
		{
			value = rdoObject[i].value;
			break;
		}
   }
   
   return value;
}
