function checkEmpty(field, msg)
{
	  var value = field.value;

	  if (!(value=="")) { // if syntax is valid
		return true;
	  }
	  alert(msg); 
	  field.focus();
	  field.select();

	  return false;
}

// The below function is used because when using a 'select' box on a form, you
// cannot use the field.select() method. If you do, 'true' is always returned.
function checkNone(field, msg)
{
	  var value = field.value;

	  if (!(value=="none")) { // if syntax is valid
		return true;
	  }
	  alert(msg); 
	  field.focus();

	  return false;
}

function checkProducts(field)
{
	  var value = field.value;
	  var strValue = "" + value;
	 
	  var letNum = strValue.length;

	  if (value == "") 
	  { 
		  alert("Please enter the major products you stock. \nSite visitors will find your details based on what you type below, so think about what they may type."); 
		  field.focus();
		  return false;
	  }
	  //else if (letNum > 255)
	  //{
	//	  msg = "Please reduce the number of items in the 'Stockists of' field\nCurrently you have written " + letNum + " letters";
	//	  alert(msg);
  	//	  field.focus();
	//	  return false;
	  //}

	  return true;
}

function validShop(form) 
{

	if(	checkEmpty(form.shopName, "Please enter your shop name") &&
		checkEmpty(form.address1, "Please enter your shop's address, e.g. 15 The Street") &&
		checkEmpty(form.town, "Please enter the town/city your shop is located, e.g. Brighton") &&
		checkEmpty(form.tel, "Please enter your shop's telephone number") &&	
		checkProducts(form.products) &&
		checkEmpty(form.password, "Please enter a password you wish to use when amending this information in the future.") )
	  	return true;
	else
		return false;

}

function validCountry(form)
{
	if( checkNone(form.countryID, "Please enter the country where your shop is located") )
		return true;
	else
		return false;
}


function validSimpleSearch(form) 
{

	if(	!checkNone(form.countryID, "Please select a country to search")  )
	{
		return false;
	}
	

	if((form.county.value =="")&&(form.town.value ==""))
	{
		alert("Please fill out one more box.\nYour results will return all hire shops for that country.");
		return false;
	}

	return true;

}

function validSearch(form) 
{

	if(	!checkNone(form.countryID, "Please select a country to search")  )
	{
		return false;
	}
	

	if( (form.county.value =="") &&
		(form.town.value =="") &&
		(form.itemWanted.value =="") &&
		(form.shopName.value =="") )
	{
		alert("Please use an additional box to specify your search criteria.\nYour results will return all hire shops for that country.");
		return false;
	}

	return true;

}


function validAdvSearch(form) 
{

	if(form.idNum.value =="") 
	{
	  if(	!checkNone(form.countryID, "Please select a country to search")  )
	  {
		  return false;
	  }
	}

	if( (form.county.value =="") &&
		(form.town.value =="") &&
		(form.itemWanted.value =="") &&
		(form.idNum.value =="") &&
		(form.member.checked == "") &&
		(form.shopName.value =="") )
	{
		alert("Please use an additional box to specify your search criteria.\nYour results will return all hire shops for that country.");
		return false;
	}

	return true;

}

function validAmend(form) 
{

	if(	!checkEmpty(form.password, "Please enter your password.")  )
	{
		return false;
	}

	return true;

}

function validDelete(form) 
{

	if(	!checkEmpty(form.password, "Please enter your password.")  )
	{
		return false;
	}

	return confirm('Are you sure you want to DELETE this record? \n\n Select OK for yes, CANCEL for no');

}