function CreateControl(DivID, CLSID, ObjectID,
                       WIDTH, HEIGHT, URL, LOOP, FLASHVARS, WMODE, SCALE, SALIGN)
{
  var d = document.getElementById(DivID);
  var objs = "<object classid=\"" + CLSID + "\" id=\"" + ObjectID + "\" width=\"" + WIDTH + "\" height=\"" + HEIGHT + "\" codebase=\"https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,16,0\">"
            + "<param name=\"src\" value=\"" + URL + "\"><param name=\"movie\" value=\"" + URL + "\">"
            + "<param name=\"quality\" value=\"high\"><param name=\"Loop\" value=\"" + LOOP + "\">"
            + "<param name=\"FlashVars\" value=\"" + FLASHVARS + "\">"
            + "<param name=\"WMode\" value=\"" + WMODE + "\">"
            + "<param name=\"salign\" value=\"" + (SALIGN ? SALIGN : "lt") + "\">"
            + (SCALE ? "<param name=\"scale\" value=\"" + SCALE + "\">" : "")
            + "<embed src=\"" + URL + "\" salign=\"" + (SALIGN ? SALIGN : "lt") + "\" quality=\"high\" pluginspage=\"https://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + WIDTH + "\" height=\"" + HEIGHT + "\" loop=\"" + (LOOP == "-1" ? "true" : "false") + "\" flashvars=\"" + FLASHVARS + "\" wmode=\"" + WMODE + "\" " + (SCALE ? "scale=\"" + SCALE + "\"" : "") + "></embed>"
            + "</object>";
  d.innerHTML = objs;  
  
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n);
  if(!x && document.getElementsByName && document.getElementsByName(n).length>0) x=document.getElementsByName(n)[0]; return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.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.src; x.src=a[i+2];}
}

function checkemail(em) {
	re1=/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
	re2=/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	emok=re1.test(em) || re2.test(em);
	return emok;
}

function SelezionaProdotto(nomecampo,id_negozio_ricerca,id_categoria_ricerca,sottocategorie,trasmetticodice) {
  toppos=(screen.height-600)/2;
  leftpos=(screen.width-400)/2;
  tc=0;
  if (trasmetticodice) tc=1;
  w=window.open("/index.aspx?m=CatalogoProdotti&f=popupricercaprodotti&nc="+nomecampo+"&nr="+id_negozio_ricerca+"&cr="+id_categoria_ricerca+"&sc="+sottocategorie+"&tc="+tc,"ricercaprodotti","top="+toppos+",left="+leftpos+",height=600,width=400,scrollbars=Yes");
  w.focus();
}

function SelezionaFamigliaProdotto(nomecampo,id_negozio_ricerca,id_categoria_ricerca,sottocategorie,trasmetticodice) {
  toppos=(screen.height-600)/2;
  leftpos=(screen.width-400)/2;
  tc=0;
  if (trasmetticodice) tc=1;
  w=window.open("/index.aspx?m=CatalogoProdotti&f=popupricercafamiglie&nc="+nomecampo+"&nr="+id_negozio_ricerca+"&cr="+id_categoria_ricerca+"&sc="+sottocategorie+"&tc="+tc,"ricercafamiglieprodotti","top="+toppos+",left="+leftpos+",height=600,width=400,scrollbars=Yes");
  w.focus();
}

function Aggiorna(campoid,valoreid,valoretxt) {
  pid=MM_findObj(campoid,window.opener.document);
  pdiv=MM_findObj(campoid+"_divprodotto",window.opener.document);
  if (pid!=null) {
    pid.value=valoreid;
    pdiv.innerHTML=valoretxt;
    if(pid.type == "text")
        pid.focus();
  }
  window.close();
}
function in_array(a,v) {
  found=false;
  for (ia=0; ia<a.length && !found; ia++) {
    found=(a[ia]==v);
  }
  return found;
}
function Fill(mdati,idp,c) {
  o=MM_findObj("cp_"+idp+"_c"+c);
  if (o) {
    for (x=0;x<o.options.length;x++) o.options[x]=null;
    o.length=0;
    o.options.add(new Option('',''));
    o.selectedIndex=0;
    var cass=new Array();
    cassidx=0
    var varsel = "";
    for (xd=0;xd<mdati.length;xd++) {
      ok=true
      for (xm=0; xm<c; xm++) {
        ok &= (MM_findObj("cp_"+idp+"_c"+xm).value==mdati[xd][xm])
      }
      if (ok) {
        if (!in_array(cass,mdati[xd][c])) {
	  if (mdati[xd]['sl']) varsel = mdati[xd][c];
          cass[cassidx]=mdati[xd][c];
          cassidx++;
        }
      }
    }
    if (cass.length>0) {
      for (xxm = 0; xxm<cass.length; xxm++) {
        var newo = new Option(cass[xxm],cass[xxm]);
        newo.selected = (cass[xxm] == varsel);
        o.options.add(newo);
      }
    }
    Fill(mdati,idp,c+1);
    return true;
  }
  return false;
}

function GoToCP(mdati,id,base,c) {
  for (xd=0;xd<mdati.length;xd++) {
    ok=true
    for (xm=0; xm<c; xm++) {
      if (MM_findObj("cp_"+id+"_c"+xm)) 
        ok &= (MM_findObj("cp_"+id+"_c"+xm).value==mdati[xd][xm]);
    }
    if (ok) {
      location.href=base+mdati[xd]['cp'];
      xd = mdati.length + 1;
    }
  }
}

function AggiornaLinkCarrello(lc,ido,idp) {
  var alc_link = MM_findObj(lc);
  if (!alc_link) return;
  var alc_url = alc_link.href;
  var idospos = alc_url.indexOf("&idbov=");
  var idoepos = 0;
  if (idospos>0) {
    var alc_par = "";
    idoepos = alc_url.indexOf("&",idospos+1);
    if (idoepos>0) alc_par = alc_url.substring(idospos,idoepos); else alc_par = alc_url.substring(idospos,alc_url.length);
    alc_url=alc_url.replace(alc_par,"");
    alc_par=alc_par.replace("&idbov=","");
    var alc_segs = alc_par.split(',');
    var alc_parnew = "";
    for (alc_i=0;alc_i<alc_segs.length;alc_i++) {
      if (alc_segs[alc_i].indexOf(ido+"|")<0) {
        if (alc_parnew != "") alc_parnew += ",";
        alc_parnew += alc_segs[alc_i];
      }
    }
    if (ido!=idp) {
      if (alc_parnew != "") alc_parnew += ",";
      alc_parnew += ido+"|"+idp;
    }
    if (alc_parnew != "") alc_url += "&idbov="+alc_parnew;
  } else {
    if (ido!=idp) alc_url += "&idbov="+ido+"|"+idp;
  }
  alc_link.href = alc_url;
}

function ApriPaginaFinestra(url,nomefinestra,dimensionex,dimensioney,scrolla) {
  var specs="toolbars=no,width="+dimensionex+",height="+dimensioney;
  if (scrolla) specs+=",scrollbars=yes"
  win=window.open(url,nomefinestra,specs);
  win.focus();
  return false;
}
function ApriImmagineFinestra(url,titolo,dimensionex,dimensioney) {
  
 
  var specs="toolbars=no,width="+dimensionex+",height="+dimensioney;
  win=window.open('','cmpopup',specs);
  
  if(!MM_findObj("idIMG",win.document)) {
	win.document.write("<html><head><title>"+titolo+"</title></head><body topmargin=0 leftmargin=0 rightmargin=0 bottommargine=0 oncontextmenu='" + (!document.body.oncontextmenu || document.body.oncontextmenu.toString().indexOf("false") >= 0 ? "return false" : "return true") + "'>");
	win.document.write("<img id=\"idIMG\" src='"+url+"' width="+dimensionex+" height="+dimensioney+" border=0></body></html>");
  } else {
	win.document.title = titolo;
	win.resizeTo(dimensionex+10,dimensioney+60);
	MM_findObj("idIMG",win.document).src = url;
	MM_findObj("idIMG",win.document).width = dimensionex;
	MM_findObj("idIMG",win.document).height = dimensioney;
  }
  win.focus();
  return false;
}

// Controlla la validità di una data
// valore deve essere un array con 1 elemento contenente la data da controllare
// in questo modo la funzione modifica la data cambiandola in base al separatore desiderato
function IsValidDate(valore,separator) {
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var strSeparatorArray = new Array("-"," ","/",".");
	var carOK = "0123456789-/ .";
	var intElementNr;
	// var err = 0;
	

	strDate = valore[0];
	if(strDate.length != 10)
		return false;
	for(i=0; i<strDate.length; i++) {
		ch = strDate.substr(i,1);
		//alert(ch);
		ok = false;
		for(c = 0; c<carOK.length; c++)
			{
			ch2 = carOK.substr(c,1);
			//alert(carOK.substr(c,1));
			if(ch == ch2)
				{
				ok = true;
				break;
				}
			}
		if(!ok)
			//carattere non valido
			return false;
				
	}


	var separatorFound = "";		
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			separatorFound = strSeparatorArray[intElementNr];
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) {
				err = 1;
				return false;
			}
			else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
		}
	}
	
	if (booFound == false) {
		if (strDate.length>5) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}

	//Adjustment for short years entered
	if (strYear.length == 2) {
		strYear = '20' + strYear;
	}
	//strTemp = strDay;
	//strDay = strMonth;
	//strMonth = strTemp;
	if(strDay.length != 2)
		return false;	
	if(strMonth.length != 2)
		return false;	
	if(strYear.length != 4)
		return false;	

	intday = parseInt(strDay, 10);
	if (isNaN(intday)) {
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		err = 3;
		return false;
	}
	
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) {
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1) {
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
		err = 7;
		return false;
	}
	if (intMonth == 2) {
		if (intday < 1) {	
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true) {
			if (intday > 29) {
				err = 9;
				return false;
   			}
		}
		else {
			if (intday > 28) {
				err = 10;
				return false;
	      		}
   		}
	}
	if(separator)
		valore[0] = strDay + separator + strMonth + separator + strYear;
	return true;
}

// Controlla se un'anno è bisestile

function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) { return true; }
	}
	else {
		if ((intYear % 4) == 0) { return true; }
	}
	return false;
}


// Controlla se il numero è valido
function IsValidNumber(valore) {
	var carOK = "0123456789.,-";
	
	
	strNumber = valore;
	decimalSeparatorFound = false;
	for(i=0; i<strNumber.length; i++) {
		ch = strNumber.substr(i,1);
		if(ch == "," || ch == ".")
			if(!decimalSeparatorFound)
				decimalSeparatorFound = true;
			else	// ci deve essere solo un separatore dei decimali!
				return false; 
		ok = false;
		for(c = 0; c<carOK.length; c++)
			{
			ch2 = carOK.substr(c,1);
			if(ch == ch2)
				{
				ok = true;
				break;
				}
			}
		if(!ok || (i > 0 && ch == "-")) // il car - può essere solo il primo
			//carattere non valido
			return false;
				
	}
	
	// Sostituisce la , col .
	pos = strNumber.indexOf(",");
	if(pos != -1)
		strNumber = strNumber.substr(0,pos-1) + "." + strNumber.substr(pos+1);
	
	fNumber = parseFloat(strNumber);
	if(isNaN(fNumber))
		return false;

	return true;		
}

// Controlla se il numero è un'intero valido
function IsValidInteger(valore) {
	var carOK = "0123456789-";
	
	
	strNumber = valore;
	for(i=0; i<strNumber.length; i++) {
		ch = strNumber.substr(i,1);
		ok = false;
		for(c = 0; c<carOK.length; c++)
			{
			ch2 = carOK.substr(c,1);
			if(ch == ch2)
				{
				ok = true;
				break;
				}
			}
		if(!ok || (i > 0 && ch == "-")) // il car - può essere solo il primo
			//carattere non valido
			return false;
				
	}
	
	
	fNumber = parseInt(strNumber,10);
	if(isNaN(fNumber))
		return false;

	return true;		
}

// Controlla la validità di un'indirizzo IP; accetta anche il carattere * per indicare una rete;
function IsValidIPAddress(ip) {
	var ipString = new String(ip);
	var ipArray = ipString.split(".");
	if(ipArray.length != 4)
		return false;
	if(ipArray[0] != "*" && !IsValidNumber(ipArray[0]))
		return false;
	if(ipArray[1] != "*" && !IsValidNumber(ipArray[1]))
		return false;
	if(ipArray[2] != "*" && !IsValidNumber(ipArray[2]))
		return false;
	if(ipArray[3] != "*" && !IsValidNumber(ipArray[3]))
		return false;
		
	if(ipArray[0] != "" && ipArray[0] != "*" && IsValidNumber(ipArray[0]) && (parseInt(ipArray[0],10) < 1 || parseInt(ipArray[0],10) > 255)) 
		return false;		 
	if(ipArray[1] != "" && ipArray[1] != "*" && IsValidNumber(ipArray[1]) && (parseInt(ipArray[1],10) < 1 || parseInt(ipArray[1],10) > 255)) 
		return false;		 
	if(ipArray[2] != "" && ipArray[2] != "*" && IsValidNumber(ipArray[2]) && (parseInt(ipArray[2],10) < 1 || parseInt(ipArray[2],10) > 255)) 
		return false;		 
	if(ipArray[3] != "" && ipArray[3] != "*" && IsValidNumber(ipArray[3]) && (parseInt(ipArray[3],10) < 1 || parseInt(ipArray[3],10) > 255)) 
		return false;		 
	return true;		 
}

// Controlla se il numero di telefono è valido
// accetta solo cifre senza spazi e separatori
// controlla solo se vengono messe delle cifre
function IsValidPhone(valore) {
	var carOK = "0123456789";
	
	strNumber = valore;
	for(i=0; i<strNumber.length; i++) {
		ch = strNumber.substr(i,1);
		ok = false;
		for(c = 0; c<carOK.length; c++)
			{
			ch2 = carOK.substr(c,1);
			if(ch == ch2)
				{
				ok = true;
				break;
				}
			}
		if(!ok ) {
			//carattere non valido
			return false;
		}		
	}
	
	
	return true;		
}

function AggiungiCampo(fld,nonaggdisp,doppiok,strconfermadoppio) {
 var oSelAvailable = MM_findObj(fld+"Available");
 var oSelSelected = MM_findObj(fld+"Selected");
 if(oSelAvailable.selectedIndex == -1)
  return;
 for (xs=0; xs<oSelAvailable.options.length; xs++) {
  if (oSelAvailable.options[xs].selected) {
   var isdoppio=SelValExists(oSelSelected,oSelAvailable.options[xs].value);
   if (!isdoppio || (doppiok && !strconfermadoppio) || (doppiok && confirm(oSelAvailable.options[xs].text+': '+strconfermadoppio))) {
     var oOption = new Option();
     oOption.text = oSelAvailable.options[xs].text;
     oOption.value = oSelAvailable.options[xs].value;
     oSelSelected.options[oSelSelected.options.length]=oOption;
     if (!nonaggdisp) oSelAvailable.options[xs] = null;
   }
  }
 }
 UpdateHiddenCampi(fld);
}
function TogliCampo(fld,nonaggdisp) {
 var oSelAvailable = MM_findObj(fld+"Available");
 var oSelSelected = MM_findObj(fld+"Selected");
 if(oSelSelected.selectedIndex == -1)
  return;
 for (xs=oSelSelected.options.length-1; xs>=0; xs--) {
   if (oSelSelected.options[xs].selected) {
     if (!nonaggdisp) {
       var oOption = new Option();
       oOption.text = oSelSelected.options[xs].text;
       oOption.value = oSelSelected.options[xs].value;
       oSelAvailable.options[oSelAvailable.options.length]=oOption;
     }
     oSelSelected.options[xs] = null;
   }
 }
 UpdateHiddenCampi(fld);
}
function UpdateHiddenCampi(fld) {
 var oSelSelected = MM_findObj(fld+"Selected");
 var oHidden = MM_findObj(fld);
 oHidden.value = "";
 for(var i=0; i<oSelSelected.options.length; i++) {
  oHidden.value += oSelSelected.options[i].value;
  if(i < oSelSelected.options.length - 1)
   oHidden.value += ",";
 }
}
function SelValExists(o,v) {
  if (o && o.options && o.options.length>0) {
    for (xxs=0; xxs<o.options.length; xxs++) {
      if (o.options[xxs].value==v) return true;
    }
  }
  return false;
}

function MarkAllCheckBox(n,op) {
  var jacopo=MM_findObj(n);
  if (!jacopo) return;
  if (!jacopo.length) jacopo=new Array(jacopo);
  for (ma_x=0; ma_x<jacopo.length; ma_x++) {
    if (op<0) {
      jacopo[ma_x].checked=!jacopo[ma_x].checked;
    } else jacopo[ma_x].checked=op;
  }
}

function OneCheckBoxChecked(n) {
  var jacopo=MM_findObj(n);
  var ocbc=false;
  if (!jacopo) return;
  if (!jacopo.length) jacopo=new Array(jacopo);
  for (ma_x=0; ma_x<jacopo.length; ma_x++) {
    if (jacopo[ma_x].checked) {
      ocbc=true;
      mx_x=jacopo.length;
    }
  }
  return ocbc;
}

function CercaIn(dove,cosa) {
  cosa=cosa.toLowerCase();
  var ci_ogg=MM_findObj(dove);
  var ci_goon=true;
  for (ci_xx=0; ci_goon && ci_xx<ci_ogg.options.length; ci_xx++) {
    if (ci_ogg.options[ci_xx].text.replace('&nbsp;','').toLowerCase().indexOf(cosa)>=0) {
      ci_ogg.options[ci_xx].selected=true;
      ci_goon=false;
    }
  }
}

function CheckForzaEBlocca(cambiato,oForzaY,oForzaN,oBloccaY,oBloccaN) {
    if(cambiato == "forza" && oForzaY.checked)
        oBloccaN.checked = true;
    else if(cambiato == "blocca" && oBloccaY.checked)
        oForzaN.checked = true;
}

function CheckForzaEBloccaChk(cambiato,oForza,oBlocca) {
    if(cambiato == "forza" && oForza.checked)
        oBlocca.checked = false;
    else if(cambiato == "blocca" && oBlocca.checked)
        oForza.checked = false;
}

function ShowHideDependentFields(arVarDeps,idxvalsel) {
    if(idxvalsel < 0)
        return;
    for(var i=0; i<arVarDeps[idxvalsel].length; i++) {
        var CellaDesc = MM_findObj(arVarDeps[idxvalsel][i][0] + "-1");
        var CellaCampo = MM_findObj(arVarDeps[idxvalsel][i][0] + "-2");
        if(arVarDeps[idxvalsel][i][1] == "1") {
            CellaDesc.style.display = "inline";
            CellaCampo.style.display = "inline";
        } else {
            CellaDesc.style.display = "none";
            CellaCampo.style.display = "none";
        }
    }
}

function RS_CaricaDati(rsurl,camposrc,campodst,testononsel) {
	var randomframenumber = Math.round(Math.random() * 10000);
	var iframestr = '<iframe id="ifrcd_' + randomframenumber + '" name="ifrcd_' + randomframenumber + '" onload="window.parent.RS_AggiornaDati('+randomframenumber+',\''+testononsel+'\');" width="0" height="0" border="0"><\/iframe>';
        var tmpdiv = document.createElement("div");
        tmpdiv.id = "div_" + randomframenumber;
        tmpdiv.name = "div_" + randomframenumber;
        tmpdiv.campodestinazione = campodst;
        tmpdiv.innerHTML += iframestr;
        document.body.appendChild(tmpdiv);
	var ricobj=MM_findObj("ifrcd_"+randomframenumber);

	var idaobj=MM_findObj(camposrc);
	var codice=idaobj.options[idaobj.selectedIndex].value;
	var thedoc;
	if (ricobj.contentDocument)
		thedoc=ricobj.contentDocument;
	else if (ricobj.contentWindow)
		thedoc=ricobj.contentWindow.document;
	else
		thedoc=ricobj.document;
//alert("chiamo: "+rsurl+codice);
	if (thedoc.location.href)
		thedoc.location.href=rsurl + codice;
	else
		ricobj.location.href=rsurl + codice;
	
	var sricobj=MM_findObj(campodst)
	for (x=0; x<sricobj.options.length; x++)
		sricobj.options[x]=null;
	sricobj.options.length=0;
	sricobj.options[0]=new Option("Caricamento...","");
}
function RS_AggiornaDati(iframename, testononsel) {
        var re= /<\S[^>]*>/g;
        var divobj = MM_findObj("div_"+iframename);
        var ricobj = MM_findObj("ifrcd_"+iframename);

	var thedoc;
	if (ricobj.contentDocument)
		thedoc=ricobj.contentDocument;
	else if (ricobj.contentWindow)
		thedoc=ricobj.contentWindow.document;
	else
		thedoc=ricobj.document;

	var rowdata=thedoc.childNodes[0].innerHTML;

	document.body.removeChild(divobj);

	if (rowdata=="SESSION ENDED") {
		alert('SESSION ENDED');
		document.location.reload();
		return;
	}

	var campodst = divobj.campodestinazione;

	var sricobj=MM_findObj(campodst);
	
	//if (!rowdata) return;

	if (rowdata) {
		rowdata = rowdata.replace(re,"");
		rowdata=rowdata.replace('\n','');
		rowdata=rowdata.replace('\r','');
		
		var righe=rowdata.split('[EOL]');

		for (x=0; x<righe.length; x++) {
			var campi=righe[x].split("|");
			if (campi.length==3) {
				arcod=campi[0];
				ardes=campi[1];
				arsel=campi[2];
				sricobj.options[x+1]=new Option(ardes,arcod);
				if(arsel=="1")
				    sricobj.options[x+1].selected=true;
			}
		}
	}
	
	sricobj.options[0]=new Option(testononsel,"");
	sricobj.selectedIndex = 0;
	if (document.createEvent) {
	  var evObj = document.createEvent('HTMLEvents');
	  evObj.initEvent( 'change', true, true );
	  sricobj.dispatchEvent(evObj);
	} else if( document.createEventObject ) {
	  sricobj.fireEvent('onchange');
	}
}

function RS_CaricaDatiBC(rsurl,camposrc,campodst,testononsel) {
	var randomframenumber = Math.round(Math.random() * 10000);
	var iframestr = '<iframe id="ifrcd_' + randomframenumber + '" name="ifrcd_' + randomframenumber + '" onload="window.parent.RS_AggiornaDatiBC('+randomframenumber+',\''+testononsel+'\');" width="0" height="0" border="0"><\/iframe>';
        var tmpdiv = document.createElement("div");
        tmpdiv.id = "div_" + randomframenumber;
        tmpdiv.name = "div_" + randomframenumber;
        tmpdiv.campodestinazione = campodst;
        tmpdiv.innerHTML += iframestr;
        document.body.appendChild(tmpdiv);
	var ricobj=MM_findObj("ifrcd_"+randomframenumber);

	var idaobj=MM_findObj(camposrc);
	var codice=idaobj.value;
	var thedoc;
	if (ricobj.contentDocument)
		thedoc=ricobj.contentDocument;
	else if (ricobj.contentWindow)
		thedoc=ricobj.contentWindow.document;
	else
		thedoc=ricobj.document;

	if (thedoc.location.href)
		thedoc.location.href=rsurl + codice;
	else
		ricobj.location.href=rsurl + codice;
	
	var ildiv = MM_findObj("cbselect_"+campodst);
	ildiv.innerHTML = "<table id=\"tblselect_"+campodst+"\" class=\"bccombo\" cellspacing=\"0\" cellpadding=\"0\" >";
	ildiv.innerHTML += "<tr class=\"option\"><td class=\"cbpassive\" onMouseover=\"this.className='cbactive';\" onMouseout=\"this.className='cbpassive';\" onClick=\"SLDV_select(this,'','"+campodst+"')\" onFocus=\"SLDV_select(this,'','"+campodst+"')\">Caricamento...</td></tr>";
	ildiv.innerHTML += "</table>";
	MM_findObj("cbtext_"+campodst).value = "Caricamento...";
	MM_findObj(campodst).value = "";
}

function RS_AggiornaDatiBC(iframename, testononsel) {
        var re= /<\S[^>]*>/g;
	var randomcellnumber = Math.round(Math.random() * 10000);
        var divobj = MM_findObj("div_"+iframename);
        var ricobj = MM_findObj("ifrcd_"+iframename);

	var thedoc;
	if (ricobj.contentDocument)
		thedoc=ricobj.contentDocument;
	else if (ricobj.contentWindow)
		thedoc=ricobj.contentWindow.document;
	else
		thedoc=ricobj.document;

	var rowdata=thedoc.childNodes[0].innerHTML;

	document.body.removeChild(divobj);

	if (rowdata=="SESSION ENDED") {
		alert('SESSION ENDED');
		document.location.reload();
		return;
	}

	var campodst = divobj.campodestinazione;

	var ildiv=MM_findObj("cbselect_"+campodst);
	var stronchange=MM_findObj("cbonchange_"+campodst).value;
	MM_findObj("cbtext_"+campodst).value = testononsel;
	MM_findObj(campodst).value = "";
	var textdiv = "<table id=\"tblselect_"+campodst+"\" class=\"bccombo\" cellspacing=\"0\" cellpadding=\"0\">\n";
	textdiv += "<tr class=\"option\"><td id=\"tmpcella_"+randomcellnumber+"\" class=\"cbpassive\" onMouseover=\"this.className='cbactive';\" onMouseout=\"this.className='cbpassive';\" onClick=\"SLDV_select(this,'','"+campodst+"'); "+stronchange+"\" onFocus=\"SLDV_select(this,'','"+campodst+"'); "+stronchange+"\">"+testononsel+"</td></tr>\n";
	//if (!rowdata) return;

	if (rowdata) {
		rowdata = rowdata.replace(re,"");
		rowdata=rowdata.replace('\n','');
		rowdata=rowdata.replace('\r','');
		
		var righe=rowdata.split('[EOL]');

		for (x=0; x<righe.length; x++) {
			var campi=righe[x].split("|");
			if (campi.length==3) {
				arcod=campi[0];
				ardes=campi[1];
				arsel=campi[2];
				textdiv += "<tr class=\"option\"><td class=\"cbpassive\" onMouseover=\"this.className='cbactive';\" onMouseout=\"this.className='cbpassive';\" onClick=\"SLDV_select(this,'"+arcod+"','"+campodst+"'); "+stronchange+"\" onFocus=\"SLDV_select(this,'"+arcod+"','"+campodst+"'); "+stronchange+"\">"+ardes+"</td></tr>\n";
                if(arsel=="1") {
                    MM_findObj("cbtext_"+campodst).value = ardes;
	                MM_findObj(campodst).value = arcod;
	            }	
			}
		}
	}
	textdiv += "</table>";
	ildiv.innerHTML = textdiv;
	if (stronchange) eval(stronchange);
}

function CMCambioNazione(cn_url, cn_suffix, testononsel, tendinanormale) {
  if(tendinanormale) 
    RS_CaricaDati(cn_url,'cdn' + cn_suffix ,'cdr' + cn_suffix, testononsel);
  else
    RS_CaricaDatiBC(cn_url,'cdn' + cn_suffix ,'cdr' + cn_suffix, testononsel);
}

function CMCambioRegione(cn_url, cn_urln, cn_suffix, testononsel,tendinanormale) {
  var tmp_oj = (tendinanormale ? MM_findObj('cdr' + cn_suffix) : MM_findObj('tblselect_cdr' + cn_suffix));
  var divreg = MM_findObj('ddr' + cn_suffix);
  var divpro = MM_findObj('ddp' + cn_suffix);
  if ((tendinanormale && tmp_oj.options.length > 1) || (!tendinanormale && tmp_oj.rows.length > 1)) {
    // Mostro i div con le tendine di regione e provincia
    if (divreg) divreg.style.display = "";
    if (divpro) divpro.style.display = ""; 
    if(tendinanormale)
        RS_CaricaDati(cn_url,'cdr' + cn_suffix ,'cdp' + cn_suffix, testononsel);
    else
        RS_CaricaDatiBC(cn_url,'cdr' + cn_suffix ,'cdp' + cn_suffix, testononsel);
  }
  else {
    // Carico i dati dei comuni presi dalla nazione direttamente
    if(tendinanormale)
        RS_CaricaDati(cn_urln,'cdn' + cn_suffix, 'cdc' + cn_suffix, testononsel);
    else
        RS_CaricaDatiBC(cn_urln,'cdn' + cn_suffix, 'cdc' + cn_suffix, testononsel);
    // Nascondo i div con le tendine di regione e provincia
    
    if (divreg) divreg.style.display = "none";
    if (divpro) divpro.style.display = "none";
  }
}

function CMCambioProvincia(cn_url, cn_suffix, testononsel,tendinanormale) {
  if(tendinanormale)
    RS_CaricaDati(cn_url,'cdp' + cn_suffix ,'cdc' + cn_suffix, testononsel);
  else
    RS_CaricaDatiBC(cn_url,'cdp' + cn_suffix ,'cdc' + cn_suffix, testononsel);
}

function RS_CallURL(rsurl,cbfunc) {
    var randomframenumber = Math.round(Math.random() * 10000);
	var iframestr = '<iframe id="ifrcd_' + randomframenumber + '" name="ifrcd_' + randomframenumber + '" onload="window.parent.RS_Callback('+randomframenumber+',\'' + cbfunc +'\');" width="0" height="0" border="0"><\/iframe>';
    var tmpdiv = document.createElement("div");
    tmpdiv.id = "div_" + randomframenumber;
    tmpdiv.name = "div_" + randomframenumber;
    tmpdiv.innerHTML += iframestr;
    document.body.appendChild(tmpdiv);
	var ricobj=MM_findObj("ifrcd_"+randomframenumber);

	var thedoc;
	if (ricobj.contentDocument)
		thedoc=ricobj.contentDocument;
	else if (ricobj.contentWindow)
		thedoc=ricobj.contentWindow.document;
	else
		thedoc=ricobj.document;
	if (thedoc.location.href)
		thedoc.location.href=rsurl;
	else
		ricobj.location.href=rsurl;	
}

function RS_Callback(iframename,cbfunc) {
    var re= /<\S[^>]*>/g;
    var divobj = MM_findObj("div_"+iframename);
    var ricobj = MM_findObj("ifrcd_"+iframename);

	var thedoc;
	if (ricobj.contentDocument)
		thedoc=ricobj.contentDocument;
	else if (ricobj.contentWindow)
		thedoc=ricobj.contentWindow.document;
	else
		thedoc=ricobj.document;

	var rowdata=thedoc.childNodes[0].innerHTML;

	document.body.removeChild(divobj);

	if (rowdata=="SESSION ENDED") {
		alert('SESSION ENDED');
		document.location.reload();
		return;
	}
	
	var arRighe = new Array();
	if (rowdata) {
		rowdata = rowdata.replace(re,"");
		rowdata=rowdata.replace('\n','');
		rowdata=rowdata.replace('\r','');
    		
		var righe=rowdata.split('[EOL]');

		for (x=0; x<righe.length; x++) {
		    var campi=righe[x].split("|");
			arRighe[arRighe.length] = campi;
			
		}
	}
	
	eval("parent." + cbfunc + "(arRighe);");
}