lWindow = {
	width : 400,
	url : new String(),
	title : new String(),
	params : false,
	
	loadContent: function(url, width, title) {
		
		if (url) this.url = url;
		if (width) this.width = width;
		if (title) this.title = title;
		this.setTitle(title);
		this.showContent();
	},
	
	loadPostContent: function(url, params, width) {
		
		if (url) this.url = url;
		if (width) this.width = width;
		if (params) this.params = params;
		this.showContent(params);
	},
	showContent: function(params) {
		$('#layer-content').html("");
		$('#layer').width(this.width).css('margin-left', -(this.width / 2)).show();
		$('#layer').css('top',  $(window).scrollTop() + 30 + 'px');
		jQuery(function() {
			jQuery("#layer").draggable({ handle: '#layer-header'}, true);
		});
		try {
			$('#layer-content').load(this.url, params);
		}
		catch (e) {
			
			$.ajax({
			   url: this.url,
			   processData: true,
			   success: function(data) {
				$('#layer-content').html(data);
			   }
			 });
		}
		
	},
	
	setTitle: function(title) {
		if (title) this.title = title;
		if (this.title) $('#layer-header-title').html(this.title);
	},
	
	hideLayer: function () {
		$('#layer').hide()
	},
	setWidth: function(width) {
		$('#layer').width(width).css('margin-left', -(width / 2))
	},
	
	showSaveInfo: function() {
		
	},
	showInfo: function(txt) {
		this.hideInfo();
		var body = document.getElementsByTagName('body')[0];
		var info = document.createElement('div');
		info.id = "info-box";
		body.appendChild(info);
		$('#info-box').css('top',  $(window).scrollTop() + ($(window).height()/2 - parseInt($('#info-box').css('height'))/2) + 'px');
		$('#info-box').css('margin-left', -(parseInt($('#info-box').css('width')) / 2)).show();
		$('#info-box').html(txt);
	},
	hideInfo: function() {
		$('#info-box').remove();
	}
	
}


function saveProduct(url, elm, callback) {
	dataString = $("#"  + elm).serialize();
	$.ajax({
		type: "POST",
		url: url,
		data: dataString,
		error: function(request) {
			if (request.responseText.length > 100){
				alert("Unexpected error");
			}
			else {
				alert(request.responseText);
			}
		},
		success: function(data) {
			location.href = location.href;
		}
	})
}

function deleteObject(url, element, id) {
	var answer = confirm("Na pewno chcesz usunąć?");

	if (answer) {
		jQuery.get(url + '?id=' + id, function(data) {
			$('#' + element).remove();
		})
	}
}
