var limiteY = 0;
function pngfix(){
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])

	if ((version >= 5.5) && (document.body.filters)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
	      var img = document.images[i]
	      var imgName = img.src.toUpperCase()
	      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	      {
	         var imgID = (img.id) ? "id='" + img.id + "' " : ""
	         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
	         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
	         var imgStyle = "display:inline-block;" + img.style.cssText 
	         if (img.align == "left") imgStyle = "float:left;" + imgStyle
	         if (img.align == "right") imgStyle = "float:right;" + imgStyle
	         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
	         var strNewHTML = "<span " + imgID + imgClass + imgTitle
	         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
	         img.outerHTML = strNewHTML
	         i = i-1
	      }
	   }
	}
}

function $id($id){
	return document.getElementById($id);
}

function ajax(url, div, info, method, form, script, func)
{
	this.url = url; // content url
	this.method = (method) ? method : 'GET'; // method GET or POST, standard = "GET"
	this.div = div; // content destination
	this.info = (info) ? info : "<center><b><font color='red'>Caricamento<br>in corso</font></b></center>"; // durante il loading mostra qualcosa se non specificato
	this.form = form; //nome del form - richiesto solo per richieste by POST
	this.script = (script==0 || script==1) ? script : 1;
	this.func = func;
}
ajax.prototype = {
    connect: function()
	{
		if(!this.url) return;
        this.xmlHttp = null;
		if( window.XMLHttpRequest ) this.xmlHttp = new XMLHttpRequest(); // tuttu i browser
		else if( window.ActiveXObject)
		{ // IE
			try
			{
				this.xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e)
			{
				try
				{
					this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		if(this.xmlHttp != null && this.xmlHttp != undefined )
		{
			var object = this;
			this.xmlHttp.onreadystatechange = function(){ object.getState.call(object); }
			
			if(this.method=="GET")
				this.executeGET(); // get request
			else 
				this.executePOST() // post request		
		}
	},
	getState: function()
	{
		if(this.xmlHttp.readyState == 4)
		{
			this.result(this.xmlHttp.responseText);
			if(this.func) eval(this.func);
			if(this.script) this.executeScripts(this.xmlHttp.responseText);
		}
		else 
		{
			this.loading();
		}
	},
	executeGET: function()
	{
		this.xmlHttp.open(this.method,this.url+"&random=" + Math.random(), true);
		this.xmlHttp.send(null);
	},
	executePOST: function()
	{
		var fields="";
		
		els = document.forms[this.form].elements;
		formLength=document.forms[this.form].elements.length;
		
		for(i=0;i<formLength;i++)
		{
			fields += els[i].name + "=" + els[i].value + "&";
		}
		
		this.xmlHttp.open(this.method,this.url+"?"+fields+"&random=" + Math.random(), true);
		this.xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		this.xmlHttp.setRequestHeader('Content-Type',"application/x-www-form-urlencoded; charset=utf-8");
		this.xmlHttp.send(fields);
	},	
	executeScripts: function(text)
	{
		var ini = 0;
		while (ini!=-1){
			ini = text.indexOf('<script', ini);
			if (ini >=0)
			{
				ini = text.indexOf('>', ini) + 1;
				var fim = text.indexOf('</script>', ini);
				text = text.substring(ini,fim);
				eval(text);
			}
		}
	},
    loading: function()
	{ 
		var DivInUse = this.div;
		
		this.result(this.info);
	},
	result: function(r)
	{
		var DivInUse = this.div;
		
		if($id(this.div))
		{
			$id(this.div).style.display="";
			$id(this.div).style.visibility="";
			$id(this.div).innerHTML=r;
		}		
	}
}

function fsAjax(url, div, info, method, form, script, func)
{
	var requestContent = new ajax(url, div, info, method, form, script, func);
	requestContent.connect();
}

