//************************************************************************
// Required Functions: NONE
// Called As: isSpace(document.frm.fieldname.value)

function isSpace(inChar) 
{
  return (inChar == ' ' | inChar == '\t' || inChar == '\n');
}
//************************************************************************
// trims a form element
// Requires Functions: isSpace()
// Called As: trim(document.frm.fieldname.value)

function trim(tmpStr) 
{
  var atChar;
 
  if (tmpStr.length > 0) atChar = tmpStr.charAt(0);

  while (isSpace(atChar)) 
  {
    tmpStr = tmpStr.substring(1, tmpStr.length);
    atChar = tmpStr.charAt(0);
  }

  if (tmpStr.length > 0) atChar = tmpStr.charAt(tmpStr.length-1);

  while (isSpace(atChar)) 
  {
    tmpStr = tmpStr.substring(0,( tmpStr.length-1));
    atChar = tmpStr.charAt(tmpStr.length-1);
  }

  return tmpStr;
}
//************************************************************************
//checks if a string is empty
// Required Functions: trim()
// Called As: isEmpty(document.frm.fieldname)

function isEmpty(inStr)
{
	if(trim(inStr.value).length == 0)
		return true;
	else
		return false;
}
//************************************************************************
//checks if a textbox is empty - replaced by checkTextBox
// Required Functions: trim()
// Called As: isEmptyText(document.frm.fieldname)

function isEmptyText(field)
{	
	var strS = trim(field.value);
	if (strS.length == 0 || strS == "")	return true;
	return false;
} 

//************************************************************************
// checks if at least one of a set of radios is selected 
// Required Functions: NONE
// Called As: isEmptyRadio(document.frm.fieldname)
function isEmptyRadio(field)
{
	if (field.length)
	{
	 	for (i=0; i < field.length; i++)
		{
			if (field[i].checked)
				return false;
		}
	}
	else 
		if (field.checked)
			return false;

	return true;
}

//************************************************************************
// checks if a valid option has been selected 
// Required Functions: NONE
// Hint: document.frm.fieldname.options[document.frm.fieldname.selectedIndex].value
// Called As: isEmptySelect(document.frm.fieldname)
function isEmptySelect(field)
{
	var strS = "";
	iIndex = field.selectedIndex;
	if (iIndex == -1) 
	{
		field.selectedIndex = -1;
		return true;
	}
	if (iIndex != null)
	{
		strS = field[iIndex].value;
	}	
	if (trim(strS) == "") return true;
	
	return false;
}

//************************************************************************
//checks if the checkbox is selected or at least one of the array is selected
// Required Functions: NONE
// Called As: isEmptyCheck(document.frm.fieldname)
function isEmptyCheck(field)
{
	if (field.length)
	{
		for (i=0; i < field.length; i++)
		{
			if (field[i].checked)
				return false;
		}
	} 
	else 
	{
		if (field.checked)
			return false;
	}
	return true;
}
//************************************************************************
// Determines if its a valid Email Address
// Required Functions: NONE
// Called As: isValidPostcode(document.frm.fieldname.value)
function isValidEmail(str)
{
	str += '';
	namestr= '';
	domainstr = '';
	namestr = str.substring(0,str.indexOf("@")); // get all the info before the "@"
	domainstr = str.substring(str.indexOf("@")+1,str.length); // get all the info after the "@"
	tailstr = str.substring(str.indexOf(".")+1,str.length) // after the first "." how many chars are they

	if( (namestr.length == 0) || (domainstr.indexOf(".") <= 0) || (domainstr.length == 0) || (domainstr.indexOf("@") != -1) || tailstr.length == 0) return false;
	
	return true;
}
//************************************************************************
//returns the value currently selected in an array of radio buttons
function getSelectedRadioValue(field)
{
	if (field.length)
	{
		for (i=0; i < field.length; i++)
		{
			if (field[i].checked)
				return trim(field[i].value);
		}
	} else {
		if (field.checked)
			return trim(field.value);
	}
	return "";
}
//************************************************************************