var pathImgLoading = "main/imgs/circle-ajax-loader.gif";
var pathImgChanged = "main/imgs/icons/error.png";
var pathImgSaved = "main/imgs/icons/accept.png";
var bStato_colorChanged = "#FFCCCC";
var bStato_colorNormal = "#FFFFFF";

var bStato_functionSave = function(){ };
var bStato_functionDontWantToSave = function(){ };

var bStato_stato = "saved"; //[saved, changed]

var bStato_divBackLoad = "";
var pathImgBackLoading = "";
/*var bStato_divBackLoad = "body"; // "" ? nonUsare : impostagliIlBackLoading
var pathImgBackLoading = "css/images/loading_pattern2.gif";*/


function bStato_hasToSave(){
	return (bStato_stato == "changed");
}

function bStato_setSaveFunction(functS){
	bStato_functionSave=functS;
	return true;
}

function bStato_setDontWantToSaveFunction(functS){
	bStato_functionDontWantToSave=functS;
	return true;
}


function bStato_clearSaveFunction(){
	bStato_functionSave=function(){ };
	return true;
}

function bStato_clearDontWantToSaveFunction(){
	bStato_functionDontWantToSave=function(){ };
	return true;
}

function bStato_save(askIf){
	askIf = askIf || true;
	if (!askIf){
		bStato_functionSave(false);	
	}else{
		bStato_functionSave();
	}
	bStato_saved();
	return true;
}

function bStato_checkSave(askIf){
	askIf = askIf || false;
	var saveIfNotNeededToo = false;
	if (bStato_hasToSave() || !saveIfNotNeededToo){
		var fSave = function(){
			if (bStato_save(false)){
				return "Saved";
			}else{
				return "ErrorSaving";
			}
		}
		if (askIf){
			if (msgBox("Sono state effettuate delle modifiche, effettuarne il salvataggio ?","Modifiche effettutate","yesNo",fSave,bStato_functionDontWantToSave)){
				return "SaveLaunched"; // esco ... ---------------
			}else{
				return "DontWantTo"; // esco ... --------------
			}
		}
		return fSave();
	}else{
		return "SaveNotNeeded";
	}
}

function bStato_changed(obj){
	$(".bStato_img").each( function(i){
		this.src = pathImgChanged;
		this.style.visibility = 'visible';
	});
	if (obj != null){
		obj.style.backgroundColor = bStato_colorChanged;
	}
	bStato_notWorkingNotSaving();
	bStato_stato = "changed";
}

function bStato_saved(){
	$(".bStato_img").each( function(i){
		this.src = pathImgSaved;
		this.style.visibility = 'visible';
	});
	bStato_notWorkingNotSaving();
	bStato_stato = "saved";
}

function bStato_processing(){
	$(".bStato_img").each( function(i){
		this.src = pathImgLoading;
		this.style.visibility = 'visible';
	});
	bStato_workingNotSaving();
}



// funzioni solo per gestire il PROCESSING globale (non legato allo stato bStato)

function bStato_workingNotSaving(){
	if (bStato_divBackLoad != ""){
		var iM = document.getElementById(bStato_divBackLoad);
		if (iM != null){
			iM.style.background = "url("+pathImgBackLoading+") repeat";
		}
	}
}

function bStato_notWorkingNotSaving(){
	if (bStato_divBackLoad != ""){
		var iM = document.getElementById(bStato_divBackLoad);
		if (iM != null){
			iM.style.background = "none";
		}
	}
}

