function init_download(){

	$$('#downloadTable .smallImgButton').addEvent('mouseover', function( thisElement ) {
		thisElement.target.style.border	=	'1px solid #000000';
	});
	
	$$('#downloadTable .smallImgButton').addEvent('mouseout', function( thisElement ) {
		thisElement.target.style.border	=	'1px solid #FFFFFF';
	});
	// Filter geschlossen halten beim laden der seite!
	var imgSrc1 = "/img/ico/arrow_black.gif";
	$('filterArrow').getProperty('src') == imgSrc1
	handle_show_filter();
	
	preparePopupLayout();
}

function send_email(){
	var Email 		= $('Email').value;
	var EmailFrom 	= $('From').value;
	
	if ( 	
			Email == '' ||
			Email.indexOf ('@') < 2  ||
			Email.indexOf ('@') == Email.length-1 ||
			Email.indexOf ('.') < 1 
		){
		//fehler am input (email)
		if ( $('errorDiv').get('text') == '' ){
			//im Normalfall wird der Text sprachspezifisch gesetzt. Im Ausnahmefall (erst richtig, dann falsch) wird dieser Text angezeigt
			$('errorDiv').set( 'text', 'Please enter a valid e-mail address!' );
		}
		
		$('statusDiv').set('text', '');
		$('errorDiv').setStyle('display', 'block');
		$('errorDiv').fade('in');
		
		$('Email').focus();
		return false;
	}else{
		$('statusDiv').set('text', '');	
		$('errorDiv').set( 'text', '' );
	}
	
	txtvalue	=	encodeURI($('EmailTxt').value);
	
	var req = new Request({
							method: 'post',
							url: '/ajax/send_download_email.php',
							data: 	{ 
										'Email' 	: Email,
										'EmailTxt' 	: txtvalue,
										'From'		: EmailFrom		
									},
							onRequest: function(){
											$('statusDiv').set('text', '');
												if ( !$defined($('sendMailLoader')) ){
										
													var loader	=	new Element( 'img', {
																								'id':	'sendMailLoader',
																								'alt': 	'loader',
																								'src':	'/img/ico/loader.gif'										
																							} );
													$('statusDiv').adopt(loader);
												}
												
											showLoader(true, 'sendMailLoader');												
									   },
							
							onComplete: function(text){
													showLoader(false, 'sendMailLoader');
							 						$('statusDiv').setStyle('color', '#FFFFFF');
													$('statusDiv').set('text', text);
													
													//var myFx = new Fx.Tween('statusDiv');
													//myFx.start('color', '#FFFFFF', '#008330');
													//$('statusDiv').setAttribute('class', 'successfull');
													$('statusDiv').morph('.successfull');														
												  }
						}).send();
	return true;	
}

function handle_show_filter(){
	var imgSrc1	=	"/img/ico/arrow_black.gif";
	var imgSrc2	=	"/img/ico/arrow_black_down.gif";

	var myFx = new Fx.Tween('filter');
	
	if ( $('filterArrow').getProperty('src') == imgSrc1 ) {
		//open
		$('filterArrow').setAttribute('src', imgSrc2 );
		
		$('filter').setStyle('opacity', '0');
		$('filter').setStyle('display', 'block' );
		myFx.start('opacity', '0', '1');
		$('Search').focus();
	}else{
		//close
		$('filterArrow').setAttribute('src', imgSrc1 );
		
		$('filter').setStyle('display', 'none' );
		myFx.start('opacity', '1', '0');
	}
}

function handle_filter(e, Element){
	e.stop();
	
	if ( searchQuerry == $('Search').value ) {
			return true;
	}
					
	//leere Anfragen muessen geschickt werden. Anfragen mit 3 Zeichen ebenfalls
	if ( $('Search').value.length < 3 && $('Search').value.length > 0 ){
		return true;
	}

	if ( e.target.id == 'Search' ){
		/*$$('\.ln.').each( function(element){
							element.setStyle('color','#000000');
							element.setStyle('text-decoration','underline');
						});*/
	}	
	
	var plPrinterOutput	=	$('downloadTable');
	searchQuerry		=	$('Search').value;

	//Set the options of the form's Request handler. 
	//("this" refers to the $('myForm') element).
	Element.set('send', {	url: '/ajax/filter_downloads.php',
							onRequest:		function(el){
												var height	=	plPrinterOutput.getStyle('height');							
												plPrinterOutput.setStyle('min-height',height);								
												plPrinterOutput.empty()
												showLoader(true);
												
										},
						
							onComplete: 	function(response) {
											showLoader(false);
											plPrinterOutput.setStyle('opacity', '0');
											plPrinterOutput.set('html', response);													
											var myFx = new Fx.Tween('downloadTable');
	 										myFx.start('opacity', '0', '1');
												 										
										}});
	
	Element.send();
	
	return true;	
}


function handle_text_link_change( fieldId, newValue ){

	$(fieldId).value	=	newValue;

	var obj	=	{
						'target': { 'id' : 'kind' },
						'stop'	: function(){  }	
					};
					
	$('fmFilter').fireEvent( 'change', obj,  $('fmFilter') );
	
	//understreichen
	$$('.ln'+fieldId).each( function(element){
		/*element.setStyle('color','#000000');
		element.setStyle('text-decoration','underline');*/
		element.removeClass('activeItem');

		if ( element.id == 'ln_'+newValue ){
			/*element.setStyle('color','#BBBBBB');
			element.setStyle('text-decoration','none');*/
			element.addClass('activeItem');
		}
	});
	
	
	return true;
}

function open_big_img(img_url,img_width,img_height){

	if (typeof Ha_popup != "undefined" && !Ha_popup.closed){
		Ha_popup.close();
	}
	var url		=	"/download/popups/show_img.php?img_url="+img_url;	
	var name	=	"img";
	var properties=	"width="+ (img_width) +",height="+ (img_height) +",screenX=1,screenY=1,left=1,top=1,status,no ,yes";
	var openerName ="";
	var msg		=	name;
	
	Ha_popup	=	openWindow(url, name, properties, openerName);		
}