// Fills a form with parameters passed by url.
// The standard format is //..../page.html?name1=value1&name2=value2
// Parameters that are not recognised are ignored.
// Parameter names must correspond with element names in the form.
// Names are NOT case sensitive.
// Values are not case sensitive but case is preserved for text fields.
// To set or clear a checkbox, use name=1 or name=0 respectively.
// To set a radiogroup value, use name=value where value is the value of the button to be checked.

function loadParam(f,p) // f is a form, p is a string : 'name=value'
{ var pa = p.split('='); if (pa.length < 2) return false;

  var n = pa[0].toLowerCase();
  var v = pa[1].toLowerCase();
  with (f) {
    for (var i = 0; i < length; i++) with (elements[i]) {
      if (n == name.toLowerCase()) {
        var tp = type.toLowerCase();
        if (tp == 'select-one') {
          for (var j = 0; j < length; j++) if (options[j].text.toLowerCase() == v) {
            selectedIndex = j;
            break;
		}}
        else if ((tp == 'radio') && (value.toLowerCase() == v)) checked = true
        else if (tp == 'checkbox') checked = ((v != '') && (v.charAt(0) != '0'))
        else value = pa[1]
    }}
}}

function loadParams(f) // f is a form
{ var tmp = unescape(document.location.search); if (tmp.charAt(0) == '?') tmp = tmp.substring(1);

  if ((typeof(f) == 'undefined') || (tmp == '')) return false;
  
  tmp = tmp.split('&'); for (var i = 0; i < tmp.length; i++) loadParam(f,tmp[i]);  
}

loadParams(document.forms[0]);