/*
script sources:
http://www.howtocreate.co.uk/
http://www.php-mysql-tutorial.com/
I am deeply grateful to these generous authors
*/

function checkForm( theForm ) {
  if( !isValidType( theForm.name, 'name' ) ) {
    window.alert( 'Please enter your name, using letters only.' );
    return false;
  }
  if( !isValidType( theForm.email, 'email' ) ) {
    window.alert( 'This does not appear to be a valid email address.' );
    return false;
  }
  if(trim(theForm.message.value) == '') {
      window.alert('Please enter a message');
      return false;
   }
  return true; //don't forget this line
}


function isValidType( oInput, oType ) {
  switch( oType.toLowerCase() ) {
    case 'select':
      return oInput.selectedIndex;
    case 'number':
      if( !oInput.value ) { return false; }
      for( var mXi = 0; mXi < oInput.value.length; mXi++ ) {
        if( oInput.value.charAt( mXi ) != '' + parseInt( oInput.value.charAt( mXi ) ) + '' ) { return false; }
      } return true;
    case 'name':
      return ( oInput.value && !oInput.value.replace( /[a-záàäçéèêñóòôöüæøå]+( ?[-']?[a-záàäçéèêñóòôöüæøå]+)*/i, "" ) );
    case 'email':
      return ( oInput.value && !oInput.value.replace( /[\w\-\+]+(\.[\w\-\+]+)*@([\w\-áàäçéèêñóòôöüæøå]+\.)+[a-z]+/i, "" ) );
  }
}

function trim(str)
{
   return str.replace(/^\s+|\s+$/g,'');
}