// Copyright 2005 Google Inc.  All Rights Reserved.

var agt = navigator.userAgent.toLowerCase();
var isIe = (agt.indexOf('msie') != -1);
var isIe5 = (agt.indexOf('msie 5') != -1);
var uniqueCounter = (new Date).getTime();
function createXmlHttpReq(handler) {
  var xmlhttp = null;
  if (isIe) {
    var control = (isIe5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
    try {
      xmlhttp = new ActiveXObject(control);
      xmlhttp.onreadystatechange = handler;
    } catch (e) {
    }
  } else {
    xmlhttp = new XMLHttpRequest();
    xmlhttp.onload = handler;
    xmlhttp.onerror = handler;
  }
  return xmlhttp;
}
function xmlHttpGET(xmlhttp, url) {
  xmlhttp.open('GET', url, true);
  xmlhttp.send(null);
}
function sendRequest(url) {
  var xmlhttp = createXmlHttpReq(function() {});
  ++uniqueCounter;
  xmlHttpGET(xmlhttp, url + "&rand=" + uniqueCounter);
}
function doesNameStartWith(itemName, itemPrefix) {
  return itemName.indexOf(itemPrefix) == 0;
}
function openTips() {
  var meta = window.open("Format.aspx", "meta", 
    "menubar=no,toolbar=no,status=no,scrollbars=yes,width=400,height=560"); 
  meta.focus();
}
function counterUpdate(opt_countedTextBox, opt_countBody, opt_maxSize) {
  var countedTextBox = opt_countedTextBox ?
    opt_countedTextBox : "countedTextBox";
  var countBody = opt_countBody ? opt_countBody : "countBody";
  var maxSize = opt_maxSize ? opt_maxSize : 1024;
    
  var field = document.getElementById(countedTextBox);
  if (field && field.value.length >= maxSize) {
    field.value = field.value.substring(0, maxSize);
  }
  var txtField = document.getElementById(countBody);
  if (txtField) {  
    txtField.innerHTML = field.value.length;
  }
}
function showHelp() {
  var obj = document.getElementById("help");
  obj.style.display = "";
  obj = document.getElementById("show_help");
  obj.style.display = "none";
}
function hideHelp() {
  var obj = document.getElementById("help");
  obj.style.display = "none";
  obj = document.getElementById("show_help");
  obj.style.display = ""; 
}
function checkAll(frm, checkboxesPrefix, checked) {
  for (var i = 0; i < frm.elements.length; i++) {
    if (doesNameStartWith(frm.elements[i].name, checkboxesPrefix)) {
      frm.elements[i].checked = checked;
    }
  }
}
function removeAllOptions(obj){
  if (obj && obj.options) {
    for (var i = (obj.options.length - 1); i >= 0; i--) {
      obj.options[i] = null;
    }
    obj.selectedIndex = -1;
  }
}
function addOption(obj, text, value, selected){
  if (obj && obj.options) {
    obj.options[obj.options.length] = new Option(text, value, false, selected);
  }
}
function populateDropDown(selectList, values, selectedItem) {
  removeAllOptions(selectList);
  for (var i = 0; i < values.length; i++) {
    addOption(selectList, values[i], i, (i == selectedItem));
  }
}
function enforceLength(obj, maxLength) {
  if (obj.value.length >= maxLength) {
    obj.value = obj.value.substring(0, maxLength);
  }
}