function getElement(name) {
  if (document.getElementById)  {
        return document.getElementById(name);
  } else if (document.all) {
        return document.all[name];
  } else if (document.layers) {
        return document.layers[name];
  }
  return false;
}

function checktool(f,check) {
   for (i=0;i<f.elements.length;i++) { f.elements[i].checked = check; }
}

// Item das gedragged wird muss der Hintergrund freigegeben werden
function sliceSlot(id) {
    if($chk($(''+id+''))) var container = $(''+id+'').get('rel');
    if($chk(id)) var oldHeight = parseInt(id.substr(2,1));
    if($chk(id)) var oldWidth = parseInt(id.substr(4,1));
    if($chk(container)) var height = parseInt(container.substr(0,1));
    if($chk(container)) var width = parseInt(container.substr(2,1));
   
    for(var i=(oldHeight);i<(height+oldHeight);i++) {
    	var slice = 'i_'+i+'_'+oldWidth+'';
		if(id != slice) 
			$(''+slice+'').setProperty('class', 'lock inventory');
		else
			$(''+slice+'_1').setProperty('class', 'lock inventory');
			
		for(var ii=(oldWidth);ii<(width+oldWidth);ii++) {
			var slice = 'i_'+i+'_'+ii+'';
			if(id != slice) 
				$(''+slice+'').setProperty('class', 'lock inventory');
			else
				$(''+slice+'_1').setProperty('class', 'lock inventory');
		}
	}
}

// Item das gedragged wird muss der Hintergrund freigegeben werden
function freeSlot(id) {
    if($chk($(''+id+''))) var position = $(''+id+'').get('rel');
	if($chk(id)) var oldHeight = parseInt(id.substr(2,1));
    if($chk(id)) var oldWidth = parseInt(id.substr(4,1));
    if($chk(position)) var height = parseInt(position.substr(0,1));
    if($chk(position)) var width = parseInt(position.substr(2,1));
    
    for(var i=(oldHeight);i<(height+oldHeight);i++) {
    	var slice = 'i_'+i+'_'+oldWidth+'';
		if(id != slice) 
			$(''+slice+'').setProperty('class', 'drop');
		else
			$(''+slice+'_1').setProperty('class', 'drop');
			
		for(var ii=(oldWidth);ii<(width+oldWidth);ii++) {
			var slice = 'i_'+i+'_'+ii+'';
			if(id != slice)
				$(''+slice+'').setProperty('class', 'drop');
			else
				$(''+slice+'_1').setProperty('class', 'drop');
		}
	}
}

// Item das gedragged wird muss der Hintergrund freigegeben werden
function blockSlot(id) {
    if($chk($(''+id+''))) var position = $(''+id+'').get('rel');  
	if($chk(id)) var oldHeight = parseInt(id.substr(2,1));
    if($chk(id)) var oldWidth = parseInt(id.substr(4,1));
    if($chk(position)) var height = parseInt(position.substr(0,1));
    if($chk(position)) var width = parseInt(position.substr(2,1));
    
    for(var i=(oldHeight);i<(height+oldHeight);i++) {
    	var slice = 'i_'+i+'_'+oldWidth+'';
		if(id != slice) 
			$(''+slice+'').setProperty('class', 'drop');
		else
			$(''+slice+'_1').setProperty('class', 'drop');
			
		for(var ii=(oldWidth);ii<(width+oldWidth);ii++) {
			var slice = 'i_'+i+'_'+ii+'';
			if(id != slice) 
				$(''+slice+'').setProperty('class', 'drop');
			else
				$(''+slice+'_1').setProperty('class', 'drop');
		}
	}
}

function number_format (number, decimals, dec_point, thousands_sep) {
  var exponent = "";
  var numberstr = number.toString ();
  var eindex = numberstr.indexOf ("e");
  if (eindex > -1)
  {
    exponent = numberstr.substring (eindex);
    number = parseFloat (numberstr.substring (0, eindex));
  }
  
  if (decimals != null)
  {
    var temp = Math.pow (10, decimals);
    number = Math.round (number * temp) / temp;
  }
  var sign = number < 0 ? "-" : "";
  var integer = (number > 0 ? 
      Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
  
  var fractional = number.toString ().substring (integer.length + sign.length);
  dec_point = dec_point != null ? dec_point : ".";
  fractional = decimals != null && decimals > 0 || fractional.length > 1 ? 
               (dec_point + fractional.substring (1)) : "";
  if (decimals != null && decimals > 0)
  {
    for (i = fractional.length - 1, z = decimals; i < z; ++i)
      fractional += "0";
  }
  
  thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? 
                  thousands_sep : null;
  if (thousands_sep != null && thousands_sep != "")
  {
	for (i = integer.length - 3; i > 0; i -= 3)
      integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
  }
  
  return sign + integer + fractional + exponent;
}