<!--
gMandatoryFields = 0x0010077F;

/*---------------------------------------------------------------------------------------------------------------------*/

function onSearchFocus()
{
	if (document.form_search.search.value == "Search...")
		 document.form_search.search.value = ""
}

/*---------------------------------------------------------------------------------------------------------------------*/

function DoSearch()
{
	var sStr = ""

	sStr += IsValidString(document.form_search.search.value, "---");
	if (sStr == "")
		if (document.form_search.search.value == "Search...")
			sStr = "---"

	if (sStr != "")
		alert("You must enter at least one keyword")
	else
	{
		document.form_search.action = "/search.asp#results"
		document.form_search.submit()
	}
}

/*---------------------------------------------------------------------------------------------------------------------*/
function SubmitForm()
{
  var sStr = ""

	if ( (document.formular["First name"]) && (gMandatoryFields & 1) )
		sStr += IsValidString(GetFieldValue("First name"), "First Name");

	if ( (document.formular["Last name"]) && (gMandatoryFields & 2) )
		sStr += IsValidString(GetFieldValue("Last name"), "Last Name");

	if ( (document.formular["Title"]) && (gMandatoryFields & 4) )
	  sStr += IsValidString(GetFieldValue("Title"), "Job Title");

	if ( (document.formular["Company"]) && (gMandatoryFields & 8) )
	  sStr += IsValidString(GetFieldValue("Company"), "Organisation");

	if ( (document.formular["Email"]) && (gMandatoryFields & 16) )
	  sStr += IsValidEmail(GetFieldValue("Email"), "Email");

	if ( (document.formular["Street"]) && (gMandatoryFields & 32) )
	  sStr += IsValidString(GetFieldValue("Street"), "Address");

	if ( (document.formular["City"]) && (gMandatoryFields & 64) )
	  sStr += IsValidString(GetFieldValue("City"), "City");

	if ( (document.formular["State"]) && (gMandatoryFields & 128) )
	  sStr += IsValidString(GetFieldValue("State"), "County");

	if ( (document.formular["Zip"]) && (gMandatoryFields & 256) )
	  sStr += IsValidString(GetFieldValue("Zip"), "Postcode");

	if ( (document.formular["Country"]) && (gMandatoryFields & 512) )
	  sStr += IsValidString(GetFieldValue("Country"), "Country");

	if ( (document.formular["Phone"]) && (gMandatoryFields & 1024) )
	  sStr += IsValidString(GetFieldValue("Phone"), "Phone");

	if ( (document.formular["Fax"]) && (gMandatoryFields & 2048) )
	  sStr += IsValidString(GetFieldValue("Phone"), "Fax");


	if ( (document.formular["Comments"]) && (gMandatoryFields & 65536) )
	  sStr += IsValidString(GetFieldValue("Comments"), "Comments");

	if ( (document.formular["Industry"]) && (gMandatoryFields & 131072) )
	  sStr += IsValidString(GetFieldValue("Industry"), "Industry");

	if ( (document.formular["Annual revenue"]) && (gMandatoryFields & 262144) )
	  sStr += IsValidString(GetFieldValue("Annual revenue"), "Annual revenue");

	if ( (document.formular["Employees"]) && (gMandatoryFields & 524288) )
	  sStr += IsValidString(GetFieldValue("Employees"), "Employees");

	if ( (document.formular["ERP"]) && (gMandatoryFields & 1048576) )
	  sStr += IsValidString(GetFieldValue("ERP"), "Primary business application");


  if (sStr != "")
    alert(sStr)
  else
    document.formular.submit()
}


/*---------------------------------------------------------------------------------------------------------------------*/

function IsValidNumber(sValue, sName)
{
  if ( (sValue == null) || (sValue == "") )
    return "[" + sName + "] must not be empty\n";

  if (isNaN(sValue))
    return "[" + sName + "] must be a number\n";

  return "";
}

/*---------------------------------------------------------------------------------------------------------------------*/

function IsValidString(sValue, sName)
{
  if ( (sValue == null) || (sValue == "") )
    return "[" + sName + "] must not be empty\n";

  return "";
}

/*---------------------------------------------------------------------------------------------------------------------*/

function IsValidEmail(sValue, sName)
{
  if (sValue == null)
      return "[" + sName + "] must be a valid email address\n";

  var pos = sValue.indexOf('@');

  if (pos < 1 || pos == (sValue.length-1))
     return "[" + sName + "] must be a valid email address\n";

  return "";
}

/*---------------------------------------------------------------------------------------------------------------------*/

function IsValidHTTPURL(sValue, sName)
{
  if (sValue == null)
      return "[" + sName + "] must not be empty\n";

  var pos1 = sValue.indexOf('http://');
  var pos2 = sValue.lastIndexOf('.');

  if (pos1 != 0 || pos2 < 8 || pos2 > (sValue.length-3))
     return "[" + sName + "] must be a valid HTTP URL address\n";

  return "";
}

/*---------------------------------------------------------------------------------------------------------------------*/

function IsInRange(sValue, min, max, sName)
{
  if ((sValue == null) || isNaN(sValue) || (sValue < min || max < sValue))
      return "[" + sName + "] must be a number between " + min + " and " + max + "\n";

  return "";
}

/*---------------------------------------------------------------------------------------------------------------------*/

function IsMatchingRegEx(sValue, sPattern, sFlag,  sName)
{
  if (sValue == null)
      return "[" + sName + "] is not a valid entry\n";

  var rRegEx = new RegExp(sPattern, sFlag);

  if (! rRegEx.test(sValue))
      return "[" + sName + "] is not a valid entry\n";

  return "";
}

/*---------------------------------------------------------------------------------------------------------------------*/

function GetFieldValue(sField)
{
  var sTemp;

  if ( (document.formular[sField].type == "select-one") || (document.formular[sField].type == "select-multiple") )
    return document.formular[sField][document.formular[sField].selectedIndex].value
  else
    return document.formular[sField].value
}

//-->
