
function popupWin(url, w, h) {
	option="menubar=no,toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,left=40,top=40";
	if (w) option+=",width="+w;
	if (h) option+=",height="+h;
	open(url,"",option);
}

function onSubmit(url)
{
	window.open(url, this.target,
'dialog,modal,scrollbars=yes,resizable=no,width=300,height=200,left=362,top=284');
}

function switchSelect(obj,is_select) {
	if (obj!=null) {
		if (is_select==1) selectAll(obj);
		else deselectAll(obj);
	}
}

function selectAll(obj) {
	if (obj.length!=null) for (i=0; i<obj.length; i++) obj[i].checked=true;
	else obj.checked=true;
}

function deselectAll(obj) {
	if (obj.length!=null) for (i=0; i<obj.length; i++) obj[i].checked=false;
	else obj.checked=false;
}

function delitem(form, url) {
	var del_selected=false;
	
	form.action=url;
	if (form.elements["del[]"].length>0) 
		for (i= 0; i < form.elements["del[]"].length;i++) {
			if (form.elements["del[]"][i].checked) del_selected=true;
		}
	else if (form.elements["del[]"].checked) del_selected=true;
	if (del_selected) { if (confirm("Are you sure to delete?")) form.submit(); }
	else alert("Please select record(s) to delete");
}

// validate time 
function IsValidTime(timeStr) {
// Checks if time is in HH:MM:SS format.

//var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?$/;

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;

}

//validate numeric
function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }


// Correctly handle PNG transparency in IE 5.5 or higher.
// http://homepage.ntlworld.com/bobosola. Updated 02-March-2004
// minor modification by Oo

function fixPng() {
	for (var i = 0; i < document.images.length; ++i) {
		var img = document.images[i];
		var imgName = img.src.toLowerCase();
		if (imgName.substring(imgName.length - 3, imgName.length) == "png") {
			var imgId = img.id ? "id='" + img.id + "' " : "";
			var imgClass = img.className ? "class='" + img.className + " img' " : "class='img' ";
			var imgTitle = img.title ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
			var imgStyle = "display:inline-block;" + img.style.cssText;
			if (img.align == "left") imgStyle = "float:left;" + imgStyle;
			if (img.align == "right") imgStyle = "float:right;" + imgStyle;
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
			var newImage = "<span " + imgId + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
			img.outerHTML = newImage;
			i--;
		}
	}
}
window.attachEvent("onload", fixPng);

