var names=new Array();
var values=new Array();

/**
* Utility function for popup windows
* @param url the url
* @param breite width of popup window
* @param hoehe height of popup window
*
*/
function openw(url, breite, hoehe) {
  popWin = window.open(url,'pop', 'width='+breite+', height='+hoehe+', resizable=1, scrollbars=yes');
  popWin.focus();
}

/**
 * Utility function to add a stop to an internal array
 * @param name the name of the stop
 * @param a string containing "omc:id"
 */
function addToStopsArray(name, value)
{
	names[names.length]=name;
	values[values.length]=value;
}

/**
 * Sends back the result as a list of stops.
 * @param names an array of String, containing the stop names
 * @param values an array of String, containing "omc:id"
 */
function sendResultStops()
{	
	// if we have a parent window
	if (window.opener)
	{
		var result = window.opener.odvMapResult;

		// if we found the result object to write to
		if (result)
		{
			// go through the list of stops and add them
			for (i=0; i<names.length; i++)
			{
				result.stopNameList[i]=names[i];
				result.stopList[i]=values[i];	
			}
			result.type="stop";
			result.placeName="";
			
			window.opener.setMapInput();
			window.opener.focus();
			window.close();
		}
	}
}


/**
 * Sends back the result by setting description, omc and id of a POI.
 * @param name the name of the POI
 * @param omc the official municipality code of the city the POI is in
 * @param id the id of the POI
 */
function sendResultPOI(name, omc, id)
{
	// if we have a parent window
	if (window.opener)
	{
		var result = window.opener.odvMapResult;

		// if we found the result object to write to
		if (result)
		{
			result.type = "poi";
			result.placeName = "";
			result.placeID = -1;
			result.desc = name;
			result.omc = omc;
			result.poiID = id;

			window.opener.setMapInput();
			window.opener.focus();
			window.close();
		}
	}
}



/**
 * Send back the map center as result.
 * @param desc the Name of the street nearest to the map center
 * @param the coordinates
 */
function sendResultMapCenter(desc, coord)
{
	//alert("Selected center: "+desc+"\n coords="+coord);
	// if we have a parent window
	if (window.opener)
	{
		var result = window.opener.odvMapResult;

		// if we found the result object to write to
		if (result)
		{
			result.desc = desc;
			result.coordValue = coord;

			window.opener.setMapInput();
			window.opener.focus();
			window.close();
		}
	}
}

function mapResult()
{
	this.type		= "address";

	this.centerX		= 0;
	this.centerY		= 0;
	this.mapName		= "";
	this.coordValue		= "";
	this.desc		= "";

	this.placeName		= "";
	this.omc		= 0;
	this.placeID		= 0;

	this.streetName		= "";
	this.streetID		= 0;
	
	this.poiID		= 0;
  
  //added: dg
  this.stopName = ".";
  
	this.stopList		= new Array();
	this.stopNameList	= new Array();
}

function mapRequest()
{
	this.odvMap		= null;
	this.mapUsage	= "unknown";
	this.mapType	= "unknown";
	this.objectList = new Array();
}

var odvMapResult  = new mapResult();
var odvMapRequest = new mapRequest();

function setMapInput()
{
  obj = document.fahrplan.elements['command'];
  if (obj) odvMapRequest.mapUsage = obj.value;
  	
	if (odvMapResult && odvMapRequest.mapUsage)
	{
		if (odvMapResult.type == "address")
		{
     
			obj = document.fahrplan.elements['typeInfo_'+odvMapRequest.mapUsage];
			if (obj) obj.value = "coord";
			
			obj = document.fahrplan.elements['nameInfo_'+odvMapRequest.mapUsage];
			if (obj) obj.value = odvMapResult.coordValue;

			if (odvMapRequest.mapUsage!='dm'){
				obj = document.fahrplan.elements['execInst'];
				if (obj) obj.value = "verifyOnly";
			}

			document.fahrplan.submit();
		}
		else if (odvMapResult.type == "poi")
		{
			var obj = document.fahrplan.elements['placeInfo_'+odvMapRequest.mapUsage]; 
			if (obj) obj.value = odvMapResult.omc + ":" + odvMapResult.placeID;

			obj = document.fahrplan.elements['typeInfo_'+odvMapRequest.mapUsage];
			if (obj) obj.value = "poiID";
			
			obj = document.fahrplan.elements['nameInfo_'+odvMapRequest.mapUsage];
			if (obj) obj.value = odvMapResult.poiID;

			if (odvMapRequest.mapUsage!='dm'){
				obj = document.fahrplan.elements['execInst'];
				if (obj) obj.value = "verifyOnly";
			}

			document.fahrplan.submit();
		}
		else if (odvMapResult.type == "stop")
		{
			var obj = document.fahrplan.elements['placeInfo_'+odvMapRequest.mapUsage];
			if (obj) obj.value = "";

			obj = document.fahrplan.elements['typeInfo_'+odvMapRequest.mapUsage];
			if (obj) obj.value = "stopID";

			var obj = document.fahrplan.elements['nameInfo_'+odvMapRequest.mapUsage];
			if (obj) 
			{
				obj.value = "";
				for (var iStop = 0; iStop < odvMapResult.stopList.length; iStop++)
				{
					if (iStop > 0) obj.value += ":";
					obj.value += odvMapResult.stopList[iStop];
				}				
			}

			if (odvMapRequest.mapUsage!='dm'){
				obj = document.fahrplan.elements['execInst'];
				if (obj) obj.value = "verifyOnly";
			}

			obj = document.fahrplan.elements['deleteAssignedStops_'+odvMapRequest.mapUsage];
			if (obj) obj.value = '1';

			document.fahrplan.submit();
		}
	}
}

/**
  * Popup for images (teaser zoom)
  * @param imgurl the url of the image displayed in the popup
  */
function openImgPopup(imgurl) {
        window.open(imgurl, "imgpopup", "left=200,top=200,width=560,height=480,resizable=yes,status=0,menubar=0,scrollbars=yes");
}

/* functions for contact formular */
    var isClicked = 0;

    function setClicked() {
      isClicked = 1;
    }

    function sendForm() {
      if(!isClicked) return;
      document.kontakt.submit();
      return 1;
    }
	
	
	
  /**
  * @author martin.dilg
  */
 
  /**
   *  controler class for fontsize scaling
   */
 
  //class:: fsControler
  function fsControler(containerId){			
			var htmlContainerId = containerId;		
			//enable debug mode
			var debug = false;		
			//set default fontsize
			var fontsize = 0.625;
			//public:: initial read cookie value and change fontsize
			this.init = function(){				
				if (debug) alert("init");			
				//generateView();		
				var cookieVal = readValueFromCookie();
			
				if(cookieVal != -1){
					fontsize = cookieVal;	
					setActiveState(fontsize);
					setFontSize(fontsize);
				}else if(cookieVal == -1){
                                        setActiveState('norm');
                                        setFontSize('norm');
                                        writeValueToCookie('norm');
                                }		
			} 
			
			
			//public:: change fontsize to a new value
			this.changeFsTo = function(fontsize){

				setActiveState(fontsize);
				setFontSize(fontsize);
				writeValueToCookie(fontsize);
				
			} 
			
			//private:: set fontsize by changing the fontsize-css value of the body-tag
			setFontSize = function(fs){
				
				switch (fs) {
  					case "norm":
    					fs = 0.625;
    					break;
  					case "medium":
    					fs = 0.7;
    					break;
  					case "big":
    					fs = 0.765;
    					break;
  					 default:
    					fs = 0.625;
    					break;
				}
				
				
				if (debug) alert("setting fontsize to " + fs + " em");				
				document.getElementsByTagName("body")[0].style.fontSize = fs + "em";
				
			}
			
			//private:: wirte value to cookie
			writeValueToCookie = function (fs){
				
				if(debug) alert("writing " + fs + " to cookie");			
				document.cookie = "fontsize=" + fs + "; path=/"; 
				
			}
			
			//private:: read value from cookie
			readValueFromCookie = function(){
					
				var cookieName = "fontsize";				
				var cookies = document.cookie;
				if (cookies.indexOf(cookieName) != -1){
					var startpos = cookies.indexOf(cookieName)+cookieName.length+1;
					var endpos = cookies.indexOf(";",startpos);
					if (endpos == -1) endpos = cookies.length;					
					retVal = unescape(cookies.substring(startpos,endpos));
				}else{
					retVal = -1; 
				}

				if(debug) alert("read '" + retVal + "' from cookie");				
				return retVal;
			}
			
			
			//private:: generate view
			generateView = function(){
				
				if (debug) alert("generating view:");
				
				var lang = document.getElementsByTagName("html")[0].lang;
				var fsize = "Schriftgröße";
				if (lang == "en") {
					fsize = "Font size";
				}
				else if (lang == "fr") {
					fsize = "Fontsize";
				}
				else if (lang == "tr") {
					fsize = "Fontsize";
				}
				else if (lang == "ru") {
					fsize = "Fontsize";
				}
				else if (lang == "it") {
					fsize = "Carattere";
				}
				
				var html = fsize + ":<a href='#' id='fsNorm' onclick='fsControler.changeFsTo(\"norm\");'>A</a><img alt='' src='../images/strichel_vertical_print.gif'/><a href='#' id='fsMedium' onclick='fsControler.changeFsTo(\"medium\");'>A</a><img alt='' src='../images/strichel_vertical_print.gif'/><a href='#' id='fsBig'' onclick='fsControler.changeFsTo(\"big\");'>A</a>";
			
				if (debug) alert(html);
			
				document.getElementById(htmlContainerId).innerHTML = html;
			};
			
			
			//private:: set active state
			setActiveState = function(id){
				
				switch (id) {
  					case "norm":
						id = 'fsNorm';
    					break;
  					case "medium":
						id = 'fsMedium';
    					break;
  					case "big":
						id ='fsBig';
    					break;
  					 default:
						id = 'fsNorm';
    					break;
				}			
				document.getElementById("fsNorm").className="";
				document.getElementById("fsMedium").className="";
				document.getElementById("fsBig").className="";
				
				if(debug) alert("setting active state of element: " + id);
				document.getElementById(id).className="active";
				
			}
			
		}
		
		