$(function(){ 
	
	$('#submitBrief').click(function() {
		
		var form_data = {
				nieuwsbrief: $('#nieuwsbrief').val()		
			};
	
			$.ajax({
				url: $('input[name="urlBrief"]').val(),
				type: 'POST',
				data: form_data,
				success: function(msg) {
					
					$("#nieuwsbrief").val("");
					$("#nieuwsbrief").focusout();
					
					$('body').append(msg);
					dialog();
					if($('input[name="mailadres"]').val())
					{
						$("#nieuwsbrief").val($('input[name="mailadres"]').val());
					}
				}
			});
		return false;
	});
	
	function dialog(){
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
	
		$( "#dialog-message" ).dialog({
			modal: true,
			buttons: {
				Ok: function() {
					$( this ).dialog( "close" );
					$('#dialog-message').remove();
				}
			}
		});
		

		
		$( "#dialog-confirm" ).dialog({
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"Uitschrijven": function() {
					$( this ).dialog( "close" );
					$('#dialog-confirm').remove();
					var form_data = {
							nieuwsbrief: $('#nieuwsbrief').val()		
						};
						$.ajax({
							url: '/nieuwsbrief/uitschrijven',
							type: 'POST',
							data: form_data,
							success: function(msg) {
								
								$("#nieuwsbrief").val("");
								$("#nieuwsbrief").focusout();
								
								$('body').append(msg);
								dialog();
							}
						});
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			}
		});
	}	

	$("#frmNieuwsbrief p input").live('click',function(){
		$("#frmNieuwsbrief p input").val('');
	});
	$("#frmNieuwsbrief p input").live('focusout',function(){
		if($("#frmNieuwsbrief p input").val() == ''){
			$("#frmNieuwsbrief p input").val('E-mailadres');
		}
	});
	
	
	
	$("a").each(function(){
		var url = $(this).attr('href');
		if(url){
		if(url.substring(0, 3) == "../")
		{
			
			$(this).attr('href',"http://www.sts1853.be/" + url);
		}
		}
	});
});
