// JavaScript Document

function init() 
{
	ScalaTempo();
}

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;
	}
}



//var popOpenErrorMsg = "Abilitare l'apertura dei popup nel proprio browser!";
var popOpenErrorMsg = "Please enable popup opening for this site in your browser!";
/*
var popupInstLionel = null;
var popupInst = null;
*/
/*
function closePop()
{
	//alert( "closePop - popupInst: " + popupInst );
	if( popupInst )
	{
		popupInst.close();
		//popupInstLionel.close();
	}
}*/
//window.onunload = closePop;
function openPopVideo2009_2()
{
  popupInstLionel = openPopup( 'VA2009', 'popupVideo2009_2.htm', 'popupVideo2009_2', '', 425, 344, 0, 0, false );
}

function openPopLionel()
{
  //popupInstLionel = window.open( 'popupLionel.htm', 'popupLionel', 'width=360,height=288,left=' + ( window.screen.width - (360 + 10) ) + ',top=' + ( /*window.screen.height -*/ (310) ) );
  //popupInstLionel = openPopup( 'Lionel', 'popupLionel.htm', 'popupLionel', '', 360, 288, 0, 0, false );
  popupInstLionel = openPopup( 'Lionel', 'popupLionel.htm', 'popupLionel', '', 248, 225, 0, 0, false );
}

function openPopVideo2009()
{
  //popupInstLionel = window.open( 'popupLionel.htm', 'popupLionel', 'width=360,height=288,left=' + ( window.screen.width - (360 + 10) ) + ',top=' + ( /*window.screen.height -*/ (310) ) );
  //popupInstLionel = openPopup( 'Lionel', 'popupLionel.htm', 'popupLionel', '', 360, 288, 0, 0, false );
  popupInstLionel = openPopup( 'Lionel', 'popupVideo2009.htm', 'popupVideo2009', '', 720, 540, 0, 0, false );
}

function openPopGuidelines( popupName )
{
  //popupInst = window.open( 'popupGuidelines.htm', popupName, 'width=360,height=285,left=' + ( 0 /*window.screen.width - (360 + 10)*/ ) + ',top=' + ( /*window.screen.height -*/ (0) ) );
  popupInst = openPopup( '', 'popupGuidelines.htm', popupName, '', 360, 285, 0, 0, true );
	/*
	if( popupInst )
	{
		window.onunload = closePop;
	}
	else
	{
		alert( popOpenErrorMsg );
	}*/
}

function openPop2005GalaDinnerHighlights()
{
  popupInst = openPopup( '', 'popup2005GalaDinnerHighlights.htm', 'popup', '', 360, 288, 0, 0, true );
}

function openPopScientificProgram( theURL ) // Scientific Program !!!
{
  //popupInst = openPopup( '', theURL, 'popup', 'scrollbars=yes,resizable=yes', 430, 400, ( screen.width ? (screen.width - 430 - 10) /*/ 2*/ : 0 ), 0, true );
  popupInst = openPopup( '', theURL, 'popup', 'scrollbars=yes,resizable=yes', 760, 500, ( screen.width ? (screen.width - 760 - 10) / 2 : 0 ), ( screen.height ? (screen.height - 500 - 10) / 2 : 0 ), false ); // false xche pdf plugin ...
}

function openPopPreviousEdition( theURL )
{
  popupInst = openPopup( '', theURL, 'popup', 'scrollbars=yes,resizable=yes', 760, 500, ( screen.width ? (screen.width - 760 - 10) / 2 : 0 ), ( screen.height ? (screen.height - 500 - 10) / 2 : 0 ), false ); // false xche pdf plugin ...
}


function openPopup( ieTtitle, theURL, winName, features, w, h, x, y, autoclose )
{
	//isIE = document.all ? true : false;
	var popInst = null;
	/*if ( isIE )
	{
		NFW = window.open( "", winName, features );
		NFW.blur();
		window.focus();
		NFW.resizeTo( w, h );
		NFW.moveTo( x, y );
		var frameString=""+
		"<html>"+
		"<head>"+
		"<title>" + ieTtitle + "</title>"+
		"</head>"+
		"<frameset rows='*,0' framespacing=0 border=0 frameborder=0>"+
		"<frame name='top' src='"+ theURL +"' scrolling=auto>"+
		"<frame name='bottom' src='about:blank' scrolling='no'>"+
		"</frameset>"+
		"</html>";
		NFW.document.open();
		NFW.document.write(frameString);
		NFW.document.close();
	}
	else
	{*/
		//NFW = window.open( theURL, "popFrameless", "scrollbars,"+dims); ,left=' + ( window.screen.width - (360 + 10) ) + ',top=' + ( /*window.screen.height -*/ (310) ) 
		dims = "width=" + w + ",height=" + h;
		pos = ",left=" + x + ",top=" + y;
		
		//alert( theURL + ", " + winName + ", " + features + ( (features.length > 0) ? ',' : '' ) + dims + pos );
		popInst = window.open( theURL, winName, features + ( (features.length > 0) ? ',' : '' ) + dims + pos );
		/*NFW.blur();
		window.focus();
		NFW.resizeTo( w, h );
		NFW.moveTo( x, y );*/
	//}
	if ( popInst ) // IE ( non so gli altri... ) se pop gia aperto non torna null ma neanche un riferimento ok al pop gia aperto ...
	{																// anzi no: mi sa che e il pdf plugin in IE ( non so gli altri... ) ... se no tutto ok !!! 
		try
		{
			popInst.focus();
			
			if ( autoclose && popInst.close )
			{
				window.onunload = function() { popInst.close(); }
			}
		}
		catch ( e ) {}
	}
	else
	{
		alert( popOpenErrorMsg );
	}
	return popInst;
}
//  End -->

/*
var iePopup = null;

function openIePopup()
{
		iePopup = window.createPopup();

    // The popup object exposes the document object and its
    // properties.
    var oPopBody = iePopup.document.body;
    // The following HTML that populates the popup object with a string.
    oPopBody.innerHTML = "<DIV>This is a popup.</DIV>"
    // Parameters of the show method are in the following order: x-coordinate,
    // y-coordinate, width, height, and the element to which the x,y 
    // coordinates are relative. Note that this popup object is displayed
    // relative to the body of the document.
    oPopup.show(15, 150, 50, 50, document.body);
}
*/

/* FIGO: CARICA UN URL IN UN IE-POPUP !!!

<!-- The DOWNLOAD element is user-defined and used only to associate the 
download default behavior with an identifier that is then associated with the 
startDownload method later in the script. -->
<DOWNLOAD ID=dwn STYLE="behavior:url(#default#download)" />

    function onDone(src){
	    oPopup.document.write(src); 
    }
    function showIePopup(){	
	    oPopup.show(0, 0, 220, 30, editbutton);
    }
    
    var oPopup = window.createPopup();
    // startDownload is a member of the download default behavior.
    // The callback function pointer (second parameter) specifies a 
    // function. When a file downloads successfully, the file contents
    // are passed as the parameter to onDone().
    dwn.startDownload("PopupHTML.htm",onDone);	
*/

