// 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 checkWholeForm(theForm) {
    var why = "";
    why += isEmpty(theForm.txtnombre.value, 'nombre');
    why += checkEmail(theForm.txtemail.value);
    why += checkPhone(theForm.txtphone.value);
	why += isEmpty(theForm.txtpais.value, 'pais');
	
    if (why != "") {
       alert("Se encontraron los siguientes errores:\n\n" + why + "\nPor favor revise el formulario de contacto y corrija los errores");
       return false;
    }
	return true;
}

// email

function checkEmail (strng) {
	var error="";
	if (strng == "") 
	{
		error = " - Direccion de email faltante.\n";	   
	}
	else
	{
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(strng))) { 
		   error = " - Direccion de email no valida.\n";
		}
		else {
	//test email for illegal characters
		   var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
			 if (strng.match(illegalChars)) {
			  error = " - La direccion de email contiene caracteres no permitidos.\n";
		   }
		}    
	}
	return error;
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) 
{
	var error = "";
	if (strng == "") 
	{
	  	error = " - Numero de telefono faltante.\n";
		return error;
	}
	else
	{
		var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
		if (isNaN(parseInt(stripped))) 
		{
			error = " - Numero de telefono contiene caracteres no permitidos.\n";
		}
	}		
	return error;
}


// non-empty textbox

function isEmpty(strng, nombreCampo) {
var error = "";
  if (strng.length == 0) {
     error = " - El campo de " + nombreCampo + " esta vacio.\n"
  }
return error;	  
}
 


