function _Ajax(target_url, target_html)
{
//console.log('_Ajax');
	$("#sender").ajaxSend(function(evt, request, settings){
		$(this).html("Loading...");
	});

	$.ajax({contentType: "text/html; charset=iso-8859-2",
		type: "GET",
		url: target_url,
		dataType:"html",
		async: false,
		error:function(){
			response = '<I>[ Error ]</I>';
			$("#_"+target_html).html("Ponw");
		}
	});

	$("#"+target_html).html( response );
};

function _Ajax_Content(target_url, target_html)
{
//console.log('_Ajax');
	$("#sender").ajaxSend(function(evt, request, settings){
		$(this).html("Loading...");
	});

	$.ajax({contentType: "text/html; charset=iso-8859-2",
		type: "GET",
		url: target_url,
		dataType:"html",
		async: false,
		success:function(data){
			response = data;
			$("#_"+target_html).remove();
		},
		error:function(){
			response = '<I>[ Error ]</I>';
			$("#_"+target_html).html("Ponw");
		}
	});

	$("#"+target_html).html( response );
};

function _Ajax_Simple(target_url)
{
	$.ajax({contentType: "text/html; charset=iso-8859-2",
		type: "GET",
		url: target_url,
		dataType:"html",
		async: false,
	});
};


















function _pu(Width, Height, Resize, Title, Url)
{
	$(document).ready(function ()
	{
		$("#_pu").dialog( "destroy" );
		$("#_pu").dialog({
			autoOpen: false,
			width: Width,
			height: Height,
			modal: true,
			title: Title,
			resizable: Resize
		});

		$('#_pu').dialog('open');
		$("#_pu").load(Url).dialog();
	});
}

function _pu_back(Width, Height, Resize, Title, Url, BackDialogType, BackWidth, BackHeight, BackResize, BackTitle, BackUrl)
{
	$(document).ready(function ()
	{
		$("#_pu").dialog( "destroy" );
		$("#_pu").dialog({
			autoOpen: false,
			width: Width,
			height: Height,
			modal: true,
			title: Title,
			resizable: Resize,
			buttons: {
				'Go Back' : function() {
					var function_to_call = BackDialogType;
					window[function_to_call](BackWidth, BackHeight, BackResize, BackTitle, BackUrl);
				}
			}
		});

		$('#_pu').dialog('open');
		$("#_pu").load(Url).dialog();
	});
}

function _pu_ok(Width, Height, Resize, Title, Url)
{
	$(document).ready(function ()
	{
		$("#_pu").dialog( "destroy" );
		$("#_pu").dialog({
			autoOpen: false,
			width: Width,
			height: Height,
			modal: true,
			title: Title,
			resizable: Resize,
			buttons: {
				'OK' : function() {
					$('#_pu').dialog('close')
				}
			}
		});

		$('#_pu').dialog('open');
		$("#_pu").load(Url).dialog();
	});
}

function _pu_ok_text(Width, Height, Resize, Title, Text)
{
	$(document).ready(function ()
	{
		$("#_pu").dialog( "destroy" );
		$("#_pu").dialog({
			autoOpen: false,
			width: Width,
			height: Height,
			modal: true,
			title: Title,
			resizable: Resize,
			buttons: {
				'OK' : function() {
					$('#_pu').dialog('close')
				}
			}
		});

		$('#_pu').dialog('open');
		$("#_pu").html(Text).dialog();
	});
}

function _pu_confirm(Width, Height, Resize, Title, Url, Text)
{
	$(document).ready(function ()
	{
		$("#_pu").dialog( "destroy" );
		$("#_pu").dialog({
			autoOpen: false,
			width: Width,
			height: Height,
			modal: true,
			title: Title,
			resizable: Resize,
			buttons: {
				'OK' : function() {
	  				window.location=Url; return false;
	  			},
				'Anuluj': function() {
					$('#_pu').dialog('close')
				}

			}
		});

		$('#_pu').dialog('open');
		$("#_pu").html(Text).dialog();
	});
}

function _pu_form(Width, Height, Resize, Title, Url)
{
	$(document).ready(function ()
	{
		$("#_pu").dialog( "destroy" );
		$("#_pu").dialog({
			autoOpen: false,
			width: Width,
			height: Height,
			modal: true,
			title: Title,
			resizable: Resize,
			buttons: {
				'Zapisz': function() {
					  $('#form_pu').submit();
				},
				'Anuluj': function() {
					$('#_pu').dialog('close');
				}
			}
		});

		$('#_pu').dialog('open');
		$("#_pu").load(Url).dialog();
	});
}

function _pu_form_ajax(Width, Height, Resize, Title, Url)
{
	$(document).ready(function ()
	{
		$("#_pu").dialog( "destroy" );
		$("#_pu").dialog({
			autoOpen: false,
			width: Width,
			height: Height,
			modal: true,
			title: Title,
			resizable: Resize,
			buttons: {
				'Zapisz': function() {submit_pu_to_pu($(this).find('#form_pu'));},
				'Anuluj': function() {
					$('#_pu').dialog('close');
				}
			}
		});

		$('#_pu').dialog('open');
		$("#_pu").load(Url).dialog();
	});
}

function submit_pu_to_pu(form) {
  form = $(form);
  $.ajax({
    url: form.attr('action'),
    data: form.serialize(),
    type: (form.attr('method')),
    dataType: 'script',
			success:function(data){
			response = data;
//			$("#_pu").remove();
	$("#_pu").html( response );
		},
		error:function(){
			response = '<I>[ Error ]</I>';
			$("#_pu").html("Ponw");
		}
  });

  return false;
}


function _pu_close()
{
	$('#_pu').dialog('close');
}



