function getGetVar(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  return null;
}

function setValue(obj, value)
{
  if (value == null) return null;
  
  var o,i;

  switch (obj.type) {
    case 'radio': case 'checkbox':
      return obj.value = value;
    case 'text': case 'hidden': case 'textarea':
      return obj.value = value;
    case 'password': 
      return obj.value = value;
    case 'select-one':
      o = obj.options;
      for(i = 0; i < o.length; i++)
	if (o[i].value == value)
	  return obj.selectedIndex = i;
      return null;
    case 'select-multiple': 
      o = obj.options;
      for(i = 0; i < o.length; i++)
      {
        o[i].selected = false;
        for (var j = 0; j < value.length; j++)
	{
	  if (o[i].value == value[j])
	      o[i].selected = true;
	}
      }	
      return null;
  }
  return null;
}

function fitImage(img, maxX, maxY) {
    if (img.src.substring(img.src.length-1) == '/') {
      return;
    }
    var tmp=new Image();
    tmp.src=img.src;
    var width=tmp.width;
    var height=tmp.height;
    if (maxX && width  > maxX) {
      height = (maxX * height) / width;
      width  = maxX;
    }
    if (maxY && height > maxY) {
      width  = (maxY * width) / height;
      height = maxY;
    }
    img.width=width;
    img.height=height;
    img.style.visibility='visible';
    img.style.display='inline';
}
