/*BOOKMARKING*/
jQuery.noConflict();


function centerPopup(popupId){  
	//request data for centering  
	var windowWidth = document.documentElement.clientWidth;  
	var windowHeight = document.documentElement.clientHeight;  
	var popupHeight = jQuery(popupId).height();  
	var popupWidth = jQuery(popupId).width();  
	var scrollL = jQuery(document).scrollLeft();
	var scrollT = jQuery(document).scrollTop();
	//centering  
	jQuery(popupId).css({  
	"position": "absolute",  
	"top": windowHeight/2-popupHeight/2+scrollT,  
	"left": windowWidth/2-popupWidth/2+scrollL
	});   
}  

function webcamRefresh() {
	var img = jQuery('img#webcam');
	var src = img.attr('src');
	var title = img.attr('title');
	var alt = img.attr('title');
	var name = img.attr('name');
	var newImg = '<img id="webcam" src="'+src+'" title="'+title+'" alt="'+alt+'" style="width:460px" />'
	jQuery("#webcamwrapper").empty().html(newImg);
	setTimeout('webcamRefresh()', 60000);
}

jQuery(document).ready(function(){
	// add a "rel" attrib if Opera 7+
	if(window.opera) {
		if (jQuery("a.jqbookmark").attr("rel") != ""){ // don't overwrite the rel attrib if already set
			jQuery("a.jqbookmark").attr("rel","sidebar");
		}
	}

	
	// Bookmark im Browser setzen.
	jQuery("a.jqbookmark").click(function(event){
		event.preventDefault(); // prevent the anchor tag from sending the user off to the link
		var url = this.href;
		var title = this.title;

		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title);
		} else if(window.opera) { // Opera 7+
			return false; // do nothing - the rel="sidebar" should do the trick
		} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
			 alert('Unfortunately, this browser does not support the requested action,'
			 + ' please bookmark this page manually.');
		}

	});
	// Ajax-Request für die Rememberfunktion - Bookmark setzen
	jQuery('a.remember').click(function(event){
		//Ajaxabfrage stellen
		jQuery.ajax({
			url: "index.php",		// Achtung mit RealURL!
			type: "GET",			// Daten per GET verschicken
			data: {
				eID: "tx_sffebookmark_pi1",	// die erstellte eID
				url: this.href,	// URL
				splitvars: this.name,
				pagetitle: this.title,
				cmd: "add"
			},
			dataType: "json",		// das gibts zurück

			// Es hat funktioniert?
			success: function(response) {
				// Code der ausgeführt wenns geklappt hat
				// !! Wesentliches Ding !!
				var new_content = "";
				jQuery.each(response, function(i, row) {
					new_content+= "<p>"+row.msg+"</p>";
				});
				jQuery('#notifycont').empty().append(new_content);
				centerPopup('#notification');
				jQuery('#notification').show('slow').delay('2000').hide('slow');
			},

			// Schade, es war ein Fehler
			error: function(error) {
				alert("Sorry, hat nicht funktioniert");
			}
		});
	});
	
	// Ajax-Request für die Rememberfunktion - Bookmark wieder löschen
	jQuery('a.delbookmark').click(function(event){
		//Ajaxabfrage stellen
		jQuery.ajax({
			url: "index.php",		// Achtung mit RealURL!
			type: "GET",			// Daten per GET verschicken
			data: {
				eID: "tx_sffebookmark_pi1",	// die erstellte eID
				uid: this.rel,	// URL
				cmd: 'del'
			},
			dataType: "json",		// das gibts zurück
		
			// Es hat funktioniert?
			success: function(response) {
				// Code der ausgeführt wenns geklappt hat
				// !! Wesentliches Ding !!
				jQuery.each(response, function(i, row) {
					jQuery('#bookmark_'+row.uid).remove();
				});
			},
			
			// Schade, es war ein Fehler
			error: function(error) {
				alert("Sorry, hat nicht funktioniert");
			}
		});
	});

	// neu erstellen der Anliegen durch die Ämterwahl
	jQuery('#uid4').change(function(event){
		jQuery('#uid16').removeAttr('value').attr('value',this.value);
		//Ajaxabfrage stellen
		jQuery.ajax({
			url: "index.php",		// Achtung mit RealURL!
			type: "GET",			// Daten per GET verschicken
			data: {
				eID: "sfcivserv_powermail_eId",	// die erstellte eID
				value: this.value,	// URL
				lang: this.lang,
				cmd: 'anliegen'
			},
			dataType: "json",		// das gibts zurück
		
			// Es hat funktioniert?
			success: function(response) {
				// Code der ausgeführt wenns geklappt hat
				// !! Wesentliches Ding !!
				jQuery.each(response, function(i, row) {
					jQuery('#uid3').empty();
					jQuery('#uid3').append(row.option);
					jQuery('#uid15').removeAttr('value').attr('value',row.hidden);
				});
			},
			
			// Schade, es war ein Fehler
			error: function(error) {
				alert("Sorry, hat nicht funktioniert");
			}
		});
	});
	// neu erstellen der Ämter durch die Anliegenwahl
	jQuery('#uid3').change(function(event){
		//Ajaxabfrage stellen
		jQuery.ajax({
			url: "index.php",		// Achtung mit RealURL!
			type: "GET",			// Daten per GET verschicken
			data: {
				eID: "sfcivserv_powermail_eId",	// die erstellte eID
				value: this.value,	// URL
				lang: this.lang,
				cmd: 'amt'
			},
			dataType: "json",		// das gibts zurück
		
			// Es hat funktioniert?
			success: function(response) {
				// Code der ausgeführt wenns geklappt hat
				// !! Wesentliches Ding !!
				jQuery.each(response, function(i, row) {
					jQuery('#uid4').empty();
					jQuery('#uid4').append(row.option);
					if(row.act == false) {
						jQuery('#uid4').attr('disabled', 'disabled');
					} else {
						jQuery('#uid4').removeAttr('disabled');
					}
					jQuery('#uid14').removeAttr('value').attr('value',row.hidden);
					jQuery('#uid15').removeAttr('value').attr('value',row.amthidden);
				});
			},
			
			// Schade, es war ein Fehler
			error: function(error) {
				alert("Sorry, hat nicht funktioniert");
			}
		});
	});
	
	// Felder vorbefüllen
	jQuery('input[name=user]').focus(function(event){
		if(this.value == 'Benutzer') {
			this.value = '';
		}
	});
	jQuery('input[name=user]').blur(function(event){
		if(this.value == '') {
			this.value = 'Benutzer';
		}
	});
	jQuery('input[name=pass]').focus(function(event){
		if(this.value == 'Passwort') {
			this.value = '';
		}
	});
	jQuery('input[name=pass]').blur(function(event){
		if(this.value == '') {
			this.value = 'Passwort';
		}
	});
	jQuery('input[name=tx_yatse_pi1\\[sword\\]]').focus(function(event){
		if(this.value == 'Suchbegriff eingeben') {
			this.value = '';
		}
	});
	jQuery('input[name=tx_yatse_pi1\\[sword\\]]').blur(function(event){
		if(this.value == '') {
			this.value = 'Suchbegriff eingeben';
		}
	});
	jQuery('input#place_origin').focus(function(event){
		if(this.value == 'Freising') {
			this.value = '';
		}
	});
	jQuery('input#place_origin').blur(function(event){
		if(this.value == '') {
			this.value = 'Freising';
		}
	});

	
	jQuery(".rzcolorbox").colorbox({
		current:"Bild {current} von {total}",
		opacity:"0.85",
		transition:"fade",
		speed:"350",
		slideshowSpeed:"2500"
	});
	
	////////////////////////////////////////////////
	// imagecycle
	////////////////////////////////////////////////
	jQuery('#imagecycle').show().cycle({
		fx: 'fade',
		easing: 'easeInOutBack',
		speed: '6000',
		timeout: '5000',
		delay: 5000,
		sync: true,
		random: true,
		before: function() {
			jQuery('span', this).css('display', 'none');
		},
		after:  function() {
			jQuery('span', this).animate({opacity: 'show'},200);
		}
	});
	
	
	////////////////////////////////////////////////
	// Absenden des MVV-Formulars im Popup
	////////////////////////////////////////////////
	jQuery('input#route').click(function(event){
		var url;
		url = 'http://efa.mvv-muenchen.de/mvv/XSLT_TRIP_REQUEST2?itdLPxx_noLeftMargin=1';
		url += '&nameInfo_destination=invalid';
		url += '&nameState_destination=empty&placeState_destination=empty&sessionID=0';
		url += '&nameState_origin=empty&placeState_origin=empty';
		url += '&itdDateDay='+jQuery('#itdDateDay').val();
		url += '&typeInfo_destination=invalid&x=0';
		url += '&type_origin='+jQuery('#type_origin').val();
		url += '&name_origin='+escape(jQuery('#name_origin').val());
		url += '&place_origin='+escape(jQuery('#place_origin').val());
		url += '&type_destination='+jQuery('#type_destination').val();
		url += '&name_destination='+escape(jQuery('#name_destination').val());
		url += '&place_destination='+escape(jQuery('#place_destination').val());
		url += '&itdDateDay='+jQuery('#itdDateDay').val();
		url += '&itdDateMonth='+jQuery('#itdDateMonth').val();
		url += '&itdTimeHour='+jQuery('#itdTimeHour').val();
		url += '&itdTimeMinute='+jQuery('#itdTimeMinute').val();
		
		fenster = window.open(url,"MVV_Fahrplanauskunft_EFA","width=600,height=700,resizable=no");
		fenster.focus();
		return false;
	});
});

function superchallenge_pass_forget2(form) {
	
	var pass = jQuery(".pass1").val();
	var pass2 = jQuery(".pass2").val();
	
	
	
	if(pass.length < 6){
		alert("Das Passwort muss mindestens 6 Zeichen lang sein.");
		return false;
	}
		
	if(pass != pass2){
		alert("Die Passwörter stimmen nicht überein.");
		return false;
	}
	
	if (pass && pass2) {
		jQuery(".pass1").val(MD5(pass));
		jQuery(".pass2").val(MD5(pass2));
		
		
		return true;
	} else
		return false;
}


