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 aElements;
	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 check_data()
{
	var oElement = document.getElementById("agbs");
	var oElementAgb = document.getElementById("agbtext");

	var bRet = false;
	if (oElement.checked == true)
	{
		bRet = true;
		document.sendpaypal.method = "POST";
		document.sendpaypal.action = "https://www.paypal.com/cgi-bin/webscr";
		document.sendpaypal.submit();
		oElementAgb.style.color = "#000000";
	}
	else
	{
		oElementAgb.style.color = "#FF6600";
	}
	
	return bRet;
}

var __isFireFox = navigator.userAgent.match(/gecko/i);  

//returns the absolute position of some element within document  
function GetElementAbsolutePos(p_oElement) 
{  
	var aRet = new Object();  
    aRet.x = 0; aRet.y = 0;  
    if (p_oElement !== null)
    {  
    	aRet.x = p_oElement.offsetLeft;   
        aRet.y = p_oElement.offsetTop;   
          
        var offsetParent = p_oElement.offsetParent;  
        var parentNode = p_oElement.parentNode;  
   
        while (offsetParent !== null) 
        {  
	        aRet.x += offsetParent.offsetLeft;  
            aRet.y += offsetParent.offsetTop;  
   
            if (offsetParent != document.body && offsetParent != document.documentElement) 
            {  
	            aRet.x -= offsetParent.scrollLeft;  
                aRet.y -= offsetParent.scrollTop;  
            }  
            //next lines are necessary to support FireFox problem with offsetParent  
            if (__isFireFox)
            {  
	            while (offsetParent != parentNode && parentNode !== null)
	            {  
	                aRet.x -= parentNode.scrollLeft;  
                    aRet.y -= parentNode.scrollTop;  
                       
                    parentNode = parentNode.parentNode;  
                }      
            }  
            parentNode = offsetParent.parentNode;  
            offsetParent = offsetParent.offsetParent;  
        }  
    }  
    return aRet;
} 
function setElementPosition(p_oLens, p_oPopup)
{
	var y = 0;
	var bigshoppic = document.getElementById("BIGSHOPPIC");
	bigshoppic.style.visibility = "hidden";
	bigshoppic.style.top  = "0px";
	var ptLens = GetElementAbsolutePos(p_oLens);
	var ptPopup = GetElementAbsolutePos(p_oPopup);
	if(ptLens.y > ptPopup.y)
		y = ptLens.y-ptPopup.y;
	else
		y = ptPopup.y-ptLens.y;
		
	y = y - 550;
	bigshoppic.style.top  = y+"px";
	bigshoppic.style.visibility = "visible";
} 