// Global vars
var waitactive = 0;
var AJAXRitorno = "";
var Base_Domain = "http://www.alonerd.net/";

// Sopprime il menu contestuale sul tasto destro
// document.oncontextmenu=new Function("alert('eh no caro!'); return false;");

// Restituisce l'accesso a un oggetto con dato ID
function GetObjId(id){
	return document.getElementById(id);
}

//recupera larghezza finestra
function getWindowWidth(){
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	} else {
		if (document.documentElement && document.documentElement.clientWidth)windowWidth = document.documentElement.clientWidth;
		else if(document.body && document.body.clientWidth)windowWidth = document.body.clientWidth;
	}
	return windowWidth;
}

//recupera larghezza finestra
function getWindowHeight(){
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight)windowHeight = document.documentElement.clientHeight;
		else if(document.body && document.body.clientHeight)windowHeight = document.body.clientHeight;
	}
	return windowHeight;
}

//Centra box in finestra
function BoxCenter(box){
	var boxt = ((getWindowHeight()/2)-(box.offsetHeight/2)) + document.body.scrollTop + "px";
	var boxl = ((getWindowWidth()/2)-(box.offsetWidth/2)) + document.body.scrollLeft + "px";
	box.style.top=boxt;
	box.style.left=boxl;
}

function ResizeAlert(w,h){
	if(!w)w=200;
	top.document.getElementById('alertBox').style.width=w+"px";
	if(!h)h=100;
	top.document.getElementById('alertBox').style.height=h+"px";
	top.BoxCenter(top.document.getElementById('alertBox'));
}

window.onresize = function() { BoxCenter(top.document.getElementById('alertBox')) };

// funzione per attivare lo schermo semitrasparente
function ActivateBackScreen(){
	top.document.getElementById('waitScreen').className="aon_darkscreen_on";
	top.document.getElementById('waitScreen').style.height = top.document.clientHeight;
}
// funzione per disattivare lo schermo semitrasparente
function DeactivateBackScreen(){top.document.getElementById('waitScreen').className="aon_darkscreen_off";}
// funzione per attivare la box di attesa
function ActivateAlertBox(css_class){
	if(!css_class)css_class='aon_alertbox';
	top.document.getElementById('alertBox').style.width="auto";
	top.document.getElementById('alertBox').style.height="auto";
	top.document.getElementById('alertBox').className=css_class + "_on";
	BoxCenter(top.document.getElementById('alertBox'));
}
// funzione per disattivare la box di alert
function DeactivateAlertBox(css_class){
	if(!css_class)css_class='alertbox';
	top.document.getElementById('alertBox').className=css_class + "_off";
}

//Crea un'alert
function AlertBox(txt){
	if(!txt)txt=AJAXRitorno;
	var DivText=txt;
	DivText+='<br /><br /><img src="'+ Base_Domain +'img/genbutton.php?text=Ok&image=spunta" alt="Ok" style="cursor:pointer" onclick="top.ClearAlertBox()"/>';
	top.document.getElementById('alertBox').innerHTML=DivText;
	ActivateBackScreen();
	ActivateAlertBox();
	waitactive = 0;
}

//Crea un'alert con funzione in uscita
function AlertFunc(txt,func){
	var DivText=txt;
	DivText+='<br /><br /><img src="'+ Base_Domain +'img/genbutton.php?text=Ok&image=spunta" alt="Ok" style="cursor:pointer" onclick="';
	if(func.length>0){
		if(func.substr(-1)!=';')func+=';';
		DivText+=func;
	}
	DivText+='top.ClearAlertBox();"/>';
	top.document.getElementById('alertBox').innerHTML=DivText;
	ActivateBackScreen();
	ActivateAlertBox();
	waitactive = 0;
}

//Crea un'alert senza pulsante di uscita, completamente vuota
function AlertFree(txt){
	if(!txt)txt=AJAXRitorno;
	top.document.getElementById('alertBox').innerHTML=txt;
	ActivateBackScreen();
	ActivateAlertBox();
	waitactive = 0;
}


//Crea un'alert con domanda
function ConfirmBox(txt,funcyes,funcno){
	DivText=txt + '<br /><br />';
	DivText+='<img src="'+ Base_Domain +'img/genbutton.php?text=Si&image=spunta" alt="Si" style="cursor:pointer" onclick="top.ClearAlertBox();'+funcyes+'"/>';
	DivText+='&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="'+ Base_Domain +'img/genbutton.php?text=No&image=annulla" alt="No" style="cursor:pointer" onclick="top.ClearAlertBox();'+funcno+'"/>'
	top.document.getElementById('alertBox').innerHTML=DivText;
	ActivateBackScreen();
	ActivateAlertBox();
	waitactive = 0;
}

// Toglie la alertbox
function ClearAlertBox(){
	DeactivateAlertBox();
	top.document.getElementById('alertBox').innerHTML='';
 	DeactivateBackScreen();
}

String.prototype.trim = function() { return this.replace(/^\s*/, '').replace(/\s*$/, ''); }
