// Copyright © 2001 by Apple Computer, Inc., All Rights Reserved.
//
function validateSignup(theForm) {
    var why = "";
    why += isEmpty(theForm.name.value, 'Name');
    why += hasNumbers(theForm.name.value, 'Name');
    why += checkEmail(theForm.email.value);
    why += isEmpty(theForm.phone.value, 'Phone');
    why += isEmpty(theForm.country.value, 'Country');
    why += isEmpty(theForm.province.value, 'Province / State');
    why += isEmpty(theForm.city.value, 'City');
    why += isEmpty(theForm.zip.value, 'ZIP Code / Postal Code');
    why += isEmpty(theForm.address.value, 'Address');
	
    if (why != "") {
       alert("The following error(s) were found:\n\n" + why + "\nPlease correct them to continue");
       return false;
    }
	return true;
}

function validateContact(theForm) {
    var why = "";
    why += isEmpty(theForm.name.value, 'Name');
    why += hasNumbers(theForm.name.value, 'Name');
    why += checkEmail(theForm.email.value);
	
    if (why != "") {
       alert("The following error(s) were found:\n\n" + why + "\nPlease correct them to continue");
       return false;
    }
	return true;
}

function checkEmail (strng) {
	var error="";
	if (strng == "") 
	{
		error = " - Missing email address.\n";	   
	}
	else
	{
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(strng))) { 
		   error = " - Invalid email address.\n";
		}
		else {
		   var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
			 if (strng.match(illegalChars)) {
			  error = " - Wrong characters found in email address.\n";
		   }
		}    
	}
	return error;
}

function isEmpty(strng, nombreCampo) {
var error = "";
  if (strng.length == 0) {
     error = " - " + nombreCampo + " field is empty.\n"
  }
return error;	  
}

function hasNumbers(strng, nombreCampo) {
var error = "";
	if (/\d/.test(strng)) {
      error = " - Numbers are not allowed for " + nombreCampo + " field.\n" // no spaces, full stops or anything but A-Z
	}
return error;
}