//safeboot.com Lead Form Validation
//Version: 2005.10.26

var whitespace = " \t\n\r";

validations = new Array();
validations[0] = ["document.frmLeadForm.first_name", "firstname"];
validations[1] = ["document.frmLeadForm.last_name", "lastname"];
validations[2] = ["document.frmLeadForm.title", "title"];
validations[3] = ["document.frmLeadForm.company", "company"];
validations[4] = ["document.frmLeadForm.country", "country"];
validations[5] = ["document.frmLeadForm.phone", "phone"];
validations[6] = ["document.frmLeadForm.email", "email"];
validations[6] = ["document.frmLeadForm.checkbox", "checkbox"];
validations[7] = ["document.frmLeadForm.00N20000000kMrr", "00N20000000kMrr"];

function isEmpty(s)
{
  var i;
  
  if((s == null) || (s.length == 0))
  return true;
	
	// Search string looking for characters that are not whitespace
	for (i = 0; i < s.length; i++)
	{
	  var c = s.charAt(i);
	  if (whitespace.indexOf(c) == -1)
	  return false;
	}
	// All characters are whitespace.
	return true;
}


function isEmail(field)
{
  var s = field.value;
  
  if (isEmpty(s))
  {
    alert("You have not entered your E-mail address.\n\nPress OK and you will be taken to that field to correct it.");
    field.focus();
    return false;
  }
  
  var apos = s.indexOf("@")
  var dotpos = s.lastIndexOf(".")
  
  if (apos < 1 || dotpos-apos < 2)
  {
    alert("You have not entered a valid E-mail format.\n\nPress OK and you will be taken to that field to correct it.");
    field.focus();
    return false;
  }
  return true;
}


function isDigit(c)
{
  return ((c >= "0") && (c <= "9"))
}


function validate()
{
  var i;
  var checkToMake;
  var field;
  
  for (i = 0; i < validations.length; i++)
  {
    checkToMake = validations[i][1];
    field = eval(validations[i][0]);
    switch (checkToMake)
    {
      case 'firstname': if (isEmpty(field.value))
      {
        alert("You have not entered your First Name.\n\nPress OK and you will be taken to that field to correct it.");
        field.focus();
        return false;
      }
      break;
      
      case 'lastname': if (isEmpty(field.value))
      {
        alert("You have not entered your Last Name.\n\nPress OK and you will be taken to that field to correct it.");
        field.focus();
        return false;
      }
      break;
      
      case 'title': if (isEmpty(field.value))
      {
        alert("You have not entered your Title.\n\nPress OK and you will be taken to that field to correct it.");
        field.focus();
        return false;
      }
      break;
      
      case 'company': if (isEmpty(field.value))
      {
        alert("You have not entered your Company.\n\nPress OK and you will be taken to that field to correct it.");
        field.focus();
        return false;
      }
      break;
      
      case 'country': if (isEmpty(field.value))
      {
        alert("You have not entered your Country.\n\nPress OK and you will be taken to that field to correct it.");
        field.focus();
        return false;
      }
      break;
      
      case 'phone': if (isEmpty(field.value))
      {
        alert("You have not entered your Phone number.\n\nPress OK and you will be taken to that field to correct it.");
        field.focus();
        return false;
      }
	   break;
      
      case '00N20000000kMrr': if (isEmpty(field.value))
      {
        alert("You have not entered a sales representative.\n\nCheck the field to correct this.");
        field.focus();
        return false;
      }
      break;
      
      case 'email' : if (!isEmail(field))
      return false;
    }
  }
  return true;
}
