Spinner.prototype.xmlhttp = function(url) 
{
//alert(url);
  //AJAX sincrono .......
  if (window.XMLHttpRequest) 
    AJAX=new XMLHttpRequest();              
  else 
    AJAX=new ActiveXObject("Microsoft.XMLHTTP");
  if (AJAX) 
  {
    var pagina = url.substring(0,url.indexOf('?'));
    var params = url.substring(url.indexOf('?')+1);
     AJAX.open("POST", pagina, false);    
     //AJAX.overrideMimeType("text/html; charset=ISO-8859-1");
     
     //AJAX.setRequestHeader('Content-type ','application/x-www-form-urlencoded;charset=UTF-8;'); 

    AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	AJAX.setRequestHeader("Content-length", params.length);
	AJAX.setRequestHeader("Connection", "close");
		         
     AJAX.send(params);
     return AJAX.responseText;                                         
  } 
  else 
  {
     return false;
  }                                             
}
	
function Spinner(eletohide,ideletoshow,newrit,idhtmltoshow) 
{	
    urltopass = "";
    _eletohide = null;
    _ideletoshow = null;
    _idhtmltoshow = null;
    _htmlc = "";
    this._ritardo = 1000;
	var corpo = document.getElementsByTagName("body")[0];
	if (eletohide != null) this._eletohide = eletohide;
	if (ideletoshow != null) this._ideletoshow = ideletoshow;
	if (idhtmltoshow != null) this._idhtmltoshow = idhtmltoshow;
	if (newrit != null) this._ritardo = newrit;
	if (eletohide != null)
	{
	    document.getElementById(eletohide).style.display = "none"; 	
	    this.createimg();	
	    this.addLoadEvent(window, 'load', this.visonload);
	}
}

Spinner.prototype.addLoadEvent = function (obj, evType, fn) 
{ 
	if (obj.addEventListener)
	{ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	} 
	else if (obj.attachEvent)
	{ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	}
	else 
	{ 
		return false; 
	} 
}

Spinner.prototype.visonload = function()
{
	var strtorimeout = "";
	strtorimeout += "document.getElementById('" + this._eletohide + "').style.display = '';";
	if(document.getElementById(this._ideletoshow) != null)	
		strtorimeout += "document.getElementById('" + this._ideletoshow + "').style.display = 'none'";	
	setTimeout(strtorimeout,this._ritardo);
}

Spinner.prototype.createimg = function()	
{
	if (this._ideletoshow != null)
	{
		if (document.getElementById(this._ideletoshow) != null)
		{
			if(document.getElementById(this._ideletoshow).innerHTML == '')
			{	
				if (this._idhtmltoshow != null)
				{
					if (document.getElementById(this._idhtmltoshow) != null)
						document.getElementById(this._ideletoshow).innerHTML = document.getElementById(this._idhtmltoshow).innerHTML;
				}
				else
				{
                    var pathimm = "";
                    if(typeof phppath == 'undefined')
                    {
	                    if (document.getElementById('spinnerjs') != null)
		                    pathimm = document.getElementById('spinnerjs').src.replace("spinner.js","") + "ajax-loader.gif";
                    }
                    else
	                    pathimm = phppath + "/javascripts/spinner/ajax-loader.gif";	

                    var showme = document.getElementById(this._ideletoshow);
					
					showme.innerHTML = ""; //'<center>Waiting.....<br /><img src="' + pathimm + '" alt="" /></center>';
					showme.style.position = "absolute";
					showme.style.top = "50%";
					showme.style.width = "100%";
				}
			}
			document.getElementById(this._ideletoshow).style.display = "block";
			
		}
	}

}
Spinner.prototype.isie = function()
{
	if ("Microsoft Internet Explorer" == navigator.appName )
		return true;
	else
		return false;
}

Spinner.prototype.loadspinner = function(eletohide,ideletoshow,newrit,idhtmltoshow)
{
	if (GLOinstSpin.isie() == true)
		document.styleSheets[0].addRule('html', 'overflow: hidden');
	else
		document.getElementsByTagName("body")[0].style.overflow = "hidden";
	new Spinner(eletohide,ideletoshow,newrit,idhtmltoshow);
}

Spinner.prototype.unloadspinner = function(eletohide,ideletoshow)
{
    //alert('Spinner.prototype.unloadspinner');
	if (GLOinstSpin.isie() == true)
		document.styleSheets[0].addRule('html', 'overflow: scroll');
	else
		document.getElementsByTagName("body")[0].style.overflow = "scroll";
	
	document.getElementById(eletohide).style.display = "block";
	document.getElementById(ideletoshow).innerHTML = "";
	
}

Spinner.prototype.spin = function(ucname,waitinganchor,waitingelement,idtohide,chechkifexist)
    {
        //alert('Spinner.prototype.spin');
        oggloc = this;
        window.location.hash = waitinganchor; 
        //alert(oggloc.urltopass);
        htmll = oggloc.xmlhttp(oggloc.urltopass);
        //indice = htmll.indexOf('<div id="spinnerImageLogo">');
        indice = htmll.indexOf('<div id="divinizio"></div>');
        htmll = htmll.substr(indice);
        //indice = htmll.indexOf('</table>') + 8;
        indice = htmll.indexOf('<div id="divfine"></div>') ;
        htmll = htmll.substr(0,indice);
        document.getElementById(waitingelement).innerHTML = htmll;
        oggloc.loadspinner(idtohide,waitingelement);
    }    



var GLOinstSpin = new Spinner(null,null,null,null); //istanza vuota !!!!!
