if ((typeof XMLHttpRequest == undefined) && (window.ActiveXObject))
{
  function my_XMLHttpRequest() 
  {
    var arrSig = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
    for (var i=0; i<arrSig.length; i++)
    {
      try
      {
        var oRequest = new ActiveXObject(arrSig[i]);
        return oRequest;
      }
      catch (oError)
      {}
    }
    throw new Error("MSXML is not installed on your system.");
  }
}

function addURLParam(sURL, sParamName, sParamValue)
{
  sURL += (sURL.indexOf("?") == -1 ? "?" : "&");
  sURL += encodeURIComponent(sParamName) + "=" + encodeURIComponent(sParamValue);
  return sURL;
}

function addPostParam(sParams, sParamName, sParamValue)
{
  if (sParams.length > 0) { sParams += "&"; }
  return sParams + encodeURIComponent(sParamName) + "=" + encodeURIComponent(sParamValue);
}

var bXmlHttpSupport = (typeof XMLHttpRequest != "undefined" || window.ActiveXObject);
var Http = new Object;

Http.get = function (sURL, fnCallback)
{
  if (bXmlHttpSupport)
  {
    try { var oRequest = new XMLHttpRequest(); }
    catch (e) { var oRequest = new my_XMLHttpRequest(); }
    oRequest.open("get", sURL, true);
    oRequest.onreadystatechange = function() { if (oRequest.readyState == 4) { fnCallback(oRequest.responseText); }};
    oRequest.send(null);
  }
  else if (navigator.javaEnabled() && typeof java != "undefined" && typeof java.net != "undefined")
  {
    setTimeout(function () { fnCallback(httpGet(sURL)); }, 10);
  }
  else
  {
    alert("Your browser doesn't support HTTP requests.");
  }
}

Http.post = function (sURL, sParams, fnCallback)
{
  if (bXmlHttpSupport)
  {
    try { var oRequest = new XMLHttpRequest(); }
    catch (e) { var oRequest = new my_XMLHttpRequest(); }
    oRequest.open("post", sURL, true);
    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    oRequest.onreadystatechange = function() { if (oRequest.readyState == 4) { fnCallback(oRequest.responseText); }};
    oRequest.send(sParams);
  }
  else if (navigator.javaEnabled() && typeof java != "undefined" && typeof java.net != "undefined")
  {
    setTimeout(function () { fnCallback(httpPost(sURL, sParams)); }, 10);
  }
  else
  {
    alert("Your browser doesn't support HTTP requests.");
  }
}

function setCookie (sName, sValue, oExpires, sPath, sDomain, bSecure)
{
  var sCookie = sName + "=" + encodeURIComponent(sValue);
  if (oExpires) { sCookie += "; expires=" + oExpires.toGMTString(); }
  if (sPath) { sCookie += "; path=" + sPath; }
  if (sDomain) { sCookie += "; domain=" + sDomain; }
  if (bSecure) { sCookie += "; secure"; }
  document.cookie = sCookie;
}

function getCookie (sName)
{
  var sRE = "(?:; )?" + sName + "=([^;]*);?";
  var oRE = new RegExp(sRE);
  if (oRE.test(document.cookie))
  { 
    return decodeURIComponent(RegExp["$1"]);
  }
  return null;
}

function deleteCookie (sName, sPath, sDomain)
{
  setCookie (sName, "", new Date(0), sPath, sDomain);
}

var ListUtil = new Object();

ListUtil.getSelectedIndexes = function (oListbox)
{
  var arrIndexes = new Array;
  for (var i=0; i < oListbox.options.length; i++)
  {
    if (oListbox.options[i].selected) { arrIndexes.push(i); }
  }
  return arrIndexes;
}

ListUtil.add = function (oListbox, sName, sValue)
{
  var oOption = document.createElement("option");
  oOption.appendChild(document.createTextNode(sName));
  if (arguments.length == 3)
  {
    oOption.setAttribute("value", sValue);
  }
  oListbox.appendChild(oOption);
}

ListUtil.remove = function (oListbox, iIndex)
{
  oListbox.remove(iIndex);
}

ListUtil.clear = function (oListbox)
{
  for (var i=oListbox.options.length; i>0; ) { ListUtil.remove(oListbox, --i); }
}

String.prototype.stripHTML = function () {
  var reTag = /<(?:.|\s)*?>/g;
  return this.replace(reTag, "");
};

/* menu a tendina */
function animatedcollapse(divId, animatetime, initstate)
{
	this.divId=divId;
	this.divObj=document.getElementById(divId);
  this.divObj.style.overflow="hidden";
	this.timelength=animatetime;
	this.initstate=(typeof initstate!="undefined" && initstate=="block")?("block"):("contract");
	this.contentheight=parseInt(this.divObj.style.height);
	var thisobj=this;
	if (isNaN(this.contentheight))
  { 
//		animatedcollapse.dotask(window, function(){thisobj._getheight()}, "load");
		thisobj._getheight();
//		if (this.initstate=="contract") {	this.divObj.style.visibility="hidden"; }
	}
 	else if (this.initstate=="contract") { this.divObj.style.height=0; }
}

animatedcollapse.prototype._getheight=function()
{
	this.contentheight=this.divObj.offsetHeight;
	if (this.initstate=="contract")
  { 
		this.divObj.style.height=0;	this.divObj.style.visibility="visible";
	}
	else 
	{	this.divObj.style.height=this.contentheight+"px"; }
}

animatedcollapse.prototype._slideengine=function(direction)
{
	var elapsed=new Date().getTime()-this.startTime;
	var thisobj=this;
	if (elapsed<this.timelength)
  { 
		var distancepercent=(direction=="down")?(animatedcollapse.curveincrement(elapsed/this.timelength)):(1-animatedcollapse.curveincrement(elapsed/this.timelength));
    this.divObj.style.height=distancepercent * this.contentheight +"px";
  	this.runtimer=setTimeout(function(){thisobj._slideengine(direction)}, 10);
	}
	else
  {
//		this.divObj.style.height=(direction=="down")?(this.contentheight+"px"):(0);
		this.divObj.style.height=(direction=="down")?(""):(0);
		this.isExpanded=(direction=="down")?("yes"):("no");
		this.runtimer=null;
	}
}

animatedcollapse.prototype.slidedown=function()
{
	if ((typeof this.runtimer=="undefined") || (this.runtimer==null))
  {
		if (isNaN(this.contentheight))
    {
      alert("Attendere che la pagina venga caricata completamente e cliccare nuovamente, grazie");
    }
		else if (parseInt(this.divObj.style.height)==0)
    {
			this.startTime=new Date().getTime();
			this._slideengine("down");
		}
	}
}

animatedcollapse.prototype.slideup=function()
{
	if ((typeof this.runtimer=="undefined") || (this.runtimer==null))
  {
		if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
    {
      alert("Attendere che la pagina venga caricata completamente e cliccare nuovamente, grazie");
    }
		else if ((this.divObj.style.height=="") || (parseInt(this.divObj.style.height)!=0))
    {

			this.startTime=new Date().getTime();
			this._slideengine("up");
		}
	}
}

animatedcollapse.prototype.slideit=function()
{
	if (isNaN(this.contentheight))
  { alert("Attendere che la pagina venga caricata completamente e cliccare nuovamente, grazie"); }
  else if (parseInt(this.divObj.style.height)==0)
	{	this.slidedown(); }   	
	else {	this.slideup(); }
}

animatedcollapse.curveincrement=function(percent)
{ return (1-Math.cos(percent*Math.PI)) / 2; }

animatedcollapse.dotask=function(target, functionref, tasktype)
{
	var tasktype=(window.addEventListener)?(tasktype):("on"+tasktype);
	if (target.addEventListener) { target.addEventListener(tasktype, functionref, false); }
	else if (target.attachEvent) { target.attachEvent(tasktype, functionref); }
}

function hasFlashPlayer()
{
  if (navigator.mimeTypes.length > 0)
  { return navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin != null; }
  else if (window.ActiveXObject)
  { try { new ActiveXObject ("ShockwaveFlash.ShockwaveFlash"); return true; } catch (oError) { return false; } }
  return false;
}

function getClientWidth() {
  return ((document.compatMode=='CSS1Compat') && (!window.opera))?(document.documentElement.clientWidth):(document.body.clientWidth);
}

function getClientHeight() {
  return ((document.compatMode=='CSS1Compat') && (!window.opera))?(document.documentElement.clientHeight):(document.body.clientHeight);
}

function apriTinyMCE(textareaName)
{
//  setTimeout(function() { tinyMCE.addMCEControl(document.getElementById(textareaName), textareaName); }, 100);
  setTimeout(function() { tinyMCE.execCommand('mceAddControl', true, textareaName); }, 100);
}

function chiudiTinyMCE(textareaName)
{
//  tinyMCE.removeMCEControl(tinyMCE.getEditorId(textareaName));
  tinyMCE.execCommand('mceRemoveControl', true, textareaName);
}