
function showMessageBg() {
	$("body").addClass("block_overflow");
	$("html").addClass("block_overflow");
	$("#message_bg").fadeIn("slow");
	$("#message_bg").animate({opacity: 0.6}, 500)
}

function hideMessageBg() {
	$("#message_bg").fadeOut("slow", function() {
		$("body").removeClass("block_overflow");
		$("html").removeClass("block_overflow");
	});
}

function showMessageText(text, klasa) {
	$("#message_text_inner").html(text);
	$("#message_text").fadeIn("slow",function() {
		if (klasa=="messageBox_source") {
			$("#code").focus();
			$("#code").select();
		}
	});
	$("#message_text_inner").attr("class",klasa);
}

function hideMessageText() {
	$("#message_text").fadeOut("slow", function() {
		$("#message_text_inner").html("");
		$("#message_text_inner").attr("class","");
	});
}

function mapActions(url) {
	if (url=="") {
		$("#alertMessageBox_ok").click(function() {
			hideMessageText();
			hideMessageBg();
			return false;
		});
	
		$("#sourceMessageBox_ok").click(function() {
			hideMessageText();
			hideMessageBg();
			return false;
		});
	}
	else {
		$("#alertMessageBox_ok").attr("href",url);
		$("#confirmMessageBox_ok").attr("href",url);
		$("#confirmMessageBox_cancel").click(function() {
			hideMessageText();
			hideMessageBg();
			return false;
		});
	}
}

function alertMessage(msg_title,msg_text) {
	$.ajax({
		type: "POST",
		url: "ajax.php",
		data: "a=msg&typ=alert&title=" + msg_title + "&text=" + msg_text,
		success: function(msg) {
			showMessageBg();
			showMessageText(msg,"messageBox_alert");
			mapActions("");
		}
	});
}

function sourceMessage() {
	$.ajax({
		type: "POST",
		url: "ajax.php",
		data: "a=msg&typ=source",
		success: function(msg) {
			showMessageBg();
			showMessageText(msg,"messageBox_source");
			mapActions("");
		}
	});
}

function confirmMessage(msg_title,msg_text,msg_url) {
	$.ajax({
		type: "POST",
		url: "ajax.php",
		data: "a=msg&typ=confirm&title=" + msg_title + "&text=" + msg_text,
		success: function(msg) {
			showMessageBg();
			showMessageText(msg,"messageBox_confirm");
			mapActions(msg_url);
		}
	});
}

function loadingMessage() {
	showMessageBg();
	showMessageText("<h1 class='alert' style='padding:10px;'>proszę czekać</h1><p class='alert' style='margin-bottom:15px;'>Trwa ładowanie, proszę czekać...</p><img src='css/img/loading_circle.gif' alt='ładowanie' />","messageBox_loading");
}

function colorPickerForId(div_id) {
	$('#' + div_id).ColorPicker({
		color: $('#' + div_id +' input[@type=text]').val().substring(1,7),
		onShow: function (colpkr) {
			$(colpkr).fadeIn(500);
			return false;
		},
		onHide: function (colpkr) {
			$(colpkr).fadeOut(500);
			return false;
		},
		onChange: function (hsb, hex, rgb) {
			$('#' + div_id +' div').css('backgroundColor', '#' + hex);
			$('#' + div_id +' input[@type=text]').addClass("changed");
			$('#' + div_id +' input[@type=text]').val("#" + hex);
		}
		/*onSubmit: function (hsb, hex, rgb) {
			//przywracanie koloru
			var color = $('#' + div_id +' input[@type=hidden]').val().substring(1,7);
			//$(this).setColor(hex);
			$('#' + div_id +' div').css('backgroundColor', '#' + color);
			$('#' + div_id +' input[@type=text]').removeClass("changed");
			$('#' + div_id +' input[@type=text]').val("#" + color);
		}*/
	});
}

//nie jquery, ale co z tego?
function isset(varname)  {
  if(typeof( window[ varname ] ) != "undefined") return true;
  else return false;
}

function TooltipBodyHandler(instr) {
var str = new String(instr);
str = str.replace(/headopen/g,"<h3>");
str = str.replace(/headclose/g,"</h3>");
str = str.replace(/breakline/g, "<br/>");
str = str.replace(/headline/g, "<hr/>");
return str;
}
