String.prototype.rtrim = function (clist) {
  // Zeichenkette mit den zu entfernenden Zeichen angegeben?
  if (clist)
    // Zeichen aus der Liste, die am Ende des String stehen
    // löschen.
    return this.replace (new RegExp ('[' + clist + ']+$'), '');
  // Whitespaces am Ende des Strings ertfernen und dann das Ergebnis
  // dieser Operation zurückgeben.
  return this.replace (/\s+$/, '');
}

String.prototype.ltrim = function (clist) {
  // Wurde eine Zeichenkette mit den zu entfernenden
  // Zeichen übergeben?
  if (clist)
    // In diesem Fall sollen nicht Whitespaces, sondern
    // alle Zeichen aus dieser Liste gelöscht werden,
    // die am Anfang des Strings stehen.
    return this.replace (new RegExp ('^[' + clist + ']+'), '');
  // Führende Whitespaces aus dem String entfernen
  // und das resultierende String zurückgeben.
  return this.replace (/^\s+/, '');
}
String.prototype.rtrim = function (clist) {
  // Zeichenkette mit den zu entfernenden Zeichen angegeben?
  if (clist)
    // Zeichen aus der Liste, die am Ende des String stehen
    // löschen.
    return this.replace (new RegExp ('[' + clist + ']+$'), '');
  // Whitespaces am Ende des Strings ertfernen und dann das Ergebnis
  // dieser Operation zurückgeben.
  return this.replace (/\s+$/, '');
}


function openPopUp(file){
	//alert(file)
	popup = window.open('fileadmin/PHP/'+file, "Zweitfenster", "width=800,height=400,left=125,top=300,location=no,status=no");
	popup.focus();
		

}



function openChart (kanal) {
	var mode=''+window.location.search
	kanal=(mode!='' ? '&channel='+kanal : '?channel='+kanal)
	
  popup = window.open('fileadmin/PHP/mdata/chart.html.php'+mode+kanal, "Zweitfenster", "width=855,height=600,left=0,top=130,location=no,status=no,resizable=no");
	popup.focus();

	return false
}
function JSExist (kanal) {
	return true
}


function optionMO (obj) {
	}

function setImageContainer (id) {
	var ic=document.getElementById(id)
	var d=ic.offsetHeight % 18;
	if(d>0){
		
			d=17-d
			ic.style.height=(ic.offsetHeight+d)+"px"

		
	}
	
	}
	/*###################################################*/
	
	
var ceN=0
var ceCurI=0

var cssPath = "/fileadmin/css/pageBrowser.css";
var cssElement;
  cssElement = document.createElement("link");
  cssElement.setAttribute("type", "text/css");
  cssElement.setAttribute("href", cssPath);
  document.getElementsByTagName("head")[0].appendChild(cssElement);



function ceItems(){
	this.N=0
	this.I=0
	this.data=new Array()
	this.add=function(id){
	    var nb=this.N
		this.data.push(new ceItem(id,this.N))
		if(this.N==1){
            this.data[0].posi()
        }
		if(this.N>0){
            this.data[this.N].posi()
        }
		
        //this.data[this.N].posi()
		this.N+=1
		
	}
	this.showItemByID=function(id){
		for(i=0;i<this.data.length;i++){
			if(id==this.data[i].id){
				if(this.data[i].state===null || this.data[i].state===false){
					this.data[i].show()
				}
			}else{
				if(this.data[i].state===null || this.data[i].state===true){
					this.data[i].hide()
				}
			}
		}
		pageBrowser.draw()
	}
	this.showItemByI=function(i){
		this.showItemByID(this.data[i].id)
	}
}

function ceItem(id,i){
	this.I=i
	this.id=id
	this.object=document.getElementById(id)
	//alert(this.object)
    this.state=null
	this.posi=function(){
	   this.object=document.getElementById(this.id)
		with(this.object.style){
			position='absolute'
			left='5px'
			//top='200px'
			top='160px'
			
            //border = "solid red 1px";
			width = '695px'
            width = '715px'	
			
		}
		
	}
	this.show=function(){
	this.object=document.getElementById(this.id)
		this.object.style.visibility="visible"
		this.state=true
	}
	this.hide=function(){
	this.object=document.getElementById(this.id)
		this.object.style.visibility="hidden"
		this.state=false
	}
	
}	


	


function pageBrowser(id,ceList){
	this.id=id
	this.object=document.getElementById(this.id)
	this.ceList=ceList
	this.draw=function(){
		var txt=""
		var clss=""
		var iCur=0
		var tmpBack=""
		var tmpForward=""
		this.object.style.visibility="hidden"
		for(var i=0;i<this.ceList.N;i++){
			//ceList[i].object=document.getElementById(ceList[i].id)
			//this.ceList.data[i].posi()
			if(this.ceList.data[i].state==true){
				clss=" class='cur item' "
				iCur=i
			}else{
				clss=" class='item' "
			}			
			var tmp="<a href=\"javascript:void(ceList.showItemByID('"+this.ceList.data[i].id+"'))\" id=\"L"+this.ceList.data[i].id+"\" "+clss+">"+(i+1)+"</a>"
			txt=txt+tmp+" "
		}
		if (iCur>0){
			tmpBack="<a href=\"javascript:void(ceList.showItemByID('"+this.ceList.data[iCur-1].id+"'))\" id=\"back\" class=\"item\"><img src=\"/fileadmin/grafik/trans.gif\"></a>"
		}else{
			tmpBack="<img src=\"/fileadmin/grafik/30arrowL.gif\" class=\"item\">"
		}
		if (iCur<this.ceList.N-1){
			tmpForward="<a href=\"javascript:void(ceList.showItemByID('"+this.ceList.data[iCur+1].id+"'))\" id=\"forward\" class=\"item\"><img src=\"/fileadmin/grafik/trans.gif\"></a>"
		}else{
			tmpForward="<img src=\"/fileadmin/grafik/30arrowR.gif\" class=\"item\">"
		}
		
		
		
		
		this.object.innerHTML='<div>'+tmpBack+txt+tmpForward+'</div>'
		this.object.style.visibility="visible"
	}

}

var ceList=new ceItems()

function ceAdd(ceId){
	ceList.add(ceId)
	
}








function init(){
	document.getElementById('loading').style.visibility="hidden"
	hist=new History(document.location.href)
	if (document.location.href.indexOf('id=1')>0) {
		//hist.clearHistory()
	}
	buildNaviHistory()
	
	
	if(ceList.N>1){
    pageBrowser=new pageBrowser('pagebrowser',ceList)
	
	pageBrowser.draw()
	
	
	}
	ceList.showItemByI(0)

		
}
function myClear(){
	hist.clearHistory()
		buildNaviHistory()

}

function myBack(){
	//document.cookie=document.location.href
	hist.back()
}

function myForward(){
	//document.cookie=document.location.href
	hist.forward()
}
function myGoTo (u) {
	document.location.href=u
}

function CheckAuswahlHist () {
		for (i = 0; i < document.naviHistForm.selectNaviHist.length; ++i){
			if (document.naviHistForm.selectNaviHist.options[i].selected == true){
				myGoTo(document.naviHistForm.selectNaviHist.options[i].value)
			}
		}
}


function buildNaviHistory(){
	var navihist=document.getElementById('navi-hist')
	var mBack =  '<table border="0" cellspacing="0" cellpadding="0"><tr><td>'+( hist.p>0       ? '<a href="javascript:myBack()" title="1 Seite zurück" id="naviBack"><img src="/fileadmin/grafik/back.gif" ></a>' : '<span id="naviBack"><img src="/fileadmin/grafik/back_f3.gif" ></span>')+'</td>'; 
	var mNext = '<td>'+ ( hist.p<hist.pm ? '<a href="javascript:myForward()" title="1 Seite vor" id="naviNext"><img src="/fileadmin/grafik/next.gif" ></a>' : '<span id="naviNext"><img src="/fileadmin/grafik/next_f3.gif" ></span>')+'</td>';
	//txt = txt + ( hist.pm>0      ? '<a href="javascript:myClear()">clear</a>' : 'clear');
	
	var mForm='<td><form id="naviHistForm" name="naviHistForm" ><select name="selectNaviHist" id="selectNaviHist" onchange="CheckAuswahlHist()">'
	for(var i=0;i<hist.hrefs.length;i++){

		var st=hist.hrefs[i].substr(hist.hrefs[i].indexOf('index.php'))
		var t=hist.titles[i]
		if(hist.p==i){st=st}
		if(hist.pm==i){st=st}
		//txt=txt+'<br/>'+st
		mForm=mForm+'<option value="'+st+'" '+(hist.p==i ?' selected="selected"' :'')+' >'+t+'</option>'
	}
	mForm=mForm+'</select></form></td>'
	navihist.innerHTML=mBack+mForm+mNext+'</tr></table>'
	//navihist.innerHTML=mBack+mForm+mNext+( hist.pm>0      ? '<a href="javascript:myClear()">clear</a>' : 'clear')
	navihist.style.visibility="visible"
}

function History(u){
	
	this.hrefs=new Array();
	this.titles=new Array();
	this.p=-1
	this.pm=0
	this.l=false


	
	
	this.readHistory = function(){
		var aa=document.cookie.split('; ');
		for( var i=0;i<aa.length;i++){
			
			var cook=aa[i].split('=')
			switch (cook[0]) {
				case "HistHrefs":
					var x=decodeURIComponent(cook[1])
					this.hrefs=x.split('\n')
					break;
				case "HistTitles":
					var x=decodeURIComponent(cook[1])
					this.titles=x.split('\n')
					break;
				case "HistP":
					this.p=cook[1]
					break;
				case "HistPm":
					this.pm=cook[1]
					break;
				case "HistL":
					this.l=(cook[1]=='true'? true : false)
					break;
			}
		}
	}
	this.writeHistory = function(){
		//alert(document.cookie)
		var x=this.hrefs.join("\n")
		//var txt="HistP="+this.p+"; HistPm="+this.pm+"; HistL="+this.l+"; HistTitles="+encodeURIComponent(x)+'; '
		var t=this.titles.join("\n")
		//var txt="HistP="+this.p+"; HistPm="+this.pm+"; HistL="+this.l+"; HistHrefs="+encodeURIComponent(x)+'; '
		//alert(txt)
		//document.cookie=txt
		document.cookie="HistP="+this.p+";"
		document.cookie="HistPm="+this.pm+";"
		document.cookie="HistL="+this.l+";"
		document.cookie="HistHrefs="+encodeURIComponent(x)+";"
		document.cookie="HistTitles="+encodeURIComponent(t)+";"
		



		
		//alert(document.cookie)

	}
	this.clearHistory =function(){
		this.p=0
		this.l=false
		this.pm=0
		this.hrefs=new Array(document.location.href)
		this.titles=new Array(document.title)
		this.writeHistory()
	}



	this.back =function(){
		if(this.p>0){
			this.p-=2
			var u=this.hrefs[this.p+1]
			this.l=true
			this.writeHistory()
			document.location.href=u	
		}
	
	}
	this.forward =function(){
		if(this.p<this.pm){
			var u=this.hrefs[this.p+1]
			this.l=true
			this.writeHistory()
			document.location.href=u	
		}
	
	}
	this.goTo=function(u,n){
		document.location.href=u	
	}

	this.debug = function(){
		var txt='p:'+this.p+' pm:'+this.p+' l:'+this.l+"\n";
		txt=txt+'[ '+this.hrefs.join("\n")+' ]'
		alert(txt)
	}


	this.readHistory()
	if(this.hrefs[this.p]!=u){
		this.p++
		this.hrefs[this.p]=u
		this.titles[this.p]=document.title

		if(this.l==false){
			this.pm=this.p
			this.hrefs=this.hrefs.slice(0,this.pm+1)
		}
		this.l=false
		while(this.hrefs.length>10){
			this.hrefs.shift()
			this.titles.shift()
			this.p--
			this.pm--
		}
		this.writeHistory()
	}
	
}




