function validateEmpty(fld) {
 
    if (fld.value.length == 0) {
        fld.style.background = '#F0EC4A'; 
		return false;
    } else {
        fld.style.background = 'none';
		return true;
    }
}

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

function validateRadio(fld) {
	var ok=false;
	for(var c=0;c<fld.length;c++){
		if(fld[c].checked){ok=true;}
	}
	return ok;	
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#F0EC4A';
        error = "Please type your email address so we can reach you.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#F0EC4A';
        error = "Please retype your email address. It is not formatted correctly.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#F0EC4A';
        error = "Please retype your email address. It is not formatted correctly.\n";
    } else {
        fld.style.background = 'none';
    }
    return error;
}

function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "You didn't enter a phone number.\n";
        fld.style.background = '#F0EC4A';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = '#F0EC4A';
    } else if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
        fld.style.background = '#F0EC4A';
    }
    return error;
}
