

function addOverlay(el)
{
  var div=cEm("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=cEm("div");
	div.style.zIndex=1001;
	div.id="overlayInput";
	div.style.position="absolute";
	var backLink=cEm("a");
	backLink.href="#";
	backLink.title="Schließen";
	backLink.id="closeOverlayDivA";
	backLink.appendChild(document.createTextNode("x"));
	backLink.onclick=function(){closeOverlay(); return false;};
	
	div.appendChild(backLink);
	div.appendChild(el);
	
	$(document.body).insertBefore(div,$(document.body).firstChild);
	window.addEvent("resize",function()
	{
    newPosOverlay();
	});
	newPosOverlay();
}

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 newPosOverlay()
{
  var boSz=$(document.body).getSize();
	var boSc=$(document.body).getScroll();
	var elSz=$("overlayInput").getSize();
	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"))
	return true;
}

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 removeChilds(parent)
{
  var pn,childs,l;
	pn=parent.childNodes;
	l=pn.length;
	childs=new Array();
	for(var i=0;i<l;i++) 
	{
  	childs[childs.length]=parent.removeChild(parent.firstChild);
	}
  return childs;
}

//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 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+/,"");
}

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 initSlideShow(elsId,SLIDE_PAUSE,SLIDE_SPEED,SLIDE_STEPS)
{
	if(elsId==null || $$(elsId).length==0) return false;
	if(SLIDE_PAUSE==null) SLIDE_PAUSE=5000;
	if(SLIDE_SPEED==null) SLIDE_SPEED=40;
	if(SLIDE_STEPS==null) SLIDE_STEPS=4;
	
	setTimeout("slideIt('"+elsId+"',100,"+SLIDE_PAUSE+","+SLIDE_SPEED+","+SLIDE_STEPS+")",2000);
}

function slideIt(elId,opacity,SLIDE_PAUSE,SLIDE_SPEED,SLIDE_STEPS)
{
  var imgs=$$(elId);
	if(opacity<101 && opacity>=0)
	{
  	imgs[imgs.length-1].setStyle("opacity",opacity/100);
		opacity=opacity-SLIDE_STEPS;
		setTimeout("slideIt('"+elId+"',"+opacity+","+SLIDE_PAUSE+","+SLIDE_SPEED+","+SLIDE_STEPS+")",SLIDE_SPEED);
	}
	else
	{
  	var img=imgs[0].parentNode.removeChild(imgs[imgs.length-1]);
		imgs[imgs.length-1].setStyle("opacity",1);
		imgs[0].parentNode.insertBefore(img,imgs[0]);
		setTimeout("slideIt('"+elId+"',100,"+SLIDE_PAUSE+","+SLIDE_SPEED+","+SLIDE_STEPS+")",SLIDE_PAUSE);
	}
}

//http://javascript.about.com/library/blsort2.htm
function randOrd()
{
  return (Math.round(Math.random())-0.5); 
} 

//http://javascript.about.com/library/blsort2.htm
function sortArrayRand(anyArray)
{
  anyArray.sort(randOrd);
	return anyArray;
}

function image_resize(img,maxHeight,maxWidth,rePos,makeBigger)
{
  var width=img.getSize().x;
	var height=img.getSize().y;
	var z=1;
	
	if((width>maxWidth || (width<=maxWidth && makeBigger===true)) && width>=height) z=maxWidth/width;
	
	if((height>maxHeight || (height<=maxHeight && makeBigger===true)) && height>=width) z=maxHeight/height;
	
	img.setStyle("width",Math.round(width*z));
	img.setStyle("height",Math.round(height*z));

	if(rePos===true)
	{
  	var newWidth=img.getSize().x;
  	var newHeight=img.getSize().y;
		if(newWidth<maxWidth) img.setStyle("paddingLeft",Math.round((maxWidth-newWidth)/2));
		if(newHeight<maxHeight) img.setStyle("paddingTop",Math.round((maxHeight-newHeight)/2));
	}
}