var ritorna_alla_home = 0;
var timeout = 5;
var redirect_destination = "home";

function pagina_completa(){
	if (caricamento==0)
	document.getElementById("cella_errore").style.display = "block";
	if (ritorna_alla_home == 1)
	wait4redirect();
}

function wait4redirect(){
	if (timeout>1){
		document.getElementById('timeout_message').innerHTML = "Redirect automatico tra "+timeout+" secondi...";
		timeout--;
		setTimeout("wait4redirect()",1000);
	}
	else if (timeout==1){
		document.getElementById('timeout_message').innerHTML = "Redirect automatico tra 1 secondo...";
		timeout--;
		setTimeout("wait4redirect()",1000);
	}
	else {
		document.getElementById('timeout_message').innerHTML = "Redirect in corso, attendere...";
		home_redirect();
	}
}

String.prototype.trim = function(){
	var x=this;
	x=x.replace(/^\s*(.*)/, "$1");
	x=x.replace(/(.*?)\s*$/, "$1");
	return x;
}

function home_redirect(){
	if (redirect_destination == "home")
	window.location.href = "index.php";
	else if (redirect_destination == "history")
	history.go(-1);
	else window.location.href = "index.php?"+redirect_destination;
}

function sposta_art(sorgente, destinazione){
	window.location.href = "index.php?scambia="+sorgente+"."+destinazione+"&qs="+escape(window.location.search);
}

function apri_aiuto(id){
	// recupero posizione della finestra corrente
	var window_pos_left = window.screenX;
	var window_pos_top = window.screenY;
	finestra_guida = window.open('index.php?cat=99&popup=1&argomentoguida='+id,'Guida','width=370, height=380, top='+(window_pos_top+180)+', left='+(window_pos_left-40)+', location=no, menubar=no, dependent=yes, toolbar=yes, scrollbars=yes');
	finestra_guida.focus();
}

function disabilitaSelezione(elemento) {
	if (typeof elemento.onselectstart != "undefined")
    elemento.onselectstart = function(){return false}
	else if (typeof elemento.style.MozUserSelect!="undefined")
    elemento.style.MozUserSelect = "none";
	else elemento.onmousedown = function(){return false}
	elemento.style.cursor = "default";
}
