function checkMaxLength(field, maxlimit) {
   if(field.value.length > maxlimit) {
      field.value = field.value.substring(0, maxlimit);
   }
}

function swap_content(containerID, newText) {
   var container = document.getElementById(containerID);
   clear_all_children(container);
   var newTextElement = document.createTextNode(newText);
   container.appendChild(newTextElement);
}

function swap_content_html(containerID, newText) {
   var container = document.getElementById(containerID);
   clear_all_children(container);
   container.innerHTML = newText;
}

function swap_image(id, newImage) {
   var image = document.getElementById(id);
   image.setAttribute("src", newImage);
}

function add_strong(container) {
   container.style.fontWeight = "bold";
}

function remove_strong(container) {
   container.style.fontWeight = "normal";
}

// this function was modified from http://www.netlobo.com
// on is boolean and if true it turns it on and if false it turns it off
function toggleDiv(elt, on) {
   if (document.getElementById) {
      // this is the way the standards work
      var style2 = document.getElementById(elt).style;
      style2.display = on? "block":"none";
   } else if (document.all) {
      // this is the way old msie versions work
      var style2 = document.all[elt].style;
      style2.display = on? "block":"none";
   } else if (document.layers) {
      // this is the way nn4 works
      var style2 = document.layers[elt].style;
      style2.display = on? "block":"none";
   }
}

// this function was modified from http://www.netlobo.com
// on is boolean and if true it turns it on and if false it turns it off
function showHideDiv(elt) {
   if (document.getElementById) {
      // this is the way the standards work
      var style2 = document.getElementById(elt).style;
      style2.display = (style2.display=="none")? "block":"none";
   } else if (document.all) {
      // this is the way old msie versions work
      var style2 = document.all[elt].style;
      style2.display = (style2.display=="none")? "block":"none";
   } else if (document.layers) {
      // this is the way nn4 works
      var style2 = document.layers[elt].style;
      style2.display = (style2.display=="none")? "block":"none";
   }
}


function find_selected(sel) {
   for(var i = 0; i < sel.length; i++) {
      var option = sel[i];
      if(option.selected) { return option; }
   }
   return false;
}

function set_selected(sel, itemValue) {
   for(var i = 0; i < sel.length; i++) {
      var option = sel[i];
      if(option.value == itemValue) { option.selected = true; return true; }
   }
   return false;
}

function clear_all_children(el) {
   while (el.childNodes[0]) {
      el.removeChild(el.childNodes[0]);
   }
}

function open_window(url,w,h) {
   var status_string = "resizable=yes,location=yes,status=no,toolbar=yes,scrollbars=yes,left=10,top=10,width="+w+",height="+h;
   window.open(url, "_blank", status_string);
}

function confirm_remove(item) {
   return confirm("Do you really want to delete this " + item + "?");
}