$(document).ready(function(){	
	function checkFormMailer(formData, jqForm, options){
		for (var i=0; i < formData.length; i++) { 
			if (!formData[i].value) { 
           		alert('Bitte alle Felder ausf'+unescape("%FC")+'llen!'); 
            	return false; 
        	}
		}
	};
	
	//load Mail-Form and Dialog
	function handleFormMailer(type, jObj){
		var mailSender = $('<div></div>').attr('id', 'mailSender'+type);
		
		var height = 410;
		if(type == "forward")
		{
			height = 250;
		}
		mailSender.appendTo(document.body);
		$('#mailSender'+type).dialog({
			title: $(jObj).text(),
			open: function(){
        	 	$('.ui-dialog-titlebar').corner("top 5px");
        	},
			close: function() {
				$(this).dialog("destroy").remove();
			},
			modal: true,
			overlay: {
		      opacity: 0.5,
		      background: "black"
		    },
		    height: height,
		    width: 500
		});
		$('#mailSender'+type).load('/pu_retter/ajax/mailSender.php?action='+type, function(){
			$('#'+type+'Form').submit(function() {
				$('#'+type+'Url').val(location.href);
				$(this).ajaxSubmit({
					beforeSubmit : checkFormMailer,
			        target: '#'+type+'Form',
			        data : ({
			        	action : type,
			        	beitrag_id : beitragId	 
			        })
			    });
			    return false;
			});
		});		
	}
	
	$('.forwardLink').live('click', function(){
		//alert('Diese Funktion steht im Beta Test nicht zur Verfuegung');
		handleFormMailer('forward', this)
	});	
	$('.reportLink').live('click', function(){
		
		handleFormMailer('report', this)
	});
	
	$('.veranstaltungsLink').live('click', function(){
		//alert('Diese Funktion steht im Beta Test nicht zur Verfuegung');
		handleFormMailer('vareport', this)
	});			
});
