function entryExist(entry, err_msg)
{
  // returns true if an entry has been filled. 
  // returns false otherwise.
  
  if(entry.value == "")
  {
    alert(err_msg);
    entry.focus();
    return false;
  }// end if
  else
    return true;
}

/*** isNum ***/
function isNum(entry, err_msg)
{
  // return true if the entry is a number.
  // return false and err_msg if the field is not a number.
  
  var string = entry.value;

  var Chars = "0123456789";

  for (var i = 0; i < string.length; i++)
  {
    if (Chars.indexOf(string.charAt(i)) == -1)
    {
      alert(err_msg);
      entry.value = "";
      entry.focus();
      return(false);
    }// end if
  }// end for
    
  // otherwise
  return(true);
  
}// end isNum

/*** isNumWithSp ***/
function isNumWithSp(entry, err_msg)
{
  // return true if the entry is a number with spaces or hyphen.
  // return false and err_msg if the field is not a number.
  
  var string = entry.value;

  var Chars = "0123456789 -()";

  for (var i = 0; i < string.length; i++)
  {
    if (Chars.indexOf(string.charAt(i)) == -1)
    {
      alert(err_msg);
      entry.value = "";
      entry.focus();
      return(false);
    }// end if
  }// end for
    
  // otherwise
  return(true);
  
}// end isNumWithSp

/*** phone_format ***/
function phone_format(inp)
{
  // checks that inp field contains only numbers in the format 00 0000 0000
  // returns true if success otherwise returns false.
  
	// initialise
	var the_test = false;
	var phone_format = /^[0-9]{2}\s[0-9]{4}\s[0-9]{4}$/;			  
	the_test = phone_format.test(inp.value);

	if(the_test == false)
	{
		alert("Invalid phone number format\n\nPlease use the following format for the phone number 00 0000 0000       \n\nUse only numbers, do not use characters");
		inp.focus();
		return false;
	}
	else
		return true;
}// end phone_format

/*** mobile_format ***/
function mobile_format(inp)
{
  // checks that inp field contains only numbers in the format 0000 000 000
  // returns true if success otherwise returns false.
  
	// initialise
	var the_test = false;
	var mobile_format = /^[0-9]{4}\s[0-9]{3}\s[0-9]{3}$/;			  
	the_test = mobile_format.test(inp.value);

	if(the_test == false)
	{
		alert("Invalid mobile phone number format\n\nPlease use the following format for the mobile phone number 0000 000 000       \n\nUse only numbers, do not use characters");
		inp.focus();
		return false;
	}
	else
		return true;
}// end mobile_format

/*** noNum ***/
function noNum(entry, err_msg)
{
  // returns err_msg and false if entry has a number in it.
  // returns true if there is no number in the entry.
 
  var string = entry.value;

  var Chars = "0123456789";

  for (var i = 0; i < string.length; i++)
  {
    if (!(Chars.indexOf(string.charAt(i)) == -1))
    {
      alert(err_msg);
      entry.value = "";
      entry.focus();
      return(false);
    }// end if
  }// end for
  
  // otherwise
  return(true);
}// end noNum


/*** radioSelected ***/
function radioSelected(radioName, err_msg)
{
  // return true if a radiobox is selected. False and error msg otherwise.

  var len = radioName.length;
  var ok = false; // assumed no radiobox selected until found.
  for( var i=0; i<len; i++)
  {
    if(radioName[i].checked)
    {
      ok = true;
      break;
    }

  }


  if(ok)
    return true;
  else
  {
    alert(err_msg);
    return false;
  }
  
}

/*** entryLenGT ***/
function entryLenGT(entry, len, err_msg)
{
  // returns true if entry's string value is greater than len.
  // returns false and err_msg otherwise.
  
  if(entry.value.length < len)
  {
    alert(err_msg);
    entry.value = "";
    entry.focus();
    return false;
  }
  else
    return true;  
}

/*** entryLenLT ***/
function entryLenLT(entry, len, err_msg)
{
  // returns true if entry's string value is less than len.
  // returns false and err_msg otherwise.
  
  if(entry.value.length > len)
  {
    alert(err_msg);
    entry.value = "";
    entry.focus();
    return false;
  }
  else
    return true;  
}

/*** entriesSame ***/
function entriesSame(entry1, entry2, err_msg)
{ 
  // return true if entry1 is the same as entry2.
  // otherwise return false.
  
  if(entry1.value != entry2.value)
  {
    entry2.value = "";
    entry1.value = "";
    alert(err_msg);
    
    return false;
  }
  else
    return true;
}

/*** SBnotSelected(entry, num, err_msg) ***/
function SBnotSelected(entry, num, err_msg)
{
  if(entry.selectedIndex == num)
  {
    alert(err_msg);
    entry.focus();
    return false;
  }
  else
    return true;  
}

/*** tickBoxSelected ***/
function tickBoxSelected(entry, err_msg)
{
  if(!entry.checked)
  {
    alert(err_msg);
    return false;
  }
  else
    return true;

}

/*** compare_passwd ***/

function compare_passwd(passwd, passwd02, err_msg)
{  
  if(passwd.value != passwd02.value)
  {
    alert(err_msg);
    passwd02.value = "";
    passwd.value = "";
    passwd.focus();
    return false;
  }
  else
  {
    return true;
  }  
}

function checkPasswdLength(passwd, passwd02, len, err_msg)
{
  // returns true if entry's string value is greater than len.
  // returns false and err_msg otherwise.
  
  if(passwd.value.length < len)
  {
    alert(err_msg);
    passwd.value = "";
    passwd02.value = "";
    passwd.focus();
    return false;
  }
  else if(passwd02.value.length < len)
  {
    alert(err_msg);
    passwd.value = "";
    passwd02.value = "";
    passwd.focus();
    return false;
  }
  else
    return true;  
}
