
function createXHR()
{
	var request = false;
		try {
			request = new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch (err2) {
			try {
				request = new ActiveXObject('Microsoft.XMLHTTP');
			}
			catch (err3) {
		try {
			request = new XMLHttpRequest();
		}
		catch (err1) 
		{
			request = false;
		}
			}
		}
	return request;
}

function loadHTML(url, storage)
{
	storage = document.getElementById(storage);
	var xhr = createXHR();
	xhr.onreadystatechange=function()
	{ 
		if(xhr.readyState == 4)
		{
			//if(xhr.status == 200)
			{
				storage.innerHTML = xhr.responseText;
			}
		}
	};
	xhr.open("GET", url , true);
	xhr.send(null);
}


function loadHTML_shadowbox(url, storage)
{
	storage = document.getElementById(storage);
	var xhr = createXHR();
	xhr.onreadystatechange=function()
	{ 
		if(xhr.readyState == 4)
		{
			//if(xhr.status == 200)
			{
				storage.innerHTML = xhr.responseText;
				if (window.Shadowbox)
				{
					window.Shadowbox.setup();
				}
			}
		}
	};
	xhr.open("GET", url , true);
	xhr.send(null);
}

function loadHTML_viewHide(url, storageId)
{
	storage = document.getElementById(storageId);

	if (storage.innerHTML == '')
	{
		loadHTML_shadowbox(url, storageId);
		storage.style.display = 'block';
	}
	else if (storage.style.display == 'none')
	{
		storage.style.display = 'block';
	}
	else
	{
//		loadHTML_shadowbox(url, storageId);
		storage.style.display = 'none';
	}
}

function CambiaCSS(IdName, Class1, Class2){
	TheBox=document.getElementById(IdName);
	if (TheBox.className == Class1) {
		TheBox.className=Class2;
	} else {
		TheBox.className=Class1;
	}
}

function ImpostaCSS(IdName, Class){
	TheBox=document.getElementById(IdName);
	if (!TheBox){
		alert('Attenzione!\n\nSi è verificato un errore imprevisto.\nContattare se possibile l\'amministratore del sistema\nsegnalando il seguente codice di errore:\n\n"util.js - ImpostaCSS - '+IdName+'"');
	} else {
		TheBox.className=Class;
	}
}

function ImpostaCSS_noCheck(IdName, Class){
	TheBox=document.getElementById(IdName);
	if (TheBox){
		TheBox.className=Class;
	}
}

function ViewHide(IdName){
	TheBox = document.getElementById(IdName);
	if (TheBox.style.display == 'none') {
		TheBox.style.display = 'block';
	} else {
		TheBox.style.display = 'none';
	}
}

function blink( id, delay ) {
	this.obj = "blinkObj" + blink.count++;
	eval( this.obj + " = this " );
	this.css = ( document.getElementById? document.getElementById( id ).style : (document.all? document.all.fooImg.style : document.layers.fooImg ) );
	if( !this.css && !document.layers ) alert( 'Errore: non trovo il DIV con id="' + id + '"' );
	this.delay = delay || 1000;
	this.blinking = false;
	
	this.setDelay = function( delay ) { this.delay = delay; }
	
	this.isBlinking = function() { return this.blinking; }

	this.start = function() { if( this.isBlinking() ) return false; else this.go(); return true; }
	
	this.go = function() {
		this.blinking = true;
		if( this.isVisible() ) this.hide();
		else this.show();
		this.timer = setTimeout( this.obj + ".go()", this.delay );
	}
	
	this.isVisible = function() { return ( this.css.visibility == "visible" || this.css.visibility == "show" ); }
	
	this.hide = function() { this.css.visibility = ( document.layers? "hide" : "hidden" );  }
	
	this.show = function() { this.css.visibility = ( document.layers? "show" : "visible" ); }

	this.stop = function() {
		this.show();
		this.blinking = false;
		clearTimeout( this.timer );
	}
	return this;
}
blink.count = 0;


function ec(domain, name)
{
	var info = new Array();
	info[4] = ': ';
	info[5] = name;
	info[1] = 'ma';
	info[6] = '@';
	info[3] = 'to';
	info[2] = 'il';
	info[7] = domain;

	str_location = '';
	for (i=1; i<=7; i++)
	{
		str_location += info[i];
	}

	document.location = str_location;
}

function write_EC(domain, name)
{
	document.write("<a href=\"javascript: ec('"+domain+"', '"+name+"')\" >" + name + String.fromCharCode(64) + domain + "</a>");
	//document.write("" + name + String.fromCharCode(64) + domain + "");
}
