﻿sub heapfy(byref V,j,byval n)
  k=j
  if ((2*j+1)<=n) then
    if (V(2*j+1)>V(k)) then
      k=2*j+1
    end if
  end if
  if ((2*j)<=n) then
    if (V(2*j)>V(k)) then
      k=2*j
    end if
  end if
  if (k<>j) then
    t=V(j)
    V(j)=V(k)
    V(k)=t
    call heapfy(V,k,n)
  end if
end sub 

sub ordina1(byref V)
  n=ubound(V)
  i=n\2
  while (i>=0)
    call heapfy(V,i,n)
    i=i-1
  wend
  i=n
  while (i>=1)
    t=V(i)
    V(i)=V(0)
    V(0)=t
    call heapfy(V,0,(i-1))
    i=i-1
  wend
end sub




sub ordina(byref VotoDif)
  n=ubound(VotoDif)
  for j=1 to n 
   x=VotoDif(j)
   i=j-1
   go=1
   while (i>=0)and(go=1)
    if (VotoDif(i)>x) then
     VotoDif(i+1)=VotoDif(i)
     i=i-1
    else
        go=0
     end if
  wend
    VotoDif(i+1)=x
  next
end sub


'-----------------------------
'converte le ' in ''
'-----------------------------
Function ToSQL(Text)
	ToSQL=replace(Text,"'","''")
end Function

Function allineatore(sstr,num,val)
dim lunghezza,i,fine,spazi,MyPos,Decim,Intera,numero,testo
	testo= replace(sstr," ", "&nbsp;")
	lunghezza=len(trim(sstr))
	fine = num-lunghezza
	spazi= ""
    ' ----------------------------------------------------------------------------------
    'se nella descrizione c'è una virgola
    ' ----------------------------------------------------------------------------------
    if (val="5") or (val="3") then sstr= replace(sstr, ",",".")
	' ----------------------------------------------------------------------------------
	' mypos - numero parte intera comprensiva di ,
	' Decim - restituisce il numero dopo la virgola se non esiste restituisce le prime 2
	'		  della parte intera
	' ----------------------------------------------------------------------------------
	MyPos = Instr(sstr, ",")
	'if MyPos <> 0 then 
	 Decim = Mid(sstr,MyPos+1,2)
	'response.write Mypos  & "-" & Decim
	' ----------------------------------------------------------------------------------
	' condizione solo per le cifre che hanno 2 decimali con la parte intera differente
	' 1,15 - 10,13 - 100,15 - 1000,43
	' ----------------------------------------------------------------------------------
	if len(Decim)=2 and (MyPos=2 or MyPos=3 or MyPos=4  or MyPos=5) then fine=fine+1
	if len(Decim)=1 then fine=fine
	if len(Decim)=0 then fine=fine-1
	'if (MyPos = 0) and (num <> "10") then fine=fine-3
	' ----------------------------------------------------------------------------------
	'condizione inserita solo per il prezzo se la parte deciamle è ,00
	'10 sta alla lunghezza passata come parametro alla funzione
	' ----------------------------------------------------------------------------------
	if num="10" then
		MyPos = Instr(sstr, ",")
		if MyPos = 0 then fine=fine-2
	end if

	' ----------------------------------------------------------------------------------
	' inserisce gli spazi
	' ----------------------------------------------------------------------------------
	for i = 1 to fine
		spazi=spazi+"&nbsp;"
	next

	' ----------------------------------------------------------------------------------
	' visualizzatore della stringa con gli spazi
	' ----------------------------------------------------------------------------------
	if val = 1  then Response.Write "" & trim(testo) & spazi & "|"
	if val = 5  then Response.Write "" & trim(testo) & spazi & "|"
	if val = 2  then Response.Write "" & spazi & FormatNumber(sstr,2) & "|"
	if val = 3  then Response.Write "" & trim(sstr) & spazi
	if val = 4  then Response.Write "" & spazi & trim(sstr)

End Function

function CriptaPassword(CodiceSblocco)
	dim Valore,ConVal

	ConVal= ""
	for g =1 to len(CodiceSblocco)
		Valore = mid(CodiceSblocco,g,1)
		'response.write Valore & " ( " & asc(Valore) & ") - " 
		ConVal = ConVal + cstr(asc(Valore))
	next	
	CriptaPassword = ConVal 
end function


function deCriptaPassword(CodiceSblocco)
	dim Valore,ConVal
	ConVal= ""
	for g =1 to len(CodiceSblocco) step 2 
		Valore = mid(CodiceSblocco,g,2)
		'response.write g & " " & Valore & " " & cstr(chr(Valore)) & "<br>"
		ConVal = ConVal + cstr(chr(Valore))
		'response.write ConVal & "<br>"
	next	
	deCriptaPassword = ConVal 
end function
 


function ShowFileAccessInfo(filespec)
   Dim fso, f, s
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFile(filespec)
   s = f.DateLastModified
   ShowFileAccessInfo = s
end function



function ValoreMassimo(Valori_Ary)
	Dim Confronto 
	Dim Vr_Max 
	Dim a 
	if isarray(Valori_Ary) then
		if UBound(Valori_Ary) = 0 then
			Vr_Max = Null
		else
			Vr_Max = Valori_Ary(UBound(Valori_Ary))

			for a = LBound(Valori_Ary) to UBound(Valori_Ary)
				Confronto = Valori_Ary(a)
				if Confronto > Vr_Max Then '* Vedi nota in fondo
					Vr_Max = Confronto
				end if
			next 
		end if
		ValoreMassimo = Vr_Max
	else
		ValoreMassimo = Null
	end if
end function


