function frm_val(theForm) {
var message = "";

  message += val_req(theForm.radio);
  message += val_song(theForm.song);
  message += val_dedication(theForm.dedication);
  message += val_email(theForm.from);
      
  if (message != "") {
    alert(message);
    return false;
  }

  return true;
}



function val_req(fld) {
	var error = "";
	my_req = -1;
	for (i=fld.length-1; i > -1; i--) {
		if (fld[i].checked) {
			my_req = i; 
			i = -1;
		}
	}
	if (my_req == -1) {
		error = "Please select a request show.\n"
	}
	return error; 
}


function val_song(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        error = "Please enter a song.\n"
    } 
    return error;  
}


function val_dedication(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        error = "Please enter a dedication.\n"
    } 
    return error;  
}


function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function val_email(fld) {
    var error="";
    var tfld = trim(fld.value);
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        error = "Please enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        error = "The email address contains illegal characters.\n";
    } 
    return error;
}

