/* requires global associative array defined: MAILTO_LIST */

function mailto(name, subject) {
  location.href=("mailto:"+MAILTO_LIST[name]+"?subject="+subject).replace(' ', '%20');
}

function optionIndex(selectObject, optionValue) {
  // check if it matches any values
  for (var i = 0; i < selectObject.options.length; i++)
    if (selectObject.options[i].value == optionValue)
      return i;

  // check if it matches any option text
  for (var i = 0; i < selectObject.options.length; i++) 
    if (selectObject.options[i].text == optionValue)
      return i;

  return -1;
}

function isset(v) {
  if (typeof(v) != 'undefined' && v != '')
    return true;
  else
    return false;
}

function stripZeros(v) {
  return v.replace(/^0*/, '');
}

var g_array_onloads;

function onloadAdd(script, obj) {
  var id = obj;

  if (!g_array_onloads)
    g_array_onloads = new Array();

  if (!g_array_onloads[id]) {
    g_array_onloads[id] = new Array();
    obj.onload = onloadRun;
  }

  g_array_onloads[id].push(script);
}

function onloadRun() {
  var id = this;

  if (g_array_onloads[id]) {
    for (var i = 0; i < g_array_onloads[id].length; i++) {
      eval(g_array_onloads[id][i]);
    }

    // clear onloads
    g_array_onloads[id] = new Array();
  } else
    alert('no onload for ' + id);
}

function id(s) {
  return document.getElementById(s);
}

function styleShow(o) {
  if (o.style) {
    o.style.visibility = "visible";
    o.style.display = "inline";
  }
}

function styleHide(o) {
  if (o.style) {
    o.style.visibility = "hidden";
    o.style.display = "none";
  }
}

function optionValue(o) {
  var so = o.options[o.selectedIndex];
  if ((!o || o.value == "") && (!so.value || so.value == ""))
    return so.text;

  return so.value;
}

function xmlhttpGet(url) {
  var xmlhttp = getXH();
  xmlhttp.open("GET", url, false);
  xmlhttp.send(null);
  return xmlhttp.responseText;
}

function xmlhttpPost(url, data) {
  var xmlhttp = getXH();
  xmlhttp.open("POST", url, false);
  xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  xmlhttp.send(data);
  return xmlhttp.responseText;
}

function xmlhttpSubmit(formObj, url) {
  var elements = formObj.elements;

  var d = "";

  for (var i = 0; i < elements.length; i++) {
    var field = false;

    var e = elements[i];
    var t = e.tagName.toLowerCase();
    if (t == "input") {
      if (e.type == "text" ||
          e.type == "hidden" ||
          (e.type == "checkbox" && e.checked == true) ||
          (e.type == "radio" && e.checked == true)
          ) {
        field = true;
      } 
    } else if (t == "select") {
      field = true;
    } else if (t == "textarea") {
      field = true;
    } else if (t == "submit") {
      field = true;
    }

    if (field)
      d += e.name + "=" + escape(e.value) + "&";
  }

  d = d.replace(/\&$/,'');

  return xmlhttpPost(url, d);
}

function getXH() {
	// xmlhttp object initialization
	var xmlhttp=false;
	try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try {
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
	xmlhttp = false;
	}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

