function element_addClassName(obj,className,offset){
  obj = isObject(obj);
  if(typeof offset == 'undefined') offset = '';
  obj.className+=offset+className;

  return true;
}
function element_removeClassName(obj,className,offset){
  obj = isObject(obj);

  if(typeof offset == 'undefined') offset = '';
  
  obj.className = str_replace(offset+className, '', obj.className);
  
  
  return true;

}
function element_replaceClassName(obj,classNameSearch,classNameReplace){
  obj = isObject(obj);
  
  obj.className = str_replace(classNameSearch, classNameReplace, obj.className);
  
  
  return true;

}


function element_getZIndex(obj,value){
  obj = isObject(obj);
      
  if(obj.style.zIndex != null) {
    return obj.style.zIndex;
  }
  
  return true; 
}

function element_setZIndex(obj,value){
  obj = isObject(obj);
      
  if(obj.style.zIndex != null) {
    obj.style.zIndex  = value;
    return true;
  }
  
  return true; 
}

function getElement(type,res){
	var obj;
	
	if(document.getElementById) {
    
    if(type=='id') obj = document.getElementById(res);
    
  } else if(document.all) {

  	if(type=='id') obj = document.all[res];
  }
  
  return obj;
}


function moveElement(obj,vleft,vtop){
  obj = isObject(obj);
  
  var size = getElementSize(obj);

  vleft = recalcValue2px(vleft,size.width);
  vtop = recalcValue2px(vtop,size.height);

  obj.style.position = 'absolute';
  obj.style.left  = vleft.toString() + "px";
  obj.style.top = vtop.toString() + "px";

  return true;
}

function setElementVisibility(obj,status){
  obj = isObject(obj);

  obj.style.display = status;
  
  return true;
}

function setElementDisplay(obj,status){
  obj = isObject(obj);
  
  obj.style.display = status;
  
  return true;

}
function getElementPosition(obj){
  
  var xpos = 0;
  var ypos = 0;

  if(typeof obj.offsetLeft =='number'){
    xpos = parseInt(obj.offsetLeft);
    ypos = parseInt(obj.offsetTop);
    
    return {x:xpos,y:ypos};
  }
  
  if(typeof obj.clientLeft =='number'){
    xpos = parseInt(obj.clientLeft);
    ypos = parseInt(obj.clientTop);
    
    return {x:xpos,y:ypos};
  }

  if(typeof obj.layerX =='number'){
    xpos = parseInt(obj.layerX);
    ypos = parseInt(obj.layerY);
    
    return {x:xpos,y:ypos};
  }
  
  return false;
}


function getElementSize(obj){
   
	return {width:getElementWidth(obj),height:getElementHeight(obj)};
}

function setElementBackground(obj,background){

  obj = isObject(obj);

  obj.style.background = background;
  
  return true;
}


function getElementWidth(obj){
  obj = isObject(obj);
  
  if(typeof obj.offsetWidth != 'undefined') return parseInt(obj.offsetWidth);
  
  if(typeof obj.width != 'undefined') return parseInt(obj.width);
  
  if(typeof obj.naturalWidth != 'undefined') return parseInt(obj.naturalWidth);
	
  if(typeof obj.clientWidth != 'undefined') return parseInt(obj.clientWidth);
  
  if(typeof obj.style.width != 'undefined' && obj.style.width!='auto') return parseInt(obj.style.width);
  
  return false;
}

function setElementWidth(obj,width){
  
  obj = isObject(obj);
  obj.style.overflow = 'hidden';
  obj.style.width = (width!='auto')?parseInt(width).toString()+'px':width;
  
  return true;
}

function setElementHeight(obj,height){
 
  obj = isObject(obj);
  obj.style.overflow = 'hidden';
  obj.style.height = (height!='auto')?parseInt(height).toString()+'px':height;
  
  return true;
}

function getElementHeight(obj){
  obj = isObject(obj);
  
  if(typeof obj.offsetHeight != 'undefined') return parseInt(obj.offsetHeight);
  
  if(typeof obj.height != 'undefined') return parseInt(obj.height);
  
	if(typeof obj.naturalHeight != 'undefined') return parseInt(obj.naturalHeight);
	
  if(typeof obj.clientHeight != 'undefined') return parseInt(obj.clientHeight);
  
  if(typeof obj.style.height != 'undefined' && obj.style.height!='auto') return parseInt(obj.style.height);
  
	return false;
}

function setElementSize(obj,width,height){
  obj = isObject(obj);
  
	setElementWidth(obj, width);
	setElementHeight(obj, height);
	
	return true;
}

function setOpacity(obj,value){
  obj = isObject(obj);
  
  value = parseInt(value);
  value = value>100?100:parseInt(value);
  value = value<0?0:parseInt(value);

  if(typeof obj.style.opacity != 'undefined') {
    obj.style.opacity  = value/100;
    return true;
  }
    
  if(typeof obj.style.MozOpacity != 'undefined') {
    obj.style.MozOpacity = value/100;  
    return true;
  }

  if(typeof obj.filters != 'undefined') { 

    if(obj.style.filter == ''){     
      obj.style.filter = 'alpha(opacity='+value.toString()+')';
    }
    
    obj.filters['alpha']['opacity'] = parseInt(value);

    return true;
  }

  if(typeof obj.style.KhtmlOpacity != 'undefined') {
    obj.style.KhtmlOpacity  = value/100;
    return true;
  } 
  
  return true; 
}

function getOpacity(obj){
  obj = isObject(obj);

  if(obj.style.opacity != null) return parseInt(obj.style.opacity*100);
  
  if(obj.style.MozOpacity != null) return parseInt(obj.style.MozOpacity*100);  
  
  if(typeof obj.filters != 'undefined') {    
    if(obj.style.filter != ''){
      return parseInt(obj.filters['alpha']['opacity']);
    }
  }
    
  if(obj.style.KhtmlOpacity != 'undefined') return parseInt(obj.style.KhtmlOpacity*100);

  //wird nichts gefunden, wird angenommen, das Element sei komplett durchsichtig
  return 0;
}


function buildUniqueObjectID(object){
	var ret = 0;
	
  //if(typeof object.sourceIndex != 'undefined') return object.sourceIndex;  

  //Fierfox doesn't know "sourceIndex"
	var id = null;
  if(typeof object.innerText != 'undefined') ret+= object.innerText;
  if(typeof object.outerText != 'undefined') ret+= object.outerText;
  if(typeof object.innerHTML != 'undefined') ret+= object.innerHTML;
  if(typeof object.childNodes != 'undefined') ret+= object.childNodes.length;
  if(typeof object.tagName != 'undefined') ret+= object.tagName;
  if(typeof object.id != 'undefined') id = object.id;
  var src = null;
  if(typeof object.src != 'undefined') {
  	src = object.src;
  	ret+= src;
  	
  	var parts = src.split('/');
  	src = parts[parts.length-1];
  	src = src.replace(/\./g, '');
  }
  
  ret = id + ret + src;
  
  var zeit = new Date();
  var timestamp = '';
  timestamp+= zeit.getFullYear();
  timestamp+= zeit.getMonth();
  timestamp+= zeit.getDay();
  timestamp+= zeit.getHours();
  timestamp+= zeit.getMinutes();
  timestamp+= zeit.getSeconds();
  timestamp+= zeit.getMilliseconds();
  
  var randomNr = Math.random();
  randomNr *= 1000;
  randomNr = Math.ceil(randomNr);
  
	return ret.length.toString() + timestamp.toString() + randomNr.toString();
}





function isObject(mixed){
  var ret = true;
  
  if (typeof(mixed)!="object"){
    mixed = getElement('id',mixed);
    if (typeof(mixed)=="object") return mixed;
    return false;
  } else {
    return mixed;  
  }
}

/*
 * recalculate px-values and percentage-values
 */
function recalcValue2px(value,val100percent){

  if(value.toString().substring((value.toString().length-1))=='%'){  //Umrechnung bei %-Angabe
    return (val100percent/100) * parseInt(value);
  }
  
  if(value.toString().substring((value.toString().length-2),2)=='px'){  //Umwandlung bei px-Angabe
    return parseInt(value);
  }

  return parseInt(value);
}