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';
}

function alternate(id) {
 if(document.getElementsByTagName){

   var table = document.getElementById(id);
   var rows = table.getElementsByTagName("tr");

   for(i = 1; i < rows.length; i++){
     if(i % 2 == 0){
       rows[i].className = "odd";
     }else{
       rows[i].className = "even";
     }
   }
 }
}

function alternateTarget() {
 var id="target";
 if(document.getElementsByTagName){

   var table = document.getElementById(id);
   var rows = table.getElementsByTagName("tr");

   for(n = 1, i = 0; i < rows.length; i++){
     if(rows[i].className == "header") {
       n = 1;
       continue;
     } else if(rows[i].className == "spacer") {
       continue;
     }
     if(n % 2 == 0){
       rows[i].className = "targetOdd";
     }else{
       rows[i].className = "targetEven";
     }
     n++;
   }
 }
}

// Parse float from currency string.
// Supports currency formats:
// 1.234,56 (default)
// 1,234.56
// Examples:
// parseCurrency("1.234,56");            // Returns 1234.56 (float)
// parseCurrency("1.234,56", ",", ".");  // Returns 1234.56 (float)
// parseCurrency("1,234.56", ".", ",");  // Returns 1234.56 (float)
function parseCurrency(str, decpoint, sep) {
  if (arguments.length == 1) {
    var decpoint = ",";
    var sep = ".";
  }
  if (decpoint == "," && sep == ".") {
    str = str.replace(/\./g, "");
    str = str.replace(/\,/g, ".");
  } else {
    str = str.replace(/\,/g, "");
  } 
  str = str.replace(/\ /g, "");
  var num = parseFloat(str);
  return num;
}

// Format number with separators.
// Note. Use toFixed to set precision after the decimal point.
// Examples:
// var num = 1234.5678;
// numberFormat(num);                      // Returns 1.234,5678
// numberFormat(num", ",", ".");           // Returns 1.234,5678
// numberFormat(num", ".", ",");           // Returns 1,234.5678
// numberFormat(num.toFixed(2));           // Returns 1.234,56
function numberFormat(number, decpoint, sep) {
  var str, n, f, num, i, dp, s=0;
  if (arguments.length == 1) {
    var sep = ".";
    var decpoint = ",";
  }
  str = number.toString();
  str = str.split(".");
  n = str[0];
  f = str[1];
  num = "";
  if (typeof(n) != "undefined") {
    if(n.charAt(0)=="-") {
      n=n.substring(1,n.length);
      s++;
    }
    for(i = n.length-1, dp = 0; i >= 0; i--) { 
      num = n.charAt(i) + "" + num;
	if ((++dp % 3 == 0) && i > 0) {
	  num = sep + "" + num;
	  dp = 0;
	}
    }
    if(s) num="-"+num;
  }
  if (typeof(f) != "undefined") {
    num += decpoint + "" + f;
  }
  return num;
}

// toFixed function for browsers which don't support JS1.5
if (!Number.prototype.toFixed) {
  Number.prototype.toFixed=function(n){
    if (isNaN(this)) return this;
    if (arguments.length <= 0) var n = 0;
    var p = Math.pow(10, n);
    var s = Math.round(this * p) / p;
    s = s.toString();
    s = s.split(".");
    var d = (s.length > 1) ? s[1] : "";
    while (n > d.length) d = d + "0";
    return (n) ? s[0] + "." + d : s[0];
  }
}
