/* Utility Javascript (Used by Pages that have Fee Elements, OptionSet Elements and EmailBuilder Elements) */

// Check if the input is numeric
function isNumeric(sText)
{
	var validChars = "0123456789";
	for (var i=0; i<sText.length; i++)
	{
		var currentChar = sText.charAt(i);
		if (validChars.indexOf(currentChar) == -1)
		{
			return false;
		}
	}
	return true;
}

// Check if the the number is negative or not
// Precondtion: it is a numeric value
function isNegativeNumber(sText)
{
	if (sText.charAt(0) == "-")
	{
		return true;
	}
	else
	{
		return false;
	}
}

// Check if the input is an appropriate Fee
function isFee(sText)
{
	var validChars = "0123456789.-";
	for (var i=0; i<sText.length; i++)
	{
		var currentChar = sText.charAt(i);
		if (validChars.indexOf(currentChar) == -1)
		{
			return false;
		}
	}
	return true;
}

// Remember Value
var utility_rememberValue = "";
function rememberValue(sText)
{
	utility_rememberValue = sText;
}

// Replace Remembered Value
function replaceRememberedValue(formObj)
{	
	formObj.value = utility_rememberValue;
}	

// Insert Text into TextArea
function InsertText(input, insTexte)
{
	startTag = '';
	endTag = '';

	 if (input.createTextRange)
	 {
	 	var text;
	 	input.focus(input.caretPos);
	 	input.caretPos = document.selection.createRange().duplicate();
	 	if(input.caretPos.text.length>0)
	 	{
	 		input.caretPos.text = startTag + input.caretPos.text + endTag;
	 	}
	 	else
	 	{
	 		input.caretPos.text = startTag + "" + insTexte + " " + endTag;
	 	}
	 }
	 else input.value += startTag + insTexte + endTag;
}						


