var popUpWin=0;
// Create the print controls
Event.observe(window, 'load', function(event) {
		if ($('printControls')) {
			$('printControls').innerHTML = "<a href=\"javascript:printPage();\"><img alt=\"Print this page\" src=\"../images/icoPrint.gif\" width=\"13\" height=\"10\" border=\"0\" />print this page</a>";
		}
});


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function len_validate (theVal, theLength)
{
	var checkVal = theVal.replace(/ /g, '');
	if (checkVal.length < theLength)
		return false;
	else
		return true
}

function isNumberInt(inputString)
{
  return (!isNaN(parseInt(inputString))) ? true : false;
}

function isNumberFloat(inputString)
{
  return (!isNaN(parseFloat(inputString))) ? true : false;
}

function popUpWindow(URLStr, width, height, left, top)
{
	if (!left)
		left = 30;

	if (!top)
		top = 30;

	if(popUpWin)
	{
		if(!popUpWin.closed) popUpWin.location = URLStr; //popUpWin.close();
	}
	else {
		popUpWin = window.open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
		popUpWin.opener = window;
	}
	popUpWin.focus();

	return popUpWin;
}

function printPage() { print(document); }

function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

function onlyNumbers(inputString)
{
  var searchForNumbers = /\D+\_+\W+\s+\S+/
  return (searchForNumbers.test(inputString)) ? false : true;
}

function stripString(source, needles)
{
	var returnStr = "";

	for (var c = 0; c < source.length; c++)
	{
		if (needles.indexOf(source.charAt(c)) != -1)
			returnStr += source.charAt(c);
	}

	return returnStr;
}

// DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)

function emailCheck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1)
		   return false;

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		   return false;

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		    return false;

		 if (str.indexOf(at,(lat+1))!=-1)
		    return false;

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		    return false;

		 if (str.indexOf(dot,(lat+2))==-1)
		    return false;
		
		 if (str.indexOf(" ")!=-1)
		    return false;

 		 return true;
}

function checkPhone(theTest)
{
	// Strip all non-numeric characters
	var theNumber = new String(stripString(theTest, "0123456789"));

	if (theNumber.length != 10)
		return false;

	if (!isNumberInt(theNumber))
		return false;

	return "(" + theNumber.substr(0, 3) + ")" + " " + theNumber.substr(3, 3) + "-" + theNumber.substr(6, 4);
}

function checkDate(theTest)
{
	// Strip all non-numeric characters
	var theNumber = new String(stripString(theTest, "0123456789"));

	if (theNumber.length != 8)
		return false;

	if (!isNumberInt(theNumber))
		return false;

	if (theNumber.substr(0, 2) > 12)
		return false;

	if (theNumber.substr(2, 2) > 31)
		return false;

	if (theNumber.substr(4, 4) > 3000)
		return false;

	return theNumber.substr(0, 2) + "/" + theNumber.substr(2, 2) + "/" + theNumber.substr(4, 4);
}

function popupAddress(url, taID, hiID, curAddress)
{
	var theURL = url + '?address=' + curAddress + '&field=' + escape(hiID) + '&view=' + escape(taID);
	var theWindow = popUpWindow(theURL, 500, 250, 100, 100);

	theWindow.opener = window;
	theWindow.focus();	
}

function toggleTbody(id, status)
{
	if (document.getElementById)
	{
		var tbod = document.getElementById(id);
		if (tbod && typeof tbod.className == 'string')
		{
			tbod.className = status;
		}
	}
	return false;
}