function key()
{
	return document.all ? event.keyCode : event.which;
}

function integer_onkeypress(inp)
{
	return event.returnValue = (key() >= 48 && key() <= 57) || String.fromCharCode(key()) == '-';
}

function number_onkeypress(inp)
{
	return event.returnValue = key() >= 48 && key() <= 57 || String.fromCharCode(key()) == '.' || String.fromCharCode(key()) == ',' ||  String.fromCharCode(key()) == '-';
}

function number_onchange(inp)
{
	inp.value = parseFloat(inp.value.replace(',','.'));
}

function date_onkeypress(inp)
{
	return event.returnValue = key() >= 48 && key() <= 57 || "/.-".indexOf(String.fromCharCode(key())) >= 0;
}

function date_padd(val,width)
{
	while (val.length < width) val = '0' + val;
	return val;
}

function date_format(val)
{
	var re = new RegExp("^((0{0,1}[1-9])|([1-2][0-9])|(3[01])) *[/.-] *((0{0,1}[1-9])|(1[0-2])) *[/.-] *([0-9]{4}|[0-9]{2}|[0-9]{1})$");
	if (!re.test(val)) return val;
	yy = RegExp.$8;
	if (yy.length == 1) yy = '200' + yy;
	else if (yy.length == 2)
	{
		if (parseInt(yy) < 50) yy = '20' + yy;
		else yy = '19' + yy;
	}
	return date_padd(RegExp.$1,2) + '-' + date_padd(RegExp.$5,2) + '-' + yy;
}

function time_onkeypress(inp)
{
	return event.returnValue = key() >= 48 && key() <= 57 || ":.".indexOf(String.fromCharCode(key())) >= 0;
}

function time_padd(val,width)
{
	while (val.length < width) val = '0' + val;
	return val;
}

function time_onchange(inp,sep)
{
	if (inp.value.length > 0)
	{
		var re = new RegExp("^((0{0,1}[0-9])|(1[0-9])|(2[0-3])) *[:.] *(([0-5][0-9]))$");
		if (re.test(inp.value))
		{
			inp.value = date_padd(RegExp.$1,2) + sep + date_padd(RegExp.$5,2);
		}
		else
		{
			alert('hh:mm');
			inp.focus();
			return event.returnValue = false;
		}
	}
	return event.returnValue = true;
}

function splitDown(dragPane,topLeftPane,bottomRightPane)
{
	document.getElementById(dragPane).style.display = '';
	if (document.all) document.getElementById(dragPane).setCapture();
}

function splitMove(splitterType,dragPane,splitPane1)
{
	if (splitterType == 1)
	{
		var x = event.x;
		var w = document.getElementById(dragPane).clientWidth;
		var pct = Math.max(5,Math.min(95,100 * x / w));
		if (navigator.appName == 'Opera') pct = Math.round(pct);
		document.getElementById(splitPane1).style.left = pct + '%';
	}
	else
	{
		var y = event.y;
		var h = document.getElementById(dragPane).clientHeight;
		var pct = Math.max(5,Math.min(95,100 * y / h));
		if (navigator.appName == 'Opera') pct = Math.round(pct);
		document.getElementById(splitPane1).style.top = pct + '%';
	}
}

function splitUp(id,splitterType,dragPane,splitPane1,splitPane2,topLeftPane,bottomRightPane)
{
	var pct;
	if (splitterType == 1)
	{
		var x = event.x;
		var w = document.getElementById(dragPane).clientWidth;
		pct = Math.max(5,Math.min(95,100 * x / w));
		if (navigator.appName == 'Opera') pct = Math.round(pct);
		document.getElementById(dragPane).style.display = 'none';
		document.getElementById(topLeftPane).style.width = pct + '%';
		document.getElementById(bottomRightPane).style.width = (100 - pct) + '%';
		document.getElementById(splitPane1).style.left = pct + '%';
		document.getElementById(splitPane2).style.left = pct + '%';
	}
	else
	{
		var y = event.y;
		var h = document.getElementById(dragPane).clientHeight;
		pct = Math.max(5,Math.min(95,100 * y / h));
		if (navigator.appName == 'Opera') pct = Math.round(pct);
		document.getElementById(dragPane).style.display = 'none';
		document.getElementById(topLeftPane).style.height = pct + '%';
		document.getElementById(bottomRightPane).style.height = (100 - pct) + '%';
		document.getElementById(splitPane1).style.top = pct + '%';
		document.getElementById(splitPane2).style.top = pct + '%';
	}
	if (document.all) document.getElementById(dragPane).releaseCapture();
	immediateEvent(true,id,'onsplit',pct + '',true);
}


