<!--
/******************************************************************************
FORM VALIDATION FUNCTIONS
-------------------------

The software and related user documentation are protected under
copyright laws.
*******************************************************************************/

/*********************************************************
Name  : 
Descr : 
Input : 
Output: 
Usage : 
*********************************************************/
function is_valid_name(string)
{
	var Chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
	
	for (var i = 0; i < string.length; i++)
	{
		if (Chars.indexOf(string.charAt(i)) == -1)
			return false;
	}
	return true;
}//

/*********************************************************
Name  : 
Descr : 
Input : 
Output: 
Usage : 
*********************************************************/
function is_valid_goal_name(string)
{
	var Chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '-.()";
	
	for (var i = 0; i < string.length; i++)
	{
		if (Chars.indexOf(string.charAt(i)) == -1)
			return false;
	}
	return true;
}//

/*********************************************************
Name  : 
Descr : 
Input : 
Output: 
Usage : 
*********************************************************/
function contains_chars(str)
{
	if (is_numeric(str))
	{
		return false;
	}
	
	return true;
}

/*********************************************************
Name  : 
Descr : 
Input : 
Output: 
Usage : 
*********************************************************/
function contains_num(str)
{
	var num_list = "0123456789";
	
	for (var i = 0; i < str.length; i++)
	{
		if (num_list.indexOf(str.charAt(i)) != -1)
		{
			return true
		}
	}//for
	return false;
}

/*********************************************************
Name  : 
Descr : 
Input : 
Output: 
Usage : 
*********************************************************/
function is_numeric(string)
{
	if (!string)
		return false;
	var Chars = "0123456789.";
	
	for (var i = 0; i < string.length; i++)
	{
		if (Chars.indexOf(string.charAt(i)) == -1)
			return false;
	}
	return true;
}//is_numeric

/*********************************************************
Name  : 
Descr : 
Input : 
Output: 
Usage : 
*********************************************************/
// function isFilled(element, minLength, maxLength)
// it returns 1 on success
// it returns -1 if form element is null or empty
// It returns -2 if element is not of the minimum length required. it does not check for the minimum length required if passed value is zero. 
// It returns -3 if element exceeds the maximum length allowed. it does not check for the maximum length allowed if passed value is zero.
//usage: isFilled(firstName, 0, 20)
function is_filled(element, minLength, maxLength)
{
	if (element.value == "" || element.value == null) 
		return -1;

	if ((minLength  != 0) && (element.value.length < minLength))
		return -2;

	if ((maxLength  != 0) && (element.value.length > maxLength))
		return -3;

	return 1;
}//is_filled()

/*********************************************************
Name  : is_checked(checkbox)
Descr : tells if a checkbox is checked or not
Input : form element - checkbox
Output: true or false
Usage : is_checked(frm_chkbox)
*********************************************************/
function is_checked(checkbox)
{
	if (checkbox.checked)
	{
		return true;
	}
	else
	{
		return false;
	}
}//is_checked

/*********************************************************
Name  : is_any_option_selected(element)
Descr : tells if an option has been selected from the drop down or not
        It checks for the null string value of the "option" tag make decision
Input : form element - select
Output: true or false
Usage : is_any_option_selected(a_form.frm_state)
*********************************************************/
function is_any_option_selected(element)
{
	if (element.options[element.selectedIndex].value == "" ) 
		return false;
	else
		return true;
}//is_any_option_selected()

/*********************************************************
Name  : 
Descr : 
Input : 
Output: 
Usage : 
*********************************************************/
function is_any_radio_selected(radio_elm)
{
	for (var i = 0; i < radio_elm.length; i++)
	{	
		//kj=eval("radio_elm[" + i + "].checked")
		//alert("eval(radio_elm[" + i + "].checked): " + kj);
		if (eval("radio_elm[" + i + "].checked") == true)
		{
			return true;
		}//if
	}//for
	return false;
}//is_any_radio_selected()

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

//-->
