function rollover(imgid, newsrc) {var img = document.getElementById(imgid); img.src=newsrc;}
function confirmDelete() {
  var agree = confirm("Are you sure you wish to delete this entry?");
  if(agree) { return true; } else { return false; }
}
function confirmEdit() {
  var agree = confirm("Are you sure you wish to edit this entry?");
  if(agree) { return true; } else { return false; }
}
function isEmpty(s) { return ((s == null) || (s.length == 0)); }
function isNotEmpty(s) { return ((s != null) || (s.length > 0)); }
function isNumeric(s)
{
  var strValidChars = "0123456789.-";
  var c;
  var r = true;
  if(s.length == 0) return false;
  
  for(i = 0; i < s.length && r == true; i++) {
    c = s.charAt(i);
    if(strValidChars.indexOf(c) == -1) { r = false; }
  }
  return r;
}

function changeClass(id, newClass) {
  //alert("Changing class of "+id+" to "+newClass);
  object = document.getElementById(id);
  object.className = newClass;
}


// VALIDATION

function valEmail(field) {
  var str = field.value;
  if (str.length==0) { field.className=""; return true; }
  if (emailIsValid(str)) { field.className=""; return true; }
  else { field.className="error"; return false; }
}
function emailIsValid(str) {
  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)
  if (str.indexOf(at)==-1){
    //alert("Invalid E-mail ID")
    return false
  }
  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
    //alert("Invalid E-mail ID")
    return false
  }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
     //alert("Invalid E-mail ID")
     return false
  }
   if (str.indexOf(at,(lat+1))!=-1){
     //alert("Invalid E-mail ID")
     return false
   }
   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
     //alert("Invalid E-mail ID")
     return false
   }
   if (str.indexOf(dot,(lat+2))==-1){
     //alert("Invalid E-mail ID")
     return false
   }
   if (str.indexOf(" ")!=-1){
     //alert("Invalid E-mail ID")
     return false
   }
  return true         
}
function valZip(field) {
  var str = field.value;
  if (str.length==0) {return true;}
  str = str.replace(new RegExp("-","g"),"");
  if (str.length==5) { field.value=str; field.className=""; return true; }
  else { field.className="error"; return false; }
}
function zipIsValid(str) {
  var i;
  var c;
  if (str.length != 5) {return false;}
  for (i = 0; i < str.length; i++) {
    c = str.charAt(i);
    if (((c < "0") || (c > "9"))) return false;
  }
  return true;
}
function valPhone(field) {
  var str = field.value;
  if (str.length==0) {return true;}
  str = str.replace(new RegExp(" ","g"),"");
  str = str.replace(/\(/g,"");
  str = str.replace(/\)/g,"");
  str = str.replace(new RegExp("-","g"),"");
  if (str.length==10) { str=str.substr(0,3)+"-"+str.substr(3,3)+"-"+str.substr(6,4); field.value=str; field.className=""; return true; }
  else { field.className="error"; return false; }
}
function phoneIsValid(str) {
  var i;
  var c;
  str = str.replace(new RegExp("-","g"),"");
  if (str.length != 10) {return false;}
  for (i = 0; i < str.length; i++) {
    c = str.charAt(i);
    if (((c < "0") || (c > "9"))) return false;
  }
  return true;
}
function valTimestamp(field) {
  var str = field.value;
  var yyyy = "";
  var mm = "";
  var dd = "";
  if (str.length == 8) {
    yyyy = str.substr(0,4);
    mm = str.substr(4,2);
    dd = str.substr(6,2);
  }
  else if (str.length == 10) {
    if ((str.charAt(2) < "0" || str.charAt(2) > "9") && (str.charAt(5) < "0" || str.charAt(5) > "9")) {
      mm = str.substr(0,2);
      dd = str.substr(3,2);
      yyyy = str.substr(6,4);
    } else if ((str.charAt(4) < "0" || str.charAt(4) > "9") && (str.charAt(7) < "0" || str.charAt(7) > "9")) {
      yyyy = str.substr(0,4);
      mm = str.substr(5,2);
      dd = str.substr(8,2);
    } else {field.className = "error"; return false;}
  }
  else {field.className = "error"; return false;}
  if (isNumeric(yyyy) && isNumeric(mm) && isNumeric(dd)) {
    field.value = mm+"-"+dd+"-"+yyyy;
    field.className = "";
    return true;
  } else {field.className = "error"; return false;}
}
function timestampIsValid(str) {
  if (isNumeric(str.substr(0,2)) && isNumeric(str.substr(3,2)) && isNumeric(str.substr(6,4))) {return true;} else {return false;}
}
function gotoSelected(selname) {
  var sel = document.getElementById(selname);
  window.location.href = sel.options[sel.selectedIndex].value;
}

