////////////////////////////////////////////////////////////////////////////////
//
// addClassName([object|string] oHTMLElement, string classNameToAdd)
//           Adds classNameToAdd to an HTMLElement. Guaranteed not to add the same className twice.
//           classNameToAdd can be a space separated list of classNames.
//           You can pass in the id to an object or the actual object
//
////////////////////////////////////////////////////////////////////////////////
function addClassName(oHTMLElement, classNameToAdd) {
  if (typeof(oHTMLElement)=="string")  { oHTMLElement = document.getElementById(oHTMLElement); }
  if (oHTMLElement) {
    var theClassName = oHTMLElement.className;
    if (theClassName && (theClassName.length > 0)) {  // If oHTMLElement already has a class name, some more work is needed
      var classNamesToAdd = classNameToAdd.split(" ");
      if (classNamesToAdd.length===1 && ((" " + theClassName + " ").lastIndexOf(" " + classNameToAdd + " ") === -1) ) { // If we only have one className to potentially add, take the "less work" approach
        oHTMLElement.className = oHTMLElement.className + " " + classNameToAdd;
      } else {
        var theClassNames = theClassName.split(" "),
            iEnd = classNamesToAdd.length,
            aClassName,
            theClassNamesToAddArray = [];
        for (var i=0;i<iEnd;i++) {
          aClassName = classNamesToAdd[i];
          if (theClassNames.indexOf(aClassName)===-1) {
            theClassNamesToAddArray.push( aClassName );
          }
        }
        oHTMLElement.className = oHTMLElement.className + " " + ((theClassNamesToAddArray.length > 1) ? theClassNamesToAddArray.join(" ") : theClassNamesToAddArray[0]);
      }
    } else {
      oHTMLElement.className = classNameToAdd;        // If oHTMLElement did not already have a class name, just add it
    }
  }
}

////////////////////////////////////////////////////////////////////////////////
//
// hasClassName([object|string] oHTMLElement, string classNameOfInterest)
//           Returns a boolean value of if an HTMLElement has the className of interest
//           You can pass in the id to an object or the actual object
//
////////////////////////////////////////////////////////////////////////////////
function hasClassName(oHTMLElement, classNameOfInterest) {
  return ((" " + oHTMLElement.className + " ").lastIndexOf(" " + classNameOfInterest + " ") > -1);
}
////////////////////////////////////////////////////////////////////////////////
//
// removeClassName([object|string] oHTMLElement, string classNameToRemove)
//           Removes classNameToRemove from an HTMLElement, if it exists.
//           classNameToRemove can be a space separated list of classNames.
//           You can pass in the id to oHTMLElement or the actual object
//
////////////////////////////////////////////////////////////////////////////////
function removeClassName(oHTMLElement, classNameToRemove) {
  if (typeof(oHTMLElement)=="string")  { oHTMLElement = document.getElementById(oHTMLElement); }
  if (oHTMLElement) {
    var theClassName = oHTMLElement.className;
    if (theClassName && (theClassName.length > 0)) {
      var theClassNameArray = theClassName.split(" "),
          classNamesToRemove = classNameToRemove.split(" "),
          iEnd = theClassNameArray.length,
          aClassName,
          theNewClassNameArray = [];
      for (var i=0;i<iEnd;i++) {
        aClassName = theClassNameArray[i];
        if (classNamesToRemove.indexOf(aClassName)===-1) {
          theNewClassNameArray.push( aClassName );
        }
      }
      switch (true) {
        case (theNewClassNameArray.length>1) :
          oHTMLElement.className = theNewClassNameArray.join(" ");
          break;
        case (theNewClassNameArray.length==1) :
          oHTMLElement.className = theNewClassNameArray[0];
          break;
        case (theNewClassNameArray.length==0) :
          oHTMLElement.className = "";
          break;
      }
    }
  }
}
////////////////////////////////////////////////////////////////////////////////
//
// Array.indexOf() - returns integer index where valueToSearchFor is in an Array
//
////////////////////////////////////////////////////////////////////////////////
if (Array.prototype.indexOf===undefined) {
  Array.prototype.indexOf = function( valueToSearchFor ) {
    var iEnd = this.length;
    var retVal = -1;
    for (var i=0;i<iEnd; i++) {
      if (this[i] == valueToSearchFor) {
        retVal = i;
        break;
      }
    }
    return retVal;
  };
}

function newXMLHttpRequest(cMethod,cUrl,bAsync) {
	var xmlhttp = false;
	var actXArray = new Array(
	"WinHttp.WinHttpRequest.5.1",
	"WinHttp.WinHttpRequest",
	"MSXML2.ServerXMLHTTP",
	"Microsoft.XmlHttp",
	"MSXML4.XmlHttp",
	"MSXML3.XmlHttp",
	"MSXML2.XmlHttp",
	"MSXML.XmlHttp"
	);

	try {
	  xmlhttp = new XMLHttpRequest();
	} catch (e) {

	}

	if (!xmlhttp) {
	  var created = false;
	  for( var i = 0; i < actXArray.length && !created; i++ ) {
	      try {
	          xmlhttp = new ActiveXObject(actXArray[i]);
	          created = true;
	      } catch (e) {

	      }
	  }
	}

	xmlhttp.open(cMethod,cUrl,bAsync);
	if (!document.all) {
	//Firefox
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
	xmlhttp.overrideMimeType('text/html; charset=ISO-8859-1');
	}
	else {
	//IE
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
	xmlhttp.setRequestHeader('Accept-Charset', 'ISO-8859-1');
	}
	return xmlhttp;
}

function utf8_decode(str_data) {
	var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;
	str_data += '';
	while ( i < str_data.length ) {
	  c1 = str_data.charCodeAt(i);
	  if (c1 < 128) {
	      tmp_arr[ac++] = String.fromCharCode(c1);
	      i++;
	  } else if ((c1 > 191) && (c1 < 224)) {
	      c2 = str_data.charCodeAt(i+1);
	      tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
	      i += 2;
	  } else {
	      c2 = str_data.charCodeAt(i+1);
	      c3 = str_data.charCodeAt(i+2);
	      tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
	      i += 3;
	  }
	}

	return tmp_arr.join('');
}

function Cookies()
{
var Cookies = unescape(document.cookie.split('; ').join('\n\n')).replace(/\+/g,' ')
return Cookies
}

function getCookie(name){
	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(name + '=');
		if (c_start!=-1){
			c_start=c_start + name.length+1;
			c_end=document.cookie.indexOf(';',c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return '';
}

function getSubCookie(name,subname) {
    var curCookie = document.cookie.split('; ');
    for (var i=0; i < curCookie.length; i++) {
	    var curName = Left(curCookie[i],InStr(curCookie[i],'=')-1*1);
        if (name == unescape(curName))
        {
	        var queryString = Right(curCookie[i],Len(curCookie[i])-InStr(curCookie[i],'='))
		    var curString = queryString.split('&');
		    for (var i=0; i < curString.length; i++) {
			    var subString = curString[i].split('=');
		        if (subname == unescape(subString[0]))
		        {
			    return unescape(subString[1]);
		        }
		    }
		    return null;
        }
    }
    return null;
}

function setCookie(name,value,expires,path)
{
	var expiration=new Date();
	expiration.setDate(expiration.getDate()+expires);
	document.cookie=name+'='+escape(value)+
	((expires==null) ? '' : ';expires='+expiration.toGMTString())+
	((path==null)    ? ';path=/' : ';path='+path );
}

function setCookieQuerystring(name,querystring,expires,path)
{
	var expiration=new Date();
	expiration.setDate(expiration.getDate()+expires);
	document.cookie=name+'='+escape(querystring).replace(/%3D/gi,'=').replace(/%26/gi,'&')+
	((expires==null) ? '' : ';expires='+expiration.toGMTString())+
	((path==null)    ? ';path=/' : ';path='+path );
}

function setSubCookie(name,subname,value,expires,path) {
    var curCookie = document.cookie.split('; ');
    var bFounded = false
    var subCookie = ''
    for (var i=0; i < curCookie.length; i++) {
	    var curName = Left(curCookie[i],InStr(curCookie[i],'=')-1*1);
        if (name == unescape(curName))
        {
	        var queryString = Right(curCookie[i],Len(curCookie[i])-InStr(curCookie[i],'='))
		    var curString = queryString.split('&');
		    var subCookie = ''
	        var bFounded = false
		    for (var ii=0; ii < curString.length; ii++) {
			    var subString = curString[ii].split('=');
		        if (subname == unescape(subString[0]))
		        {
		        subCookie += ((ii==0) ? '' : '&')+subString[0]+'='+value
		        var bFounded = true
		        }
		        else
		        {
		        subCookie += ((ii==0) ? '' : '&')+subString[0]+'='+subString[1]
		        }
		    }
		    subCookie += ((bFounded) ? '' : '&'+subname+'='+value)
             setCookieQuerystring(name,subCookie,expires,path)
        }
    }
    if (subCookie==''){
		subCookie = subname+'='+value
		setCookieQuerystring(name,subCookie,expires,path)
	 }
}

function Mid(String, Start, Length)
{
    if (String == null)
        return (false);

    if (Start > String.length)
        return '';

    if (Length == null || Length.length == 0)
        return (false);

    return String.substr((Start - 1), Length);
}


function InStr(String1, String2)
{
    var a = 0;

    if (String1 == null || String2 == null)
        return (false);

    String1 = String1.toLowerCase();
    String2 = String2.toLowerCase();

    a = String1.indexOf(String2);
    if (a == -1)
        return 0;
    else
        return a + 1;
}

function trim(string){
    while (string.substring(0,1) == ' '){
        string = string.substring(1, string.length);
    }
    while (string.substring(string.length-1, string.length) == ' '){
        string = string.substring(0,string.length-1);
    }
    return string;
}

function Len(string)
{
    if (string == null)
        return (false);

    return String(string).length;
}

function Left(str, n) {
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n) {
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function isDate(cStringaData) {
	var dateNoFormat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchFormat = cStringaData.match(dateNoFormat);
	if (matchFormat == null) {
		alert('Inserire la data nel formato mm/dd/yyyy o mm-dd-yyyy');
		return false;
	}
	var month = matchFormat[1];
	var day = matchFormat[3];
	var year = matchFormat[5];
	if (month < 1 || month > 12) {
		alert('Indicare un mese fra 1 e 12');
		return false;
	}
	if (day < 1 || day > 31) {
		alert('Indicare un giorno fra 1 e 31');
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert('Indicare una data valida (il mese indicato non ha 31 giorni)')
		return false;
	}
	if (month == 2) {
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
		alert('Indicare una data valida (febbraio ' + year + ' non ha ' + day + ' giorni)');
		return false;
		}
	}
	return true;
}

function IsNumeric(n) {
   var ValidChars = "0123456789.,+";
   var IsNumber=true;
   var Char;
   for (i = 0; i < n.length && IsNumber == true; i++)
      {
      Char = n.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
			}
      }
	return IsNumber;
}

function fmtInt(n){
	var num = new NumberFormat();
	num.setInputDecimal(',');
	num.setNumber(n); // obj.value is '1.000,00'
	num.setPlaces('0', false);
	num.setCurrencyValue('€');
	num.setCurrency(false);
	num.setCurrencyPosition(num.LEFT_OUTSIDE);
	num.setNegativeFormat(num.LEFT_DASH);
	num.setNegativeRed(true);
	num.setSeparators(true, '.', ',');
	return num.toFormatted();
}

function fmtC2C(n){
	var num = new NumberFormat();
	num.setInputDecimal(',');
	num.setNumber(n); // obj.value is '1.000,00'
	num.setPlaces('2', false);
	num.setCurrencyValue('€');
	num.setCurrency(false);
	num.setCurrencyPosition(num.LEFT_OUTSIDE);
	num.setNegativeFormat(num.LEFT_DASH);
	num.setNegativeRed(false);
	num.setSeparators(true, '.', ',');
	return num.toFormatted();
}

function fmtC2P(n){
	var num = new NumberFormat();
	num.setInputDecimal(',');
	num.setNumber(n); // obj.value is '1.000,00'
	num.setPlaces('2', false);
	num.setCurrencyValue('€');
	num.setCurrency(false);
	num.setCurrencyPosition(num.LEFT_OUTSIDE);
	num.setNegativeFormat(num.LEFT_DASH);
	num.setNegativeRed(false);
	num.setSeparators(false, ',', ',');
	return num.toFormatted();
}

function fmtP2C(n){
	var num = new NumberFormat();
	num.setInputDecimal('.');
	num.setNumber(n); // obj.value is '1,000.00'
	num.setPlaces('2', false);
	num.setCurrencyValue('€');
	num.setCurrency(false);
	num.setCurrencyPosition(num.LEFT_OUTSIDE);
	num.setNegativeFormat(num.LEFT_DASH);
	num.setNegativeRed(false);
	num.setSeparators(true, '.', ',');
	return num.toFormatted();
}

function fmtP2P(n){
	var num = new NumberFormat();
	num.setInputDecimal('.');
	num.setNumber(n); // obj.value is '1,000.00'
	num.setPlaces('2', false);
	num.setCurrencyValue('€');
	num.setCurrency(false);
	num.setCurrencyPosition(num.LEFT_OUTSIDE);
	num.setNegativeFormat(num.LEFT_DASH);
	num.setNegativeRed(false);
	num.setSeparators(false, ',', ',');
	return num.toFormatted();
}

function calcIva(s,v,k){
	var v = parseFloat(v)
	var k = parseFloat(k)
	if (s=='-'){
		return v/((100+k)/100);
	}
	else if (s=='+'){
		return v+(v/100*k);
	}
}

function calcPerc(s,v,k){
	var v = parseFloat(v)
	var k = parseFloat(k)
	if (s=='-'){
		return v-(v/100*k);
	}
	else if (s=='+'){
		return v+(v/100*k);
	}
}

//Swap 2.0---------------------------------------------
	function Swap(oElement,bMarginOnLastElement,nRows,nCols,nInterval,cMode){
		switch (cMode) {
			case 'stop':
				if ($('swap_stop')) $('swap_stop').style.backgroundPosition='right center'
				if ($('swap_play')) $('swap_play').style.backgroundPosition='left center'
				clearInterval(timerIdOff)
				break;
			case 'step':
				if ($('swap_stop')) $('swap_stop').style.backgroundPosition='right center'
				if ($('swap_play')) $('swap_play').style.backgroundPosition='left center'
				clearInterval(timerIdOff)
				Swapper(oElement,bMarginOnLastElement,nRows,nCols)
				break;
			default:
				if ($('swap_stop')) $('swap_stop').style.backgroundPosition='left center'
				if ($('swap_play')) $('swap_play').style.backgroundPosition='right center'
				try{clearInterval(timerIdOff)}
				catch(e){}
				finally{
					Swapper(oElement,bMarginOnLastElement,nRows,nCols)
					var timerIdOff = setInterval('Swapper(\''+oElement+'\','+bMarginOnLastElement+','+nRows+','+nCols+')',nInterval)
				}
		}
	}

	function Swapper(oElement,bMarginOnLastElement,nRows,nCols){
		var aEls = $$(oElement).toArray();
		var iEls = aEls.size()-1
		var nEls = nRows*nCols

		if (iEls+1 > nEls) {
         var bFirstCycle = true
			aEls.each(function(Element,index) {
				if (hasClassName(Element,'outlay') || hasClassName(Element,'inlay')) {
					bFirstCycle = false;
					throw $break;
				}
			})
//$('debug').innerHTML += bFirstCycle

			if (bFirstCycle==true){
         	var iPos = 0
			}else{
	         var i = 0
				var iPos = -1
				while (true){
					if (hasClassName(aEls[i],'inlay')) {
						for (j=1;j<=nEls;j++){
							i++; if (i>iEls){i = 0};
							if (j==nEls) {iPos = i; break;}
							if (!hasClassName(aEls[i],'inlay')) {iPos = -1; break;}
						}
					}
					if (iPos > -1) break;
					i++; if (i>iEls){i = 0};
				}
			}
//$('debug').innerHTML += iPos + ':'

			//inizializzazione
			aEls.each(function(Element,index) {
					removeClassName(Element,'inlay');
					removeClassName(Element,'last');
					addClassName(Element,'outlay');
				}
			);

			if (bFirstCycle==true){
	         var i = 0
				while (true){
					if (iPos==i){
						for (iRows=1;iRows<=nRows;iRows++){
							for (iCols=1;iCols<=nCols;iCols++){
								removeClassName(aEls[i],'outlay');
								addClassName(aEls[i],'inlay');
//$('debug').innerHTML += i
								if (iCols==nCols && bMarginOnLastElement) addClassName(aEls[i],'last');
								i++
								if (i>iEls){i = 0};
							}
						}
						break
					}
					i++
					if (i>iEls){i = 0};
				}
			}else{
				var aInlay = [nEls-1];
	         var j = 0
	         var i = 0
				while (true){
					if (iPos==i){
						for (iRows=1;iRows<=nRows;iRows++){
							for (iCols=1;iCols<=nCols;iCols++){
								removeClassName(aEls[i],'outlay');
								addClassName(aEls[i],'inlay');
//$('debug').innerHTML += i
								if (bMarginOnLastElement){
					            aInlay[j] = Right('000000'+i,6)
//$('debug').innerHTML += j+'='+ Right('000000'+i,6)+';'
									j++
								}
								i++
								if (i>iEls){i = 0};
							}
						}
						break
					}
					i++
					if (i>iEls){i = 0};
				}
				if (bMarginOnLastElement){
					aInlay.sort().each(function(Element,index){
//$('debug').innerHTML += '#'+parseFloat(Element)
						return (index+1) % nCols == 0 ? addClassName(aEls[parseFloat(Element)],'last') : null
					});
				}
			}
		}
//$('debug').innerHTML += '|'
	}

//-----------------------------------------------------------------------

function rollover_fading(id, start, end, time) {
    var velocity = Math.round(time / 100);
    var timer = 0;

    if(start > end) {
        for(i = start; i >= end; i--) {
            setTimeout("change_opacity(" + i + ",'" + id + "')",(timer * velocity));
            timer++;
        }
    } else if(start < end) {
        for(i = start; i <= end; i++)
            {
            setTimeout("change_opacity(" + i + ",'" + id + "')",(timer * velocity));
            timer++;
        }
    }
}
function change_opacity(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}
//-----------------------------------------------------------------------

//-----------------------------------------------------------------------
//Gradual Elements Fader- By Dynamic Drive at http://www.dynamicdrive.com
//Last updated: Nov 8th, 07'
//-----------------------------------------------------------------------

var gradualFader={}

gradualFader.baseopacity=0.75 //set base opacity when mouse isn't over element (decimal below 1)
gradualFader.increment=0.05 //amount of opacity to increase after each iteration (suggestion: 0.1 or 0.2)

document.write('<style type="text/css">\n') //write out CSS to enable opacity on "gradualfader" class
document.write('.gradualfader{filter:progid:DXImageTransform.Microsoft.alpha(opacity='+gradualFader.baseopacity*100+'); -moz-opacity:'+gradualFader.baseopacity+'; opacity:'+gradualFader.baseopacity+';}\n')
document.write('</style>')

gradualFader.setopacity=function(obj, value) { //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
	var targetobject=obj
	if (targetobject && targetobject.filters && targetobject.filters[0]) { //IE syntax
		if (typeof targetobject.filters[0].opacity=="number") //IE6
			targetobject.filters[0].opacity=value*100
		else //IE 5.5
			targetobject.style.filter="alpha(opacity="+value*100+")"
		}
	else if (targetobject && typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax
		targetobject.style.MozOpacity=value
	else if (targetobject && typeof targetobject.style.opacity!="undefined") //Standard opacity syntax
		targetobject.style.opacity=value
	targetobject.currentopacity=value
}

gradualFader.fadeupdown=function(obj, direction) {
	var targetobject=obj
	var fadeamount=(direction=="fadeup")? this.increment : -this.increment
	if (targetobject && (direction=="fadeup" && targetobject.currentopacity<1 || direction=="fadedown" && targetobject.currentopacity>this.baseopacity)) {
		this.setopacity(obj, targetobject.currentopacity+fadeamount)
		window["opacityfader"+obj._fadeorder]=setTimeout(function() {gradualFader.fadeupdown(obj, direction)}, 50)
	}
}

gradualFader.clearTimer=function(obj) {
if (typeof window["opacityfader"+obj._fadeorder]!="undefined")
	clearTimeout(window["opacityfader"+obj._fadeorder])
}

gradualFader.isContained=function(m, f) {
	var e=window.event || f
	var c=e.relatedTarget || ((e.type=="mouseover")? e.fromElement : e.toElement)
	while (c && c!=m)try {c=c.parentNode} catch(e) {c=m}
	if (c==m)
		return true
	else
		return false
}

gradualFader.fadeinterface=function(obj, e, direction) {
	if (!this.isContained(obj, e)) {
		gradualFader.clearTimer(obj)
		gradualFader.fadeupdown(obj, direction)
	}
}

gradualFader.collectElementbyClass=function(classname) { //Returns an array containing DIVs with specified classname
	var classnameRE=new RegExp("(^|\\s+)"+classname+"($|\\s+)", "i") //regular expression to screen for classname within element
	var pieces=[]
	var alltags=document.all? document.all : document.getElementsByTagName("*")
	for (var i=0; i<alltags.length; i++) {
		if (typeof alltags[i].className=="string" && alltags[i].className.search(classnameRE)!=-1)
			pieces[pieces.length]=alltags[i]
	}
	return pieces
}

gradualFader.init=function() {
	var targetobjects=this.collectElementbyClass("gradualfader")
	for (var i=0; i<targetobjects.length; i++) {
		targetobjects[i]._fadeorder=i
		this.setopacity(targetobjects[i], this.baseopacity)
		targetobjects[i].onmouseover=function(e) {gradualFader.fadeinterface(this, e, "fadeup")}
		targetobjects[i].onmouseout=function(e) {gradualFader.fadeinterface(this, e, "fadedown")}
	}
}
//eoGradualfader---------------------------------------------------------

function fixPNG() {
   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

         }
      }
   }

// mredkj.com
function NumberFormat(num, inputDecimal)
{
this.VERSION = 'Number Format v1.5.4';
this.COMMA = ',';
this.PERIOD = '.';
this.DASH = '-';
this.LEFT_PAREN = '(';
this.RIGHT_PAREN = ')';
this.LEFT_OUTSIDE = 0;
this.LEFT_INSIDE = 1;
this.RIGHT_INSIDE = 2;
this.RIGHT_OUTSIDE = 3;
this.LEFT_DASH = 0;
this.RIGHT_DASH = 1;
this.PARENTHESIS = 2;
this.NO_ROUNDING = -1
this.num;
this.numOriginal;
this.hasSeparators = false;
this.separatorValue;
this.inputDecimalValue;
this.decimalValue;
this.negativeFormat;
this.negativeRed;
this.hasCurrency;
this.currencyPosition;
this.currencyValue;
this.places;
this.roundToPlaces;
this.truncate;
this.setNumber = setNumberNF;
this.toUnformatted = toUnformattedNF;
this.setInputDecimal = setInputDecimalNF;
this.setSeparators = setSeparatorsNF;
this.setCommas = setCommasNF;
this.setNegativeFormat = setNegativeFormatNF;
this.setNegativeRed = setNegativeRedNF;
this.setCurrency = setCurrencyNF;
this.setCurrencyPrefix = setCurrencyPrefixNF;
this.setCurrencyValue = setCurrencyValueNF;
this.setCurrencyPosition = setCurrencyPositionNF;
this.setPlaces = setPlacesNF;
this.toFormatted = toFormattedNF;
this.toPercentage = toPercentageNF;
this.getOriginal = getOriginalNF;
this.moveDecimalRight = moveDecimalRightNF;
this.moveDecimalLeft = moveDecimalLeftNF;
this.getRounded = getRoundedNF;
this.preserveZeros = preserveZerosNF;
this.justNumber = justNumberNF;
this.expandExponential = expandExponentialNF;
this.getZeros = getZerosNF;
this.moveDecimalAsString = moveDecimalAsStringNF;
this.moveDecimal = moveDecimalNF;
this.addSeparators = addSeparatorsNF;
if (inputDecimal == null) {
this.setNumber(num, this.PERIOD);
} else {
this.setNumber(num, inputDecimal);
}
this.setCommas(true);
this.setNegativeFormat(this.LEFT_DASH);
this.setNegativeRed(false);
this.setCurrency(false);
this.setCurrencyPrefix('$');
this.setPlaces(2);
}
function setInputDecimalNF(val)
{
this.inputDecimalValue = val;
}
function setNumberNF(num, inputDecimal)
{
if (inputDecimal != null) {
this.setInputDecimal(inputDecimal);
}
this.numOriginal = num;
this.num = this.justNumber(num);
}
function toUnformattedNF()
{
return (this.num);
}
function getOriginalNF()
{
return (this.numOriginal);
}
function setNegativeFormatNF(format)
{
this.negativeFormat = format;
}
function setNegativeRedNF(isRed)
{
this.negativeRed = isRed;
}
function setSeparatorsNF(isC, separator, decimal)
{
this.hasSeparators = isC;
if (separator == null) separator = this.COMMA;
if (decimal == null) decimal = this.PERIOD;
if (separator == decimal) {
this.decimalValue = (decimal == this.PERIOD) ? this.COMMA : this.PERIOD;
} else {
this.decimalValue = decimal;
}
this.separatorValue = separator;
}
function setCommasNF(isC)
{
this.setSeparators(isC, this.COMMA, this.PERIOD);
}
function setCurrencyNF(isC)
{
this.hasCurrency = isC;
}
function setCurrencyValueNF(val)
{
this.currencyValue = val;
}
function setCurrencyPrefixNF(cp)
{
this.setCurrencyValue(cp);
this.setCurrencyPosition(this.LEFT_OUTSIDE);
}
function setCurrencyPositionNF(cp)
{
this.currencyPosition = cp
}
function setPlacesNF(p, tr)
{
this.roundToPlaces = !(p == this.NO_ROUNDING);
this.truncate = (tr != null && tr);
this.places = (p < 0) ? 0 : p;
}
function addSeparatorsNF(nStr, inD, outD, sep)
{
nStr += '';
var dpos = nStr.indexOf(inD);
var nStrEnd = '';
if (dpos != -1) {
nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
nStr = nStr.substring(0, dpos);
}
var rgx = /(\d+)(\d{3})/;
while (rgx.test(nStr)) {
nStr = nStr.replace(rgx, '$1' + sep + '$2');
}
return nStr + nStrEnd;
}
function toFormattedNF()
{
var pos;
var nNum = this.num;
var nStr;
var splitString = new Array(2);
if (this.roundToPlaces) {
nNum = this.getRounded(nNum);
nStr = this.preserveZeros(Math.abs(nNum));
} else {
nStr = this.expandExponential(Math.abs(nNum));
}
if (this.hasSeparators) {
nStr = this.addSeparators(nStr, this.PERIOD, this.decimalValue, this.separatorValue);
} else {
nStr = nStr.replace(new RegExp('\\' + this.PERIOD), this.decimalValue);
}
var c0 = '';
var n0 = '';
var c1 = '';
var n1 = '';
var n2 = '';
var c2 = '';
var n3 = '';
var c3 = '';
var negSignL = (this.negativeFormat == this.PARENTHESIS) ? this.LEFT_PAREN : this.DASH;
var negSignR = (this.negativeFormat == this.PARENTHESIS) ? this.RIGHT_PAREN : this.DASH;
if (this.currencyPosition == this.LEFT_OUTSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c0 = this.currencyValue;
} else if (this.currencyPosition == this.LEFT_INSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c1 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_INSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c2 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_OUTSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c3 = this.currencyValue;
}
nStr = c0 + n0 + c1 + n1 + nStr + n2 + c2 + n3 + c3;
if (this.negativeRed && nNum < 0) {
nStr = '<font color="red">' + nStr + '</font>';
}
return (nStr);
}
function toPercentageNF()
{
nNum = this.num * 100;
nNum = this.getRounded(nNum);
return nNum + '%';
}
function getZerosNF(places)
{
var extraZ = '';
var i;
for (i=0; i<places; i++) {
extraZ += '0';
}
return extraZ;
}
function expandExponentialNF(origVal)
{
if (isNaN(origVal)) return origVal;
var newVal = parseFloat(origVal) + '';
var eLoc = newVal.toLowerCase().indexOf('e');
if (eLoc != -1) {
var plusLoc = newVal.toLowerCase().indexOf('+');
var negLoc = newVal.toLowerCase().indexOf('-', eLoc);
var justNumber = newVal.substring(0, eLoc);
if (negLoc != -1) {
var places = newVal.substring(negLoc + 1, newVal.length);
justNumber = this.moveDecimalAsString(justNumber, true, parseInt(places));
} else {
if (plusLoc == -1) plusLoc = eLoc;
var places = newVal.substring(plusLoc + 1, newVal.length);
justNumber = this.moveDecimalAsString(justNumber, false, parseInt(places));
}
newVal = justNumber;
}
return newVal;
}
function moveDecimalRightNF(val, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimal(val, false);
} else {
newVal = this.moveDecimal(val, false, places);
}
return newVal;
}
function moveDecimalLeftNF(val, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimal(val, true);
} else {
newVal = this.moveDecimal(val, true, places);
}
return newVal;
}
function moveDecimalAsStringNF(val, left, places)
{
var spaces = (arguments.length < 3) ? this.places : places;
if (spaces <= 0) return val;
var newVal = val + '';
var extraZ = this.getZeros(spaces);
var re1 = new RegExp('([0-9.]+)');
if (left) {
newVal = newVal.replace(re1, extraZ + '$1');
var re2 = new RegExp('(-?)([0-9]*)([0-9]{' + spaces + '})(\\.?)');
newVal = newVal.replace(re2, '$1$2.$3');
} else {
var reArray = re1.exec(newVal);
if (reArray != null) {
newVal = newVal.substring(0,reArray.index) + reArray[1] + extraZ + newVal.substring(reArray.index + reArray[0].length);
}
var re2 = new RegExp('(-?)([0-9]*)(\\.?)([0-9]{' + spaces + '})');
newVal = newVal.replace(re2, '$1$2$4.');
}
newVal = newVal.replace(/\.$/, '');
return newVal;
}
function moveDecimalNF(val, left, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimalAsString(val, left);
} else {
newVal = this.moveDecimalAsString(val, left, places);
}
return parseFloat(newVal);
}
function getRoundedNF(val)
{
val = this.moveDecimalRight(val);
if (this.truncate) {
val = val >= 0 ? Math.floor(val) : Math.ceil(val);
} else {
val = Math.round(val);
}
val = this.moveDecimalLeft(val);
return val;
}
function preserveZerosNF(val)
{
var i;
val = this.expandExponential(val);
if (this.places <= 0) return val;
var decimalPos = val.indexOf('.');
if (decimalPos == -1) {
val += '.';
for (i=0; i<this.places; i++) {
val += '0';
}
} else {
var actualDecimals = (val.length - 1) - decimalPos;
var difference = this.places - actualDecimals;
for (i=0; i<difference; i++) {
val += '0';
}
}
return val;
}
function justNumberNF(val)
{
newVal = val + '';
var isPercentage = false;
if (newVal.indexOf('%') != -1) {
newVal = newVal.replace(/\%/g, '');
isPercentage = true;
}
var re = new RegExp('[^\\' + this.inputDecimalValue + '\\d\\-\\+\\(\\)eE]', 'g');
newVal = newVal.replace(re, '');
var tempRe = new RegExp('[' + this.inputDecimalValue + ']', 'g');
var treArray = tempRe.exec(newVal);
if (treArray != null) {
var tempRight = newVal.substring(treArray.index + treArray[0].length);
newVal = newVal.substring(0,treArray.index) + this.PERIOD + tempRight.replace(tempRe, '');
}
if (newVal.charAt(newVal.length - 1) == this.DASH ) {
newVal = newVal.substring(0, newVal.length - 1);
newVal = '-' + newVal;
}
else if (newVal.charAt(0) == this.LEFT_PAREN
&& newVal.charAt(newVal.length - 1) == this.RIGHT_PAREN) {
newVal = newVal.substring(1, newVal.length - 1);
newVal = '-' + newVal;
}
newVal = parseFloat(newVal);
if (!isFinite(newVal)) {
newVal = 0;
}
if (isPercentage) {
newVal = this.moveDecimalLeft(newVal, 2);
}
return newVal;
}

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: 'Cow' | http://cow.neondragon.net/Licensed under: MIT License
 */

/* From prototype.js */
if (!document.myGetElementsByClassName) {
	document.myGetElementsByClassName = function(className) {
		var children = document.getElementsByTagName('*') || document.all;
		var elements = new Array();

		for (var i = 0; i < children.length; i++) {
			var child = children[i];
			var classNames = child.className.split(' ');
			for (var j = 0; j < classNames.length; j++) {
				if (classNames[j] == className) {
					elements.push(child);
					break;
				}
			}
		}
		return elements;
	}
}

var Reflection = {
	defaultHeight : 0.5,
	defaultOpacity: 0.4,

	add: function(image, options) {
		Reflection.remove(image);

		doptions = { "height" : Reflection.defaultHeight, "opacity" : Reflection.defaultOpacity }
		if (options) {
			for (var i in doptions) {
				if (!options[i]) {
					options[i] = doptions[i];
				}
			}
		} else {
			options = doptions;
		}

		try {
			var d = document.createElement('div');
			var p = image;

			var classes = p.className.split(' ');
			var newClasses = '';
			for (j=0;j<classes.length;j++) {
				if (classes[j] != "reflect") {
					if (newClasses) {
						newClasses += ' '
					}

					newClasses += classes[j];
				}
			}

			var reflectionHeight = Math.floor(p.height*options['height']);
			var divHeight = Math.floor(p.height*(1+options['height']));

			var reflectionWidth = p.width;

			if (document.all && !window.opera) {
				/* Fix hyperlinks */
                if(p.parentElement.tagName == 'A') {
	                var d = document.createElement('a');
	                d.href = p.parentElement.href;
                }

				/* Copy original image's classes & styles to div */
				d.className = newClasses;
				p.className = 'reflected';

				d.style.cssText = p.style.cssText;
				p.style.cssText = 'vertical-align: bottom';

				var reflection = document.createElement('img');
				reflection.src = p.src;
				reflection.style.width = reflectionWidth+'px';
				reflection.style.display = 'block';
				reflection.style.height = p.height+"px";

				reflection.style.marginBottom = "-"+(p.height-reflectionHeight)+'px';
				reflection.style.filter = 'flipv progid:DXImageTransform.Microsoft.Alpha(opacity='+(options['opacity']*100)+', style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy='+(options['height']*100)+')';

				d.style.width = reflectionWidth+'px';
				d.style.height = divHeight+'px';
				p.parentNode.replaceChild(d, p);

				d.appendChild(p);
				d.appendChild(reflection);
			} else {
				var canvas = document.createElement('canvas');
				if (canvas.getContext) {
					/* Copy original image's classes & styles to div */
					d.className = newClasses;
					p.className = 'reflected';

					d.style.cssText = p.style.cssText;
					p.style.cssText = 'vertical-align: bottom';

					var context = canvas.getContext("2d");

					canvas.style.height = reflectionHeight+'px';
					canvas.style.width = reflectionWidth+'px';
					canvas.height = reflectionHeight;
					canvas.width = reflectionWidth;

					d.style.width = reflectionWidth+'px';
					d.style.height = divHeight+'px';
					p.parentNode.replaceChild(d, p);

					d.appendChild(p);
					d.appendChild(canvas);

					context.save();

					context.translate(0,image.height-1);
					context.scale(1,-1);

					context.drawImage(image, 0, 0, reflectionWidth, image.height);

					context.restore();

					context.globalCompositeOperation = "destination-out";
					var gradient = context.createLinearGradient(0, 0, 0, reflectionHeight);

					gradient.addColorStop(1, "rgba(255, 255, 255, 1.0)");
					gradient.addColorStop(0, "rgba(255, 255, 255, "+(1-options['opacity'])+")");

					context.fillStyle = gradient;
					context.rect(0, 0, reflectionWidth, reflectionHeight*2);
					context.fill();
				}
			}
		} catch (e) {
	    }
	},

	remove : function(image) {
		if (image.className == "reflected") {
			image.className = image.parentNode.className;
			image.parentNode.parentNode.replaceChild(image, image.parentNode);
		}
	}
}

function addReflections() {
	var rimages = document.myGetElementsByClassName('reflect');
	for (i=0;i<rimages.length;i++) {
		var rheight = null;
		var ropacity = null;

		var classes = rimages[i].className.split(' ');
		for (j=0;j<classes.length;j++) {
			if (classes[j].indexOf("rheight") == 0) {
				var rheight = classes[j].substring(7)/100;
			} else if (classes[j].indexOf("ropacity") == 0) {
				var ropacity = classes[j].substring(8)/100;
			}
		}

		Reflection.add(rimages[i], { height: rheight, opacity : ropacity});
	}
}

// Multiple onload function created by: Simon Willison
// http://simonwillison.net/2004/May/26/addLoadEvent/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  addReflections();
  // add other functions here
});

function check(act,ele,txt){
	switch(act) {
		case 'f':
			switch(ele.name) {
				case 'q':
				case 'cog':
				case 'nom':
				case 'ind':
				case 'tel':
				case 'mai':
					if (ele.value==txt) ele.value='';
					break;
				case 'txt':
					if (ele.innerHTML==txt) ele.innerHTML='';
					break;
				default:
			}
			break;
		case 'b':
			switch(ele.name) {
				case 'q':
				case 'cog':
				case 'nom':
				case 'ind':
				case 'tel':
				case 'mai':
					if (ele.value=='') ele.value=txt;
					break;
				case 'txt':
					if (ele.innerHTML=='') ele.innerHTML=txt;
					break;
				default:
			}
			break;
	}
}
function checkParameters(form){
	var checkParameters = true;
	var ele = $$(form);
	ele.each(function(Element) {
   	if (Element.name=='cog' && (Element.value=='cognome\/Azienda' || InStr(Element.value,' ')==0 )) {
			alert('Indicare il proprio cognome oppure la ditta dell\'Azienda.');
			checkParameters = false;
         throw $break;
		};
   	if (Element.name=='nom' && (Element.value=='nome\/Responsabile' || InStr(Element.value,' ')==0 )) {
			alert('Indicare il proprio nome oppure il cognome e il nome del Responsabile dell\'Azienda.');
			checkParameters = false;
         throw $break;
		};
   	if (Element.name=='ind' && (Element.value=='indirizzo\/città' || InStr(Element.value,' ')==0 )) {
			alert('Indicare l\'indirizzo e la città di residenza.');
			checkParameters = false;
         throw $break;
		};
   	if (Element.name=='tel' && (Element.value=='telefono' || InStr(Element.value,' ')>0 || !IsNumeric(Element.value) )) {
			alert('Indicare un recapito telefonico senza spazi e utilizzando solo in cifre numeriche');
			checkParameters = false;
         throw $break;
		};
   	if (Element.name=='mai' && (InStr(Element.value,'@')==0 || InStr(Element.value,'.')==0)) {
			alert('Inserire un indirizzo e-mail valido.');
			checkParameters = false;
         throw $break;
		};
	});
	return checkParameters
}
function updateLink(ID){
	var oXHR = newXMLHttpRequest('post','inc/ajax_link.asp',true);
	oXHR.onreadystatechange = function(){
		if (oXHR.readyState == 1){
		}
		if (oXHR.readyState == 4){
			if (oXHR.status == 200){
			}
			else{
				if (!oXHR.status==0) {alert('errore ' + oXHR.status + '\n\n' + Right(oXHR.responseText,2000))};
			}
		}
	}
	var data = 'ID=' + escape(ID);
	oXHR.send(data);
}
function updateLinkDir(ID){
	var oXHR = newXMLHttpRequest('post','inc/ajax_link_directory.asp',true);
	oXHR.onreadystatechange = function(){
		if (oXHR.readyState == 1){
		}
		if (oXHR.readyState == 4){
			if (oXHR.status == 200){
			}
			else{
				if (!oXHR.status==0) {alert('errore ' + oXHR.status + '\n\n' + Right(oXHR.responseText,2000))};
			}
		}
	}
	var data = 'ID=' + escape(ID);
	oXHR.send(data);
}
function addSet(bMode){
	var oXHR = newXMLHttpRequest('post','inc/ajax_set.asp',true);
	oXHR.onreadystatechange = function(){
		if (oXHR.readyState == 1){
		}
		if (oXHR.readyState == 4){
			if (oXHR.status == 200){
				$('container_lnk_sub').innerHTML = oXHR.responseText;
				$('lnk_sub').focus();
			}else{
				if (!oXHR.status==0) {alert('errore ' + oXHR.status + '\n\n' + Right(oXHR.responseText,2000))};
			}
		}
	}
	oXHR.send("bMode=" + escape(bMode));
}
function expandNews(id){
	var oXHR = newXMLHttpRequest('post','inc/ajax_news.asp',true);
	oXHR.onreadystatechange = function(){
		if (oXHR.readyState == 1){
			$('nws_'+id).innerHTML = '<img src="ico/loading19.gif" alt="" />'
		}
		if (oXHR.readyState == 4){
			if (oXHR.status == 200){
				$('nws_'+id).innerHTML = oXHR.responseText;
			}else{
				if (!oXHR.status==0) {alert('errore ' + oXHR.status + '\n\n' + Right(oXHR.responseText,2000))};
			}
		}
	}
	oXHR.send("id=" + escape(id));
}
function oldNews(nMax,nTot,nNow){
	var oXHR = newXMLHttpRequest('post','inc/ajax_oldnews.asp',true);
	oXHR.onreadystatechange = function(){
		if (oXHR.readyState == 1){
			$('ico_oldnews').innerHTML = '<img src="ico/loading19.gif" alt="" />'
		}
		if (oXHR.readyState == 4){
			if (oXHR.status == 200){
				$('oldnews').innerHTML += oXHR.responseText;
				if (nTot<=nNow) {
					$('ico_oldnews').innerHTML = '<a href="articoli precedenti" onclick="oldNews('+nMax+','+nTot+','+parseInt(nNow+nMax)+');return false;">articoli precedenti</a>'
				}else{
               $('ico_oldnews').innerHTML = ''
				}
			}else{
				if (!oXHR.status==0) {alert('errore ' + oXHR.status + '\n\n' + Right(oXHR.responseText,2000))};
			}
		}
	}
	oXHR.send("nMax=" + escape(nMax) + "&nTot=" + escape(nTot) + "&nNow=" + escape(nNow));
}

