// -------------------------------------------------------------------------------
// Name: Aggiorna select data attuale (data.js, JQuery, HTML)
// Author: Altea Software S.r.l.
// Version: 1.0.0
// Description: Questo script aggiorna i campi della select con la data attuale
// Required: Jquery 1.21+, Form HTML
//
// Devel Date: 10/03/2009
// Last Modify: 10/03/2009
// CacheLog:
//
// -------------------------------------------------------------------------------


// Aggiorna la select del giorno e del mese con il valore attuale.
// La select dei giorni deve avere ID "gg" e del mese ID "mm", le select devono avere
// come option soltanto i giorni, niente option vuote o altro.
// La select dell'anno, che deve avere ID "aa" ne svuota il contenuto e riscrive le
// option con l'anno corrente e i prossimi 3 anni.
$(document).ready(function() {
	
	selectedDate = new Date();
	selectedDate7 = new Date();
	selectedDate7.setDate (selectedDate.getDate() + 7);
	
	var d = selectedDate.getDate();
	var m = selectedDate.getMonth();
	var y = selectedDate.getFullYear();
	
	var d2 = selectedDate7.getDate();
	var m2 = selectedDate7.getMonth();
	var y2 = selectedDate7.getFullYear();
	
	// aggiorno giorno e mese arrivo a oggi
	($('#gg')[0]).selectedIndex = d - 1;
	($('#mm')[0]).selectedIndex = m;
	
	($('#gg2')[0]).selectedIndex = d2 - 1;
	($('#mm2')[0]).selectedIndex = m2;
	
	// sostituisco il contenuto della select dell'anno di arrivo con l'anno corrente + altri 3 anni
	$('#aa').html("<option value=\"" + y + "\" selected>" + y + "</option>");
	$('#aa').append("<option value=\"" + (y+1) + "\">" + (y+1) + "</option>");
	$('#aa').append("<option value=\"" + (y+2) + "\">" + (y+2) + "</option>");
	$('#aa').append("<option value=\"" + (y+3) + "\">" + (y+3) + "</option>");
	
	$('#aa2').html("<option value=\"" + y2 + "\" selected>" + y2 + "</option>");
	$('#aa2').append("<option value=\"" + (y2+1) + "\">" + (y2+1) + "</option>");
	$('#aa2').append("<option value=\"" + (y2+2) + "\">" + (y2+2) + "</option>");
	$('#aa2').append("<option value=\"" + (y2+3) + "\">" + (y2+3) + "</option>");
	
	
});

//apertura in pop up
function gowindow(str, titolo,w,h) {
 openwin = window.open(str,titolo,'width='+ w +',height='+ h +',status=no,scrollbars=no,resizable=no,location=no,toolbar=no');
 } 