//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function checkEditKey(keycode)
{
	return(keycode == 8 || keycode == 37 || keycode == 38 || keycode == 39 || keycode == 40);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function checkNumber(str)
{
	return checkRegExp(str, "([0-9]\\d*)");
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function checkInt(str)
{
	return checkRegExp(str, "((-?[1-9]\\d*)|(0)|(-))");
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function checkUInt(str)
{
	return checkRegExp(str, "(([1-9]\\d*)|(0))");
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function checkFloat(str, decimals, decsep)
{
	if(decimals == 0)
	{
		if (checkInt(str))
		{			
			ret = true;
		}
		else if (checkRegExp(str, "((-?[1-9]\\d*\\" + decsep + "\\d*)|(-?0\\" + decsep + "\\d*))"))
		{
			ret = true;
		}
		else
		{
			ret = false;
		}
	}
	else
	{	
	    if (checkInt(str))
		{
			ret = true;
		}				    
		else if (checkRegExp(str, "((-?[1-9]\\d*\\" + decsep + "\\d{0," + decimals + "})|(-?0\\" + decsep + "\\d{0," + decimals + "}))"))
		{
			ret = true;
		}		
		else
		{
			ret = false;
		}		
	}
	
	return ret;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function checkUFloat(str, decimals, decsep)
{
	if(decimals == 0)
	{
		if (checkUInt(str))
		{			
			ret = true;
		}
		else if (checkRegExp(str, "(([1-9]\\d*\\" + decsep + "\\d*)|(0\\" + decsep + "\\d*))"))
		{
			ret = true;
		}
		else
		{
			ret = false;
		}
	}
	else
	{	
	    if (checkUInt(str))
		{		    
			ret = true;
		}				    
		else if (checkRegExp(str, "(([1-9]\\d*\\" + decsep + "\\d{0," + decimals + "})|(0\\" + decsep + "\\d{0," + decimals + "}))"))
		{
			ret = true;
		}		
		else
		{
			ret = false;
		}		
	}

	return ret;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function checkCustom(str, pattern)
{
	return checkRegExp(str, "([" + pattern + "]+)");
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function onKeyPressIntTextBox(str, e)
{
    var keyCode = e.which ? e.which : e.keyCode;    
    return checkInt(str + String.fromCharCode(keyCode)) || checkEditKey(keyCode);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function onKeyPressUIntTextBox(str, e)
{
    var keyCode = e.which ? e.which : e.keyCode;    
    return checkUInt(str + String.fromCharCode(keyCode)) || checkEditKey(keyCode);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function onKeyPressFloatTextBox(decimals, decsep, str, e)
{
    var keyCode = e.which ? e.which : e.keyCode;    
    return checkFloat(str + String.fromCharCode(keyCode), decimals, decsep) || checkEditKey(keyCode);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function onKeyPressUFloatTextBox(decimals, decsep, str, e)
{
    var keyCode = e.which ? e.which : e.keyCode;    
    return checkUFloat(str + String.fromCharCode(keyCode), decimals, decsep) || checkEditKey(keyCode);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function onKeyPressCustomTextBox(pattern, str, e)
{
    var keyCode = e.which ? e.which : e.keyCode;    
    return checkCustom(str + String.fromCharCode(keyCode), pattern) || checkEditKey(keyCode);
}