
function errore(testoErrore,titolo){
	$(document).ready(function() {
                $("#dialog-modal").dialog({
						autoOpen: true,
                        height: 140,
						modal: true
					});
				$("#dialog-modal").html(testoErrore);
	});
}

function debug(testoErrore){
	$(document).ready(function() {
				$("body").prepend('<div id="debugModal"></div>');			   
                $("#debugModal").dialog({
						autoOpen: true,
						title: 'Debug',
						position: ['right','top'],
						minHeight: 600
					});
				$("#debugModal").html(testoErrore);
	
	$(function() {
		$("#debug").accordion({
			fillSpace: true
		});
	});
	
	
	});	
}

function ajaxDebug(variabile){
	$("#ajaxDebug").append(variabile);
}

function confermaBuonfine(testoErrore){
		$(function() {
					// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
					$("#dialog").dialog("destroy");
				
					$("#dialog-modal").dialog({
						autoOpen: true,
						height: 140,
						modal: true
					});
					$("#dialog-modal").html(testoErrore, function(){
								
																				  });
					$("#dialog-modal").parent().delay(2000).fadeOut('slow');
					$(".ui-widget-overlay").delay(2000).fadeOut('slow', function(){
																		 $("#dialog-modal").dialog('close');
																				 });
					//
				});
}

function conferma(titolo,testo,modulo){
		$("#dialog-confirm").dialog({
			title: titolo,
			resizable: false,
			height: 'auto',
			modal: true,
			buttons: {
				'Si' : function() {
					$(modulo).submit();
				},
				'No': function() {
					$(this).dialog('close');
				}
			}
		});
		$("#dialog-confirm").html(testo);
}

jQuery.conferma = function(titolo,testo)
{
	$("#dialog-confirm").dialog({
			title: titolo,
			resizable: false,
			height: 'auto',
			modal: true,
			buttons: {
				'Si' : function() {
					$(this).parent('form').submit();
				},
				'No': function() {
					$(this).dialog('close');
				}
			}
		});
		$("#dialog-confirm").html(testo);
}

var Utf8 = {
 
	// public method for url encoding
	encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// public method for url decoding
	decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}
//Controlla che i box con dimensione ridotta si allarghino se sono soli
function controlloBox50(selettore){
	var quanti = $(selettore).length;
	if(quanti==1){	
		$(selettore).css('width','100%');
	}
}


