var timerP;
var timerCP;
var timerSP;
var arraynoteril=new Array();
var arrayservizi=new Array();
function ApriAggiornamenti()
{
	//javascript:Loader('riservata/aggiornamenti/download.php','framecentrale',false);
	
	FiltraperIV();		
//	if (/Firefox[\/\s](\d+.\d+)/.test(navigator.userAgent))
//	{
//	    alert("vado");
//	    ChiediPatch();
//	    alert("arrivato");
//	}
//	else
/*	{
	    alert("vado");
	    var timerSP = setTimeout(function() {alert("lachiedo");ChiediPatch();},500);
	    alert("OK");
	}
*/	
	
}
function ApriNotePerServizio()
{
	var rispostaric=new Array();
	var rispostona=new Array();	
//	alert("CP2");	
	var mandoquesto=CreaRichiestaNotePerServizio();
//	alert(printArray(mandoquesto));
	rispostona=SynchPOSTRequestA("../../PHPSER.php",mandoquesto);
//	alert("rispostona: "+(rispostona));
	rispostaric=PHP_Unserialize(rispostona);
//	alert("rispostaric: "+printArray(rispostaric));
//	rispostaric=rispostaric["siv"];
	if (rispostaric["errore"])
	{
	  info= rispostaric["errore"];
	  alert(info);
//	  javascript:Chiudi();
	  return;
//	  alert(info);
	}
	else
	{
	//    alert("vado con PDF");
	   window.open("pdf.php?pdf="+rispostaric['data']+"","_new"); 
	}
	
}
function ScaricaServiziPerNote()
{
	var rispostaric=new Array();
	var rispostona=new Array();	
//	alert("CP2");	
	var mandoquesto=CreaRichiestaServiziPerNote();
//	alert(printArray(mandoquesto));
	rispostona=SynchPOSTRequestA("../../PHPSER.php",mandoquesto);
//	alert("rispostona: "+(rispostona));
	rispostaric=PHP_Unserialize(rispostona);
//	alert("rispostaric: "+printArray(rispostaric));
//	rispostaric=rispostaric["siv"];
	if (rispostaric["errore"])
	{
	  info = rispostaric["errore"];
	  alert(info);
	//  javascript:Chiudi();
	  return;
	}
	else
	{
	  rispostaric=rispostaric["siv"];
//	  alert("rispostaric [servizi]: "+printArray(rispostaric["servizi"]));
	  arrayservizi=rispostaric["servizi"];
	  arrayservizi=arrayservizi["servizio"];
//	  alert("Arrayservizi: "+printArray(rispostaric["servizi"]));
//	   alert("Arrayservizi: "+printArray(rispostaric["servizi"]));
	  doc=undefined;
	   docum=document.getElementById("framecentrale");
	  if (!docum || docum==undefined)
	      docum=parent.document.getElementById("framecentrale");
	  if (docum && docum!=undefined)  
	      doc=docum.contentWindow.document.getElementById("iservizidellenote");
	  
	  if (arrayservizi[0]!=undefined && is_array(arrayservizi))
	  {
	//	 alert("arrayservizi[0]!=undefined "+printArray(rispostaric["servizi"]));
		for (i in arrayservizi)
		{
		  des="";
		  des=arrayservizi[i]['descri'];
		  id="servizi";
		  id+=""+arrayservizi[i]['codice']+"";
		  info="<input type='hidden' value=\""+des+"\" id ="+id+" name= "+id+">";
		   if (doc && doc!=undefined)
		   {
	//	    alert(info);  
		    doc.innerHTML+=info;
		   }  
	//	    else alert("doc not found");
		}
	  }
	  else
	  {
	//	alert("arrayservizi[0]===undefined "+printArray(rispostaric["servizi"]));
		des="";
		des=arrayservizi['descri'];
		id="servizi";
		id+=""+arrayservizi['codice']+"";
		info="<input type='hidden' value=\""+des+"\" id ="+id+" name= "+id+">";
		if (doc && doc!=undefined)
		{
	//	    alert(info);  
		    doc.innerHTML+=info;
		}  
	//	else alert("doc not found");
	  }
	}
	
}
function ScaricaTipologieLavori()
{
	var rispostaric=new Array();
	var rispostona=new Array();	
//	alert("CP2");	
	var mandoquesto=CreaRichiestaTipologieLavori();
//	alert(printArray(mandoquesto));
	rispostona=SynchPOSTRequestA("../../PHPSER.php",mandoquesto);
//	alert("rispostona: "+(rispostona));
	rispostaric=PHP_Unserialize(rispostona);
//	alert("rispostaric: "+printArray(rispostaric));
//	rispostaric=rispostaric["siv"];
	if (rispostaric["errore"])
	{
	  info = rispostaric["errore"];
	  alert(info);
	//  javascript:Chiudi();
	  return;
	}
	else
	{
	  rispostaric=rispostaric["siv"];
//	  alert("rispostaric [servizi]: "+printArray(rispostaric["servizi"]));
	  arrayservizi=rispostaric["tipi"];
	  arrayservizi=arrayservizi["tipo"];
//	  alert("Arrayservizi: "+printArray(rispostaric["servizi"]));
//	   alert("Arrayservizi: "+printArray(rispostaric["servizi"]));
	  doc=undefined;
	   docum=document.getElementById("framecentrale");
	  if (!docum || docum==undefined)
	      docum=parent.document.getElementById("framecentrale");
	  if (docum && docum!=undefined)  
	      doc=docum.contentWindow.document.getElementById("tipologielavori");
	  
	  if (arrayservizi[0]!=undefined && is_array(arrayservizi))
	  {
	//	 alert("arrayservizi[0]!=undefined "+printArray(rispostaric["servizi"]));
		for (i in arrayservizi)
		{
		  des="";
		  des=arrayservizi[i]['descri'];
		  id="tipolavori";
		  id+=""+arrayservizi[i]['codice']+"";
		  info="<input type='hidden' value=\""+des+"\" id ="+id+" name= "+id+">";
		   if (doc && doc!=undefined)
		   {
	//	    alert(info);  
		    doc.innerHTML+=info;
		   }  
	//	    else alert("doc not found");
		}
	  }
	  else
	  {
	//	alert("arrayservizi[0]===undefined "+printArray(rispostaric["servizi"]));
		des="";
		des=arrayservizi['descri'];
		id="tipolavori";
		id+=""+arrayservizi['codice']+"";
		info="<input type='hidden' value=\""+des+"\" id ="+id+" name= "+id+">";
		if (doc && doc!=undefined)
		{
	//	    alert(info);  
		    doc.innerHTML+=info;
		}  
	//	else alert("doc not found");
	  }
	}
	
}
function MostraAggiornamenti()
{
	//javascript:Loader('riservata/aggiornamenti/download.php','framecentrale',false);
	Hide("display_list");
	docum=document.getElementById("framecentrale");
	if (!docum || docum==undefined)
	  docum=parent.document.getElementById("framecentrale");
	if (docum && docum!=undefined)
	{
		docum.style.height="750px";
		docum.style.backgroundColor="transparent";
		docum.style.border="0px";
		docum.style.frameborder="0px";
		docum.src="";
		docum.style.width="100%";
		docum.src='riservata/aggiornamenti/download.php';
		Mostra("framecentrale");	
	}
	
}
function FiltraperIV()
{
    javascript:Chiudi();
    StoppaFader();
    var iv=0;
     
    var doc1=document.getElementById("ivhidden");
    if (!doc1 || doc1==undefined)
      doc1=parent.document.getElementById("ivhidden");
    if (doc1 && doc1!=undefined)	    
	iv=doc1.value;
    var riv=0;
    doc1=document.getElementById("rivhidden");
    if (!doc1 || doc1==undefined)
      doc1=parent.document.getElementById("rivhidden");
    if (doc1 && doc1!=undefined)	    
	riv=doc1.value;
 //   alert("iv: "+iv+"");
    if (iv==1 || iv=='1' || riv=='1' || riv==1)
    {
      var info="<div class=\"consfondo\" align=\"justify\" style=\"margin:80px; margin-top:0; padding:20px; \"><br>\
	<table  align=\"center\" cellspacing=0  cellpadding=2 bgcolor=\"#28359B\" style=\"padding:40px; width:600px;\" >\
					<tr align=center >\
						<td align=\"center\" colspan=\"2\" >\
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color=\"#FFFFFF\" size=\"3\">SELEZIONE SIGLA E FILIALE per UTENTI RIVENDITORI <br><br></font><font color=\"#FFFFFF\" size=\"2\"> Cliccare INVIA lasciando vuoti i campi per ottenere i dati installazione GPL</font></b><br><br>\
						</td>\
					</tr>\
					<tr>\
						<td align=\"center\" colspan=\"2\" style=\" border-top: 1px solid #eeeeee;\">\<br><font   color=\"#FFFFFF\">\
						SIGLA&nbsp;&nbsp;<input type=\"text\" id=\"sigla_a\" name=\"sigla_a\" MAXLENGTH='3' style=\"width: 80;\">&nbsp;&nbsp;&nbsp;\
						FILIALE&nbsp;&nbsp;<input type=\"text\" id=\"filiale_a\" name=\"filiale_a\" MAXLENGTH='3' style=\"width: 80;\">\
						</td>\
					</tr>\
					<tr>\
						<td colspan=2 align=right>\
							<hr>\
							<a href=\"javascript:RegistraSiglaFiliale()\" onmouseover=\"image2.src='images/inviaMO.png';\"\
								onmouseout=\"image2.src='images/invia.png'; \">\
								<img name=\"image2\" src=\"images/invia.png\" border=0>\
							</a>\
							<hr>\
								<input type=\"hidden\" name=\"inviato\" value=\"si\">\
							<br>\
						</td>\
					</tr>\
				</table>\
			</div>";
    //	alert(risparray["errore"]);
    //else
    //	alert("daticorretti: "+risparray["daticorretti"]+"\ncodcli" +risparray["codcli"]+"\nmail"+ risparray["mail"]+" dest"+risparray["coddest"]);
      dok2=document.getElementById("display_list");
      if (!dok2 || dok2==undefined)
	dok2=parent.document.getElementById("display_list");
      if (dok2 && dok2!=undefined)
      {
//	alert("DOK2 C'èèèè");
	dok2.innerHTML=(info);
	dok2.style.display="block";
	dok2.style.visibility="visible";
      } 
 //     else alert("DOK2?");	
    }
    else
    {
      MostraAggiornamenti();
    }
	
}
function RegistraSiglaFiliale()
{
  //crea gli input type hidden e ci mette SIGLA E FILIALE	
    var sigagg="";
    var filagg="";
    var doc1=document.getElementById("sigla_a");
    if (doc1 && doc1!=undefined)
    {
       sigagg=doc1.value;
//       alert("BECCATA: *"+doc1.value+"*");	  
    }
//    else
//    alert("NON BECCATA: *"+doc1.value+"*");
    doc1=document.getElementById("filiale_a");
    if (doc1 && doc1!=undefined)
	filagg=doc1.value;
    if (sigagg=="")
	sigagg="SRL";    
    doc1=undefined;
    doc1=parent.document.getElementById("SIGLA_AGG");
    if (doc1 && doc1!=undefined)
      doc1.value=sigagg;
    doc1=parent.document.getElementById("FILIALE_AGG");
    if (doc1 && doc1!=undefined)
      doc1.value=filagg;

    MostraAggiornamenti();
}
function ChiediPatch()
{
//	alert("CP1");
	var iv=0;
	var doc1=document.getElementById("ivhidden");
	if (!doc1 || doc1==undefined)
	  doc1=parent.document.getElementById("ivhidden");
	if (doc1 && doc1!=undefined)	    
	    iv=doc1.value;
	var riv=0;
	doc1=document.getElementById("rivhidden");
	if (!doc1 || doc1==undefined)
	  doc1=parent.document.getElementById("rivhidden");
	if (doc1 && doc1!=undefined)	    
	    riv=doc1.value;
//	alert(" IV: "+doc1.value);
//	alert(" iv: "+iv)
	var rispostaric=new Array();
	var rispostona=new Array();	
//	alert("CP2");	
	var mandoquesto=CreaRichiestaChiediPatch();
//	alert(printArray(mandoquesto));
	rispostona=SynchPOSTRequestA("../../PHPSER.php",mandoquesto);
//	alert("rispostona: "+(rispostona));
	rispostaric=PHP_Unserialize(rispostona);
//	alert("rispostaric: "+printArray(rispostaric));
	
//	alert("rispostaric [siv]: "+printArray(rispostaric));
	if (rispostaric["errore"])
	{
	  info= rispostaric["errore"];
	  alert(info);
	 // FiltraperIV();
	  javascript:Chiudi();
	//  parent.document.getElementById("display_list").postMessage("RICARICAPAGINA",*);
	  return;
//	  alert(info);
	}
	else
	{
	  rispostaric=rispostaric["siv"];
	  doc=undefined;
	  docum=document.getElementById("framecentrale");
	  if (!docum || docum==undefined)
	  {
	//    alert("not found primo");
	     docum=parent.document.getElementById("framecentrale");
	  }
	  if (docum && docum!=undefined) 
	  {
	    doc=docum.contentWindow.document.getElementById("rilascio");
	  }
	//  else alert("not found secondo");
	  if (doc && doc!=undefined)
	  {
	    if (rispostaric["rilascio"] && rispostaric["rilascio"]!="")
	      doc.value=rispostaric["rilascio"];
	    else 
	      doc.value="N.P.";
	    if (iv==1 || iv=='1' || ( (riv==1 || riv=='1') && (rispostaric["changeril"]==1 || rispostaric["changeril"]=='1') ) )
	    {
	      doc.readOnly=false;
	    }
	  }
	
	//  else alert("not found DOC");
	  doc=undefined;
	  if (docum && docum!=undefined)
	     doc=docum.contentWindow.document.getElementById("datarilascio");
	  if (doc && doc!=undefined)
	  {
	    if (rispostaric["data-inst"] && rispostaric["data-inst"]!="")
	      doc.value=rispostaric["data-inst"];
	    else
	      doc.value="N.P.";	
	    doc.display="block";
	    doc.visibility="visible";
//	    alert("data-inst: "+doc.innerHTML);
	  } 
	//   else alert("not found DOC2");
	  doc=undefined;
	  if (docum && docum!=undefined)
	     doc=docum.contentWindow.document.getElementById("dataultimorilascio");
	  if (doc && doc!=undefined)
	  {
	    if (rispostaric["data-new"] && rispostaric["data-new"]!="")
	      doc.innerHTML=rispostaric["data-new"];
	    else 
	      doc.innerHTML="N.P.";
	    doc.display="block";
	    doc.visibility="visible";
//	    alert("data-new: "+doc.innerHTML);
	  } 
	//     else alert("not found DOC3");
	  doc=undefined;
	  if (docum && docum!=undefined)
	     doc=docum.contentWindow.document.getElementById("ultimorilascio");
	  if (doc && doc!=undefined)
	  {
	    if (rispostaric["ril-new"] && rispostaric["ril-new"]!="")
	      doc.innerHTML=rispostaric["ril-new"];
	    else 
	      doc.innerHTML="N.P.";
	    doc.display="block";
	    doc.visibility="visible";
//	    alert("ril-new: "+doc.innerHTML);
	  }
	//     else alert("not found DOC4");
	  doc=undefined;
	  if (docum && docum!=undefined)
	     doc=docum.contentWindow.document.getElementById("ultril");
	  if (doc && doc!=undefined)
	  {
	    if (rispostaric["ril-new"] && rispostaric["ril-new"]!="")
	      doc.value=rispostaric["ril-new"];
	    else 
	      doc.value="N.P.";
	    doc.display="block";
	    doc.visibility="visible";
	  }
	//  alert("Vado con note RIL:");
	  var count=0;
	  doc=undefined;
	  if (docum && docum!=undefined)
	    doc=docum.contentWindow.document.getElementById("lenotedeirilasci");
	  if (rispostaric["rilasci"] && rispostaric["rilasci"]!=undefined && is_array(rispostaric["rilasci"]))
	  {
	      arraynoteril=rispostaric["rilasci"];
	//       alert("arraynoteRIL: "+printArray(arraynoteril)+"");
	      if (arraynoteril["rilascio"] && arraynoteril["rilascio"]!=undefined && is_array(arraynoteril["rilascio"]))
	      {
	//	alert("rispostaric: "+printArray(rispostaric)+"");
		arraynoteril=arraynoteril["rilascio"];
		doc=undefined;
		if (docum && docum!=undefined)
		  doc=docum.contentWindow.document.getElementById("lenotedeirilasci");
	//	alert("arraynoteRIL: "+printArray(arraynoteril)+"");
		
		if (arraynoteril[0]!=undefined && is_array(arraynoteril))
		{
		    for (i in arraynoteril)
		    {
		//	alert("I: "+i+" ARRAYNOTERIL: "+arraynoteril[i]+"");
			id="noteril";
			id+=""+i+"";
			info="<input type='hidden' value="+arraynoteril[i]+" id ="+id+" name= "+id+">";
			if (doc && doc!=undefined)
			{
			  doc.innerHTML+=info;
			  count++;
			}
		    }
		  // else alert("doc not found");
		}
		else
		{	
		    id="noteril";
		    id+="0";
		    info="<input type='hidden' value="+rispostaric["ril-new"]+" id ="+id+" name= "+id+">";
		    if (doc && doc!=undefined)
		    {
		  //   alert(info);  
		      doc.innerHTML+=info;
		      count++;
		    }  
		  // else alert("doc not found");
		}
	      }
	      else 
	      {
		    id="noteril";
		    id+="0";
		    info="<input type='hidden' value="+rispostaric["ril-new"]+" id ="+id+" name= "+id+">";
		    if (doc && doc!=undefined)
		    {
		  //   alert(info);  
		      doc.innerHTML+=info;
		      count++;
		    }  
	      }
	  }
	  if (count==0)
	  {
	      doc=undefined;
	      if (docum && docum!=undefined)
		  doc=docum.contentWindow.document.getElementById("lenotedeirilasci");
	      if (doc && doc!=undefined)
	      {
		var i="0";
		id="noteril";
		id+=""+i+"";
		info="<input type='hidden' value="+rispostaric["ril-new"]+" id ="+id+" name= "+id+">";
		if (doc && doc!=undefined)
		{
		  doc.innerHTML+=info;
		}
	      }
	  }
	//  alert("arraynoteRIL: "+printArray(arraynoteril)+"");
	}
	StatoPatch();	
//	alert("Scarico servizi per note");
	ScaricaServiziPerNote();
	ScaricaTipologieLavori();
//	alert("FATTO  per note");
//	alert("Fatto statopatch");
	
}
function StatoPatch()
{
	var rispostaric=new Array();
	var rispostona=new Array();	
//	alert("SP1");	
	var ultima="";
	var attuale="";
	doc=undefined;

	var iv=0;
	var doc1=document.getElementById("ivhidden");
	if (!doc1 || doc1==undefined)
	  doc1=parent.document.getElementById("ivhidden");
	if (doc1 && doc1!=undefined)	    
	    iv=doc1.value;
	var riv=0;
	doc1=document.getElementById("rivhidden");
	if (!doc1 || doc1==undefined)
	  doc1=parent.document.getElementById("rivhidden");
	if (doc1 && doc1!=undefined)	    
	    riv=doc1.value;
    //   alert("iv: "+iv+"");
	if (iv==1 || iv=='1' || riv==1 || riv=='1') 
	{
	  if (docum && docum!=undefined)
	      doc=docum.contentWindow.document.getElementById("siglafiliale");
	  if (doc && doc!=undefined)
	  {
	      var filagg="";
	      var sigagg="";
	      doc1=undefined;
	      doc1=parent.document.getElementById("SIGLA_AGG");
	      if (doc1 && doc1!=undefined)
		sigagg=doc1.value;
	      doc1=parent.document.getElementById("FILIALE_AGG");
	      if (doc1 && doc1!=undefined)
		filagg=doc1.value;
	      doc.innerHTML="<div style='border:1px solid white; width:150px;'><font size='2' color='white'>Sigla: <b>"+sigagg+"</b> Filiale: <b>"+filagg+"</b></font></div>";
	      doc.display="block";
	      doc.visibility="visible";
	  }
	}
	if (docum && docum!=undefined)
	     doc=docum.contentWindow.document.getElementById("ultril");
	if (doc && doc!=undefined)
	{
	    ultima=doc.value;
	   
	}
	if (docum && docum!=undefined)
	    doc=docum.contentWindow.document.getElementById("rilascio");
	if (doc && doc!=undefined)
	{
	  attuale= doc.value;
	
	}
//	alert("ultima: "+ultima+"attuale: "+attuale+"");
	if (ultima==attuale && ultima!="" && attuale!="" && ultima!="undefined" && attuale!="undefined" && ultima!="N.P." && attuale!="N.P.")
	{
	  if (!docum || docum==undefined)
	    docum=parent.document.getElementById("framecentrale");
	  if (docum && docum!=undefined)  
	    doc=docum.contentWindow.document.getElementById("personal");
	  if (doc && doc!=undefined)
	  {
	    doc.innerHTML="<br><font size='3' ><b>Congratulazioni,<br> il vostro sistema risulta aggiornato all'ultima versione SIV disponibile.</b></font><br><br>";
	    doc.display="block";
	    doc.visibility="visible";
	  //    	alert("A video patch pronta");
	  } 
	  if (!docum || docum==undefined)
	    docum=parent.document.getElementById("framecentrale");
	  if (docum && docum!=undefined)  
	    doc=docum.contentWindow.document.getElementById("downloadb");
	  if (doc && doc!=undefined)
	  {
	        doc.innerHTML="";
		doc.value="";
		doc.display="block";
		doc.visibility="visible";	    
	  }
	  
	}  
	else
	{
	  var mandoquesto=CreaRichiestaStatoPatch();
  //	alert(printArray(mandoquesto));
	  rispostona=SynchPOSTRequestA("../../PHPSER.php",mandoquesto);
  //	alert("rispostona: "+(rispostona));
  //	alert("SP2");	
	  rispostaric=PHP_Unserialize(rispostona);
  //	alert("rispostaric: "+printArray(rispostaric));
	  rispostaric=rispostaric["siv"];
//	  alert("rispostaric: "+printArray(rispostaric));
  //	alert("SP3");	
	  if (rispostaric["errore"])
	  {
	    info= rispostaric["errore"];
	    alert(info);
	  //  javascript:Chiudi();
	  //  return;
	    //  docum=document.getElementById("framecentrale");
	    //  if (docum && docum!=undefined)
	    //     doc=framecentrale.document.getElementById("personal");
	    //  else
	    doc=undefined;
	    docum=document.getElementById("framecentrale");
	    if (!docum || docum==undefined)
	      docum=parent.document.getElementById("framecentrale");
	    if (docum && docum!=undefined)  
	      doc=docum.contentWindow.document.getElementById("personal");

	    if (doc && doc!=undefined)
	    {
	      doc.innerHTML="<br><font size='3' color=\"red\"><b>Informazioni non pervenute correttamente. Ritentare. Se si ripete contattare l'assistenza</font></b><br><br>";
	      doc.display="block";
	      doc.visibility="visible";
	    } 

	  }
	  else
	  {
	    if (rispostaric["iniziato"]==0 || rispostaric["iniziato"]=="0") 
	    {
		doc=undefined;
		docum=document.getElementById("framecentrale");
		if (!docum || docum==undefined)
		  docum=parent.document.getElementById("framecentrale");
		if (docum && docum!=undefined)  
		  doc=docum.contentWindow.document.getElementById("personal");
		if (doc && doc!=undefined)
		{
		  doc.innerHTML="<br><font size='3' ><b>Se la versione installata non risulta quella sopra indicata contattate l'assistenza.</font></b><br><br>";
		  doc.display="block";
		  doc.visibility="visible";
		} 
	    //   alert("INIZIATO = ZERO ");
		return;
	    }
	    else if ((rispostaric["iniziato"]==1 || rispostaric["iniziato"]=="1") && (rispostaric["finito"]=="0" || rispostaric["finito"]==0) )
	    {
		
		doc=undefined;
		docum=document.getElementById("framecentrale");
		if (!docum || docum==undefined)
		  docum=parent.document.getElementById("framecentrale");
		if (docum && docum!=undefined)  
		  doc=docum.contentWindow.document.getElementById("personal");
		if (doc && doc!=undefined)
		{
		  doc.innerHTML="<font size='3' ><center><blink><b>Preparazione aggiornamento in corso..</b></blink><center><img src=\"../../images/aspetta.gif\" border=0 width='120px' height='80px'> </center> Il processo potrebbe richiedere alcuni minuti.<br></center></font>";
		  doc.display="block";
		  doc.visibility="visible";
		}
		setTimeout(StatoPatch,10000);
  //	      docum=document.getElementById("framecentrale");
  //	      if (docum && docum!=undefined)
  //		doc=docum.contentWindow.document.getElementById("scarichi");
  //	      else
  //		doc=document.getElementById("scarichi");
  //	      if (doc && doc!=undefined)
  //	      {
  //		doc.display="block";
  //		doc.visibility="hidden";
  //	      } 
	    }
	    else if (rispostaric["finito"]!=0 && rispostaric["finito"]!="0") 
	    {
	    //    alert("FINITO = 1 ");
		doc=undefined;
		docum=document.getElementById("framecentrale");
		if (!docum || docum==undefined)
		  docum=parent.document.getElementById("framecentrale");
		if (docum && docum!=undefined)  
		  doc=docum.contentWindow.document.getElementById("directoryhidden");
		if (doc && doc!=undefined)
		{
		  dir = rispostaric["directory"];
	  //	dir=dir.replace("/user/ivweb/","");
		  doc.value=dir;
	      //   alert("directoryhidden OK "+dir+" !!");
		}
		doc=undefined;	    
		if (!docum || docum==undefined)
		  docum=parent.document.getElementById("framecentrale");
		if (docum && docum!=undefined)  
		  doc=docum.contentWindow.document.getElementById("personal");
		if (doc && doc!=undefined)
		{
		  doc.innerHTML="<font size='3' ><center><blink><font size='2' color='blue'><b>L'aggiornamento &egrave; pronto per essere scaricato.</b></font></blink><center><img src=\"../../images/aspetta.gif\" border=0 width='120px' height='80px'> </center> Il Download inizier&agrave; tra pochi istanti.<br></center></font>";
		  doc.display="block";
		  doc.visibility="visible";
	    //    	alert("A video patch pronta");
		}
	    //    docum=document.getElementById("framecentrale");
	    //    if (docum && docum!=undefined)
	    //	doc=docum.contentWindow.document.getElementById("scarichi");
	    //    else
	    //	doc=document.getElementById("scarichi");
	    //    if (doc && doc!=undefined)
	    //    {
	    //	doc.style.display="block";
	    //	doc.style.visibility="visible";
	    //	doc.style.zIndex="100";
	    //	alert("mostroscarichi");
	    //     }
	    //   alert("Apro download"); 
	      setTimeout(ApriDownload,1000);
	    //   alert("Aperto download");   
	    }
	  }
	}
	//alert("rispostaric: "+printArray(rispostaric));
}
function ScaricaPatch()
{
	var rispostaric=new Array();
	var rispostona=new Array();	
	var mandoquesto=CreaRichiestaScaricaPatch();
//	alert(printArray(mandoquesto));
	rispostona=SynchPOSTRequestA("../../PHPSER.php",mandoquesto);
//	alert("rispostona: "+(rispostona));
	rispostaric=PHP_Unserialize(rispostona);
//	rispostaric=rispostaric["siv"];
//	alert("rispostaric: "+printArray(rispostaric));
	if (rispostaric["errore"])
	{
	  info="Attenzione\n";
	  info+= rispostaric["errore"];
	  alert(info);
	}
	else
	{
	  StatoPatch();	
	}
	  
	//alert("rispostaric: "+printArray(rispostaric));
}
function CreaRichiestaStatoPatch()
{
	var chiedop = new Array();
	chiedop["azione"]="statopatch";
	var ditta="";
	doc1=parent.document.getElementById("dittahidden");
	if (doc1 && doc1!=undefined)
	    ditta=doc1.value;
	chiedop["ditta"]=ditta;
	doc1=undefined;
	doc1=parent.document.getElementById("SIGLA_AGG");
	if (doc1 && doc1!=undefined)
	    chiedop["sigla_agg"]=doc1.value;
	doc1=parent.document.getElementById("FILIALE_AGG");
	if (doc1 && doc1!=undefined)
	    chiedop["filiale_agg"]=doc1.value;
	docID=parent.document.getElementById("ID_SIV");
	chiedop["id"]=docID.value;
	doc=parent.document.getElementById("ID_UTE");
	if (doc && doc!=undefined)
	    chiedop["id-ute"]=doc.value;
	return chiedop;
}
function CreaRichiestaNotePerServizio()
{
	var chiedop = new Array();
	chiedop["azione"]="lavorixservizio";
	var ditta="";
	doc1=parent.document.getElementById("dittahidden");
	if (doc1 && doc1!=undefined)
	    ditta=doc1.value;
	chiedop["ditta"]=ditta;
	docID=parent.document.getElementById("ID_SIV");
	chiedop["id"]=docID.value;
	doc=parent.document.getElementById("ID_UTE");
	if (doc && doc!=undefined)
	    chiedop["id-ute"]=doc.value;
	doc1=undefined;
	doc1=parent.document.getElementById("SIGLA_AGG");
	if (doc1 && doc1!=undefined)
	    chiedop["sigla_agg"]=doc1.value;
	doc1=parent.document.getElementById("FILIALE_AGG");
	if (doc1 && doc1!=undefined)
	    chiedop["filiale_agg"]=doc1.value;  
	var i=0;
	var finite=0;
	var primanota="";
	var ultimanota="";  
	while (!finite)
	{
	  id="noteril";
	  id+=""+i+"";
	  docn=document.getElementById(id);
	  if (docn && docn!=undefined)
	  {
	    if (i==0)
	      primanota=docn.value;
	    else
	      ultimanota=docn.value;
	  }
	  else finite=1;
	  i++;
	}
	if (ultimanota==undefined || ultimanota=="undefined")
	    ultimanota="";
	if (primanota==undefined || primanota=="undefined")
	    primanota="";
	if (ultimanota=="")
	  ultimanota=primanota;
	chiedop["da-patch"]=primanota;
	chiedop["a-patch"]=ultimanota;
	return chiedop;
}
function CreaRichiestaServiziPerNote()
{
	var chiedop = new Array();
	chiedop["azione"]="servizixlavori";
	var ditta="";
	doc1=parent.document.getElementById("dittahidden");
	if (doc1 && doc1!=undefined)
	    ditta=doc1.value;
	chiedop["ditta"]=ditta;
	docID=parent.document.getElementById("ID_SIV");
	chiedop["id"]=docID.value;
	doc=parent.document.getElementById("ID_UTE");
	if (doc && doc!=undefined)
	    chiedop["id-ute"]=doc.value;
	doc1=undefined;
	doc1=parent.document.getElementById("SIGLA_AGG");
	if (doc1 && doc1!=undefined)
	    chiedop["sigla_agg"]=doc1.value;
	doc1=parent.document.getElementById("FILIALE_AGG");
	if (doc1 && doc1!=undefined)
	    chiedop["filiale_agg"]=doc1.value;
	var i=0;
	var finite=0;
	var primanota="";
	var ultimanota="";  
	while (!finite)
	{
	  id="noteril";
	  id+=""+i+"";
	  docn=document.getElementById(id);
	  if (docn && docn!=undefined)
	  {
	    if (i==0)
	      primanota=docn.value;
	    else
	      ultimanota=docn.value;
	  }
	  else finite=1;
	  i++;
	}
	if (ultimanota==undefined || ultimanota=="undefined")
	    ultimanota="";
	if (primanota==undefined || primanota=="undefined")
	    primanota="";
	if (ultimanota=="")
	  ultimanota=primanota;
	chiedop["da-patch"]=primanota;
	chiedop["a-patch"]=ultimanota;
	return chiedop;
}
function CreaRichiestaTipologieLavori()
{
	var chiedop = new Array();
	chiedop["azione"]="tipologielavori";
	var ditta="";
	doc1=parent.document.getElementById("dittahidden");
	if (doc1 && doc1!=undefined)
	    ditta=doc1.value;
	chiedop["ditta"]=ditta;
	docID=parent.document.getElementById("ID_SIV");
	chiedop["id"]=docID.value;
	doc=parent.document.getElementById("ID_UTE");
	if (doc && doc!=undefined)
	    chiedop["id-ute"]=doc.value;
	doc1=undefined;
	doc1=parent.document.getElementById("SIGLA_AGG");
	if (doc1 && doc1!=undefined)
	    chiedop["sigla_agg"]=doc1.value;
	doc1=parent.document.getElementById("FILIALE_AGG");
	if (doc1 && doc1!=undefined)
	    chiedop["filiale_agg"]=doc1.value;
	var i=0;
	var finite=0;
	var primanota="";
	var ultimanota="";  
	while (!finite)
	{
	  id="noteril";
	  id+=""+i+"";
	  docn=document.getElementById(id);
	  if (docn && docn!=undefined)
	  {
	    if (i==0)
	      primanota=docn.value;
	    else
	      ultimanota=docn.value;
	  }
	  else finite=1;
	  i++;
	}
	if (ultimanota==undefined || ultimanota=="undefined")
	    ultimanota="";
	if (primanota==undefined || primanota=="undefined")
	    primanota="";
	if (ultimanota=="")
	  ultimanota=primanota;
	chiedop["da-patch"]=primanota;
	chiedop["a-patch"]=ultimanota;
	return chiedop;
}

function CreaRichiestaChiediPatch()
{
	var chiedop = new Array();
	chiedop["azione"]="askpatch";
	var ditta="";
	doc1=parent.document.getElementById("dittahidden");
	if (doc1 && doc1!=undefined)
	    ditta=doc1.value;
	doc1=parent.document.getElementById("SIGLA_AGG");
	if (doc1 && doc1!=undefined)
	    chiedop["sigla_agg"]=doc1.value;
	doc1=parent.document.getElementById("FILIALE_AGG");
	if (doc1 && doc1!=undefined)
	    chiedop["filiale_agg"]=doc1.value;
	chiedop["ditta"]=ditta;
	docID=parent.document.getElementById("ID_SIV");
	chiedop["id"]=docID.value;
	doc=parent.document.getElementById("ID_UTE");
	if (doc && doc!=undefined)
		chiedop["id-ute"]=doc.value;
	return chiedop;
}
function CreaRichiestaScaricaPatch()
{
	var chiedop = new Array();
	chiedop["azione"]="scaricapatch";
	var ditta="";
	doc1=parent.document.getElementById("dittahidden");
	if (doc1 && doc1!=undefined)
	    ditta=doc1.value;
	chiedop["ditta"]=ditta;
	doc1=parent.document.getElementById("SIGLA_AGG");
	if (doc1 && doc1!=undefined)
	    chiedop["sigla_agg"]=doc1.value;
	doc1=parent.document.getElementById("FILIALE_AGG");
	if (doc1 && doc1!=undefined)
	    chiedop["filiale_agg"]=doc1.value;
	doc1=document.getElementById("rilascio");
	if (doc1 && doc1!=undefined)
	    chiedop["patch"]=doc1.value;
	docID=parent.document.getElementById("ID_SIV");
	chiedop["id"]=docID.value;
	doc=parent.document.getElementById("ID_UTE");
	if (doc && doc!=undefined)
		chiedop["id-ute"]=doc.value;
	return chiedop;
}
function ApriNote(SOLONUOVE)
{
//	alert("SOLONUOVE: "+SOLONUOVE+"");
	var iv=0;
	var doc1=document.getElementById("ivhidden");
	if (!doc1 || doc1==undefined)
	  doc1=parent.document.getElementById("ivhidden");
	if (doc1 && doc1!=undefined)	    
	  iv=doc1.value;
 //   alert("iv: "+iv+"");
	var riv=0;
	doc1=document.getElementById("rivhidden");
	if (!doc1 || doc1==undefined)
	  doc1=parent.document.getElementById("rivhidden");
	if (doc1 && doc1!=undefined)	    
	    riv=doc1.value;
	var passo=new Array();
	var mirende="";
	var versione="";
	var azione="";
	var doc1=undefined;
	doc=undefined;
	
	docum=document.getElementById("framecentrale");
	if (!docum || docum==undefined)
	  docum=parent.document.getElementById("framecentrale");
	if (docum && docum!=undefined)  
	  doc=docum.contentWindow.document.getElementById("idpernote");

	if (doc && doc!=undefined)
	{
	    doc1=parent.document.getElementById("dittahidden");
	    if (doc1 && doc1!=undefined)
	    {
	      info="<input type='hidden' value="+doc1.value+" id =\"ditta\" name= \"ditta\">";
	      doc.innerHTML+=info;
	    }
	    doc1=parent.document.getElementById("ID_SIV");
	    if (doc1 && doc1!=undefined)
	    {
	      info="<input type='hidden' value="+doc1.value+" id =\"id\" name= \"id\">";
	      doc.innerHTML+=info;
	    }
	    doc1=parent.document.getElementById("ID_UTE");
	    if (doc1 && doc1!=undefined)
	    {
	      info="<input type='hidden' value="+doc1.value+" id =\"id-ute\" name= \"id-ute\">";
	      doc.innerHTML+=info;
	    }
	     doc1=undefined;
	    doc1=parent.document.getElementById("SIGLA_AGG");
	    if (doc1 && doc1!=undefined)
	    {
	      info="<input type='hidden'  id =\"SIGLA_AGG\" name= \"SIGLA_AGG\" value="+doc1.value+">";
	      doc.innerHTML+=info;
	    }
	    doc1=parent.document.getElementById("FILIALE_AGG");
	    if (doc1 && doc1!=undefined)
	    {
	      info="<input type='hidden'  id =\"FILIALE_AGG\" name= \"FILIALE_AGG\" value="+doc1.value+">";
	      doc.innerHTML+=info;
	    }
	    if (iv==1 || iv=='1' || riv=='1' || riv==1)
	    {
	      doc1=document.getElementById("rilascio");
	      if (doc1 && doc1!=undefined)
	      {
		info="<input type='hidden' value="+doc1.value+" id =\"noterilZ\" name= \"noterilZ\">";
		doc.innerHTML+=info;
	      }
	      
	    }
	}
	docum=document.getElementById("formdownload");
//	azione=versione+"/_siv.Z";
	
	if (docum && docum!=undefined)
	{
		if (SOLONUOVE!=undefined && SOLONUOVE!="")
		  docum.action="note.php?SN=1";
	        else 
		  docum.action="note.php";
	//	docum.action=azione;
	//	alert(docum.action);
		docum.target = "_self" ;
		docum.submit();
	}
	
}
function LeggiNote()
{
  	docum=document.getElementById("formnote");
	if (docum && docum!=undefined)
	{
		docum.action="../../pdf.php";
		docum.target = "_new" ;
		docum.submit();
	}
}
function ApriDownload()
{
//onchange="camion_RicaricaCamion(this.options[this.selectedIndex].value);"
//	alert("Apridownload-0");
	var passo=new Array();
	var mirende="";
	var versione="";
	var azione="";
	doc=undefined;
	docum=document.getElementById("framecentrale");
	if (!docum || docum==undefined)
	    docum=parent.document.getElementById("framecentrale");
	if (docum && docum!=undefined)  
	  doc=docum.contentWindow.document.getElementById("versione");
	var ceversione=0;
	if (doc && doc!=undefined)
	{
	    if (doc.value!="" && doc.value!=undefined)
	    {
	       ceversione=1;	
	       versione=doc.value;
	    }
//		if (docum.selectedIndex)
//			versione=docum.options[docum.selectedIndex].value;
	}
	if (ceversione==0)
	{
	  doc=undefined;
	  docum=document.getElementById("framecentrale");
	  if (!docum || docum==undefined)
	      docum=parent.document.getElementById("framecentrale");
	  if (docum && docum!=undefined)  
	      doc=docum.contentWindow.document.getElementById("rilascio");
	  if (doc && doc!=undefined)
	  {
	      versione=doc.value;
	  }
	}
//	alert("Apridownload-1");
	
	 doc=undefined;
	  docum=document.getElementById("framecentrale");
	  if (!docum || docum==undefined)
	      docum=parent.document.getElementById("framecentrale");
	  if (docum && docum!=undefined)  
	      doc=docum.contentWindow.document.getElementById("formdownload");
//	alert("Apridownload-2");
//	inserire qui l'invio della MAIL all'hotline.
//	azione=versione+"/_siv.Z";
	if (doc && doc!=undefined)
	{
	//	docum.action=azione;
	//	alert("SUBMITTO");
	//	docum.target = "_self" ;
		doc.submit();
	}
	if (versione)
	{
	      InviaRichiestaMailDownloadPatch(versione);
	}
//	alert("Apridownload-done");
	//docum=document.getElementById("framecentrale");
	//
//	passo["versione"]=versione;
//	mirende=SynchPOSTRequestA("download1.php",passo);
//	dokdes=document.getElementById("aggiornamenti");
//	if (dokdes)
//	{
//		dokdes.innerHTML=mirende;
//		Mostra("aggiornamenti");
//	}
//	if (docum)
//	{
//		docum.submit();
//	}	
	//javascript:Loader('riservata/aggiornamenti/note.php','display_list',false);
}
function DisplayNote(PATH)
{
	var docum=document.getElementById("noterilascio");
	var documpar=document.getElementById("framecentrale");
	if (documpar)
	{
		documpar.style.height="1200px";
		documpar.style.width="680px";
	}
	if (docum)
	{
		docum.style.height="900px";
		docum.style.width="680px";
		docum.src="";
		docum.src=PATH;
	}
	Hide("display_list");
}
function InviaRichiestaMailDownloadPatch(PATCHNUM)
{
	Busy();
	var rispostaric=new Array();
	var rispostona=new Array();	
		
	var mandoquesto=CreaRichiestaMailDownloadPatch(PATCHNUM);
//	alert(printArray(mandoquesto));
	rispostona=SynchPOSTRequestA("../../PHPSER.php",mandoquesto);
//	alert("rispostona: "+(rispostona));
	rispostaric=PHP_Unserialize(rispostona);
//	rispostaric=rispostaric["siv"];
//	alert("rispostaric: "+printArray(rispostaric));
	if (rispostaric["errore"])
	{
	  info="Attenzione l'invio della mail all'assistenza non &egrave; avvenuto correttamente.\n";
	  info+= rispostaric["errore"];
	  alert(info);
	}
}
function CreaRichiestaMailDownloadPatch(versione)
{
	var chiedoric = new Array();
	chiedoric["azione"]="scaricatapatch";
	var doc1=undefined;
	doc1=parent.document.getElementById("dittahidden");
	if (doc1 && doc1!=undefined)
	    ditta=doc1.value;
	chiedoric["ditta"]=ditta;
	doc1=parent.document.getElementById("SIGLA_AGG");
	if (doc1 && doc1!=undefined)
	    chiedoric["sigla_agg"]=doc1.value;
	doc1=parent.document.getElementById("FILIALE_AGG");
	if (doc1 && doc1!=undefined)
	    chiedoric["filiale_agg"]=doc1.value;
	docID=parent.document.getElementById("ID_SIV");
	chiedoric["id"]=docID.value;
	doc=parent.document.getElementById("ID_UTE");
	if (doc)
		chiedoric["id-ute"]=doc.value;
	chiedoric["patch"]=versione+"";	
	return chiedoric;
}
function LanciaIntra()
{
   docum=document.getElementById("framecentrale");
  if (docum)
  {
	  docum.style.height="750px";
	  docum.style.backgroundColor="transparent";
	  docum.style.border="0px";
	  docum.style.frameborder="0px";
	  docum.src="";
	  docum.style.width="100%";
	  docum.src='riservata/intra/intra.php';
  }
  Hide("display_list");
//	frames['framecentrale'].location.href='riservata/aggiornamenti/download.php';
//	document.all.framecentrale.src='riservata/aggiornamenti/download.php';
  Mostra("framecentrale");

}
function LanciaManuali()
{
   docum=document.getElementById("framecentrale");
  if (docum)
  {
	  docum.style.height="750px";
	  docum.style.backgroundColor="transparent";
	  docum.style.border="0px";
	  docum.style.frameborder="0px";
	  docum.src="";
	  docum.style.width="100%";
	  docum.src='riservata/download/manuali.php';
  }
  Hide("display_list");
//	frames['framecentrale'].location.href='riservata/aggiornamenti/download.php';
//	document.all.framecentrale.src='riservata/aggiornamenti/download.php';
  Mostra("framecentrale");
}
function LanciaTool()
{
  docum=document.getElementById("framecentrale");
  if (docum)
  {
	  docum.style.height="750px";
	  docum.style.backgroundColor="transparent";
	  docum.style.border="0px";
	  docum.style.frameborder="0px";
	  docum.src="";
	  docum.style.width="100%";
	  docum.src='riservata/download/download.php';
  }
  Hide("display_list");
//	frames['framecentrale'].location.href='riservata/aggiornamenti/download.php';
//	document.all.framecentrale.src='riservata/aggiornamenti/download.php';
  Mostra("framecentrale");
}

