var arraysos=new Array();
var rispostasos=new Array();
var nrecordsos=0;
var ultimosos="";
var primosos="";
var paginasos=0;
var npaginesos=0;
var quantisos=20;
function InviaRichiestaSospesi(ancora,qualepag)
{
	var rispostona=new Array();	
		
	mandoquesto=CreaRichiestaSospesi(ancora,qualepag);
	rispostona=SynchPOSTRequestA("PHPSER.php",mandoquesto);
//	alert("risposta"+rispostona);
	rispostasos=PHP_Unserialize(rispostona);
//	alert("Rispostasos:  "+printArray(rispostasos));
	if (rispostasos["errore"])
	{
		info="<table  align=center width=\"400px\" height=\"250px\" border=\"0\" cellspacing=0 cellpadding=4 >\
					<tr align=center ><td align=center width=\"50%\"><font  color="+coloresfondo+" size=\"3\"><b>Attenzione</b></font><br></td></tr><tr align=center ><td align=center  style=\" background-color:"+coloresfondo+";\"><b><font color=\"#FFFFFF\" size=\"3\">";
		info+= rispostasos["errore"];
		info+="</font></b></td></tr>";
		info+="<tr align=center ><td align=CENTER width=\"50%\" style=\" height:20px;\"><a href=\"javascript:Chiudi()\"><font   size=\"2\" color=\"#FFFFFF\"><img  src=\"images/home.png\" border=0></font></a></td></tr></table>";
		dok2=document.getElementById('display_list');
		dok2.innerHTML=(info);
		Mostra("display_list");
		paginasos=0;
//		alert(info);
	}
	else
	{
		rispostasos=rispostasos["siv"];
		npaginesos=parseInt(rispostasos["npag"]);
		paginasos=parseInt(rispostasos["pag"]);
		arraysos=rispostasos["sospesi"];
		DisplaySospesi();
		CaricaBarraPagine(CaricaArrayFunzioniSos(npaginesos),paginasos,"barretta");
		CaricaBarraPagine(CaricaArrayFunzioniSos(npaginesos),paginasos,"barrettafondo");
	}
}
function DisplaySospesi()
{
	doc=document.getElementById("cli_sel");
	if (doc)
		clientesel=doc.value;
	document.getElementById('display_list').innerHTML=("");
	info="<br><table width=\"98%\" border=\"0\" class=\"consfondod\" cellspacing=0 cellpadding=0 align=center style=\" border: 1px solid #eeeeee; padding:1px; margin-left:5px; margin-right:5px; \">\
			<tr>";
	info+="<td colspan=\"6\" align=\"center\" ><font  size=\"3\" color="+coloresfondo+"><b>FATTURE DA PAGARE</b><br><br><font  size=\"1\" color="+coloresfondo+"><b>Se presente l'icona nella colonna PDF cliccarla per visualizzare il documento.</b></font><br><br><br><br></font></td>";
	info+="<td width=\"100px\" align=right valign=\"top\" class=\"consfondod\">&nbsp;\
		<a href=\"javascript:Chiudi()\"><font  size=\"2\"><img  src=\"images/home.png\" border=0></font></a>&nbsp;";
	info+="<input type=\"hidden\"  id=\"n_recsos\" size = \"6\" MAXLENGTH=\"40\" value=\""+nrecordsos+"\"></td></tr>";
	info+="<tr><td colspan=\"7\" align=\"center\" bgcolor=\"transparent\" ><table cellspacing='0' cellpadding='0' width=\"98%\" bgcolor=\"transparent\" style=\"padding:5px; padding-bottom:20px;\">";
	   info+="<tr><td  colspan='3' style=\"height:35px; \" align='center'> &nbsp; &nbsp;<font color="+coloresfondo+" size='2'><b><i>PROSPETTO RIEPILOGATIVO</i>&nbsp;&nbsp;</b></font></td>\
			</tr>";
	if (rispostasos["totdom"] && rispostasos["totsos"]!=undefined && rispostasos["totdom"]!='undefined')
	{
	    info+="<tr><td  style=\"height:25px; border-top: 1px solid #eeeeee; border-left: 1px solid #eeeeee;\" align='left' class='chiarissimo'> &nbsp; &nbsp;<font color=#000000 size='2'><i><b>Domiciliato presso istituto di credito&nbsp;&nbsp;</b></i></font></td>\
			<td  style=\"height:25px; border-top: 1px solid #eeeeee; \" align='right' class='chiarissimo'>&euro;&nbsp;&nbsp;</td>\
		       <td  style=\"height:25px; border-top: 1px solid #eeeeee; border-right: 1px solid #eeeeee;\" align='right' class='chiarissimo'><font color=#000000 size='2'><b>"+rispostasos["totdom"]+"</b>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>\
		      </tr>";
	}
	if (rispostasos["totsos"] && rispostasos["totsos"]!=undefined && rispostasos["totsos"]!='undefined')
	{
	    info+="<tr><td  style=\"height:25px; border-top:  solid #eeeeee; border-left: 1px solid #eeeeee;\" align='left' class='chiarissimo'> &nbsp; &nbsp;<font color=#000000 size='2'><i><b>Scoperto da pagare&nbsp;&nbsp;</b></i></font></td>\
		       <td  style=\"height:25px; border-top:  solid #eeeeee;\" align='right' class='chiarissimo'>&euro;&nbsp;&nbsp;</td>\
		      <td  style=\"height:25px; border-top: 1 solid #eeeeee; border-right: 1px solid #eeeeee;\" align='right' class='chiarissimo'><font color=#000000 size='2'><b>"+rispostasos["totsos"]+"</b>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>\
		     </tr>";
	}
	if (rispostasos["totesp"] && rispostasos["totesp"]!=undefined && rispostasos["totesp"]!='undefined')
	{
	    info+="<tr><td  style=\"height:25px; border-top:  solid #eeeeee; border-left: 1px solid #eeeeee;\" align='left' class='bianco' > &nbsp; &nbsp;<font color=#000000 size='2'><b>TOTALE ESPOSIZIONE&nbsp;&nbsp;</b></font></td>\
			<td  style=\"height:25px;border-top:  solid #eeeeee;\" align='right' class='bianco'>&euro;&nbsp;&nbsp;</td>\
			<td  style=\"height:25px; border-top:  solid #eeeeee; border-right: 1px solid #eeeeee;\" align='right' class='bianco'><font color=#000000 size='2'><b>"+rispostasos["totesp"]+"</b>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>\
			</tr>";
	}
//	if ((rispostasos["scadoltre30gg"] && rispostasos["scadoltre30gg"]!=undefined && rispostasos["scadoltre30gg"]!='undefined') || (rispostasos["scadoltre30gg"] && rispostasos["scadoltre30gg"]!=undefined && rispostasos["scadoltre30gg"]!='undefined') || (rispostasos["scaduto"] && rispostasos["scaduto"]!=undefined && rispostasos["scaduto"]!='undefined'))
//	{
//	    info+="<tr><td colspan='4' style=\"height:25px;\"  class='sfumatoDX' >&nbsp;<font color=#112233 size='1'><b><i>SCADENZE</i></b></font></td>\
//		       <td style=\"height:25px;\" align='center' class='bianco'>&nbsp;</td>\</tr>";
//	}
	if (rispostasos["scaduto"] && rispostasos["scaduto"]!=undefined && rispostasos["scaduto"]!='undefined')
	{
	    info+="<tr><td  style=\"height:25px; border-bottom:  solid #eeeeee; border-left: 1px solid #eeeeee;\" align='left' class='consfondod'> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<font color=#ff2211 size='2'><b>&nbsp;Scaduti&nbsp;&nbsp;</b></font></td>\
		       <td  style=\"height:25px; border-bottom:  solid #eeeeee;\" align='right' class='consfondod'>&euro;&nbsp;&nbsp;</td>\
		       <td  style=\"height:25px; border-bottom:  solid #eeeeee; border-right: 1px solid #eeeeee;\" align='right' class='consfondod'><font color=#445566 size='2'><b>"+rispostasos["scaduto"]+"</b>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>\
		      </tr>";
	}
	if (rispostasos["scadin30gg"] && rispostasos["scadin30gg"]!=undefined && rispostasos["scadin30gg"]!='undefined')
	{
	    info+="<tr><td  style=\"height:25px; border-bottom:  solid #eeeeee; border-left: 1px solid #eeeeee;\" align='left' class='consfondod'> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<font color=#aa2211 size='2'><b>&nbsp;Con scadenza entro 30gg&nbsp;&nbsp;</b></font></td>\
		       <td  style=\"height:25px; border-bottom:  solid #eeeeee;\" align='right' class='consfondod'>&euro;&nbsp;&nbsp;</td>\
		       <td  style=\"height:25px; border-bottom:  solid #eeeeee; border-right: 1px solid #eeeeee;\" align='right' class='consfondod'><font color=#445566 size='2'><b>"+rispostasos["scadin30gg"]+"</b>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>\
			</tr>";
	}
	if (rispostasos["scadoltre30gg"] && rispostasos["scadoltre30gg"]!=undefined && rispostasos["scadoltre30gg"]!='undefined')
	{
	    info+="<tr><td  style=\"height:25px; border-bottom: 1px solid #eeeeee; border-left: 1px solid #eeeeee;\" align='left' class='consfondod'> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<font color=#772211 size='2'><b>&nbsp;Con scadenza oltre 30 gg&nbsp;&nbsp;</b></font></td>\
		       <td  style=\"height:25px; border-bottom: 1px solid #eeeeee;\" align='right' class='consfondod'>&euro;&nbsp;&nbsp;</td>\
		       <td  style=\"height:25px; border-bottom: 1px solid #eeeeee; border-right: 1px solid #eeeeee;\" align='right' class='consfondod'><font color=#445566 size='2'><b>"+rispostasos["scadoltre30gg"]+"</b>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>\
			</tr>";
	}
	
	
	info+="</table></td></tr>";
	info+="<tr><td colspan=\"7\"  style=\"height:35px; \"  align='center'> <font color="+coloresfondo+" size='2'><i><b>DETTAGLIO DOCUMENTI&nbsp;&nbsp;</b></i></font></td></tr>";
	if (npaginesos>1)
	{
		info+="<tr>";
	//INIZIO riga con scorrimento pagine:	
		
		info+="<td colspan=\"7\" style=\"border: 1px solid #eeeeee;\" ><div ID=\"barretta\" align=\"center\" style=\"height:25px;\"></div></td>";
		info+="</tr>";
		//FINE riga con scorrimento pagine:	
	}
	
	info+="<tr><td align=center style=\"height:25px; border-left: 1px solid #eeeeee; border-top: 1px solid #eeeeee;\" width='80px' class='chiarissimo'><font  color='#8cacbb' size='1'><b>NUMERO DOCUMENTO</b></font></td>\
		    <td align=center style=\"height:25px;  border-top: 1px solid #eeeeee;\" class='chiarissimo' width='80px'><font  color='#8cacbb' size='1'><b>DATA</b></font></td>\
		    <td align=center style=\"height:25px;  border-top: 1px solid #eeeeee;\" class='chiarissimo'><font color='#8cacbb' size='1'><b>MODALIT&Agrave; PAGAMENTO</b></font></td>\
		    <td align=center style=\"height:25px;  border-top: 1px solid #eeeeee;\" class='chiarissimo'><font  color='#8cacbb' size='1'><b>IMPORTO DOCUMENTO &nbsp;&euro;</b></font></td>\
		    <td align=center style=\"height:25px;  border-top: 1px solid #eeeeee;\" class='chiarissimo'><font  color='#8cacbb' size='1'><b>DA PAGARE &nbsp;&euro;</b></font></td>\
		    <td align=center style=\"height:25px;  border-top: 1px solid #eeeeee;\" class='chiarissimo' width='80px'><font  color='#8cacbb' size='1'><b>SCADENZA</b></font></td>\
		    <td align=center style=\" height:25px; border-right: 1px solid #eeeeee; border-top: 1px solid #eeeeee;\" class='chiarissimo'><font color='#8cacbb' size='1'><b>PDF</b></font></td></tr>";
	arraysos=arraysos["sospeso"];
	primo=true;
	ultimosos="";
	primosos="";
	coloreriga="trasparent";
	if (arraysos[0]!=undefined)
	{
		for (i in arraysos)
		{	
			if (primo)
			{
				primosos=arraysos[i]["id-rec"];
				primo=false;
			}
			info+=CaricaListaSospesi(arraysos[i],coloreriga);
			//alert("Bottoni:  "+printArray(buttons));
		}
	}
	else
	{
		primosos=arraysos["id-rec"];
		info+=CaricaListaSospesi(arraysos);
	}
	info+="<tr><td colspan=\"7\" style=\"height:1px; border-top: 1px solid #eeeeee;\">&nbsp;<input type=\"hidden\" name=\"id\" id=\"first_sos\" size = \"6\" MAXLENGTH=\"40\" value="+primosos+">\
<input type=\"hidden\" name=\"id\" id=\"last_sos\" size = \"6\" MAXLENGTH=\"40\" value="+ultimosos+"></td></tr>";
//alert("arraysos[sos]:  "+printArray(arraysos));	
	if (npaginesos>1)
	{
		info+="<tr>";
	//INIZIO riga  in fondo con scorrimento pagine:	
		
		info+="<td colspan=\"7\"  style=\"border: 1px solid #eeeeee;\"><div ID=\"barrettafondo\" align=\"center\" style=\"height:25px;\">$nbsp;</div></td>";

		info+="</tr>";
		//FINE riga in fondo con scorrimento pagine:	
	}
	info+=	"</table><br><br><br>";
	dok=document.getElementById("display_list");
	dok.innerHTML=(info);
	Mostra("display_list");
}
function CreaRichiestaSospesi(avanti,pagina)
{
	var chiedosos = new Array();
	bravo=true;
	chiedosos["azione"]="sospesi";
	chiedosos["ditta"]=ditta;
	docID=document.getElementById("ID_SIV");
	chiedosos["id"]=docID.value;
	doc=document.getElementById("ID_UTE");
	if (doc)
		chiedosos["id-ute"]=doc.value;
	docclisel=document.getElementById("cli_sel");
	if (docclisel)
		chiedosos["cliente"]=docclisel.value;
	doc=document.getElementById("des_sel");
	if (doc)
		chiedosos["destin"]=doc.value;
	chiedosos["n-elem"]="20";
	if (npaginesos>1)
	{
	  doclast=document.getElementById("last_sos");
	  if (doclast)
	  {
	//	  chiedosos["last-rec"]=doclast.value;
  //		alert("last_fat = "+chiedofat["last_fat"]);
	  }
	  docfi=document.getElementById("first_sos");
	  if (docfi)
	  {
	//	  chiedosos["first-rec"]=docfi.value;
  //		alert("first_fat = "+chiedofat["first_fat"]);
	  }
	}
	if (avanti==1)
		chiedosos["go"]="next";
	if (avanti==-1)
		chiedosos["go"]="prev";
	 
	if (pagina!=0 && pagina!=undefined) 
		chiedosos["pag"]=pagina;
	return chiedosos;
}

function CaricaListaSospesi(isospesi,coloreriga)
{
	var colore="#002299";
	var coloreres="#002299";
	var importo="";
	var residuo="";
	if (isospesi["importo"] && isospesi["importo"]!=undefined)
	  importo=isospesi["importo"];
	var pos=importo.indexOf("-");
	if (pos>=0)  
	    colore="#992200";
	if (isospesi["residuo"] && isospesi["residuo"]!=undefined)
	  residuo=isospesi["residuo"];
	pos=residuo.indexOf("-");
	if (pos>=0)  
	    coloreres="#992200";
	sputa="<tr ><td class=\"consfondod\" style=\" height:30px; border-top: 1px solid #eeeeee;border-right: 1px  solid #eeeeee; border-left: 1px solid #eeeeee;\" align=center><font  size=\"2\" color=\"#002299\"><i><b>"+isospesi["numero"]+"</b></i></font></td><td class=\"consfondod\" style=\" border-top: 1px solid #eeeeee;border-right: 1px  solid #eeeeee; \" align=\"center\"><font  size=\"2\"><b>"+isospesi["data"]+"</b></font></td>\
		    <td class=\"consfondod\" style=\" border-top: 1px solid #eeeeee;border-right: 1px  solid #eeeeee; \" align=\"center\"><font  size=\"2\" color=\"#002299\"><i>"+isospesi["tipag"]+"<i></font></td>\
		    <td align=right class=\"consfondod\" style=\" border-top: 1px solid #eeeeee;border-right: 1px  solid #eeeeee; \" ><font  size=\"3\" color=\""+colore+"\"><b>"+isospesi["importo"]+"</b>&nbsp;&nbsp;</font></td>\
		    <td class=\"consfondod\" style=\" border-top: 1px solid #eeeeee;border-right: 1px  solid #eeeeee; \" align=\"right\"><font  size=\"3\" color=\""+coloreres+"\"><b>"+isospesi["residuo"]+"</b>&nbsp;&nbsp;</font></td>\
		    <td class=\"consfondod\" style=\" border-top: 1px solid #eeeeee;border-right: 1px  solid #eeeeee; \" align=\"center\"><font  size=\"2\" color=\"#1122ee\"><b>"+isospesi["scadenza"]+"</b></font></td>";
	sputa+="<td class=\"consfondod\"  class=\"norepeat\"  align=center style=\"  height:30px; border-top: 1px solid #eeeeee; border-right: 1px solid #eeeeee;\">&nbsp;";
	if (isospesi["cepdf-ft"]=="1")
	{
		sputa+="<a href\ =\"pdf.php?id="+document.getElementById("ID_SIV").value+"&id-rec="+isospesi["id-pdf-ft"]+"&ditta="+ditta+"&sigla="+document.getElementById("siglahidden").value+"&filiale="+document.getElementById("filialehidden").value+"&tipopdf="+isospesi["tipopdf-ft"]+"\"  TARGET=\"_blank\"  >&nbsp;<img src=\"images/document20px.png\"></img></a>";
	}
	if (isospesi["cepdf-bl"]=="1")
	{
		sputa+="<a href\ =\"pdf.php?id="+document.getElementById("ID_SIV").value+"&id-rec="+isospesi["id-pdf-bl"]+"&ditta="+ditta+"&sigla="+document.getElementById("siglahidden").value+"&filiale="+document.getElementById("filialehidden").value+"&tipopdf="+isospesi["tipopdf-bl"]+"\"  TARGET=\"_blank\"  >&nbsp;<img src=\"images/document20px.png\"></img></a>";
	}  
	sputa+="</td></tr>";
	ultimosos=isospesi["id-rec"];
	return sputa;
}
function CaricaArrayFunzioniSos(numpag)
{
	var funzione=new Array();
	for(var i=0;i<numpag;i++)
	{
	    funzione[i]=new Array();
	    funzione[i]["npag"]=i+1+"";
	    funzione[i]["funzione"]="javascript:InviaRichiestaSospesi("+0+","+(i+1)+")";
	}
	return funzione;
}


