// Copyright © 2001 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.

function checkContacto(theForm) {
    var why = "";
    why += isEmpty(theForm.txtnombre.value, 'name');
    why += checkEmail(theForm.txtemail.value);
	
    if (why != "") {
       alert("The following errors were found:\n\n" + why + "\nPlease check the contact form to correct them");
       return false;
    }
	return true;
}

// email

function checkEmail (strng) {
	var error="";
	if (strng == "") 
	{
		error = " - The e-mail address is missing.\n";	   
	}
	else
	{
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(strng))) { 
		   error = " - The e-mail address is invalid.\n";
		}
		else {
	//test email for illegal characters
		   var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
			 if (strng.match(illegalChars)) {
			  error = " - The e-mail address contains forbidden characters.\n";
		   }
		}    
	}
	return error;
}

// non-empty textbox

function isEmpty(strng, nombreCampo) {
var error = "";
  if (strng.length == 0) {
     error = " - The " + nombreCampo + " field is empty.\n"
  }
return error;	  
}
