function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function NewWindow(loadURL) {
window.open(loadURL,"","width=590,height=485,scrollbars=yes,resizable=yes,screenX=0,screenY=0");
}

function NewListWindow(loadURL) {
//alert('new');
window.open(loadURL,"","width=460,height=500,scrollbars=yes,resizable=yes,screenX=0,screenY=0");
}



function NewRouteListWindow(loadURL) {
//alert('new');
window.open(loadURL,"","width=650,height=600,scrollbars=yes,resizable=yes,screenX=0,screenY=0");
}

function NewPrintWindow(loadURL) {
//alert('new');
window.open(loadURL,"","width=600,height=600,scrollbars=yes,resizable=yes,screenX=0,screenY=0");
}

function NewNormalWin(url){
	//alert(url);
	newWin = window.open(url,"Haltestellenredaktionssystem_Editierfenster","");
	newWin.focus();
 }

function NewStandardWin(url){
	//alert(url);
	newWin = window.open(url,"Fenster","","scrollbars=yes,resizable=yes,screenX=0,screenY=0");
	newWin.focus();
 }
function NewStandardWin2(loadURL) {
//alert('new');
newWin = window.open(loadURL,"","width=725,height=690,scrollbars=yes,resizable=yes,screenX=0,screenY=0");
}

function newWindow(loadURL) {
//alert('new');
window.open(loadURL,"","width=980,height=700,scrollbars=yes,resizable=yes,screenX=0,screenY=0");
}

function newWindowFix(loadURL,w,h) {
//alert('new');
//w=100;
//h=200;
window.open(loadURL,"","width=600,height=700,scrollbars=yes,resizable=no,screenX=0,screenY=0");
}



function newRWindow(loadURL) {
//alert('new');
window.open(loadURL,"","width=535,height=700,scrollbars=no,resizable=yes,screenX=0,screenY=0");
}



//-----------------------------------------------
// utility functions
//-----------------------------------------------

/*
delete input fields of a form
*/
function deleteInputFields(formName) {

	var formObj = document.getElementsByName(formName)[0];
	if(formObj == null) return;

	for(var i=0; i<formObj.elements.length; i++) {
		if(formObj.elements[i].type == "text") {
			formObj.elements[i].value = "";
		}
	}

	formObj.elements[0].focus();
}


/*
show tooltip of the location
*/
function showTooltip(e) {
	var nameOfIconDiv = this.id;
	//id extrahieren
	var lfdIdOfIconDiv = nameOfIconDiv.match(/\d+$/);
	var nameOfTooltipDiv = document.getElementById("TOOLTIPTEXT" + lfdIdOfIconDiv);

	if(nameOfTooltipDiv!=null) {

		var intPosX = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
		var intPosY = (document.all) ? window.event.y + document.body.scrollTop  : e.pageY;

		nameOfTooltipDiv.style.left = parseInt(intPosX+10) + "px";
		nameOfTooltipDiv.style.top = parseInt(intPosY+10) + "px";

		nameOfTooltipDiv.style.zindex = 1000;
		nameOfTooltipDiv.style.visibility = "visible";
	}

	return true;
}


/*
hide tooltip of the location
*/
function hideTooltip(e) {
	var nameOfIconDiv = this.id;
	//id extrahieren
	var lfdIdOfIconDiv = nameOfIconDiv.match(/\d+$/);
	var nameOfTooltipDiv = document.getElementById("TOOLTIPTEXT" + lfdIdOfIconDiv);

	if(nameOfTooltipDiv!=null) {
		nameOfTooltipDiv.style.zindex = 0;
		nameOfTooltipDiv.style.visibility = "hidden";
	}
	return true;
}


/*
disable object(s)
*/
function disable(obj) {
	if(obj==null) return;
	name = obj.name;
	objects = document.getElementsByName(name);
	for(var i=0; i<objects.length; i++) {
		objects[i].disabled = true;
	}
}


/*
show or hide the input form
the property value clickObj.innerHTML will be replaced by dynamic php variables, i.e. <?=$lng_showinput?>
*/
function showInputForm(clickObj, id, texts) {
	var obj = document.getElementById(id);
	if(obj==null) return;
	if(obj.tagName != "DIV") return;

	var visibility = obj.style.visibility;
	if(visibility == "hidden") {
		obj.style.visibility = "visible";
		clickObj.innerHTML = texts[0]["hide"];
	} else {
		obj.style.visibility = "hidden";
		clickObj.innerHTML = texts[0]["show"];
	}
}


/*
load the detail map for the route
*/
function showDetailMap(iframe_name, iframe_src) {
	iframes = document.getElementsByTagName("IFRAME");
	for(var i=0; i<iframes.length; i++) {
		iframes[i].width=0;
		iframes[i].height=0;
	}
	iframe = document.getElementsByName(iframe_name)[0];
	if(iframe==null) return;
	if(iframe.nodeName!="IFRAME") return;
	iframe.src = iframe_src;
	iframe.width = 350;
	iframe.height = 350;
}


/*
KK, am 09.06.06
Konfigurierbarer Progressbar

- parent: wo soll der Progressbar eingebettet werden
- width: Breite
- fontSize: Schritgröße
- progressbarClass: ist die eigene Konfiguration (css-Klasse)
*/
function ProgressBar(parent, width, fontSize, progressbarClass) {
	//breite
  	this.pixels = width;
  	this.pct = 0;

  	this.progressbarWrapper = document.createElement("div");
  	this.progressbarWrapper.style.border = "1px solid #000000";
  	this.progressbarWrapper.style.background = "#FFFFFF";
  	this.progressbarWrapper.style.fontFamily = "Arial,Verdana";
  	this.progressbarWrapper.style.fontSize = fontSize + "px";
  	this.progressbarWrapper.style.width = (width + 2) + "px";
  	this.progressbarWrapper.style.textAlign = "left";
  	parent.appendChild(this.progressbarWrapper);

  	this.progressbar = document.createElement("div");
  	this.progressbar.style.textAlign = "center";
  	this.progressbar.style.overflow = "hidden";
  	this.progressbar.innerHTML = "x";
  	this.progressbar.style.width = "0px";

  	if(progressbarClass) {
		//benutzerdefiniert
		this.progressbar.className = progressbarClass;
	} else {
		//default layout
		this.progressbar.style.background = "#00008b";
  	  	this.progressbar.style.border = "1px solid #FFFFFF";
  	  	this.progressbar.style.color = "#FFFFFF";
  	}

  	this.progressbarWrapper.appendChild(this.progressbar);


  	/*
  	Funktion, die eine Simulation durchführt
  	*/
  	this.setPercent = function(pct) {
		this.pct = pct;

  		// expects 'pct' values between 0.0 and 1.0
  		var fillPixels;

  		if(pct < 1.0) {
			fillPixels = Math.round(this.pixels * pct);
  		} else { // avoid round off error
    		pct = 1.0;
    		fillPixels = this.pixels;
    	}

  		this.progressbar.innerHTML = Math.round(100 * pct) + "%";
  		this.progressbar.style.width = fillPixels + "px";
	}

}

//müssen global sein
var timerID = null;

var totPct = 0;
var pctIncr = 0.01;
var fetchInterval = 10;
var progressBarObj = null;

function simulate(aProgressBarObj) {

	//das zu simulierende ProgressBar-Objekt setzen
	if(progressBarObj == null) progressBarObj = aProgressBarObj;

	//bisheriges Timeout leeren
	clearTimeout(timerID);

	//Wert erhöhen
  	totPct += pctIncr;

  	//Wert setzen
	progressBarObj.setPercent(totPct);

    if(progressBarObj.pct <= 1.0) {
		timerID = setTimeout("simulate()", fetchInterval);
	}
}

var screenWidth = 800;
xSize = 0;
ySize=0;

function resizeWindow(xSize,ySize){

	//ermitteln der Auflösung
	screenWidth = screen.width;

	//Fenstergröße anpassen
	if (screenWidth < xSize || screenWidth < ySize){

		if (screenWidth < xSize && screenWidth < ySize){

			window.resizeTo(screenWidth,screenWidth);

		} else{
			if (screenWidth < xSize){


				window.resizeTo(screenWidth,ySize);

			} else{
				window.resizeTo(xSize,screenWidth);
			}
		}
	} else{

		window.resizeTo(xSize,ySize);
	}
}
