// JavaScript Document

function openPopCredits()
{
	MM_openBrWindow( 'popCredits.htm','popCredits','scrollbars=no,width=500,height=310' );
}

function openPopPrivacyPolicy()
{
	MM_openBrWindow( 'popPrivacyPolicy.htm','popPrivacyPolicy','scrollbars=no,width=500,height=310' );
}

function newsSubscribe(linkObj) { //v3.0
  //document.getElementById( "formNewsletter" ).submit();
}



function init() 
{
	SetData();
}

function SetData() 
{
	try
	{
		var now = new Date();
		//alert( 'timeLeft: ' + timeLeft );
		//timeLeft.setTime( ( Secondi * 1000 ) - ( 60 * 60 * 1000 ) );
		var month = "";
		switch ( now.getMonth() )
		{
			case 0:
				month = "gennaio";
				break;
			case 1:
				month = "febbraio";
				break;
			case 2:
				month = "marzo";
				break;
			case 3:
				month = "aprile";
				break;
			case 4:
				month = "maggio";
				break;
			case 5:
				month = "giugno";
				break;
			case 6:
				month = "luglio";
				break;
			case 7:
				month = "agosto";
				break;
			case 8:
				month = "settembre";
				break;
			case 9:
				month = "ottobre";
				break;
			case 10:
				month = "novembre";
				break;
			case 11:
				month = "dicembre";
				break;
		}
		var strData = now.getDate() + ' ' + month + ' ' + now.getFullYear();
		document.getElementById( 'headerInnerData' ).innerHTML = strData;
	}
	catch ( ex )
	{}
}

function ScalaTempo()
{
	try
	{
		//var dd = document.getElementById('divContoRovescia');
		//var VaDate = new Date( 2007, 07, 30 );
		var VaDate = new Date( 2009, 10, 04 );
		var now = new Date();
		var nowDate = new Date( now.getFullYear(), now.getMonth(), now.getDate() );
		
		var daysDiff = DaysDiff( VaDate, nowDate ) - 1;
		var hourDiff = pad ( ( 24 - now.getHours()   ) - 1 );
		var minDiff =  pad ( ( 60 - now.getMinutes() ) - 1 );
		var secDiff =  pad ( ( 60 - now.getSeconds() ) - 1 );
		
		//alert( 'timeLeft: ' + timeLeft );
		
		//timeLeft.setTime( ( Secondi * 1000 ) - ( 60 * 60 * 1000 ) );
		var strTempo = hourDiff + ':' + minDiff + ':' + secDiff;
		//dd.innerHTML = tempo;
		
		//timer = setTimeout( 'ScalaTempo(' + ( Secondi - 1 ) + ')', 1000 );
		timer = setTimeout( 'ScalaTempo()', 1000 );
		//if ( Secondi == 60 ) 
		//{
			document.getElementById( 'counterDay' ).innerHTML = daysDiff;
			document.getElementById( 'counterTime' ).innerHTML = strTempo;
		//}
	}
	catch ( ex )
	{}
}

function DaysDiff( D1, D2 ) 
{ // Date Objects, with similar times
	return Math.round( ( D1 - D2 ) / 864e5 );
}

function pad( strDatePart ) 
{
	if ( strDatePart.toString().length < 2 )
	{
		return "0" + strDatePart;
	}
	else
	{
		return  strDatePart;
	}
}

function openPopGallery( strImgName )
{
	if ( ! strImgName || strImgName == "" )
	{
		return;
	}
	MM_openBrWindow( 'popGallery.htm?strImgName=' + strImgName,'popGallery','scrollbars=yes,width=1020,height=800' );
}


var strImgName = "";
var imageIdGallery = "foto";
var imageObjGallery = null;
var imgTempGallery = new Image();
imgTempGallery.onload = imgTempLoadGallery; 

function initPopGallery()
{
	setStrImgName();
	
	//alert( "strImgName: " + strImgName );
	
	imageObjGallery = MM_findObj( imageIdGallery );
	
	//alert( "imageObjGallery: " + imageObjGallery );
	
	if ( !imageObjGallery )
	{
		return;
	}
	
	imgTempGallery.src = "doc/Gallery04-05-06-07/" + strImgName;// + ".jpg";
	
}

function setStrImgName()
{
	var qs = new Querystring();
	strImgName = qs.get("strImgName", "");
}

function imgTempLoadGallery()
{
	if ( !imageObjGallery )
	{
		return;
	}
	//alert( "imgTempGallery.height: " + imgTempGallery.height );
	
	if ( imgTempGallery.height > 100 && imgTempGallery.width > 100 )
	{
		imageObjGallery.src = "doc/Gallery04-05-06-07/" + strImgName;// + ".jpg";
	}
	window.focus();
}



function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}





/* Client-side access to querystring name=value pairs
	Version 1.2.4
	30 March 2008
	Adam Vandenberg
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	this.get=Querystring_get;
	
	if (qs == null);
		qs=location.search.substring(1,location.search.length);

	if (qs.length == 0) 
		return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var pair = args[i].split('=');
		var name = unescape(pair[0]);
		
		var value = (pair.length==2)
			? unescape(pair[1])
			: name;
		
		this.params[name] = value;
	}
}

function Querystring_get(key, default_) {
	var value=this.params[key];
	return (value!=null) ? value : default_;
}

function fillScreen()
{
	if (window.screen)
	{
		var w = screen.availWidth;
		var h = screen.availHeight;
		window.moveTo(0, 0);
		window.resizeTo(w, h);
	}
} 

