var fields = new Array ( 'fx_name', 'fx_email', 'fx_subject', 'fx_message' );

function setFocus () {
  this.style.border = "1px solid gray";
}

function clearFocus () {
  this.style.border = "1px solid silver";
}
  
function xonLoad () {
  for ( var i = 0; i < fields.length; i++ ) {
    document.getElementById(fields[i]).onfocus = setFocus;	
    document.getElementById(fields[i]).onblur = clearFocus;	
  } 

  document.getElementById('fx_name').focus();
}

document.onload = xonLoad;

function validateEmail () {
  email = document.getElementById ( 'fx_email' ).value;

  while ( email.length > 0 && email.charAt(0) == ' ' )
    email = email.substring ( 1 );
  
  while ( email.length > 0 && email.charAt(email.length-1) == ' ' )
    email = email.substring ( 0, email.length-1 );

  if ( email.length == 0 )
    return true;
  
  noAt = 0;
  for ( i = 0; i < email.length; i++ ) {
    if ( email.charAt(i) == '@' )
      noAt++;
    else if ( email.charAt(i) == ' ' ) {
      alert ( "You have typed a space character in the email address. This is not a valid character in an email address.\n\nPlease make sure the email address is valid and try again.\n" );
      return false;
    }
  }
  
  if ( noAt == 0 ) {
    alert ( "The email address you have entered does not contain an @-character. This character is mandatory in email addresses.\n\nPlease make sure the email address is valid and try again.\n" );
    return false;
  } else if ( noAt > 1 ) {
    alert ( "The email address you have entered contains multiple @-character. This makes the email address you have typed in invalid.\n\nPlease make sure the email address is valid and try again.\n" );
    return false;
  }

  return true;
}

