function setDivsSameHigh(elids)
{
	height=0;
	for(i=0;i<elids.length;i++)
  {
    size=$(elids[i]).getSize();
		height=(size.y>height)?size.y:height;
  }
	for(i=0;i<elids.length;i++)
  {
    pt=$(elids[i]).getStyle("padding-top").toInt();
		pb=$(elids[i]).getStyle("padding-bottom").toInt();
		mt=$(elids[i]).getStyle("margin-top").toInt();
		mb=$(elids[i]).getStyle("margin-bottom").toInt();
		
		$(elids[i]).setStyle("height",height-pt-pb-mt-mb);
  }
}

function addOffsetHeight(elid,offset)
{
  var sz=$(elid).getSize();
  $(elid).setStyle("height",sz.y+offset);
}

function setToBottom(elid)
{
  H=$(elid).parentNode.getStyle("height").toInt();
	$(elid).parentNode.setStyle("height","auto");
	prevH=$(elid).parentNode.getStyle("height").toInt();
	$(elid).parentNode.setStyle("height",H);
	maxH=H-prevH;
	if(top<0 || top==NaN) maxH=0;
	$(elid).setStyle("top",maxH);
	$(elid).setStyle("position","relative");
}


/*SLIDE SHOW*/
var SLIDE_STEPS=4;
var SLIDE_SPEED=80;
var SLIDE_PAUSE=5000;

function initSlideShow(elId)
{
	//alert($(elId).nodeName.toLowerCase());
	try{if($(elId).nodeName.toLowerCase()!="div") return;}
	catch(e){return;}
	setTimeout("slideIt('"+elId+"',100)",2000);
}

function slideIt(elId,opacity)
{
  var imgs=$(elId).getElementsByTagName("img");
	if(opacity<101 && opacity>=0)
	{
  	try{imgs[imgs.length-1].style.filter="Alpha(opacity="+opacity+")";} catch(e){;}
		imgs[imgs.length-1].style.opacity=(opacity/100);
		opacity=opacity-SLIDE_STEPS;
		setTimeout("slideIt('"+elId+"',"+opacity+")",SLIDE_SPEED);
	}
	else
	{
  	img=document.getElementById(elId).removeChild(imgs[imgs.length-1]);
		try{img.style.filter="Alpha(opacity=100)";} catch(e){;}
		img.style.opacity=1;
		
		document.getElementById(elId).insertBefore(img,imgs[0]);
		setTimeout("slideIt('"+elId+"',100)",SLIDE_PAUSE);
	}
}

function initNav(img)
{
  nimg=new Image();
  nimg.src=img.src.substring(0,img.src.length-5)+"h.gif";
  nimg.style.display="none";
  $(document.body).appendChild(nimg);
  normal(img);
}

function onloadNav(elId)
{
  var imgs=$(elId).getElements("img");
  for(i=0;i<imgs.length;i++) 
  {
    imgs[i].onmouseout=function(e) {normal( this );};
    imgs[i].onmouseover=function(e) {hover( this );};  
    initNav(imgs[i]);
  }
}

function normal(img)
{
	if(img.parentNode.className=="aktiv") n="h";
  else n="n";
  img.src=img.src.substring(0,img.src.length-5)+n+".gif";
}

function hover(img)
{
  img.src=img.src.substring(0,img.src.length-5)+"h.gif";
}

//gets ChildNode Index to direkt parent
//returns index
//needs testElementV1000
//1n: DOM-Element
//2n: (#Id,.Class,Nodename,DOM-Element)
function getChildPosV1000(child,allowedElements)
{
  var pn;
	if(child==false) return false;
  pn=child.parentNode.childNodes;
	var a=-1;
	for(var i=0;i<pn.length;i++) 
	{
  	if(testElementV1000(pn[i],allowedElements)===false) continue;
		a++;
  	if(pn[i]==child) return a;
	}
  return false;
}

//gets a "non-direct" perent, identified by:
//1n: DOM-Element
//2n: (#Id,.Class,Nodename,DOM-Element)
//3o: how Deep to search
function searchRelativeParentV1000(el,pIdentifier,depth)
{
  if(pIdentifier==null) return false;
	if(depth==null) depth=20; 
	var ptest=false;
	while(ptest==false && depth>0)
	{
  	oldEl=el;
		el=el.parentNode;
		ptest=testElementV1000(el,pIdentifier)
		depth--;
	}
	if(ptest===true) return el;
	else return false;
}

//test if element belongs to a given el
//el: DOM-Element
//2n: (#Id,.Class,Nodename,DOM-Element)
function testElementV1000(el,classID)
{
  var ptest=false;
	//if classId == ClassName
	if(classID.indexOf(".")===0 
  	&& el.className==classID.substr(1)) ptest=true;
	
	//if classId == IdName
	if(classID.indexOf("#")===0 
  	&& el.id==classID.substr(1)) ptest=true;
	
	//else (!IdName && !ClassName)
	if(classID.indexOf(".")===false 
  	&& classID.indexOf("#")===false)
		{
  		//if classId == nodeName
			if(el.nodeName==classID) ptest=true;
			//if classId == Element
			if(el==classID) ptest=true
		}
	return ptest;	
}

function moveThisInRowV1000(el,offsetTop,to)
{
  //get the DOM-Parent of el
	var p=searchRelativeParentV1000(el,offsetTop);
	if(p===false) return false;
	
	//get the x in p.parent.childNodes[x]
	var pos=getChildPosV1000(p,offsetTop);
	p=p.parentNode;
	
	//is no offsetParent found?
	if(pos===false) return false;
	
	//if is first or last Element
	if($$(offsetTop).length>=(pos+to+1) && pos+to>=0)
	{
  	if($$(offsetTop).length==(pos+to+1)) 
  		p.appendChild(p.removeChild($$(offsetTop)[pos]),$$(offsetTop)[pos+to]);
		else 
			p.insertBefore(p.removeChild($$(offsetTop)[pos]),$$(offsetTop)[pos+to]); 
	}
}

function mootoolsEffectFxMorphStart(elid,duration,fromOpacity,toOpacity)
{
  var myEffect1 = new Fx.Morph(elid, 
    {
      'duration': duration, 
      transition: Fx.Transitions.Sine.easeOut
    }
  );
	myEffect1.start({'opacity': [fromOpacity,toOpacity]});
}
var DEACTIVATE_SELS=new Array();
function addOverlay(el)
{
  var div=document.createElement("div");
	div.id="overlay";
	div.style.position="absolute"
	div.style.top="0px";
	div.style.left="0px";
	div.style.height=$(document.body).getScrollSize().y+"px";
	div.style.width=$(document.body).getScrollSize().x+"px";
	div.style.zIndex=1000;
	$(document.body).insertBefore(div,$(document.body).firstChild);
	
	div=document.createElement("div");
	div.style.zIndex=1001;
	div.id="overlayInput";
	div.style.width="500px";
	div.style.position="absolute";
	var backLink=cEm("a");
	backLink.href="#";
	backLink.title="Schließen";
	backLink.id="closeOverlayDivA";
	backLink.appendChild(document.createTextNode("x"));
	backLink.addEvent("click",function(){closeOverlay(); return false;});
	
	div.appendChild(backLink);
	div.appendChild(el);
	
	//ie6 -> hide all selectFields
	var sels=$(document.body).getElementsByTagName("select");
	for(var i=0;i<sels.length;i++)
	{
  	DEACTIVATE_SELS[DEACTIVATE_SELS.length]=Array(sels[i],sels[i].style.display=="none");
  	sels[i].style.display="none";
	}
	
	$(document.body).insertBefore(div,$(document.body).firstChild);
	window.addEvent("resize",function()
	{
    newPosOverlay();
	});
	newPosOverlay();
}

function newPosOverlay()
{
  var boSz=$(document.body).getSize();
	var boSc=$(document.body).getScroll();
	try{var elSz=$("overlayInput").getSize();}catch(e){return}
	var t=Math.round((boSz.y-elSz.y)/2);
	t=(t<0)?0:t;
	$("overlayInput").style.top=t+boSc.y+"px";
	var l=Math.round((boSz.x-elSz.x)/2);
	l=(l<0)?0:l;
	$("overlayInput").style.left=l+boSc.x+"px";
}

function closeOverlay()
{
	$(document.body).removeChild($("overlay"));
	$(document.body).removeChild($("overlayInput"));
	//ie6 -> show all hidden selectFields
	for(var i=0;i<DEACTIVATE_SELS.length;i++)
	{
  	if(DEACTIVATE_SELS[i][1]!==true) DEACTIVATE_SELS[i][0].style.display="";
  	
	}
	return true;
}


function overlayRePos()
{
  var elSz=$("overlayInput").getSize();
	var boSz=$(document.body).getSize();
	var boSc=$(document.body).getScroll();
	var t=Math.round((boSz.y-elSz.y)/2);
	t=(t<0)?0:t;
	$("overlayInput").style.top=t+boSc.y+"px";
	var l=Math.round((boSz.x-elSz.x)/2);
	l=(l<0)?0:l;
	$("overlayInput").style.left=l+boSc.x+"px";
}

function getScreenSize()
{
  boSz=$(document.body).getSize();
	return boSz;
}

function implode(array,delimiter,start,end)
{
  if(start==null) start=0;
	if(end==null) end=array.length;
	var text="";
  for(var i=start;i<end;i++) text+=array[i]+delimiter;
	return text.substr(0,text.length-2);
}

//createTextNode
function cTn(tn) 							{ 	return document.createTextNode(tn); 		}
//createElement
function cEm(el) 							{		return new Element(el);			}
//cloneNode
function cN(el)  							{		return document.cloneNode(el);					}
//appendChild
function aC(pa,el)  					{		return pa.appendChild(el);							}
//append Elemenents to one child
function aCs(pa,els)   		 		{ 	for(i=0;i<els.length;i++) aC(pa,els[i]);}

//create element x-times 
function cEs(el,count) 
{		
  els=new Array();
  for(i=0;i<count;i++)  els[i]=cEm(el);
  return els;		
}

function returnDayName(day)
{
  if(day==1) return "Montag";
  if(day==2) return "Dienstag";
  if(day==3) return "Mittwoch";
  if(day==4) return "Donnerstag";
  if(day==5) return "Freitag";
  if(day==6) return "Samstag";
  if(day==0 || day==7) return "Sonntag";
}

function returnMonthName(mnr)
{
  if(mnr==0) return "Januar";
  if(mnr==1) return "Februar";
  if(mnr==2) return unescape("M%E4rz");
  if(mnr==3) return "April";
  if(mnr==4) return "Mai";
  if(mnr==5) return "Juni";
  if(mnr==6) return "Juli";
  if(mnr==7) return "August";
  if(mnr==8) return "September";
  if(mnr==9) return "Oktober";
  if(mnr==10) return "November";
  if(mnr==11) return "Dezember";
}

function returnMonthLength(mnr,year)
{
  if(mnr==0) return 31;
  if(mnr==1) 
  {
    r=28;
    if (year % 4 == 0) r++;
    if (year % 100 == 0) r--;
    if (year % 400 == 0) r++;
    return r;
  }
  if(mnr==2) return 31;
  if(mnr==3) return 30;
  if(mnr==4) return 31;
  if(mnr==5) return 30;
  if(mnr==6) return 31;
  if(mnr==7) return 31;
  if(mnr==8) return 30;
  if(mnr==9) return 31;
  if(mnr==10) return 30;
  if(mnr==11) return 31;
}

//makes 0=monday and 6=sunday not english formated
function parseEngDayToGerman(actdate)
{
  actDay=actdate.getDay()-1;
	actDay=(actDay<0)?6:actDay;
	return actDay;
}

//returns php time() (in js time() is with milisecounds
function dateToUnixTime(actdate) 
{
  actdate=actdate.getTime()+"";
	return actdate.substr(0,actdate.length-3);
}

//reset hours/minutes/secounds/milisec. from date
function dateToFullDayInUnixTime(actdate)
{
  actdate.setHours(0);
	actdate.setMilliseconds(0);
  actdate.setMinutes(0);
	actdate.setSeconds(0);
	return dateToUnixTime(actdate);
}

function repGermanUmlauts(str)
{
  str=str.replace(unescape("%E4"),"ae");
	str=str.replace(unescape("%F6"),"oe");
	str=str.replace(unescape("%FC"),"ue");
	str=str.replace(unescape("%C4"),"Ae");
	str=str.replace(unescape("%D6"),"Oe");
	str=str.replace(unescape("%DC"),"Ue");
	str=str.replace(unescape("%DF"),"ss");
  return str;
}

function trim(str)
{
  return str.replace(/\s+$/,"").replace(/^\s+/,"");
}
