jQuery.fn.extend({
  showAjaxLoading: function (){
    jQuery(this).html('<div class="ajaxloader" style="text-align:center;"><img src="/images/ajax-loader_big.gif"></div>');
    },
    
  showVoteLoading: function (){
    jQuery(this).html('<div style="text-align:center;font-size:10px">voto...<img src="/images/ajax-loader.gif"></div>');
    },

  ajaxload: function(url,data,callback){ 
    jQuery(this).show();
    jQuery(this).showAjaxLoading();
    jQuery(this).load(url,data,callback);
  }  
});


/**
 * 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 modalAjax(url,width,height){
 if ($('#modaliframe').length==0) $('body').append('<div id="modaliframe"></div>');
 
 if (width!=undefined) $('#modaliframe').css('width',width);
 else $("#modaliframe").css('width',$(window).width()*80/100);
 if (height!=undefined) $('#modaliframe').css('height',height);
 else $("#modaliframe").css('height',$(window).height()*80/100); 
 
 
 
 $('#modaliframe').modal({
     overlayClose: true
     });
 $('#modaliframe').ajaxload(url);
}

/**
 * visualizza una finestra modal in una finestra modale tramite SimpleModal
 */ 
function modalWindow(obj,width,height){
 if ($('#modaliframe').length==0) $('body').append('<div id="modaliframe"></div>');
 
 if (width!=undefined) $('#modaliframe').css('width',width);
 else $("#modaliframe").css('width',$(window).width()*80/100);
 if (height!=undefined) $('#modaliframe').css('height',height);
 else $("#modaliframe").css('height',$(window).height()*80/100); 
 
 
 
 $('#modaliframe').modal({
     overlayClose: true,
     onClose: function(){
      obj.hide();
      $('body').append(obj);
      $.modal.close();
     }
     });
 $('#modaliframe').append(obj);
 obj.show();
}

/**
 * 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
     });
 $('#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
}

