﻿// Funzioni di utilità

//Visualizza una finestra popup
function ShowPopupWin(strUrl, strWidth, strHeight)
{
	var posX = event.screenX;
	var posY = event.screenY + 20;
	var screenW = screen.width;                                 
	var screenH = screen.height - 20;                           
	
	if (posX + 232 > screenW) { posX = posX - 232 - 40; }       
	if (posY + 164 > screenH) { posY = posY - 164 - 80; }       
	
	var wPosition = 'dialogLeft:' + posX + '; dialogTop:' + posY;
	
	showModalDialog(strUrl, null, 'dialogWidth: ' + strWidth + '; ' 
	                            + 'dialogHeight: ' + strHeight + '; '
	                            + 'status: no; resizable: yes; help: no; scroll: yes; '
	                            + wPosition);
  return false;
}

//Visualizza una finestra a popup con l'elenco dei progetti realizzati
function ShowElencoProg(idProg)
{
  var strUrl = 'pggridelpop.aspx?Codice=' + idProg;
  var strWidth = '400px';
  var strHeight = '320px';
  
  return ShowPopupWin(strUrl, strWidth, strHeight);
}

//Stampa una data nel formato di sistema
//Parametri:
//- intYear : Anno
//- intMonth: Mese
//- intDay  : Giorno
function PrintLocalDate(intYear, intMonth, intDay)
{
  var dtmDate = new Date();
  var strDate= new String('');
  
  if(intYear>1)
  {
    //Crea un oggetto data in base ai valori passati come parametro
    //  La variabile intMonth è decrementata di una unità perchè
    //  in JavaScript gennaio è il mese 0
    dtmDate = new Date(intYear, intMonth -1, intDay);
    
    //Converte la data nel formato locale
    strDate = new String(dtmDate.toLocaleString());
    
    //Elimina l'ora
    strDate = strDate.replace('12:00:00 AM', '');
    strDate = strDate.replace('00:00:00 AM', '');
    strDate = strDate.replace('0:00:00 AM', '');
    
    strDate = strDate.replace('12.00.00 AM', '');
    strDate = strDate.replace('00.00.00 AM', '');
    strDate = strDate.replace('0.00.00 AM', '');
    
    strDate = strDate.replace('00.00.00', '');
    strDate = strDate.replace('00:00:00', '');
    strDate = strDate.replace('0.00.00', '');
    strDate = strDate.replace('0:00:00', '');
  }

  //Stampa la data nel documento
  document.write(strDate);

  return strDate;
}

//Funzione che visualizza l'immagine passata come parametro in un oggetto della pagina
//Parametr:
//- strImgSRC   : percorso e nome dell'immagine da visualizzare
//- objImg      : oggetto in cui visualizzare l'immagina
function ShowImg(strImgSRC, objImg)
{
  strIMG = new String(strImgSRC);
  
  objImg.filters[0].Apply();
  objImg.src = strIMG;
  objImg.filters[0].Play();
  
  return true;
}

//Funzione per tornare alla pagina precedente
function Indietro()
{
  window.history.back();
  return true;
}
