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;
}

function entryExistFname(entry, err_msg)
{
  // returns true if an entry has been filled. 
  // returns false otherwise.
  if(entry.value == "First Name")
  {
    alert(err_msg);
    entry.focus();
    return false;
  }// end if
  else
    return true;
}

function entryExistLname(entry, err_msg)
{
  // returns true if an entry has been filled. 
  // returns false otherwise.
  if(entry.value == "Last Name")
  {
    alert(err_msg);
    entry.focus();
    return false;
  }// end if
  else
    return true;
}

function entryExistEmail(entry, err_msg)
{
  // returns true if an entry has been filled. 
  // returns false otherwise.
  if(entry.value == "Email Address")
  {
    alert(err_msg);
    entry.focus();
    return false;
  }// end if
  else
    return true;
}


function entryExistSearchTerm(entry, err_msg)
{
  // returns true if an entry has been filled. 
  // returns false otherwise.
  if(entry.value == "Enter Search Term")
  {
    alert(err_msg);
    entry.focus();
    return false;
  }// end if
  else
    return true;
}

function entryExistValue(entry, err_msg)
{
  // returns true if an entry has been filled. 
  // returns false otherwise.
  if(entry.id == "")
  {
    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);
    alert("reset");
    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;
  }  
}

/*Validate Number in a range*/
function validateNumber(field, msg, min, max) { 
if (!min) { min = 0 } 
if (!max) { max = 255 } 

if ( (parseInt(field.value) != field.value) ||  
       field.value.length < min || field.value.length > max) { 
alert(msg); 
field.focus(); 
field.select(); 
return false; 
} 

return true; 
}

/**Validate String in a range**/
function validateString(field, msg, min, max) { 
if (!min) { min = 1 } 
if (!max) { max = 65535 } 

if (!field.value || field.value.length < min ||  
field.value.max > max) { 
alert(msg); 
field.focus(); 
field.select(); 
return false; 
} 

return true; 
}

/**Validate Email string**/
function validateEmail(email, msg, optional) { 
if (!email.value && optional) { 
return true; 
} 

var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/; 
if (!re_mail.test(email.value)) { 
alert(msg); 
email.focus(); 
email.select(); 
return false; 
} 

return true; 
}


function VoteTotal(field)
{
	var total = 0;
	for (var i=0;i<field.length;i++)
		if (field[i].checked)
			total++;
	return total;
}

function CheckVoteLimit(field, min, msg)
{
	if (!min) { min = 1} 


	var isValid = true;
	var total = VoteTotal(field);

	if (total < min)
	{
		isValid = false;
		alert(msg);
	}
	return isValid;
}
/**********************************************/
function validate(dayfield, monthfield, yearfield, msg) {
		
		if (!validateDate(dayfield, monthfield, yearfield)) 
		{
			alert(msg);
			return false;
			
		}
		else 
		{
			return true;
		} 
	}


	function validateDate(dayfield, monthfield, yearfield) {
		day = dayfield.options[dayfield.selectedIndex].text;
		if (day < 29) {
			return true;
		}
		else {
			month = monthfield.options[monthfield.selectedIndex].text;
			if (month == "01" | month == "03" | month == "05" | month == "07" | month == "08" | month == "10" | month == "12" ) {
				return true;
			}
			else {
				if (month != "02") {
					if (day <= 30) {
						return true;
					}
					else {
						return false;
					}
				}
				else {
					//check for leap year because it is Feruary
					year = yearfield.options[yearfield.selectedIndex].text;
					if ( (1996-year)%4 == 0) {
						if (day <= 29) {
							return true;
						}
						else {
							return false;
						}
					}
					else {
						if (day <=28) {
							return true;		
						}
						else {
							return false;
						}
					}
				}
								
			}


		}		
	}
/**********************************/

function compareTwoDate(startDate, endDate, startMonth, endMonth, startYear, endYear){

	if (endYear.value >= startYear.value && endMonth.value < startMonth.value){
		alert("Expire Month must be greater than or equal to Start Month");
	}
	else if (endYear.value >= startYear.value && endMonth.value >= startMonth.value){
	
		if (endDate.value < startDate.value){
			alert ("Expire Date must be greater than or equal to Start Date");
		}
		else
			return true;
	}
	else 
		alert("Expire Year must be greater than or equal to Start Year");
		return true; 
	
}
/***************************************************/



