function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 


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 = 'Yellow';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateEmpty(fld,name) {
    var error = "";
  
    if (fld.value.length == 0 || fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "The required field has not been filled in: " + name + ".\n"
    } else {
        fld.style.background = 'White';
    }
    return error;   
}

function validateFormOnSubmit(theForm) {
var reason = "";
  reason += validateEmpty(theForm.file, "Upload File");
  reason += validateEmpty(theForm.title,"Song Title");
  reason += validateEmpty(theForm.artist, "Song Artist");
  reason += validateEmpty(theForm.contributor, "Your Name");
  reason += validateEmpty(theForm.comment, "Comment");
  reason += validateEmail(theForm.contributorem);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }

function changeMusic (title, artist, mp3, path) {

document.getElementById("mp3player").innerHTML = "<br /><div style='font-size:14px;'>" + title + " - " + artist + "</div><object type='application/x-shockwave-flash' data='" + path + "/wp-content/plugins/mp3upload/player_mp3.swf' width='200' height='20'><param name='movie' value='" + path + "/wp-content/plugins/mp3upload/player_mp3.swf' /><param name='bgcolor' value='#ffffff' /><param name='FlashVars' value='mp3=" + path + "/wp-content/uploads/mp3upload/" + mp3 + "&amp;bgcolor1=2282B5&amp;bgcolor2=C6E3F9&amp;sliderovercolor=ffffff&amp;autoplay=1' /></object><br /><br />";

   var mydiv = document.getElementById("mp3player");
   //div found
   mydiv.style.visibility="visible";
}
