jQuery.fn.extend({
  showAjaxLoading: function (){
    jQuery(this).html('<div style="text-align:center;"><img src="/images/ajax-loader_big.gif"></div>');
    },
    
  ajaxload: function(url,data,complete){ 
    jQuery(this).show();
    jQuery(this).showAjaxLoading();
    jQuery(this).load(url,data,complete);
  },  
  
  myAjaxForm: function(options){
    var newoptions = { beforeSubmit: function (){ jQuery(options.target).showAjaxLoading();} }; 
    jQuery.extend(options,newoptions);
    jQuery(this).ajaxForm(options);
  }
});


/**
 * sincronizza il contenuto dell'editor con la texarea
 */ 
function nicEditorSync(editorObj){
 for(var i=0;i<editorObj.nicInstances.length;i++){editorObj.nicInstances[i].saveContent();}
}

/**
 * visualizza un iframe in una finestra modale tramite SimpleModal
 */ 
function modalIframe(url){
 if ($('#modaliframe').length==0) $('body').append('<div id="modaliframe"></div>');
 
 $("#modaliframe").css('height',$(window).height()*80/100);
 $("#modaliframe").css('width',$(window).width()*80/100);
 $("#modaliframe").css('overflow','auto');
 $('#modaliframe').modal({
     overlayClose: true,
     onClose: function(){
        restoreCurrLayout();
        $.modal.close();
     }
     });
 $('#modaliframe').showAjaxLoading();
 //$('#modaliframe').('<iframe style="width:100%;height:100%;border:0px" src="/images/ajax-loader_big.gif"></iframe>');
 $('#modaliframe').append('<iframe style="width:100%;height:99%;border:0px" src="'+url+'"></iframe>');
 $('#modaliframe iframe').one('load',function(){$('#modaliframe .ajaxloader').remove();});
 
 setTimeout(function(){$('#modaliframe .ajaxloader').remove();},3000); //per sicurezza togliamo il loader topo 3 secondi
}


/**
 * visualizza un iframe in una finestra modale tramite SimpleModal
 */ 
function modalAjax(url,width,height){
 if ($('#modaliframe').length==0) $('body').append('<div id="modaliframe"></div>');
 
 if (height==undefined) $("#modaliframe").css('height',$(window).height()*80/100);
 else $("#modaliframe").css('height',height);
  
 if (height==undefined) $("#modaliframe").css('width',$(window).width()*80/100);
 else $("#modaliframe").css('width',width); 
 $('#modaliframe').modal({
     overlayClose: true,
     onClose: function(){
        $.modal.close();
     }
     });
 $('#modaliframe').ajaxload(url);
}

