String.prototype.trim = function ()
{
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

String.prototype.padL = function (nLength, sChar)
{
	var sreturn = this;
	while (sreturn.length < nLength)
	{
		sreturn = String(sChar) + sreturn;
	}
	return sreturn;
}

function date_onkeydown()
{
	if (window.event.srcElement.readOnly)
	return;
	var key_code = window.event.keyCode;
	var oElement = window.event.srcElement;
	if (window.event.shiftKey && String.fromCharCode(key_code) == "T")
	{
		var d = new Date();
		oElement.value = String(d.getMonth() + 1).padL(2, "0") + "/" +
		String(d.getDate()).padL(2, "0") + "/" +
		d.getFullYear();
		window.event.returnValue = 0;
	}
	
	if (!window.event.shiftKey && !window.event.ctrlKey && !window.event.altKey)
	{
		if ((key_code > 47 && key_code < 58) || (key_code > 95 && key_code < 106))
		{
			if (key_code > 95) key_code -= (95-47);
			oElement.value =
			oElement.value.replace(/[dma]/, String.fromCharCode(key_code));
		}
		if (key_code == 8)
		{
			if (!oElement.value.match(/^[dma0-9]{2}\/[dma0-9]{2}\/[dma0-9]{4}$/))
			oElement.value = "dd/mm/aaaa";
			oElement.value = oElement.value.replace(/([dma\/]*)[0-9]([dma\/]*)$/,
			function ($0, $1, $2)
			{
				var idx = oElement.value.search(/([dma\/]*)[0-9]([dma\/]*)$/);
				if (idx >= 5)
				{
					return $1 + "a" + $2;
				}
				else if (idx >= 2)
				{
					return $1 + "m" + $2;
				}
				else
				{
					return $1 + "d" + $2;
				}
			});
			window.event.returnValue = 0;
		}
	}
	if (key_code != 9)
	{
		event.returnValue = false;
	}
}