var http_start="";


function checkall(val) {
//   alert("checkall");
//  alert(document.forms.length);
  nform=document.forms.length;
  for(j=0;j<nform;j++){
    thisform=document.forms[j];
	if(thisform)
	with(thisform) {
		for(i=0;i<elements.length;i++) {
			thiselm = elements[i];
			if(thiselm.name == val)
				thiselm.checked = !thiselm.checked
		}//end for
	}//end width
  }//end for
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);



function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


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_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); return x;
}

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 apri(){
   window.open("popup.html","","resizable=no,scrollbars=no,top=250,left=250");
      }

function aprilegenda(){
   window.open("/legenda.php","","resizable=no,scrollbars=no,width=265px,height=430px");
      }

	  
function oc(node) {
	var theDiv = document.getElementById("div" + node);
	var theIcon = document.getElementById("icon" + node);
	
	if (theDiv.style.display == "none") {
		theIcon.src = "/img/meno.gif";
		theDiv.style.display = "";
	} else {
		theIcon.src = "/img/piu.gif";
		theDiv.style.display = "none";
	}
}


function gethelp(fieldname) {
// apre una finestra a cui passa tramite querystring il nome del msg da visualizzare
// ricordarsi per i cointestatari di settare prima della chiamata la variabile localdir
	var pageurl = "/inc/gethelp.php?id=" + fieldname;
	var pageparams = "width=273,height=231,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=50,left=50";
	window.open (pageurl,"HelpWin",pageparams);
}

function ScegliComune(nomecampo,ctr){
	var provincia=eval("(document.formx.PROV_"+nomecampo+".value);");
	var pageparams = "width=273,height=231,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=50,left=50";
	val=showModalDialog("/inc/listacomuni.php?prov="+provincia,"ScegliComune",pageparams);
	//ll='<a href="/inc/listacomuni.php?prov="'+provincia+'"></a>';
	//document.getElementById("link_hide").innerHTML=ll;
	//document.write();
	if(val != "none"){
	    index = val.split("|")
		str_cap="document.formx.CAP_"+nomecampo+".value='"+index[0]+"'";
		eval(str_cap);
		str_citta="document.formx.CITTA_"+nomecampo+".value='"+index[1]+"'";
		eval(str_citta);
	}
}


function cercaprofessioni(ID_TIPO_ATTIVITA,PROFESSIONE,crt){
	str="document.formx."+ID_TIPO_ATTIVITA+".value";
	var id_tipo=eval(str);
	var pageparams = "width=273,height=231,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=50,left=50";
	val=showModalDialog("/inc/cercaprofessioni.php?tipo="+id_tipo,"ScegliProfessione",pageparams);
	if(val != "none"){
	    index = val.split("|")
		str_1="document.formx."+PROFESSIONE+"_ID.value='"+index[0]+"'";
		eval(str_1);
		str_2="document.formx."+PROFESSIONE+"_NOME.value='"+index[1]+"'";
		eval(str_2);
	}
}


//"cercaprodotti('MOTIVO_FINANZIAM','PRODOTTO')"
function cercaprodotti(MOTIVO_FINANZIAM,PRODOTTO){
	id=eval("document.formx."+MOTIVO_FINANZIAM+".value");
	var pageparams = "width=273,height=231,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=50,left=50";
	val=showModalDialog("/inc/cercaprodotti.php?id="+id,"cercaprodotti",pageparams);
//	document.write('<a href="/inc/ccercaprodotti.php?id="'+id+'></a>');
	if(val != "none"){
	    index = val.split("|")
		eval("document.formx."+PRODOTTO+"_VALUE.value='"+index[0]+"'")
		eval("document.formx."+PRODOTTO+"_NOME.value='"+index[1]+"'")
	}
}

//"cercadurate('PRODOTTO_VALUE')"
function cercadurate(PRODOTTO_VALUE){
	id=eval("document.formx."+PRODOTTO_VALUE+".value");
	var pageparams = "width=273,height=231,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=50,left=50";
	val=showModalDialog("/inc/cercadurate.php?id="+id,"cercadurate",pageparams);
//	document.write('<a href="/inc/cercadurate.php?id="'+id+'></a>');
	if(val != "none"){
	    index = val.split("|")
		document.formx.DURATA_ANNI_VALUE.value="'"+index[0]+"'";
		document.formx.DURATA_ANNI_NOME.value="'"+index[1]+"'";
	}
}

//"cercatipiacquisto('PRODOTTO_VALUE')"
function cercatipiacquisto(PRODOTTO_VALUE){
	id=eval("document.formx."+PRODOTTO_VALUE+".value");
	var pageparams = "width=273,height=231,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=50,left=50";
	val=showModalDialog("/inc/cercatipiacquisto.php?id="+id,"cercatipiacquisto",pageparams);
//	document.write('<a href="/inc/cercatipiacquisto.php?id="'+id+'></a>');
	if(val != "none"){
	    index = val.split("|");
		document.formx.TIPOACQUISTO_VALUE.value="'"+index[0]+"'";
		document.formx.TIPOACQUISTO_NOME.value="'"+index[1]+"'";
	}
}


function fnAdd(oList,text,clsname){
   var oNewItem = document.createElement("LI");	
//   document.getElementById(oList).children(0).insertAdjacentElement("BeforeBegin",oNewItem);
   var o=document.getElementById(oList)
  // if(!o) o=document.getElementById(0);
   if(o)
   o.appendChild(oNewItem);
   
   oNewItem.className=clsname;
   switch(clsname){
//   		case "page":break;
//		case "menu":break;
		default: oNewItem.innerHTML = text;
   } // end switch
   
}// end function

function fnAddUL(oList,id,clsname){
   var oNewItem = document.createElement("UL");	
//   document.getElementById(oList).children(0).insertAdjacentElement("BeforeBegin",oNewItem);
   var o=document.getElementById(oList);
//   if(!o) o=document.getElementById(0);
   if(o)
   o.appendChild(oNewItem);
   oNewItem.id = id;
   oNewItem.className=clsname;
   
}


function fnAddblock(id,id_padre,text,clsname){
   	var oNewItem = document.createElement("blockquote");	
//   document.getElementById(oList).children(0).insertAdjacentElement("BeforeBegin",oNewItem);
   var o=document.getElementById(id_padre)
  // if(!o) o=document.getElementById(0);
   if(o)   o.appendChild(oNewItem);
   oNewItem.id=id;
   oNewItem.innerHTML = text;
   oNewItem.className=clsname;
   
}// end function


function refresh(){
	var sURL = unescape(window.location.pathname);
//	alert(sURL);
    alert("operazione con successo");
//	window.location.href = sURL;
    window.location.reload( false );

}


function change_col(idtext,idtable){
	oldcolor="babbeo";
	var newcolor = showModalDialog("../../admin/htmlarea3/popups/select_color.html", oldcolor, "resizable: no; help: no; status: no; scroll: no;");
	document.getElementById(idtext).value='#'+newcolor;
	document.getElementById(idtable).bgColor='#'+newcolor;
}

function change_img(idtext,idimg){
	//var newimg = showModalDialog("/admin/htmlarea3/popups/insert_image.php", document, "resizable: no; help: no; status: no; scroll: no;");
	var newimg = showModalDialog("../../admin/htmlarea3/popups/insertimg1/filedialog.php", document, "resizable: no; help: no; status: no; scroll: no;");
	//alert(newimg.replace(/.*src/,""));
	newimg=newimg.replace(/.*src%3D(.*)%20/,"$1");
    newimg=newimg.replace(/(.*)%20.*/,"$1");
	document.getElementById(idtext).value=newimg;
	document.getElementById(idimg).src=newimg;
}

function change_file(idtext){
	var newimg = showModalDialog("../../admin/htmlarea3/popups/insert_file.php", document, "resizable: no; help: no; status: no; scroll: no;");
	document.getElementById(idtext).value=newimg;
}





