var gText = "";

function trimLF(p_strSubject) 
{
  while (p_strSubject.substring(0,1) == '\n') 
  {
    p_strSubject = p_strSubject.substring(1,p_strSubject.length);
  }
  
  while (p_strSubject.substring(p_strSubject.length-1,p_strSubject.length) == '\n') 
  {
    p_strSubject = p_strSubject.substring(0,p_strSubject.length-1);
  }
  return p_strSubject;
}

function countChars(p_iMax,p_strElement)
{
	var aElement;
	aElements = document.getElementsByName(p_strElement);
	if (aElements[0].value.length > p_iMax)
	{
		aElements[0].value = gText;
	}
	else
	{
		gText = aElements[0].value;
	}
	
	oCount = document.getElementById('charcount');
	oCount.childNodes[0].data = (p_iMax-aElements[0].value.length);
}

function openWindowScroll(p_strUrl,p_iWidth,p_iHeight)
{
	if (p_strUrl.length > 0)
	{
		if (p_iWidth == 0)
			p_iWidth = 800;
		
		if (p_iHeight == 0)
			p_iHeight = 650;

		win = window.open(p_strUrl, "Edit", "width="+p_iWidth+",height="+p_iHeight+",left=0,top=0,scrollbars=yes");
		win.focus();
	}
}

function openWindow(p_strUrl,p_iWidth,p_iHeight)
{
	if (p_strUrl.length > 0)
	{
		if (p_iWidth == 0)
			p_iWidth = 800;
		
		if (p_iHeight == 0)
			p_iHeight = 650;

		win = window.open(p_strUrl, "Edit", "width="+p_iWidth+",height="+p_iHeight+",left=0,top=0");
		win.focus();
	}
}

function oW(p_strUrl)
{
	openWindow(p_strUrl,0,0);
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function CPreloadGrafics()
{
	var m_aFiles;
	this.m_aFiles = new Array();

	this.addGrafic = function(p_strTarget)
	{
		this.m_aFiles[this.m_aFiles.length] = p_strTarget;
	}
	
	this.preLoadGrafics = function()
	{
		var oBild;
		
		for (var i = 0; i < this.m_aFiles.length; i++)
		{
			oBild = new Image();
			oBild.src = this.m_aFiles[i];
		}
	}
}

var g_oPreload = new CPreloadGrafics();

function CZitatGrafics()
{
	var m_aFiles;
	this.m_aFiles = new Array();
	var m_iNext;

	this.addGrafic = function(p_strTarget)
	{
		this.m_aFiles[this.m_aFiles.length] = p_strTarget;
	}
	
	this.SetNext = function(p_strId)
	{
		
		do {
			iNext = Math.floor(((this.m_aFiles.length) * Math.random()));
		} while (iNext == this.m_iNext);
		this.m_iNext = iNext;
		document.getElementById(p_strId).src = this.m_aFiles[this.m_iNext];
	}
}


function CChangeNavImg(p_strIDOver,p_strLang,p_iWithOver)
{
	//alert(p_strIDOver);
	refImg = document.getElementById('SUBNAVTEXT');
	refImg.style.visibility='hidden';
	refImg.src='res/img/nav/'+p_strLang+'/pas_'+ p_strIDOver+'.png';
	//alert(refImg.src);
	//refImg.width=p_iWithOver;
	//refImg.height=25;
	//while (refImg.complete != true)
	//{
	//	refImg.style.visibility='hidden';
	//}
	refImg.style.visibility='visible';
}
function ChangeGraficByID(p_strID,p_strPath,p_strButtonID,p_iButtonCount, p_iKey)
{
	for(i=0; i<p_iButtonCount;i++)
	{
		if((i+1)<10)
			document.getElementById(p_strID+i).className="w016 h016 hcenter flft cupointer bctriol ctriod";
		else
			document.getElementById(p_strID+i).className="w020 h016 hcenter flft cupointer bctriol ctriod";
		
	}
	document.getElementById(p_strID).src=p_strPath;
	if(p_iKey<10)
		document.getElementById(p_strButtonID).className="w016 h016 hcenter flft cupointer bctriom ctriol";
	else
		document.getElementById(p_strButtonID).className="w020 h016 hcenter flft cupointer bctriom ctriol";
}


// Lösung von http://js-tut.aardon.de/js-tut/tutorial/position.html
function getPosition(obj){
	var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent || obj.id == "nav")
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;

}

/*
function alertPosition(elementId)
gibt eine Meldung mit x und y des zu elementId gehoerenden Elements aus 
{
  var a,element;

 Element-Objekt zur ID ermitteln 
  element=document.getElementById(elementId);
 
 Position bestimmen und melden 
  a=getPosition(element);
  window.alert("Position "+elementId+": ("+a.x+","+a.y+")");
}

function NavOver(p_oElement,p_iID)
{
	if(p_iID != null)
		oDropDown = document.getElementById("div_"+p_iID);
	
	
	if(p_oElement != null && oDropDown != null)
	{
		p_oElement.className = "bcbobotnavtrio bobotnav ctriom flft h023 IEh025 wauto";
		aPos = getPosition(p_oElement);;
		oDropDown.className="zi060 posabs w304 hauto visvis flft";
		
		oDropDown.style.left=aPos+"px";
		
		oDropDown.setAttribute("style","left:"+aPos+"px");
	}
}
function NavOut(p_oElement,p_iID)
{
	//
	if(p_iID != null)
		oDropDown = document.getElementById(p_iID);
	if(p_oElement != null && oDropDown != null)
	{
		//alert(p_iID);
		document.getElementById(p_iID).className = "h023 IEh025 ctriom flft wauto";
		p_iID = "div_"+p_iID;
		document.getElementById(p_iID).className="zi060 posabs w304 hauto vishid flft";
	}
}*/