<!--
/* nur für Datei "startseite/programm/sommer.html" und "startseite/programm/winter.html" (Semesterprogramm) */


var places = new Array();
var my_typeAddress = true;
var my_address = "";
var my_station = "";
var my_location = "Dresden";
var dir = "../../pic/";
var maxCounter = 5;


/* Initialisiert alle Plätze () */
function initPlaces(){
	places.push(new Array("ksg", "Dresden", "Eisenstuckstraße 27"));
  places.push(new Array("esg", "Dresden", "Liebigstraße 30"));
  places.push(new Array("paulus", "Dresden", "Bernhardstraße 42"));
  places.push(new Array("kathedrale", "Dresden", "Schloßstraße 24"));
  places.push(new Array("antonius", "Dresden", "Schillingplatz 17"));
  places.push(new Array("xaverius", "Dresden", "Stauffenbergallee 9h"));
  places.push(new Array("petrus", "Dresden", "Dohnaer Straße 53"));
  places.push(new Array("auferstehungskirche", "Dresden", "Reckestraße 6"));
  places.push(new Array("dreikoenigskirche", "Dresden", "Hauptstrasse (Innere Neustadt) 23"));
  places.push(new Array("frauenkirche", "Dresden", "Georg-Treu-Platz 3"));
  places.push(new Array("zionskirche", "Dresden", "Bayreuther Straße 28"));
  places.push(new Array("rektorat", "Dresden", "Mommsenstraße 11"));
  places.push(new Array("hoheneichen", "Dresden", "Dresdner Straße 73"));
  places.push(new Array("naundorf", "Struppen", "Sankt-Ursula-Weg 24"));
  places.push(new Array("josef", "Dresden", "Rehefelder Straße 61"));
  places.push(new Array("lukas", "Dresden", "Lukasplatz 1"));

  //places.push(new Array("#jesu", "Dresden", "Borsbergstraße 13"));
  /*places[0]  = new Array("ksg", "Dresden", "Eisenstuckstrasse+27");
  places[1]  = new Array("esg", "Dresden", "Liebigstrasse+30");
  places[2]  = new Array("paulus", "Dresden", "Bernhardstrasse+42");
  places[3]  = new Array("kathedrale", "Dresden", "Schlossstrasse+24");
  places[4]  = new Array("antonius", "Dresden", "Schillingplatz+17");
  places[5]  = new Array("xaverius", "Dresden", "Stauffenbergallee+9h");
  places[6]  = new Array("petrus", "Dresden", "Dohnaer+Strasse+53");
  places[7]  = new Array("auferstehungskirche", "Dresden", "Reckestrasse+6");
  places[8]  = new Array("dreikoenigskirche", "Dresden", "Hauptstrasse+(Innere+Neustadt)+23");
  places[9]  = new Array("frauenkirche", "Dresden", "Georg-Treu-Platz+3");
  places[10]  = new Array("zionskirche", "Dresden", "Bayreuther+Strasse+28");
  //places[11]  = new Array("#jesu", "Dresden", "Borsbergstrasse+13");*/

  //loadCookies();
  var tmp = getCookie("address", true);
  if (tmp.length>0) my_address = tmp;
  var tmp = getCookie("station", true);
  if (tmp.length>0) my_station = tmp;
  var tmp = getCookie("location", true);
  if (tmp.length>0) my_location = tmp;
  var tmp = getCookie("typeAddress", true);
  if (tmp.length>0) my_typeAddress = tmp;
}

function addNull(str){
	if (str.length){
		if (str.length < 2) return "0" + str;
	}
	else if (str<10) return "0" + str;
	return str;
}

function decodePlace(str){
	str = str.replace(/ /g, '+');
	str = str.replace(/ß/g, 'ss');
	str = str.replace(/ö/g, 'oe');
	str = str.replace(/ä/g, 'ae');
	str = str.replace(/ü/g, 'ue');
	str = str.replace(/Ö/g, 'Oe');
	str = str.replace(/Ä/g, 'Ae');
	str = str.replace(/Ü/g, 'Ue');
	return str;
}

function getURL(locat, date, time){
	var result = "http://www.dvb.de/de/Fahrplan/Verbindungsauskunft/";
	//index.aspx?vaform[zieltypeswitch_address]=1&vaform[zielort]=Dresden&vaform[zielname]=Eisenstuckstrasse+27&vaform[zeittyp]=0&vaform[zeit]=19:00&vaform[datum]=12.04.2010";
	var place = null;
	for(var i=0; i<places.length; i++){
		place = places[i];
		if (locat.toLowerCase().indexOf(place[0].toLowerCase())>=0) break;
	}

	if (place && place.length && locat.toLowerCase().indexOf(place[0].toLowerCase())>=0){
		if (!my_typeAddress && my_station.length>1)
			result += "direkt.do?vaform[startort]=" + decodePlace(my_location) + "&vaform[startname]=" + decodePlace(my_station) + "&";
		else{
			if (my_address.length>1)
				result += "direkt.do?vaform[starttypeswitch_address]=1&vaform[startort]=" + decodePlace(my_location) + "&vaform[startname]=" + decodePlace(my_address) + "&";
			else result += "index.aspx?";
		}
		result += "vaform[zieltypeswitch_address]=1&vaform[zielort]=" + decodePlace(place[1]) + "&vaform[zielname]=" + decodePlace(place[2]) + "&vaform[zeittyp]=0&vaform[zeit]=" + time + "&vaform[datum]=" + date;
		
		
		return result;
	}
	return "";
}

function findFirst(node, name){
	if (node.nodeType == 3/*Node.TEXT_NODE*/) return "";
	var child = node.childNodes;
	if (child) for (var j=0; j<child.length; j++){
		if (child[j].nodeType != 3/*Node.TEXT_NODE*/){
			if(child[j].className == name) return child[j].innerHTML;
			else{
				var tmp = findFirst(child[j], name);
				if (tmp.length>0) return tmp;
			}
		}
	}
	return "";
}

function addPlan(div, year){
	var p = div.getElementsByTagName("p")[0];
	var h3 = div.getElementsByTagName("h3")[0];
	
	var locat = findFirst(p, "location");		// location
	
	var date = div.id.substr(5);		
	date = date.substr(0,2) + "." + date.substr(2,2) + ".";
	date += year;
	
	var time = findFirst(p, "zeit");		// zeit
	var ind1 = time.indexOf("Uhr");
	var ind2 = time.indexOf(" ");
	if (0<ind2 && ind2<ind1) time = time.substr(0, ind2);
	else if (0<ind1) time = time.substr(0, ind1);
	
	// <a class="fahrplan" href="http://www.dvb.de/de/Fahrplan/Verbindungsauskunft/index.aspx?vaform[zieltypeswitch_address]=1&vaform[zielort]=Dresden&vaform[zielname]=Eisenstuckstrasse+27&vaform[zeittyp]=0&vaform[zeit]=19:00&vaform[datum]=12.04.2010" target="_blank" title="Externer Link: Verbindungsauskunft der DVB"><img src="../pic/dvb.gif" alt="DVB-Logo" title="DVB-Logo"/></a>

	var url = "";
	// alert(locat + "\t"+date+"\t"+time);
	if (locat.length>1 && date.length>1 && time.length>1) url = getURL(locat, date, time);

	if (url.length>10){
	  var a = document.createElement("a");
	  var attr = document.createAttribute("class");
	  attr.nodeValue = "fahrplan";
	  a.setAttributeNode(attr);
	  var attr = document.createAttribute("href");
	  attr.nodeValue = url;
	  a.setAttributeNode(attr);
	   var attr = document.createAttribute("target");
	  attr.nodeValue = "_blank";
	  a.setAttributeNode(attr);
	  var attr = document.createAttribute("title");
	  attr.nodeValue = "Externer Link: Verbindungsauskunft der DVB";
	  a.setAttributeNode(attr);
	  var img = document.createElement("img");
	  var attr = document.createAttribute("src");
	  attr.nodeValue = dir + "dvb.gif";
	  //attr.nodeValue = dir + "haltestelle.gif";
	  img.setAttributeNode(attr);
	  var attr = document.createAttribute("alt");
	  attr.nodeValue = "DVB-Verbindungsauskunft";
	  img.setAttributeNode(attr);
	  var attr = document.createAttribute("title");
	  attr.nodeValue = "DVB-Verbindungsauskunft";
	  img.setAttributeNode(attr);  
	  a.appendChild(img);
	  //var txt = document.createTextNode("Fahrplan");
	  //a.appendChild(txt);
	  
	  //h3.appendChild(a);
	  h3.insertBefore(a, h3.firstChild);
	}
}

function initPlans(input_dir, input_maxCounter){
  initPlaces();
  
  dir = input_dir;	//"../../pic/";
  maxCounter = input_maxCounter;
  
  var today = new Date();
  var year = today.getFullYear();
  var month = today.getMonth()+1;
  var day = today.getDate();
  var sommer = false;
  if (month>=3 && month<=8) sommer = true;
  var future = sommer;

  var counter = 0;
  while((maxCounter<0 || counter<maxCounter) && (sommer==future)){
  	var year = today.getFullYear();
  	var month = today.getMonth()+1;
  	var day = today.getDate();
  	
  	future = false;
  	if (month>=3 && month<=8) future = true;
  	
  	var div = document.getElementById("title" + addNull(day) + addNull(month));
  	if (div){
  		addPlan(div, year);
  		//alert("title" + addNull(day) + addNull(month));
  		counter++;
  	}
  	today.setDate(today.getDate()+1);
  }
}

//-->
