
function apriDialogGallery(val){
//	var g=showModalDialog("popup.php?azione=fotogal&id="+val,"foto gall","resizable: yes; help: no; status: no; scroll: yes; ");
    window.open("popup.php?azione=fotogal&id="+val,"FotoGallery","toolbar=no");
}


function apridialog(idfield){
var e=document.getElementById(idfield);
var e1=document.getElementById("div" + idfield);
//e.value="pippo";

var myTitle = "Insert Today's Date";
var myText = showModalDialog("wnd_tree_menu_pagine.php",myTitle, "resizable: yes; help: no; status: no; scroll: yes; ");
if(myText){
    var mytool_array=myText.split("|");
	e.value=mytool_array[0];
	e1.innerHTML=mytool_array[0]+")  "+mytool_array[1];
}
return false;
}




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/insertimg1/filedialog.php", document, "resizable: no; help: no; status: no; scroll: no;");
	newimg=newimg.replace(/.*src%3D(.*)%20/,"$1");
    newimg=newimg.replace(/(.*)%20.*/,"$1");
	document.getElementById(idtext).value=newimg;
	document.getElementById(idimg).src=newimg;
/*	var outparam=null;
	var manager = "../ExtendedFileManager/manager.php?mode=link";
	Dialog(manager, function(param) {
		if (!param) {	// user must have pressed Cancel
			return false;
		}
		f=document.getElementById(idtext);
		f.value=param.f_href;
		f1=document.getElementById(idimg);
 		f1.src=param.f_href;
	}, outparam);
	*/
    return false;
}

function change_doc(idtext){
	var outparam=null;
	var manager = "../ExtendedFileManager/manager.php?mode=link";
	Dialog(manager, function(param) {
		if (!param) {	// user must have pressed Cancel
			return false;
		}
		f=document.getElementById(idtext);
		
		if(f) f.value=param.f_href;
		else{
		  /*   l="";
		      for(i in document){
			  	l+=i+"  : "+document[i]+" \n";
			  }*/
		 		alert("non trovo "+idtext+" !!");
		}
	}, outparam);
	
    return false;
}




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;
}



var dragapproved=false
var minrestore=0
var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all

function iecompattest(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? 		document.documentElement : document.body
}

function drag_drop(e){
	if (ie5&&dragapproved&&event.button==1){
		document.getElementById("dwindow").style.left=tempx+event.clientX-offsetx+"px"
		document.getElementById("dwindow").style.top=tempy+event.clientY-offsety+"px"
	}else if (ns6&&dragapproved){
		document.getElementById("dwindow").style.left=tempx+e.clientX-offsetx+"px"
		document.getElementById("dwindow").style.top=tempy+e.clientY-offsety+"px"
	}
}

function initializedrag(e){
	offsetx=ie5? event.clientX : e.clientX
	offsety=ie5? event.clientY : e.clientY
	document.getElementById("dwindowcontent").style.display="none" //extra
	tempx=parseInt(document.getElementById("dwindow").style.left)
	tempy=parseInt(document.getElementById("dwindow").style.top)

	dragapproved=true
	document.getElementById("dwindow").onmousemove=drag_drop
}

function loadwindow(url,width,height){
	if (!ie5&&!ns6)
		window.open(url,"","width=width,height=height,scrollbars=1")
	else{
		document.getElementById("dwindow").style.display='block'
		document.getElementById("dwindow").style.width=initialwidth=width+"px"
		document.getElementById("dwindow").style.height=initialheight=height+"px"
		document.getElementById("dwindow").style.left="30px"
		document.getElementById("dwindow").style.top=ns6? window.pageYOffset*1+30+"px" : 		iecompattest().scrollTop*1+30+"px"
		//document.getElementById("cframe").src=url
	}
}

function maximize(){
	if (minrestore==0){
		minrestore=1 //maximize window
		document.getElementById("maxname").setAttribute("src","restore.gif")
		document.getElementById("dwindow").style.width=ns6? window.innerWidth-20+"px" : 			iecompattest().clientWidth+"px"
		document.getElementById("dwindow").style.height=ns6? window.innerHeight-20+"px" : 		iecompattest().clientHeight+"px"
	}else{
		minrestore=0 //restore window
		document.getElementById("maxname").setAttribute("src","max.gif")
		document.getElementById("dwindow").style.width=initialwidth
		document.getElementById("dwindow").style.height=initialheight
	}
	document.getElementById("dwindow").style.left=ns6? window.pageXOffset+"px" : iecompattest().scrollLeft+"px"
	document.getElementById("dwindow").style.top=ns6? window.pageYOffset+"px" : iecompattest().scrollTop+"px"
}

function closeit(){
	document.getElementById("dwindow").style.display="none"
}

function stopdrag(){
	dragapproved=false;
	document.getElementById("dwindow").onmousemove=null;
	document.getElementById("dwindowcontent").style.display="" //extra
}

function showCalendar(id, format) {
  var el = document.getElementById(id);
  if (calendar != null) {
    // we already have some calendar created
    calendar.hide();                 // so we hide it first.
  } else {
    // first-time call, create the calendar.
    var cal = new Calendar(false, null, selected, closeHandler);
    // uncomment the following line to hide the week numbers
    // cal.weekNumbers = false;
    calendar = cal;                  // remember it in the global var
    cal.setRange(1900, 2070);        // min/max year allowed.
    cal.create();
  }
  calendar.setDateFormat(format);    // set the specified date format
  calendar.parseDate(el.value);      // try to parse the text in field
  calendar.sel = el;                 // inform it what input field we use

  // the reference element that we pass to showAtElement is the button that
  // triggers the calendar.  In this example we align the calendar bottom-right
  // to the button.
  calendar.showAtElement(el.nextSibling, "Br");        // show the calendar

  return false;
}



