/*************************************************************************************************************/
/********************************************* application.js ************************************************/
/*************************************************************************************************************/



/**************************************************************************************************************/
/* Button Over MainNavi */
/**************************************************************************************************************/

	function buttonMainNaviOverOut( oThisElement ){
		$(oThisElement).toggleClass('HoverMainNavi');
	}




/**************************************************************************************************************/
/* Button Over Configure */
/**************************************************************************************************************/

	function buttonConfigureOverOut( oThisElement ){
		$(oThisElement).toggleClass('HoverButtonConfigure');
	}




/**************************************************************************************************************/
/* Table Over DashboardElement */
/**************************************************************************************************************/
	
	function BoxElementOver( oThisElement ){
		$(oThisElement).addClass('mouseOver');
	}
	
	function BoxElementOut( oThisElement ){
		$(oThisElement).removeClass('mouseOver');
	}
	
	
	
	
	
/**************************************************************************************************************/
/* Activity Item SlideDown / SlideUp */
/**************************************************************************************************************/
	
	function ExpandElementShowHide( oThisElement, onlyIfClosed ) {
		
		var currentSlideTime = 500;
		var activityItem = $(oThisElement).parents('.itemLight:first');
		var nextElement = activityItem.find('.ExpandableContent');
		
		if( !$(activityItem).hasClass('expand') )
		{
			$(activityItem).addClass('expand');
			$(nextElement).slideDown(currentSlideTime);	
		}
		else
		{													
			if( !onlyIfClosed )
			{
				$(nextElement).slideUp(currentSlideTime,function(){
					$(activityItem).removeClass('expand');		
				});	
			}
		}
		
	}
	
	
	
/**************************************************************************************************************/
/* toggle Strukture Menü */
/**************************************************************************************************************/

	function toggleStructureMenu( currentId ){			
		if ( currentId != null ){
			
			var currentSlideTime = 500;
			var currentObject = $('#'+currentId);
			
			// Ist Menü sichtbar dann slideup sonst slideDown
			if (currentObject.is(':visible')){
				
				// Hide
				currentObject.slideUp(currentSlideTime);	
				
			}else{
				
				// Show
				currentObject.slideDown(currentSlideTime);	
				
			}		
			
		}								
	}
	
	
	
	
/**************************************************************************************************************/
/* 	Show Loading in Element */
/**************************************************************************************************************/		
	
	/*************************************************************************************************
	* mEnterMenueWindow - Parameter:	
	*	currentObject			=	current Elment (this)
	*	ajaxUrl					=	String Url für Ajax auruft 
	*	ajaxParams				=	(Optional) Daten die mit übergeben werden z.B.: {limit: 25}
	*	ajaxCompleteFunction	=	(Optional) angabe der Complete Funktion die aufgerufen wird wenn der Ajax auruf durchgefürt wurde
	*************************************************************************************************/
		function mEnterMenueWindow( currentObject, ajaxUrl, ajaxParams, ajaxCompleteFunction ){
		
			var currentObject = $(currentObject);			
			var windowMenue = $('#idWindowMenue');	
			var windowMenueContent = windowMenue.find('.ContentElement');	
																
			// window Pos setzen
				var pos = currentObject.position();
			
				windowMenue.css('top', (pos.top + currentObject.height() - 4 ) );
				windowMenue.css('left', (pos.left + (currentObject.width() / 2) ) );
			
			// Ajax Loading
				showLoadingInElement( windowMenueContent );	
			
			// Ajax Url load
				windowMenueContent.load( ajaxUrl, ajaxParams, ajaxCompleteFunction );
			
			// Window FadeIn
				windowMenue.fadeIn();
			
		}
	
	
	/* On Enter Show Window */	
		function mLeaveMenueWindow (){
			
			var windowMenue = $('#idWindowMenue');					
			
			// Window Fadeout
				windowMenue.fadeOut();
		}
	




/**************************************************************************************************************/
/* 	Show Loading in Element */
/**************************************************************************************************************/

	/*************************************************************************************************
	* showLoadingInElement - Parameter:	
	*	oCurrentElement		=	Element Id oder Object
	*************************************************************************************************/
	function showLoadingInElement( oCurrentElement ){
							
		var oElement = null;
		
		//  jQuery Object ermitteln
			if ( typeof(oCurrentElement) == 'string' ){					
				oElement = $('#'+ oCurrentElement);
			}else{				
				oElement = $(oCurrentElement);	
			}
								
		// Loading HTML Code						
			var sHtml = '<div style="margin: 0px 0px 0px 0px;"><table cellpadding="0" cellspacing="0" border="0"><tr><td><img src="../../shared/images/loading/loading.gif" alt="loading" border="0"></td><td width="8"></td><td>loading...</td></tr></table></div>';								
			oElement.html(sHtml);						
		
	}
	
	
	
	
/**************************************************************************************************************/
/* Expand Window Height / width */
/**************************************************************************************************************/

	/*************************************************************************************************
	* mEnterMenueWindow - Parameter:	
	*	cmpWindowId			=	ExtJs Cmp Window Id
	*	addWidth			=	(Optional) Width die dem window hinzugefügt wird
	*	addHeight			=	(Optional) Height die dem window hinzugefügt wird
	*	absoluteValue		=	(Optional) wenn True dan wird wert nicht dazugerechnet sondern als absoluter wert gesetzt
	*/
	function expandWindow( cmpWindowId, addWidth, addHeight, absoluteValue ){
						  
		if ( absoluteValue == null ) absoluteValue = false;
						
											
		var oCurrentWindow  = Ext.getCmp( cmpWindowId );
	   
		// Akteuille Höhe / Breite
			var iHeight = oCurrentWindow.getHeight();
			var iWidth = oCurrentWindow.getWidth();				
		
		// Neue Höhe
			if ( absoluteValue ){
				if (addWidth != null)iWidth = addWidth;
				if (addHeight != null) iHeight = addHeight;	
			}else{
				if (addWidth != null) iWidth = iWidth + addWidth;
				if (addHeight != null) iHeight = iHeight + addHeight;
			}
				   
		// Browser Width anpassen wenn nicht ie6 wegen Bug
			if( Ext.isIE6 == false && Ext.isIE7 == false && Ext.isIE8 == false ){
				iWidth = iWidth -10;
				iHeight = iHeight -10;		   
			}
				   
		// Anpassen der Höhe bzw. breite		
			//if (addWidth != null) oCurrentWindow.setWidth( iWidth );				
			//if (addHeight != null) oCurrentWindow.setHeight( iHeight );
			if (addWidth != null) oCurrentWindow.setWidth({ to:{ height: iHeight, width: iWidth  }});				
			if (addHeight != null) oCurrentWindow.animate({ to:{ height: iHeight, width: iWidth  }});
						
									
	}	
	
	
	

/**************************************************************************************************************/
/* Funktion GroupActivityShowHide */
/**************************************************************************************************************/	
	
	var oExpandableContent;
	var defaultContent;
	var contentheight;
	
	function GroupActivityShowHide( oThisElement, activityTreeUrl )
	{
		if( !$(oThisElement).hasClass('Active') )
		{
			$(oThisElement).addClass('Active');
			
			var outTable = $(oThisElement).parents('.tableActivityElement:first');
			oExpandableContent = $(outTable).find('.ExpandableContent:first');										
			
			contentheight = oExpandableContent.height();
			defaultContent = oExpandableContent.html();
			
			// Feste höhe setzen
				oExpandableContent.height(contentheight);
			
			// Ajax Loading in Content setzen
				showLoadingInElement( oExpandableContent );
				
			// Ajax Url load
				oExpandableContent.load( activityTreeUrl + "", function( response, status, xhr ){
					
					if (status == "error" || status == null) {
						oExpandableContent.html('<div class="textColorVoithRed">Coud not load the tree view.</div>');		
					}
						
					// Content Animate Heigth
						oExpandableContent.animate({
								 width: 872,
								 height: oExpandableContent.children().height()
							}, function(){
								
								// Höhe auf Auto stellen damit Inhalt Dynamisch
								oExpandableContent.height('auto');
								
								// Element einblenden falls nicht vorhanden
								ExpandElementShowHide( oThisElement, true );
							}
						);
						
				});	
		} 
		else
		{
			$(oThisElement).removeClass('Active');
			
			// Content auf ursprüngliche Größe zurücksetzen
			oExpandableContent.animate({
					 width: oExpandableContent.width(),
					 height: contentheight
				}, function(){
					
					// Default Content einblenden
					oExpandableContent.html(defaultContent);
					
					// Höhe auf Auto stellen damit Inhalt Dynamisch
					oExpandableContent.height('auto');
				}
			);
		}
		
	}
	
	
	
	
/**************************************************************************************************************/
/* Funktion ShowActivityContentBy / Ladet Inhalt per Ajax je nach Auswahl */
/**************************************************************************************************************/
	
	/*$(document).ready(function(){
		UncheckShowActivityBoxes();
	});*/

    function ApplyFilter() {
        var region = $('#selectRegion').val();
        var thema = $('#selectThema').val();
        var monat = $('#selectMonat').val();
        /*console.log(region);
        console.log(thema);
        console.log(monat);*/
        var params = "";
        if (region != "") {
            params += "filterRegion="+region;
        }
        if (thema != "") {
            if (params != "")
                params += "&";
            params += "filterThema="+thema;
        }
        if (monat != "") {
            if (params != "")
                params += "&";
            params += "filterMonat="+monat;
        }
        //console.log(params);
        if (params != "") {
            $('#delFilter').css('display','block');
        }
        else {
            $('#delFilter').css('display','none');
        }

        VeranstaltungenLaden(params);
    }

    function VeranstaltungenLaden(params) {
        showLoadingInElement($('#divContentVeranstaltungen'));
        var isArchive = $('#isArchive').val();
        $('#divContentVeranstaltungen').load('kulturlandschaft_veranstaltungen_ajax.php?isArchive='+isArchive + "&" + params);


    }

	function ShowActivityContentBy( input, strLoadUrl )
	{
		
		var activityAjaxContainer = $('#ActivityAjaxContent');	
		
		if( $(input).attr('checked') )
		{
			// Restliche Checkboxen deaktivieren
				
				var inputContainer = $('.divActivityShowSelector');
				var checkboxes = $('.inputShowActivity');
				var checkboxCount = checkboxes.length;
				
				for( var i=0; i<checkboxCount; i++) {
					
					if ( $(checkboxes[i]).attr('id') != $(input).attr('id') ) {
						$(checkboxes[i]).attr('checked', false);
					}
					
				}
				
			// Content laden
				var windowMenueContent = $(activityAjaxContainer);	
				
			// Ajax Loading
				showLoadingInElement( windowMenueContent );	
					
			// Ajax Url load
				windowMenueContent.load( strLoadUrl );
					
		}
		else
		{
			UncheckShowActivityBoxes();
			$(activityAjaxContainer).html("");
		}
		
	}
	
	function UncheckShowActivityBoxes()
	{
		var checkboxes = $('.inputShowActivity');
		var checkboxCount = checkboxes.length;
		
		for( var i=0; i<checkboxCount; i++) {
			$(checkboxes[i]).attr('checked', false);
		}
	}
									
									
									



/**************************************************************************************************************/
/* Expand Element Toggle Function Window */
/**************************************************************************************************************/


	
	function toggleExpandElementWindow( oThisElement ){
		
		var oElement = $(oThisElement);
		var sContentElement = oElement.attr("contentElement");
		var sScrollContentElement = oElement.attr("scrollContentElement");
	
		var bShowContent = true;	
			
		// Prüfen ob Content angegeben wurde
			if (sContentElement == null){
				// Meldung wenn Attribut "contentElement" nicht vorhanden
				bShowContent = false;
				alert('The contentElement for element "'+ oElement.text() +'" is not defined!');			
			}
		
		//Prüfen ob expand or collapse
			if ( oElement.hasClass("expand") ){			
				// Einblenden				
				oElement.removeClass("expand");
				oElement.addClass("collapse");
				
													
				if (bShowContent){ 
				
					//  Window Größe anpassen
						expandWindow('idWindowElement1',null,664, true);
					
					// Window Goals Scroll Content höhe anpassen
						if (sScrollContentElement != null){						
							//$('#'+sScrollContentElement).height(561);
							$('#'+sScrollContentElement).animate({
								height: 561	
							});
						}
					
					// Expand Element content
						$("#"+ sContentElement).slideDown( function(){
							$("#"+ sContentElement).css('overflow-y', 'auto');		
						}); 
				}				
				
			}else{
				// Ausblenden
				oElement.removeClass("collapse");
				oElement.addClass("expand");
				
				
				
				if (bShowContent){ 
				
					// Collaps Element content																																			
						$("#"+ sContentElement).slideUp( function(){						
							//  Window Größe anpassen
								//expandWindow('idWindowElement1',975,490, true);		
								$("#"+ sContentElement).css('overflow-y', 'auto');									
						}); 
					
					// Window Goals Scroll Content höhe anpassen
						if (sScrollContentElement != null){						
							//$('#'+sScrollContentElement).height(387);
							$('#'+sScrollContentElement).animate({
								height: 387	
							}, function(){ $('#'+sScrollContentElement).css('overflow-y', 'auto'); });
						}		
					
					//  Window Größe anpassen
						expandWindow('idWindowElement1',null,490, true);
				}	
				
			}
		
	}
	
	
