function emailCheck (fieldname,blankOK,emailStr) {

var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

if(emailStr=="") {
	if (blankOK==true) {
		return true;
	} else {
		alert(fieldname + " cannot be blank");
		return false;
	}
}
	emailStr = emailStr.replace(/\s/g,"");
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
	alert(fieldname + ": Seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert(fieldname + ": The username doesn't seem to be valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert(fieldname + ":Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert(fieldname + ":The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   two or more letter domain or country (allowing for new >3 domains), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 ) {
   // the address must end in a two or more letter domain name .
   alert(fieldname + ":The address must end in a two or more letter domain (e.g., com, edu, org).")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr=": This address is missing a hostname!"
   alert(fieldname + errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}

function notBlank(fieldname,value){

if (value == "") {
	alert(fieldname + ": favor de este espacio");
	return false;
}
return true;
}
function notNull(fieldname,value){

if (value == null) {
	alert(fieldname + ": a value must be selected");
	return false;
}
return true;
}

function notUnchecked(fieldname,rad) {

for (i=0;i< rad.length;i++) {
	if (rad[i].checked) {
		return true;
	}
}
alert(fieldname + ": one option must be checked");
return false;
}

function validateNumericField_notBlank(fieldname,field,length) {
var valid = "0123456789";


if (field.length!=length) {
alert(fieldname + " must be " + length + " digits long");
return false;
}
for (var i=0; i < field.length; i++) {
temp = "" + field.substring(i, i+1);
if (valid.indexOf(temp) == "-1") {
alert(fieldname + ": Only numbers are allowed  Please try again.");
return false;
}
}
return true;
}
function validateNumericField_BlankOK(fieldname,field,length) {
var valid = "0123456789";

if (field.length == 0) {
	return true;
}

if (field.length!=length) {
alert(fieldname + " must be " + length + " digits long or blank.");
return false;
}
for (var i=0; i < field.length; i++) {
temp = "" + field.substring(i, i+1);
if (valid.indexOf(temp) == "-1") {
alert(fieldname + ": Only numbers are allowed  Please try again.");
return false;
}
}
return true;
}
function validateOnePhoneOrEmailNonBlank(phone1,phone2,email1)
{

if (phone1 == "" && phone2 == "" && email1 == "") {
	alert(" You must supply either a phone number or an email address");
	return false;
}

return true;
}

function validatePhoneOrEmailNonBlank(phone,email)
{

if (phone == ""  && email == "") {
	alert(" You must supply either a phone number or an email address");
	return false;
}

return true;
}
