function popitup(url, popW, popH, scrolls, resize)
{
  w = screen.availWidth;
  h = screen.availHeight;
	
  var leftPos = (w-popW)/2, topPos = (h-popH)/2;
  newwindow=window.open(url,'_blank','width='+popW+',height='+popH +',top='+topPos+',left='+leftPos + ',scrollbars='+scrolls+',resizable='+resize);
  if (window.opener == null) {newwindow.opener = self}
}

function popitupfull(url)
{
  var w = 800, h = 600;
  if (document.all || document.layers) {
     w = screen.availWidth;
     h = screen.availHeight;
  }
	
  w = w - 10; h = h - 30;
  newwindow=window.open(url,'_blank','width='+w+',height='+w+',top=0,left=0,scrollbars=1,resizable=1');
  if (window.opener == null) {newwindow.opener = self}
}

function EmptyPopup(WName, popW, popH, scrolls, resize)
{
  w = screen.availWidth;
  h = screen.availHeight;
	
  var leftPos = (w-popW)/2, topPos = (h-popH)/2;
  newwindow=window.open('',WName,'width='+popW+',height='+popH +',top='+topPos+',left='+leftPos + ',scrollbars='+scrolls+',resizable='+resize);
  if (window.opener == null) {newwindow.opener = self}
}

function fnMaxLen(obj){
// onKeyUp
	var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length > mlength)
		obj.value=obj.value.substring(0, mlength)
}

function ConvertToDate(Dt) {
	Dt = Dt.replace(/(\d+).(\d+).(\d+)/, '$3/$2/$1'); // make as yy/mm/dd
	if (Dt.indexOf('/') < 4)
		Dt = Dt.replace(/^(\d\d\/)/, '20$1') // make as yyyy/mm/dd
	return new Date(Dt);
}
function IsValidTime(timeStr) {
	// Checks if time is in HH:MM:SS AM/PM format.
	// The seconds and AM/PM are optional.
	
	var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
	
	var matchArray = timeStr.match(timePat);
	if (matchArray == null) {
		alert("Time is not in a valid format.");
		return false;
	}
	hour = matchArray[1];
	minute = matchArray[2];
	second = matchArray[4];
	ampm = matchArray[6];
	
	if (second=="") { second = null; }
	if (ampm=="") { ampm = null }
	
	if (hour < 0  || hour > 23) {
//	alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
	return false;
	}
/*	if (hour <= 12 && ampm == null) {
	if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) {
	alert("You must specify AM or PM.");
	return false;
	   }
	}*/
	if  (hour > 12 && ampm != null) {
//		alert("You can't specify AM or PM for military time.");
		return false;
	}
	if (minute<0 || minute > 59) {
//	alert ("Minute must be between 0 and 59.");
	return false;
	}
	if (second != null && (second < 0 || second > 59)) {
//	alert ("Second must be between 0 and 59.");
	return false;
	}
	return true;
}
