// Removes leading whitespaces
function LTrim(value) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim(value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");	
}

// Removes leading and ending whitespaces
function trim(str)
{
	if (str == null)
		return false;
   return str.replace(/^\s*|\s*$/g,"");
}

//function IsNumeric(sText)
//{
//	if (isNaN(parseInt(form.field1.value))) {
//		alert('Please enter only numerical values into Field 1.');
//	}
//}

function IsNumeric(sText)
{
	sText = trim(sText);
	if (sText.length == 0)
		return false;

	var ValidChars = "0123456789";
	var Char;
			
	for (i = 0; i < sText.length; i++)
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			return false;
		}
	}
	return true;
}

//validates if text box is not empty and shows a message box if it's
function vaidate_has_text(ctrl, errorText)
{
	var len = trim(ctrl.value).length;
	if (len == 0) 
	{
		ctrl.focus();
		return false;
	}
	else
	{	
		return true;
	}
}

//validates if text box has numeric value and shows a message box if it's
function vaidate_has_num(ctrl, errorText)
{
	if (IsNumeric(ctrl.value) == false)
	{
		ctrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}

//inverses checkbox check state
function OnInverseCheckbox(checkboxID) {
	var ctrl = document.getElementById(checkboxID);
	ctrl.checked = !ctrl.checked;
}