

function openWindow(WindowURL,WindowName,WindowW,WindowH)
{
	var str = ",height=" + WindowH + ",width=" + WindowW;
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;

		var xc = (aw - WindowW) / 2;
		var yc = (ah - WindowH) / 2;
	}

	if (navigator.appName == "Netscape") {
		//alert('Estou no Netscape!');
		str += ",screenX=" + xc;
		str += ",screenY=" + yc;
	}
	else {
		//alert('Estou no Internet Explorer!');
		str += ",left=" + xc;
		str += ",top=" + yc;
	}
	
	WindowFeatures = "toolbar=no,directories=no,status=no,scrollbars=no,resizable=no,menubar=no,location=no,copyhistory=no" + str;
	newWindow = window.open(WindowURL, WindowName, "" + WindowFeatures + "");
	newWindow.focus();
}


function openWindow2(WindowURL,WindowName,WindowW,WindowH)
{
	var str = ",height=" + WindowH + ",width=" + WindowW;
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;

		var xc = (aw - WindowW) / 2;
		var yc = (ah - WindowH) / 2;
	}

	if (navigator.appName == "Netscape") {
		// alert('Estou no Netscape!');
		str += ",screenX=" + xc;
		str += ",screenY=" + yc;
	}
	else {
		// alert('Estou no Internet Explorer!');
		str += ",left=" + xc;
		str += ",top=" + yc;
	}
	
	WindowFeatures = "toolbar=no,directories=no,status=no,scrollbars,resizable=no,menubar=no,location=no,copyhistory=no" + str;
	newWindow = window.open(WindowURL, WindowName, "" + WindowFeatures + "");

	newWindow.focus();
}

function openModalWindow(WindowURL,WindowW,WindowH)
{
	if (navigator.appName == "Netscape") {
		var str = ",height=" + WindowH + ",width=" + WindowW;
		if (window.screen) {
			var ah = screen.availHeight - 30;
			var aw = screen.availWidth - 10;

			var xc = (aw - WindowW) / 2;
			var yc = (ah - WindowH) / 2;
		}
		str += ",screenX=" + xc;
		str += ",screenY=" + yc;
		WindowFeatures = "toolbar=no,directories=no,status=no,scrollbars=no,resizable=no,menubar=no,location=no,copyhistory=no" + str;
		newWindow = window.open(WindowURL, "", "" + WindowFeatures + "");
	}
	else {
		var pos = showModalDialog(WindowURL, '','dialogHeight:' + WindowH +'px; dialogWidth:' + WindowW + 'px; ; ; center: Yes; help: No; resizable: No; status: No; scoll:No;');
	}
}
function loadmain(FrameURL)
{
	window.parent.main.location=FrameURL;
}
// if (navigator.userAgent.substring(0,9) >= "Mozilla/4") {


function isDate(dateStr)
	{
					
		// Checks for the following valid date formats:
		// YYYYMMDD

		var datePat = /^(\d{4})(\d{2})(\d{2})$/;

		var matchArray = dateStr.match(datePat)
		if (matchArray == null)
			return false

		month = matchArray[2]
		day = matchArray[3]
		year = matchArray[1]
		
		if (month < 1 || month > 12)
			return false

		if (day < 1 || day > 31)
			return false

		if ((month==4 || month==6 || month==9 || month==11) && day==31)
			return false

		if (month == 2)
		{
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
			if (day>29 || (day==29 && !isleap))
				return false;
		}
		return true;
	}

	
	
	
/**************************************************************
 LTrim: Returns a String containing a copy of a specified 
        string without leading spaces 

 Parameters:
      String = The required string argument is any valid 
               string expression. If string contains null, 
               false is returned

 Returns: String
***************************************************************/
function LTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for (i = 0; i < String.length; i++)
	{
		if (String.substr(i, 1) != ' ' &&
		    String.substr(i, 1) != '\t')
			break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

/**************************************************************
 RTrim: Returns a String containing a copy of a specified 
        string without trailing spaces 

 Parameters:
      String = The required string argument is any valid 
               string expression. If string contains null, 
               false is returned

 Returns: String
***************************************************************/
function RTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for(j = String.length - 1; j >= 0; j--)
	{
		if (String.substr(j, 1) != ' ' &&
			String.substr(j, 1) != '\t')
		break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

/**************************************************************
 RTrim: Returns a String containing a copy of a specified 
        string without both leading and trailing spaces 

 Parameters:
      String = The required string argument is any valid 
               string expression. If string contains null, 
               false is returned

 Returns: String
***************************************************************/
function Trim(String)
{
	if (String == null)
		return (false);

	return RTrim(LTrim(String));
}
