function ajax(url,ld,md,nd){
	if(md===undefined){md='GET';}
	var od;
	if(window.XMLHttpRequest){
		od=new XMLHttpRequest();
	}
	else
		if(window.ActiveXObject){
		 	try
			 	{od=new ActiveXObject("Msxml2.XMLHTTP");}
			catch(e){
				try {od=new ActiveXObject("Microsoft.XMLHTTP");}
				catch(e){}
			}
		}
		else{
			throw'Can not create XMLHTTP-instance';
		}

	od.onreadystatechange=function(){
		if(od.readyState==4){
			if(od.status==200){
				var pd=od.getResponseHeader('Content-Type');
				pd=pd.substr(0,pd.indexOf(';'));
				switch(pd){
					case'application/json':
						ld((od.responseText==''?null:eval('('+od.responseText+')')));
						break;
					case'text/plain':
						ld(od.responseText);
						break;
					case "text/html":
						ld(od.responseText);
						break;
					default:
						throw'Illegal content type';
				}
			}
			else
				{throw'An error has occurred during request';}
		}
	};
	od.open(md,url,true);
	if(md=='POST'){
		od.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=utf-8');
		var qd=rd(nd);
	}
	else{
		var qd=null;
	}
	od.send(qd);
}
function rd(sd){
	var td='';
	var ud=true;
	for(var vd in sd){
		td+=(ud?'':'&')+vd+'='+window.encodeURI(sd[vd]);
		if(ud)
			ud=false;
	}
	return td;
}
function ajax_get(link,funzione){
	req=new createXMLHttpRequest();
	req.onreadystatechange=funzione;
	req.open('get',link);
	req.send(null);
}
function createXMLHttpRequest() {
var ua;
	if(window.XMLHttpRequest) {
    	try {
      		ua = new XMLHttpRequest();
		  }
		  catch(e)  {
		      ua = false;
		  }
	} else if(window.ActiveXObject) {
		   try {
			ua = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e) {
			   ua = false;
			}
	}
	return ua;
}
function f_order_by(campo){
	f1.orderby.value=campo;
	avviaricerca("submit");
}
function f_pagina_prima(){
	f1.pag.value=1;
	avviaricerca("submit");
}
function f_pagina_ultima(p){
	f1.pag.value=p;
	avviaricerca("submit");
}
function f_pagina_succ(){
	if (f1.pag.value=="" || f1.pag.value=="0")
		f1.pag.value=1;
	f1.pag.value=f1.pag.value*1+1;
	avviaricerca("submit");
}
function f_pagina_prec(){
	f1.pag.value=f1.pag.value*1-1;
	avviaricerca("submit");
}
//Serve per allargare dinamicamente i campi textarea
function fnCheckScroll(id){
    var iNewHeight = id.scrollHeight;
	id.style.height=iNewHeight+2;
}
function ver_tasti(e,t){
   //alert(e.keyCode);
   vnCode2CaptureF2 = 113; //F2
   vnCode2CaptureF4 = 115; //F4
/*   if(!e)
   {
      if( window.event )
      {
         //Internet Explorer
         e = window.event;
      }
      else
      {
         return;
      }
   }

   if( typeof( e.keyCode ) == 'number'  )
   {
      //DOM standard
      e = e.keyCode;
   }
   else if( typeof( e.which ) == 'number' )
   {
      //vecchio Netscape 4
      e = e.which;
   }
   else if( typeof( e.charCode ) == 'number'  )
   {
      //Compatibile Mozilla 0.9+ e Netscape
      e = e.charCode;
   }
   else
   {
      //c'e' qualcosa che non va, non si riesce ad ottenere il codice
      return;
   }
*/
   if (t==2){
	   if(e.keyCode==vnCode2CaptureF2){
		  if (!f1.p_ok.disabled){
	      	verifica_campi();
		  }
		  return false;
	   }
   }
   if (t==4){
	   if(e.keyCode==vnCode2CaptureF4){
			f_avvia_ricerca();
			return false;
	   }
   }
}

function openw(url,nome){
var w=screen.width-10;
var h=screen.height-100;

	var rif=window.open(url,nome,'Width='+w+',Height='+h+',resizable=1,titlebar=1,toolbar=0,location=0,status=1,menubar=0,scrollbars=1');
	rif.moveTo(0,0);
	rif.focus();
	return rif;
}

function openw_popup(url,nome){
var w=250;
var h=140;

	var rif=window.open(url,nome,'Width='+w+',Height='+h+',resizable=0,titlebar=1,toolbar=0,location=0,status=0,menubar=0,scrollbars=0');
	rif.moveTo(screen.width/2-w/2,screen.height/2-h/2);
	rif.focus();
	return rif;
}

function openw_popup2(url,nome){
var w=350;
var h=200;

	var rif=window.open(url,nome,'Width='+w+',Height='+h+',resizable=0,titlebar=0,toolbar=0,location=0,status=0,menubar=0,scrollbars=0');
	rif.moveTo(screen.width/2-w/2,screen.height/2-h/2);
	rif.focus();
	return rif;
}

function openw_popupxy(url,nome,x,y){
var w=x;
var h=y;

	var rif=window.open(url,nome,'Width='+w+',Height='+h+',resizable=0,titlebar=0,toolbar=0,location=0,status=0,menubar=0,scrollbars=0');
	rif.moveTo(screen.width/2-w/2,screen.height/2-h/2);
	rif.focus();
	return rif;
}

function openw_popupxy_sb(url,nome,x,y,scrool_bar){
var w=x;
var h=y;

	var rif=window.open(url,nome,'Width='+w+',Height='+h+',resizable=0,titlebar=0,toolbar=0,location=0,status=0,menubar=0,scrollbars='+scrool_bar);
	rif.moveTo(screen.width/2-w/2,screen.height/2-h/2);
	rif.focus();
	return rif;
}

function openw_popupxy_resizable_sb(url,nome,x,y,scrool_bar){
var w=x;
var h=y;

	var rif=window.open(url,nome,'Width='+w+',Height='+h+',resizable=1,titlebar=0,toolbar=0,location=0,status=0,menubar=0,scrollbars='+scrool_bar);
	rif.moveTo(screen.width/2-w/2,screen.height/2-h/2);
	rif.focus();
	return rif;
}

function mano(obj){
	obj.style.cursor = "pointer";
}

function TurnOn_td(objRow) {
	//Evidenzia la riga
	objRow.style.cursor = "pointer";
	objRow.style.backgroundColor = "#FFFF00";
	objRow.style.padding="2px 2px 2px 2px";
	objRow.style.bordertop="1px solid #0000FF";
}
function TurnOff_td(objRow) {
	objRow.style.backgroundColor = "#FFFFFF";
	objRow.style.padding="2px 2px 2px 2px";
	objRow.style.bordertop="1px solid #0000FF";
}

function TurnOn(objRow) {
	objRow.style.cursor = "pointer";
	objRow.style.backgroundColor = "#FFFF00";
}

function TurnOff(objRow) {
	objRow.style.backgroundColor="#FFFFFF";
}
function TurnOff_color(objRow,c) {
	objRow.style.backgroundColor=c;
}
function TurnOff2(objRow) {
	objRow.style.backgroundColor = "#c0c0c0";
}
function TurnOn2(objRow) {
	//objRow.style.cursor = "pointer";
	objRow.style.backgroundColor = "#FFFF00";
}

function pieno(campo){
	if (f1[campo].value+'x'!='x') {
		return true;
	}
	else{
		return false;
	}
}
function isnumeric(campo){
	for (i=0;i<=campo.length-1;i++){
		if ((campo.substr(i,1)>='0' && campo.substr(i,1)<='9') || campo.substr(i,1)==',' || campo.substr(i,1)=='.' || campo.substr(i,1)==' ') {
			//return 1;
		}
		else{
			return false;
		}
	}
	return true;
}
function IvDt(d){
	var dd;
	if (d=='') {
		return '00000000';
	}
	else{
		dd=d.substr(6,4)+d.substr(3,2)+d.substr(0,2);
		return dd;
	}
}
function chk_data(campo,testo){
	if (f1[campo].value+'x'!='x') {
		if (!isdata(f1[campo].value)) {
			if (testo=="") {
				alert("Data errata! Il formato corretto e' (gg/mm/aaaa)");
			}
			else{
				alert(testo);
			}
			f1[campo].focus();
			return false;
		}
	}
	return true;
}
function chk_data_ric(campo,testo){
	if (ricerca[campo].value+'x'!='x') {
		if (!isdata(ricerca[campo].value)) {
			if (testo=="") {
				alert("Data errata! Il formato corretto e' (gg/mm/aaaa)");
			}
			else{
				alert(testo);
			}
			ricerca[campo].focus();
			return false;
		}
	}
	return true;
}

function chk_data_obb(campo,testo){
	if (f1[campo].value+'x'!='x'){
		if (!chk_data(campo,testo)){
		 return false;
		}
	}
	else{
		alert('Data obbligatoria!');
		f1[campo].focus();
		return false;
	}
	return true;
}
function chk_data_obb_ricerca(campo,testo){
	if (ricerca[campo].value+'x'!='x'){
		if (!chk_data_ricerca(campo,testo)){
		 return false;
		}
	}
	else{
		alert('Data obbligatoria!');
		ricerca[campo].focus();
		return false;
	}
	return true;
}
function isdata(campo){
	var contabarre=0;
	for (i=0;i<=campo.length-1;i++){
		if (((campo.substr(i,1)>='0') && (campo.substr(i,1)<='9')) || (campo.substr(i,1)=='/')) {
			if (campo.substr(i,1)=='/') {
				contabarre++;
			}
		}
		else{
			return false;
		}
	}
	if (contabarre!=2) {
		return false;
	}
	if (campo.length!=10) {
		return false;
	}
	gg=campo.substr(0,2);
    mm=campo.substr(3,2);
    aa=campo.substr(6,4);

   strdata=gg+"/"+mm+"/"+aa;
   data = new Date(aa,mm-1,gg);
   daa=data.getFullYear().toString();
   dmm=(data.getMonth()+1).toString();
   dmm=dmm.length==1?"0"+dmm:dmm;
   dgg=data.getDate().toString();
   dgg=dgg.length==1?"0"+dgg:dgg;
   dddata=dgg+"/"+dmm+"/"+daa;
   if (dddata!=strdata){
	   return false;
   }
	return true;
}

function Trim() {
return this.replace(/\s+$|^\s+/g,"");
}

function LTrim() {
return this.replace(/^\s+/,"");
}

function RTrim() {
return this.replace(/\s+$/,"");
}

String.prototype.Trim=Trim;
String.prototype.RTrim=RTrim;
String.prototype.LTrim=LTrim;

function Normalizza(s){
	if(s.search(".")!=-1 && s.search(",")==-1) {
		//alert("trovato 1 solo punto senza virgola!");
		var x=s.replace(/\./g,",");
		return x;
	}
	return s;
}
function isCurrency(_stringToSearch)
{
	var re = /^[\d\.]*,*\d+$/;
	s=_stringToSearch.Trim();
	if (s.substr(0,1)=="-" || s.substr(0,1)=="+"){
		s=s.substr(1);
	}
	if(s.search(re)==-1) {
	  alert("Quanto inserito non e' una cifra in Euro corretta.");
  	return false;
	}
	else {
	  return true;
	}
}
function isCurrencyPlus(_stringToSearch)
{
	var re = /^[\d\.]*,*\d+$/;
	s=_stringToSearch.Trim();
	if(s.search(re)==-1) {
	  alert("Quanto inserito non e' una cifra in Euro corretta.");
  	return false;
	}
	else {
	  return true;
	}
}
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 correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
{
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
var imgAttribs = img.attributes;
var onMouseOver = "", onMouseOut = "";
for (var j=0; j<imgAttribs.length; j++)
{
var imgAttrib = imgAttribs[j];
if (imgAttrib.nodeName == "align")
{
if (imgAttrib.nodeValue == "left") imgStyle = "float:left;" + imgStyle
if (imgAttrib.nodeValue == "right") imgStyle = "float:right;" + imgStyle
break
}
}
if (img.name && !img.id) imgID= "id='" + img.name + "' "
if ((pos=img.outerHTML.toUpperCase().indexOf("ONMOUSEOVER="))>0) {
	onMouseOver=img.outerHTML.substring(pos);
	pos=onMouseOver.indexOf(");");
	if (onMouseOver.substr(12,1)== "\"") pos=onMouseOver.indexOf(");\"");
	onMouseOver=" " + onMouseOver.substring(0,pos+2).replace("MM_swap","MM_PNGswap") + ((onMouseOver.substr(12,1)== "\"") ? "\"":"") + " ";
}
pos=0
if ((pos=img.outerHTML.toUpperCase().indexOf("ONMOUSEOUT="))>0) {
	onMouseOut=img.outerHTML.substring(pos);
	pos=onMouseOut.indexOf(");");
	if (onMouseOut.substr(11,1)== "\"") pos=onMouseOut.indexOf(");\"");
	onMouseOut=" " + onMouseOut.substring(0,pos+2).replace("MM_swap","MM_PNGswap") + ((onMouseOut.substr(11,1)== "\"") ? "\"":"") + " ";
}
pos=0
var strNewHTML = "<span " + imgID + imgClass + imgTitle
strNewHTML += " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
strNewHTML += "(src=\'" + img.src + "\', sizingMethod='scale');\"";
strNewHTML += onMouseOver + onMouseOut + "></span>"
img.outerHTML = strNewHTML
i = i-1
}
}

for(var i=0; i<document.links.length; i++)
{
var lnk = document.links[i];
var tStr="";
if ((pos=lnk.outerHTML.indexOf("MM_swapImage("))>0) {
	tStr=lnk.outerHTML.substring(pos+13);
	pos=tStr.indexOf(");");
	if (pos>0) {
		pos=tStr.substring(0,pos).toUpperCase().indexOf(".PNG");
		if (pos>0) lnk.outerHTML = lnk.outerHTML.replace(/MM_swap/g,"MM_PNGswap");
	}
}
}


}

function MM_PNGswapImage() { //v3.0
	var i,j=0,x,a=MM_PNGswapImage.arguments;
	document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
		if ((x=MM_findObj(a[i]))!=null){
			document.MM_sr[j++]=x;
			if(!x.oSrc) x.oSrc=x.filters(0).src;
			x.filters(0).src=a[i+2];
		}
}

function MM_PNGswapImgRestore() { //v3.0
	var i,x,a=document.MM_sr;
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.filters(0).src=x.oSrc;
}


//window.attachEvent("onload", correctPNG);

