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,callback){ 
    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();}
}

function pathencode(str){
 return str.replace(/\//g,'|');
}


function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

/**
 * visualizza un iframe in una finestra modale tramite SimpleModal
 */ 
function modalAjax(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').modal({
     overlayClose: true,
     onClose: function(){
        $.modal.close();
     }
     });
 $('#modaliframe').ajaxload(url);
}

/**************************************
 * imposta un cookie
 * name   string  : nome del cookie
 * value:         : valore
 * expires        : tempo di scadenza in minuti
 * path           : inserire / per tutto il dominio
 * domain         : dominio (lasciare vuoto per il dominio corrente)
 ***************************************/      
function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

