$(document).ready(function() {
	$("#tNotes").click(function() {
		$(".ofertaHolder").toggle("slow");
	});

	$("#filtryRZ").click(function() {
		$("#filtryOfert").toggle("slow");
	});

	$('#notesOferty').load('box_notes.php');

	$.ajaxSetup( {
		type : "GET",
		contentType : "application/x-www-form-urlencoded; charset=iso-8859-2"
	});

});

function Dodaj_Notes(ID) {
	$('#notesOferty').html("");
	$("#notes-loader").ajaxStart(function() {
		$(this).addClass("loader-notes");
	});

	$
			.get(
					"box_notes.php?akcja=dodaj",
					{
						oferta : ID
					},
					function(data) {
						$('#notesOferty').load('box_notes.php');
						$('#notes' + ID)
								.replaceWith(
										"<a id=notes"
												+ ID
												+ " href='javascript:void(null);' onclick='Usun_Notes("
												+ ID
												+ ")'><img	src='/gfx/tla/boksy/listaOfert/lista/delNotes.jpg' width='36' height='35' alt=''></a>");

						$('li.optNote a').replaceWith(
								"<a href='javascript:void(null);' onclick='Usun_Notes("
										+ ID + ")'>Usuń z notesu</a>");

					});

	$("#notes-loader").ajaxStop(function() {
		$(this).removeClass("loader-notes");
	});
}

function Usun_Notes(ID) {
	$('#notesOferty').html("");
	$("#notes-loader").ajaxStart(function() {
		$(this).addClass("loader-notes");
	});

	$
			.get(
					"box_notes.php?akcja=usun",
					{
						oferta : ID
					},
					function(data) {
						$('#notesOferty').load('box_notes.php');
						$('#notes' + ID)
								.replaceWith(
										"<a id=notes"
												+ ID
												+ " href='javascript:void(null);' onclick='Dodaj_Notes("
												+ ID
												+ ")'><img src='/gfx/tla/boksy/listaOfert/lista/addNotes.jpg' width='36' height='35' alt=''></a>");

						$('li.optNote a').replaceWith(
								"<a href='javascript:void(null);' onclick='Dodaj_Notes("
										+ ID + ")'>Dodaj do notesu</a>");
					});

	$("#notes-loader").ajaxStop(function() {
		$(this).removeClass("loader-notes");
	});
}
