﻿
var GiorniDiAperturaSettimanali = { 
	0:false, /* domenica */
	1:true, 
	2:true, 
	3:true, 
	4:true, 
	5:true, 
	6:true 
};

var GiorniAnomali = {
	2009: {
		1:  [ 10, 14, 24, 28, 1, 6 ],
		2:  [ 7, 11, 21, 25 ],
		3:  [ 7, 11, 21, 25 ],
		4:  [ 4, 8, 22, 29, 13, 25 ],
		5:  [ 2, 6, 16, 20, 30, 1, 17, 4, 5 ],
		6:  [ 3, 13, 17, 27, 2, 24 ],
		7:  [ 1, 8, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 31 ],
		8:  [ 1, 15, 29, 30 ],
		9:  [ 5, 9, 19, 23 ],
		10: [ 3, 4, 7, 17, 21, 31 ],
		11: [ 4, 14, 18, 28 ],
		12: [ 2, 8, 12, 16, 25, 26 ]
	},
	2010: {
		1:  [ 1, 6, 13, 23, 27 ],
        2:  [ 6, 10, 20, 24, 21 ],
        3:  [ 6, 10, 20, 24 ],
        4:  [ 5, 3, 6, 7, 10, 17, 21 ],
        5:  [ 5, 15, 19, 29 ],
        6:  [ 2, 24, 12, 16, 26, 30 ],
        7:  [ 10, 24 ],
        8:  [ 4, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28 ],
        9:  [ 4, 8, 18, 22 ],
        10: [ 2, 6, 16, 20, 30 ],
        11: [ 1, 3, 13, 17, 27, 28 ],
        12: [ 8, 25, 1, 15, 29 ]
	},
	2011: {
		1:  [ 1, 6, 8, 12, 22, 26 ],
        2:  [ ],
        3:  [ ],
        4:  [ ],
        5:  [ ],
        6:  [ ],
        7:  [ ],
        8:  [ ],
        9:  [ ],
        10: [ ],
        11: [ ],
        12: [ ]
	}
};

function GiornataAnomala( d ) { 
	if ( typeof( GiorniAnomali[ d.getFullYear() ] ) == "undefined" ) return false;
	if ( typeof( GiorniAnomali[ d.getFullYear() ][ d.getMonth() + 1 ] ) == "undefined" ) return false;
	return GiorniAnomali[ d.getFullYear() ][ d.getMonth() + 1 ].indexOf( d.getDate() ) != -1;
}

function GiornataApertura( d ) {
	return ( GiorniDiAperturaSettimanali[ d.getDay() ] ) ^ ( GiornataAnomala( d ) );
}

function AperturaOdierna() {
	var d = new Date();
	document.write( "Oggi, " + d.toLocaleDateString() + ", la farmacia é " + ( GiornataApertura(d) ? "aperta con orario continuato dalle 9:00 alle 19:30" : "chiusa" ) + "." );
}