var w, h;
var coloreBgMod  = "#000";
var coloreBg     = "#FFF";
var coloreBordo  = "#FFC484";
var coloreBordoA = "#FF0000";
var larghBordo   = 12;

function showAjax(pagina,div_id){

	$("#"+div_id).bind("ajaxStart",function(){
		$("#"+div_id).html('<img style="margin:30px" src="images/mini_loading.gif" border="0" alt="Attendere" align="absmiddle" /> Caricamento in corso...'); 
	});

	$.ajax({ 
	    complete : function(){ }, 
		url      : pagina, 
		cache    : false, 
		data     : "", 
		success  : function (risultato,esito){
			// Mostro risultato
			$("#"+div_id).html(risultato);
		},
		error : function (richiesta,stato,errori) {
			alert("Attenzione, si e' verificato un errore");    
	}});
}

function popup() {

	/* CREO LA FINESTRA OSCURA */
	var oggetto = $("<div></div>");

	oggetto.css('position','fixed').css('z-index','9990').css('top','0px').css('left','0px').css('height','100%').css('opacity','0.5');
	oggetto.css('width','100%').css('background-color',coloreBgMod).css('filter','alpha(opacity=50)').css('-moz-opacity','0.5');

	oggetto.attr("id","bgoscuro");
	oggetto.attr("onclick","andyClose()");
	//oggetto.fadeIn("fast").appendTo(document.body);
	oggetto.appendTo(document.body);

}

function andyPop(link,w,h){

	popup();
	var div = $("<div></div>");

	w==null ? w='300' : w=w ;
	h==null ? h='130' : h=h ;

	w_Wintot = document.compatMode=='CSS1Compat' && !window.opera ? document.documentElement.clientWidth : document.body.clientWidth;
	w_Win = parseInt((w_Wintot/2)-(w/2));

	div.attr("id", "cdiv").css('position','fixed').css('-moz-border-radius','10px').css('-webkit-border-radius','10px').css('-moz-opacity', '1.0');
	div.css('border-radius','10px').css('z-index','9999').css('top','160px').css('left', w_Win+'px').css('height', h+'px').css('width', w+'px').css('opacity', '1.0');
	div.css('border', larghBordo+'px solid '+coloreBordo).css('background-color', coloreBg).css('filter', 'alpha(opacity=100)');

		div.appendTo(document.body);
		//div.fadeIn("fast").appendTo(document.body);
		showAjax(link,"cdiv");

}

function andyAlert(link,w,h){

	popup();
	var div = $("<div></div>");

	w==null ? w='300' : w=w ;
	h==null ? h='130' : h=h ;

	w_Wintot = document.compatMode=='CSS1Compat' && !window.opera ? document.documentElement.clientWidth : document.body.clientWidth;
	w_Win = parseInt((w_Wintot/2)-(w/2));

	div.attr("id", "cdiv").css('position','fixed').css('-moz-border-radius','10px').css('-webkit-border-radius','10px').css('-moz-opacity', '1.0');
	div.css('border-radius','10px').css('z-index','9999').css('top','160px').css('left', w_Win+'px').css('width', w+'px').css('opacity', '1.0');
	div.css('border', larghBordo+'px solid '+coloreBordoA).css('background-color', coloreBg).css('filter', 'alpha(opacity=100)');

		div.appendTo(document.body);
		//div.fadeIn("fast").appendTo(document.body);
		showAjax(link,"cdiv");

}

function andyClose(){
   $("#cdiv").remove();
   $("#bgoscuro").remove();
}
