
// utf8 -> iso-8859
function decode_utf8(utftext) {
	var plaintext = ""; var i=0; var c=c1=c2=0;
	// while-Schleife, weil einige Zeichen uebersprungen werden
	while(i<utftext.length){
		c = utftext.charCodeAt(i);
		if (c<128) {
			plaintext += String.fromCharCode(c);
			i++;
		} else if((c>191) && (c<224)) {
			c2 = utftext.charCodeAt(i+1);
			plaintext += String.fromCharCode(((c&31)<<6) | (c2&63));
			i+=2;
		} else {
			c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2);
			plaintext += String.fromCharCode(((c&15)<<12) | ((c2&63)<<6) | (c3&63));
			i+=3;
		}
	}
	return plaintext;
}

// iso-8859 -> utf8
function encode_utf8(rohtext) {
	// dient der Normalisierung des Zeilenumbruchs
	rohtext = rohtext.replace(/\r\n/g,"\n");
	var utftext = "";
	for(var n=0; n<rohtext.length; n++) {
		// ermitteln des Unicodes des  aktuellen Zeichens
		var c=rohtext.charCodeAt(n);

		if (c<128) {
			// alle Zeichen von 0-127 => 1byte
			utftext += String.fromCharCode(c);
		} else if((c>127) && (c<2048)) {
			// alle Zeichen von 127 bis 2047 => 2byte
			utftext += String.fromCharCode((c>>6)|192);
			utftext += String.fromCharCode((c&63)|128);
		} else {
			// alle Zeichen von 2048 bis 66536 => 3byte
			utftext += String.fromCharCode((c>>12)|224);
			utftext += String.fromCharCode(((c>>6)&63)|128);
			utftext += String.fromCharCode((c&63)|128);
		}
	}
	return utftext;
}


// Positionsangaben zu einem beliebigen Element
function getPosition(element, type) {

  var elem    = element;
  var tagname = "";
  var x       = 0;
  var y       = 0;
  var w				= 0;
  var h				= 0;

  while ((typeof(elem)=="object") && (typeof(elem.tagName)!="undefined")) {

    y += elem.offsetTop;
    x += elem.offsetLeft;
    w += w ? 0 : elem.offsetWidth;
    h += h ? 0 : elem.offsetHeight;

    tagname=elem.tagName.toUpperCase();

    if (tagname=="BODY") {
      elem=0;
    }

    if (typeof(elem)=="object") {
      if (typeof(elem.offsetParent)=="object") {
        elem=elem.offsetParent;
      }
    }
  }

  position   = new Object();
  position.e = element;
  position.x = x;
  position.y = y;
  position.w = w;
  position.h = h;
  if (type) {
  	switch (type) {
  		case 'vertical':
	      position.mx = x + Math.round(w/2);
	      position.my = y + Math.round(h/2);
	    break;

	    default:
	      position.mx = x + Math.round(w/2);
	      position.my = y + Math.round(h/2);
	    break;
	  }
  }

  return position;
}

function setOpacity (obj, opac) {
	opac = opac>100	? 100		: opac;
	opac = opac<0		? 0			: opac;

	for (id in obj.style) {
		if (id == 'filter'			) {	obj.style.filter			=	'alpha(opacity='+opac+')';	}
		if (id == 'MozOpacity'	) {	obj.style.MozOpacity	=	opac/100;										}
		if (id == 'opacity'			) {	obj.style.opacity			= opac/100;										}
	}
}


