function checkrequired(which) {
  var pass=true;
  if (document.images) {
    for (i=0; i < which.length; i++) {
      var tempobj=which.elements[i];
      if (tempobj.name.substring(0,9)=="required_") {
        if (((tempobj.type=="text"||tempobj.type=="textarea")&&
          tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
          tempobj.selectedIndex==0)) {
          pass=false;
          break;
        }
      }
    }
  }
  if (!pass) {
    shortFieldName = tempobj.name.substring(9,tempobj.name.length).toUpperCase();
    alert("The "+convertSpaces(shortFieldName)+" field is required. Please enter the "+convertSpaces(shortFieldName.toLowerCase())+" and try again.");
    return false;
  } else {
    return true;
  }
}

function checkrequired2(which) {
  var pass=true;
  if (document.images) {
    for (i=0; i < which.length; i++) {
      var tempobj=which.elements[i];
      if (tempobj.name) {
	  if (tempobj.name.substring(0,9)=="required_") {
        if (((tempobj.type=="text"||tempobj.type=="textarea")&&
          tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
          tempobj.selectedIndex==0)) {
                pass=false;
                break;
              }
          }
      }
    }
  }
  if (!pass) {
    shortFieldName = tempobj.name.substring(9,tempobj.name.length).toUpperCase();
    alert("The "+convertSpaces(shortFieldName)+" field is required. Please enter the "+convertSpaces(shortFieldName.toLowerCase())+" and try again.");
    return false; 
  } else {
      if (!document.eventForm.AGREEMENT.checked) {
	  alert("You must indicate your agreement with the principles of World Environment Day to submit an event. Please review the principles above and indicate your agreement by selecting the checkbox.")
         return false;
       } else {
         return true;
      }
  }
}

function convertSpaces(str) {
  var out = "", flag = 0;
  for (i = 0; i < str.length; i++) {
    if (str.charAt(i) != "_") {
      out += str.charAt(i);
      flag = 0;
    } else {
      if (flag == 0) {
        out += " ";
        flag = 1;
      }
    }
  }
  return out;
}

function r_on(i) {
  if (document.images) { 
    if (document[i].src.indexOf("down") < 0) {
      document[i].src = "images/" + i + "_over.png"; 
    }
  }
}

function r_off(i) {
  if (document.images) { 
    if (document[i].src.indexOf("down") < 0) {
      document[i].src = "images/" + i + ".png"; 
    }
  }
}

function s_on(i) {
  if (document.images) { 
    if (document[i].src.indexOf("down") < 0) {
      document[i].src = "../images/" + i + "_over.png"; 
    }
  }
}

function s_off(i) {
  if (document.images) { 
    if (document[i].src.indexOf("down") < 0) {
      document[i].src = "../images/" + i + ".png"; 
    }
  }
}


function writeDate() {
  document.write(new Date().getFullYear());
}

