

/*

	EMCU1349503  	

	<img class="infobutton" id="infobutton_16" 
		src="../pics/box_info2.gif?url=index.php#F#page#G#infobutton_ajax#U#nr#G#10&width=500">
	
	-> die Klasse MUSS infobutton sein
	-> die ID MUSS eindeutig sein
	-> es gibt box_info2.gif (mit weissem Hintergrund) und box_info.gif (mit grauem Hintergrund) 
	
	
	-> der Parameter URL kann beliebig vergeben werden
		Aufruf eines Fensters mit der url "index.php?page=infobutton_ajax&nr=10"
		#G# steht für =
		#U# steht für &
		#F# steht für ?

	-> width=500
		stellt auf 500Px Breite ein, ohne / default: 300px

	-> height=700
		stellt auf 700Px Breite ein, ohne / default: 260px

	-> scroll=0
		öffnet das Infofenster ohne feste Höhenangabe, es wird also nicht gescrollt 
		sondern die Box wächst vertikal mit dem Content mit

	
	-> Für die Hilfefunktion gibt es eine Kurzform für faule Tipper:
	
		<img class="infobutton" id="infobutton_2" src="../pics/box_info2.gif?help=2">
		
		das lädt automatisch die Hilfe Nr = 2 in der Standardgröße mit Scrollbars
*/



	Event.observe( window, 'load', start_infobuttonobserver );

	function start_infobuttonobserver(){
		
		var sfEls = $$(".infobutton");
		
		for (var i=0; i<sfEls.length; i++) { init_infobuttonobserver (sfEls[i].id); }
		
		Event.observe( 'lightboxoverlay' , 'click', function ( event ) {
			close_laitbox();
			Event.stop( event );
		} );
		
	}

	function init_infobuttonobserver (div_id) {
	
		Event.observe( div_id , 'click', function ( event ) {
			infobutton(div_id, 'click');
			Event.stop( event );
		} );
	}

	function trim(s) {
	  while (s.substring(0,1) == ' ') {
	    s = s.substring(1,s.length);
	  }
	  while (s.substring(s.length-1,s.length) == ' ') {
	    s = s.substring(0,s.length-1);
	  }
	  return s;
	}

	var aktuelle_infobox = 0;


	/* Zwei Funktionen von: http://www.ajaxschmiede.de/javascript/fenstergrose-und-scrollposition-in-javascript-auslesen/ */

		function getSize() {
			var myWidth = 0, myHeight = 0;

			if( typeof( window.innerWidth ) == 'number' ) {
				//Non-IE
				myWidth = window.innerWidth;
				myHeight = window.innerHeight;
			} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
				//IE 6+ in 'standards compliant mode'
				myWidth = document.documentElement.clientWidth;
				myHeight = document.documentElement.clientHeight;
			} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
			}
			return [ myWidth, myHeight ];
		}


		function getScrollXY() {
			var scrOfX = 0, scrOfY = 0;

			if( typeof( window.pageYOffset ) == 'number' ) {
				//Netscape compliant
				scrOfY = window.pageYOffset;
				scrOfX = window.pageXOffset;
			} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
				//DOM compliant
				scrOfY = document.body.scrollTop;
				scrOfX = document.body.scrollLeft;
			} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
				//IE6 standards compliant mode
				scrOfY = document.documentElement.scrollTop;
				scrOfX = document.documentElement.scrollLeft;
			}
			return [ scrOfX, scrOfY ];
		}

	function wwCalendar(div, was){
		
		a = div.split("_");
		
		if ( div == "out")	was = "out";
		else {
			if ( aktuelle_infobox == 0 || aktuelle_infobox != a[1]) was = "over";
			else was = "out";
		}
		
		if(was == "over") {
			
			if ( document.getElementById('page') && ( document.getElementById('page').value == 'buchung' ||  document.getElementById('page').value == 'fahrplan_detailsuche' ) ) {
			
				var stati = 'buchung';
				
			}
			else {
			
				
				
				var stati = '';
				
			}

			document.getElementById("calendarwin_content").innerHTML = "<table border='0' width='100%' height='100%'><tr><td align='center'><img style='margin: 30px 0 30px 0' src='../pics/ajax-loading.gif'></td></tr></table>";

			param_width	= 620;
			param_height	= 230;
			param_scroll 	= 1;


			pos_cum 	= Position.cumulativeOffset($(div));
			pos_cum1 	= pos_cum + " ";
			pos_cum1	= pos_cum1.split(",");
			pos_cum1[0] = trim(pos_cum1[0]) * 1;
			pos_cum1[1] = trim(pos_cum1[1]) * 1;

			new_x	= pos_cum1[0] + 40;
			new_y	= pos_cum1[1] + 30;

			new_xtop	= new_x + 20;
			new_ytop	= new_y - 10;

			if(new_x > 600) new_x = new_x - param_width + 260;
			
			document.getElementById("calendarwin").style.top		=	new_y + "px";
			document.getElementById("calendarwin").style.left		=	new_x + "px";
			document.getElementById("calendarwin").style.width		=	param_width + "px";
			document.getElementById("calendarwin").style.height		=	param_height + "px";
			document.getElementById("calendarwin").style.display		=	"block";

			contentheight = param_height - 30;
			document.getElementById("calendarwin_content").style.height 	= contentheight + "px";
			document.getElementById("calendarwin_content").style.overflow 	= "auto";

			if(param_scroll == 0){
				document.getElementById("calendarwin").style.height = "";
				document.getElementById("calendarwin_content").style.height = "";
			}

			document.getElementById("calendarwintop").style.top		= new_ytop + "px";
			document.getElementById("calendarwintop").style.left		= new_xtop + "px" ;
			document.getElementById("calendarwintop").style.display	= "block";
			
		
			
			new Ajax.Updater('calendarwin_content', '../start/index.php?page=calendar&div=' + div + '&init=' + $(div).value + "&stati=" + stati);
			aktuelle_infobox = a[1];
			
			ie6_selectfelder(0);
			flash_aus();
			
		}
		else {

			document.getElementById("calendarwin").style.display			= "none";
			document.getElementById("calendarwintop").style.display		= "none";
			aktuelle_infobox = 0;

			flash_ein();
			ie6_selectfelder(1);
			
			if( $('new_asc_date_field') ) {
        			getNewAssetDate();
      		}
		}
	}

	function wwCalendarClose() {

		document.getElementById("calendarwin").style.display			= "none";
		document.getElementById("calendarwintop").style.display		= "none";

	}
	
	
	function open_laitbox(url, width, top, left){

		document.getElementById("lightboxwin_content").innerHTML = "<table border='0' width='100%' height='100%'><tr><td align='center'><img style='margin: 50px 0 50px 0' src='../pics/ajax-loading.gif'></td></tr></table>";
	
		winSize = getSize();
		Scrollstate = getScrollXY();
		
		scrollpos =  Scrollstate[1];
		bodyhoehe = document.body.offsetHeight;
		sichthoehe = winSize[1];
		
		if( top <= scrollpos ) top = scrollpos + 50;
		
		//alert("sichthoehe: " + sichthoehe + "\nbodyhoehe: " + bodyhoehe + "\nscrollpos: " + scrollpos);

		document.getElementById("lightboxwin").style.top		=	top + "px";
		document.getElementById("lightboxwin").style.left		=	left + "px";
		document.getElementById("lightboxwin").style.width		=	width + "px";

		if(sichthoehe >= bodyhoehe) overlayhoehe = sichthoehe ;
		else overlayhoehe = bodyhoehe ;
		
		document.getElementById("lightboxoverlay").style.height		=	overlayhoehe + "px";
		document.getElementById("lightboxoverlay").style.display	=	"block";	
		
		document.getElementById("lightboxwin").style.display		=	"block";	

		document.getElementById("lightboxoverlay").style.zIndex		=	"101";	
		document.getElementById("lightboxwin").style.zIndex		=	"102";	
			
		if(url != "open_only") new Ajax.Updater('lightboxwin_content', url, {onComplete: iefocus_nachladen});
	
		ie6_selectfelder(0);
		setTimeout("flash_aus()", 300);
	
	}
	
	function close_laitbox(){
	
		document.getElementById("lightboxwin").style.display			= "none";	
		document.getElementById("lightboxoverlay").style.display		= "none";

		ie6_selectfelder(1);
		flash_ein();
		
	}
	
	function infobutton(div, was){


		a = div.split("_");
		if(div == "out") was = "out";
		else if(aktuelle_infobox == 0 || aktuelle_infobox != a[1]) was = "over";
		else was = "out";


		if(was == "over"){
			
			document.getElementById("infobuttonwin_content").innerHTML = "<table border='0' width='100%' height='100%'><tr><td align='center'><img style='margin: 30px 0 30px 0' src='../pics/ajax-loading.gif'></td></tr></table>";

			param_width	= 300;
			param_height	= 260;
			param_scroll 	= 1;

			params = document.getElementById(div).src;
			params = params.split("?");
			params = params[1].split("&");

			kurzurl = false;
			kurzcheck = params[0].split("=");
			if(kurzcheck[0] == "help"){
				param_url = "index.php?page=infobutton_ajax&nr=" + kurzcheck[1];
				kurzurl = true;
			}

			for (var i = 0; i < params.length; i++){

				param = params[i].split("=");
				if(param[0] == "width")		param_width 	= param[1];
				if(param[0] == "height")	param_height 	= param[1];
				if(param[0] == "scroll") 	param_scroll 	= param[1];
				
				if(param[0] == "url" && kurzurl == false){
					param_url = param[1];
					param_url = param_url.replace(/---F---/g, "?");
					param_url = param_url.replace(/---U---/g, "&");
					param_url = param_url.replace(/---G---/g, "=");
				}
			}

			pos_cum 	= Position.cumulativeOffset(document.getElementById(div));
			pos_cum1 	= pos_cum + " ";
			pos_cum1	= pos_cum1.split(",");
			pos_cum1[0] = trim(pos_cum1[0]) * 1;
			pos_cum1[1] = trim(pos_cum1[1]) * 1;

			new_x	= pos_cum1[0] - 20;
			new_y	= pos_cum1[1] + 30;

			new_xtop	= new_x + 20;
			new_ytop	= new_y - 10;

			if(new_x > 600) new_x = new_x - param_width + 60;

			document.getElementById("infobuttonwin").style.top		= new_y + "px";
			document.getElementById("infobuttonwin").style.left		= new_x + "px";
			document.getElementById("infobuttonwin").style.width		= param_width + "px";
			document.getElementById("infobuttonwin").style.height		= param_height + "px";
			document.getElementById("infobuttonwin").style.display		= "block";

			contentheight = param_height - 30;
			document.getElementById("infobuttonwin_content").style.height = contentheight + "px";
			document.getElementById("infobuttonwin_content").style.overflow = "auto";

			if(param_scroll == 0){
				document.getElementById("infobuttonwin").style.height = "";
				document.getElementById("infobuttonwin_content").style.height = "";
			}

			document.getElementById("infobuttonwintop").style.top		= new_ytop + "px";
			document.getElementById("infobuttonwintop").style.left		= new_xtop + "px";
			document.getElementById("infobuttonwintop").style.display	= "block";
			
			flash_aus();
			ie6_selectfelder(0);

			new Ajax.Updater('infobuttonwin_content', param_url);
			aktuelle_infobox = a[1];
		}
		else{
			
			ie6_selectfelder(1);
			document.getElementById("infobuttonwin").style.display	= "none";
			document.getElementById("infobuttonwintop").style.display	= "none";
			aktuelle_infobox = 0;
			
			flash_ein();
		}
	}


	function nextMonth(init , m , Y , div , from_buchung ) {
	
		new Ajax.Updater('calendarwin_content', '../start/index.php?page=calendar&start_monat=' + m + '&start_jahr=' + Y + '&div=' + div + '&from_buchung=' + from_buchung + '&init=' + init);
	
	}