



$(document).ready(	
	function() {


		/** csv export 
		$('#csvexport').click(function(event) {
			$('#csvexportvalue').attr('value','1');
			$('#pasearchform').submit();		
			event.preventDefault();
		});
		**/
		
		$('input#name').focus();

		/** maxrowsinpage onselect **/
		$('.maxrowsinpage').change(function(event) {
			//$('.maxrowsinpage').		($(this).val()); 
			$(".maxrowsinpage").val($(this).val());
			$('#pasearchform').submit();
			
		});
		$('#asmaxrowsinpage').change(function(event) {
			$(".maxrowsinpage").val($(this).val());		
		});
		


		/** reset link **/
		try {
			$('#formreset').click(function(event) {	
				$('#pasearchform')
				.find( ':text, :password, textarea' ).attr( 'value', '' ).end()
				.find( ':checkbox, :radio' ).attr( 'checked', true).end()
				.find( 'select' ).attr( 'selectedIndex', 0 );
				$('#pricefrom').attr('value','von');
				$('#priceto').attr('value','bis');
				event.preventDefault();		
			});
		} catch(e){alert(e.message)}

		/** on selected maingroup nach page reload select subgroup **/
		if ($('#maingroup').attr('value') > 0) {
			var option;
			$.each(subgroup['subgroup' + $('#maingroup').val()],function(i,item) {					
					if ( selectedSubgroupUID == item.value ) {
						$('#subgroup').append('<option selected="selected" value="' + item.value + '">' + item.title + '</option>' );
					} else {
						$('#subgroup').append('<option  value="' + item.value + '">' + item.title + '</option>' );
					}		
            });
		}

		/** change "einfache Suche" , "erweiterte Suche" **/
		$("#changesearchmode").click(function () { 
			if ($('#searchmode').attr('value') == 'simple') {
				//this.firstChild.nodeValue  = 'Einfache Suche';
				$(this).attr('src',"/fileadmin/dev/images/bt_simple_search.gif");
				$('#searchmode').attr('value','advanced');
				$('#advanced_search').show();
			} else {
				//this.firstChild.nodeValue = 'Erweiterte Suche';
				$(this).attr('src',"/fileadmin/dev/images/bt_advanced_search.gif");
				$('#searchmode').attr('value','simple');
				$('#advanced_search').hide();
			}
    	});	
		/** presseangebot-suche  register sorting **/
		try {
			$('tr.header-asc-desc a').each(
				function (n) {
					$(this).click(function(event) {
						try {
							_sorting = $(this).attr('class').split(' ');
							$('#sortby').attr('value', _sorting[0]);
							$('#sortorder').attr('value',_sorting[1]);	
							$('#pasearchform').submit();				
						} catch (e) {}					
						return false;
					});
				}
			);
			/** presseangebot-suche  register paging **/
			$('#paging span').each(
				function (n) {					
					$(this).click(function(event) {
						try {							
							$('#page').attr('value',(this.firstChild.nodeValue -1));
							$('#pasearchform').submit();				
						} catch (e) {alert(e.message);}					
						return false;
					});
				}
			);	

			/** goto first page **/	
			$('.page_first').each(
				function (n) {					
					$(this).click(function(event) {
						try {							
							$('#page').attr('value',0);
							$('#pasearchform').submit();				
						} catch (e) {alert(e.message);}					
						return false;
					});
			});


			/** goto back page **/	
			$('.page_back').each(
				function (n) {					
					$(this).click(function(event) {
					try {	
						var _page;
						if (($('.page-current:first').text() - 2	 ) < 0) {
							_page = 0;
						} else {
							_page = $('.page-current:first').text() - 2;
						}				
						$('#page').attr('value', _page);
						$('#pasearchform').submit();				
					} catch (e) {alert(e.message);}					
					return false;
					});
			});
			/** goto next page **/	
			$('.page_next').each(
				function (n) {					
					$(this).click(function(event) {
					try {	
						var _page;
						if (($('.page-current:first').text() ) > $('.page_last_number:first').text() -1) {
							_page = $('.page_last_number:first').text() -1;
						} else {
							_page = $('.page-current:first').text();
						}				
						$('#page').attr('value', _page);
						$('#pasearchform').submit();				
					} catch (e) {alert(e.message);}					
					return false;
					});
			});
			/** goto last page **/	
			$('.page_last').each(
				function (n) {					
					$(this).click(function(event) {
					try {		
						$('#page').attr('value', $('.page_last_number:first').text() -1 );
						$('#pasearchform').submit();				
					} catch (e) {alert(e.message);}					
					return false;
					});
			});
			
		
			/**  presseangebot-suche clear navigation elements **/	
			$('#submitbtn').click(function(event) {
				try {
					$('#page').attr('value',0);
					$('#sortby').attr('value', 'title');
					$('#sortorder').attr('value','ASC');	
					$('#pasearchform').submit();				
				} catch (e) {}					
				return false;
			});
			/**   presseangebot-suche subgroup filter **/	
			$('#maingroup').change(function(event) {
				try {
					//remove current options keep option "Unterkategorien alle"
					$('#subgroup').children().each(
						function(n) {
							if( n > 0) { 
								$(this).remove();		
							}
						}
					);				
					/**add by selected maingroup**/	
					var option;
					$.each(subgroup['subgroup' + $('#maingroup').val()],function(i,item) {
							$('#subgroup').append('<option value="' + item.value + '">' + item.title + '</option>');							
		            });
		           // $('#subgroup').html(options);						
					
				} catch (e) {}					
				return false;
			});
						
		} catch (e)  {}		
	}
);
