function highlight(text)
{
	text.select();
}

function formatDateKeyDown(t)
{
	var s = String(t.value);

	if ((s.length == 4 || s.length == 7) && !s.match(/^\w*\/\w*\/\w*/)) {
		t.value = t.value + "/";
	}
}

function formatTimeKeyDown(t)
{
	var s = String(t.value);

	if ((s.length == 2) && !s.match(/^\w*[:]\w*/)) {
		t.value = t.value + ":";
	}
}

function selectAll(frm, name, check)
{
	var chk = frm.elements[name];
	if (chk.length == null) {
		chk.checked = check.checked;
	} else {
		for (var i=0; i<chk.length; i++) {
			chk[i].checked = check.checked;
		}
	}
}

function popUp(url, name, width, height, maximize, offsetWidth, offsetHeight, dialog)
{
	maxHeight = screen.availHeight - 50;
	maxWidth  = screen.availWidth  - 10;
	if (maximize == true) {
		height  = maxHeight;
		width   = maxWidth;
	}
	if (height > maxHeight) height  = maxHeight;
	if (width > maxWidth) width = maxWidth;

	if (isNaN(offsetHeight)) offsetHeight = 0;
	if (isNaN(offsetWidth)) offsetWidth = 0;
	if (offsetHeight > maxHeight - 100) offsetHeight  = maxHeight - 100;
	if (offsetWidth > maxWidth - 100) offsetWidth = maxWidth - 100;
	
	height = height - offsetHeight;
	width  = width  - offsetWidth;

  l = (maxWidth  - width) /2;
  t = (maxHeight - height) /2;

  if (name == "") {
  	var d = new Date();
  	name = "tmp" + d.valueOf();
  }
	
	if (dialog) {
		win = window.open (url, name,'location=no,titlebar=no,toolbar=no,scrollbars=no,menubar=no,status=no,resizable=no,left=' + l + ',top=' + t + ',height=' + height + ',width=' + width)
	} else {
		win = window.open (url, name,'location=no,titlebar=no,toolbar=no,scrollbars=yes,menubar=no,status=yes,resizable=yes,left=' + l + ',top=' + t + ',height=' + height + ',width=' + width)
	}
	
	if (win != undefined && win != null) {
		win.focus();
	}
	//return win;
}

function SelectRow()
{
}

function getTop(el)
{
	var temp = el;
	var y = 0;
	while (temp != null) {
		temp = temp.parentElement;
		if (temp != null) {
			y += temp.offsetTop;
		}
	}
	return y;
}

function getLeft(el)
{
	var temp = el;
	var x = el.offsetLeft;
	while (temp != null) {
		temp = temp.parentElement;
		if (temp != null) {
			x += temp.offsetLeft;
		}
	}
	return x;
}

function Round(num, dec)
{
	if (isNaN(parseFloat(num))) num = 0;
	if (dec < 0) dec = 0;
	var base = Math.pow(10, dec);
	var tmp = Math.round(num * base).toString();

	var sign = "";
	if (tmp.substr(0,1) == "-") {
		sign = "-";
		tmp = tmp.substr(1);
	}	
	
	if (tmp.length > dec) {
		if (dec == 0) {
			return sign + tmp.substr(0, tmp.length-dec);
		} else {
			return sign + tmp.substr(0, tmp.length-dec) + "." + tmp.substr(tmp.length-dec);
		}
	} else {
		var prefix = "";
		for (var i=0; i<dec+1-tmp.length; i++) {
			prefix += "0";
		}
		tmp = prefix + tmp;
		return sign + tmp.substr(0, tmp.length-dec) + "." + tmp.substr(tmp.length-dec);
	}
	return tmp;
}

function RTrim(s)
{
	re = /(\S+)\s+$/;
	return s.replace(re, "$1");
}

function LTrim(s)
{
	re = /^\s+(\S+)/;
	return s.replace(re, "$1");
}

function Trim(s)
{
	return LTrim(RTrim(s));
}

function ShowDatePicker(t)
{
	var win     = popUp('datepicker.htm', 'PickDate', 250, 200, false, 0, 0, true);
	win.opener  = self;
	win.srcCtrl = t;
}

function ShowTimePicker(t)
{
	var win     = popUp('timepicker.htm', 'PickTime', 230, 230, false, 0, 0, true);
	win.opener  = self;
	win.srcCtrl = t;
}

function ShowToolTips(control, content, heading, align, scroll)
{
	// align : 1 - top, 2 - bottom, 3 - left, 4 - right
	
	var html = "<div id=\""+control.name+"_tooltips\" style=\"position:absolute; top:0; left:0; width:100%; height:100%; border:1px solid black; font:normal 8pt arial; filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#FFFF66, EndColorStr=#FFFFFF); padding:5px; \">";
	if (heading != undefined && heading != "") {
		html += "<b>"+heading+"</b>";
		html += "<hr size=\"1\" style=\"border:1px solid black;\">";
	}
	html += content;
	html += "</div>";
	
	if (self.oPopup == undefined) {
		self.oPopup = window.createPopup();
	}
	
	toolTipsWidth = 150;
	
	oPopup = self.oPopup;
	oPopup.document.body.innerHTML = html;
  oPopup.show(0, 0, toolTipsWidth, 0);
  var realHeight = oPopup.document.body.scrollHeight;

	if (realHeight > 100 && scroll) {
		oPopup.document.all[control+"_tooltips"].style.overflow = "auto";
		realHeight = 100;
	}

  oPopup.hide();
  
  if (align == 1) {
  	posLeft = 0;
  	posTop  = 0 - realHeight - 5;
	} else if (align == 2) {
  	posLeft = 0;
  	posTop  = control.clientHeight + 5;
	} else if (align == 3) {
		posLeft = 0 - toolTipsWidth - 5;
		posTop  = 0;
	} else {
		posLeft = control.clientWidth + 5;
		posTop  = 0;
	}
	oPopup.show(posLeft, posTop, toolTipsWidth, realHeight, control);
	
	setTimeout("self.oPopup.hide();", 5000);
}

function uppercase()
{
	var strIn = String.fromCharCode(event.keyCode);
	strIn=strIn.toUpperCase();
	event.keyCode=strIn.charCodeAt(0);
}

function checkNum(control, controlName)
{
	var strIn = String.fromCharCode(event.keyCode);
	if(isNaN(strIn) && strIn != ".") {
		event.keyCode = null
	}
	else if(isNaN(control.value + strIn)) {
		event.keyCode = null
		alert('Number is required for ' + controlName + '.');
	}
}

function checkInt(control, controlName)
{
	var strIn = String.fromCharCode(event.keyCode);
	if(isNaN(strIn)) {
		event.keyCode = null
	}
	else if(isNaN(control.value + strIn)) {
		event.keyCode = null
		alert('Number is required for ' + controlName + '.');
	}
}

function checkmail(a) {
	var i=a.length;
	var temp = a.indexOf('@');
	var tempd = a.indexOf('.');
	if (temp > 1) {
		if ((i-temp) > 3){
			if ((i-tempd)>0){
				return 1;
			}
		}
	}
	return 0;
}
