String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
//pads left
String.prototype.lpad = function(padString, length) {
	var str = this;
	while (str.length < length)
	{
		str = padString + str;
	}
	return str;
}
//pads right
String.prototype.rpad = function(padString, length) {
	var str = this;
	while (str.length < length)
	str = str + padString;
	return str;
}
String.prototype.pad = function(l, s, t){
	s	= String(s);
	return s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length)
	+ 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2))
	+ this + s.substr(0, l - t) : this;
};

function isNull(val)
{
	return(val==null);
}

function goBack(url)
{
	window.location	= url;
}

function isValidFile(obj, extension, label, mesg)
{
	if (isObjEmpty(obj))
	{
		label.innerHTML=mesg;
		obj.value = '';
		obj.focus();
		return false;
	}

	var arr;
	arr = obj.value.split('.');
	len	= arr.length;

	var pattern=new RegExp(extension,"ig");

	if (!arr[len-1].match(pattern))
	{
		label.innerHTML=mesg;
		obj.value = '';
		obj.focus();
		return false;
	}

	label.innerHTML='';
	return true;
}

function isObjEmpty(obj)
{
	if(obj.value.trim() == "" || isNull(obj.value))
	{
		return true;
	}
	return false;
}

function getEl(id)
{
	return document.getElementById(id);
}

function popupWindow(url, width, height)
{
	if (width == undefined)
	{
		width	= screen.width * 0.8;
	}

	if (height == undefined)
	{
		height	= screen.height * 0.8;
	}

	mywindow = window.open(url, "Jeywin","location=0, width="+width+",height="+height+", status=0,toolbar=0, scrollbars=1");
	mywindow.moveTo(100,100);
}

function closeWindow()
{
	window.close();
}

function redirectParentWindow(url)
{
	if (window.opener && !window.opener.closed)
	{
		window.opener.location = url;
	}
}

/*
window.onload = function() {
	var forms = document.getElementsByTagName('form');

	for (var i=0;i < forms.length;i++) {
		var inputs = forms[i].getElementsByTagName('input');

		for (var j=0;j < inputs.length;j++)
		addInputSubmitEvent(forms[i], inputs[j]);
	}
};

function addInputSubmitEvent(form, input) {
	input.onkeydown = function(evt) {
		var evt = (evt) ? evt : event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		if (charCode == 13) {
			form.submit();
			return false;
		}
	};
}
*/

function toggleDisplay(id, status)
{
	if (getEl(id))
	{
		if (status == undefined)
		{
			if (getEl(id).style.display == 'none')
			{
				status	= '';
			}
			else
			{
				status	= 'none';
			}
		}

		getEl(id).style.display = status;
	}
}

function getMonth(m)
{
	var months	= new Array();
	months[1]	= 'Jan';
	months[2]	= 'Feb';
	months[3]	= 'Mar';
	months[4]	= 'Apr';
	months[5]	= 'May';
	months[6]	= 'Jun';
	months[7]	= 'Jul';
	months[8]	= 'Aug';
	months[9]	= 'Sep';
	months[10]	= 'Oct';
	months[11]	= 'Nov';
	months[12]	= 'Dec';

	return months[m];
}

function padLZero(no, digits)
{
//	max	= 1;
//	// add a zero in front of numbers<10
//	for (i=0, maxStr='0'; i<digits; i++)
//	{
//		max = i*10;
//		maxStr	= maxStr + "0";
//	}
//
//	if (no < max)
//	{
//		no = maxStr + no;
//	}

	if (no < 10)
	{
		no	= '0' + no;
	}

	return no;
}


function in_array(needle, haystack, argStrict)
{
    // Checks if the given value exists in the array
    // *     example 1: in_array('bb', ['aa', 'bb', 'cc']);
    // *     returns 1: true
    // *     example 2: in_array('bb', {0: 'aa', bb: 'cc', 1: 'dd'});
    // *     returns 2: false
    // *     example 3: in_array(1, ['1', '2', '3']);
    // *     returns 3: true
    // *     example 3: in_array(1, ['1', '2', '3'], false);
    // *     returns 3: true
    // *     example 4: in_array(1, ['1', '2', '3'], true);
    // *     returns 4: false
    var key = '', strict = !!argStrict;

    if (strict)
    {
        for (key in haystack)
        {
            if (haystack[key] === needle)
            {
                return true;
            }
        }
    }
    else
    {
        for (key in haystack)
        {
            if (haystack[key] == needle)
            {
            	return true;
            }
        }
    }

    return false;
}

function doClear(theText) {
     if (theText.value == theText.defaultValue) {
         theText.value = ""
     }
}

function setText(theText) {
	if (theText.value == "") {
		theText.value = theText.defaultValue;
	}
}

function selectText(theBox)
{
	if(theBox&&theBox.value)theBox.select();
}