$(document).ready(function() {
	$(".fancybox_ajax").fancybox({
		'scrolling'			: 'no',
		'width'				: 600,
		'height'			: 550,
		'margin'			: 0,
		'autoDimensions'	: false,
		'autoScale'			: false
	});
	
	$(".fancybox_inline").fancybox({
		'titleShow'		: false
	});
	
	$("#datepicker").datepicker( { dateFormat: 'yy-mm-dd' } );

	$("#submit_button").click(function(){
		checkForm('normal');
	});
	
	$("#close_button").click(function(){
		checkForm('close');
	});
	
	$(".required_input").change(function(event){
		$(this).css("background-color", "white");
	});
	
	$(".optional_required").change(function(event){
		$(this).css("background-color", "white");
	});
});


function checkForm( type )
{
	var ok = true;
	
	// kötelező mezők
	$(".required_input").each(function(){
		if ($(this).val() == '')
		{
			$(this).css("background-color", "yellow");
			ok = false;
			alert_message = 'Kérem töltse ki a kötelező mezőket!';
		}
	})
	
	// státusztól függő kötelező mezők
	if ( ($("#new_status").val() == 'public' && type == 'normal')
	|| ( type == 'close') )
	{
		$(".optional_required").each(function(){
			if ($(this).val() == '')
			{
				$(this).css("background-color", "yellow");
				ok = false;
				alert_message = 'Minden mezőt kötelező kitölteni!';
			}
		})
	}
	
	if (!ok)
		alert( alert_message );
	else
	{
		if ( type == 'close' )
			$("#closeit").val("1");
			
		$("#form_status").val("1");
		$("#form2submit").submit();
	}
}