var visible_calendar = '';
var calendars_moved_to_body = new Array();

function showCalendar( id, e ) {
	var block = document.getElementById( id );
	var oX = 0;
	var oY = 25;
	var boxWidth = parseInt( block.style.width  );

    // Close visible calendar
    if ( id != visible_calendar && visible_calendar ) hideCalendar( visible_calendar );

    // Mark as visible calendar ( catch events that never catch an onmouseout )
    visible_calendar = id;

	// Take out of any nested layer issues
	
	//if ( calendars_moved_to_body.valueOf().indexOf( id ) == -1 ) {
        document.body.appendChild( block );
        calendars_moved_to_body[ calendars_moved_to_body.length ] = id;
    //}

	// Ensure box is hidden before repositioning
	//if ( block.style.display == 'none' ) {
		// Position Box
		if (!e) var e = window.event;
		if ( e.pageX || e.pageY ) {
			block.style.top  = oY + e.pageY + 'px';
			block.style.left = oX + e.pageX + 'px';
		} else if ( e.clientX || e.clientY ) {
			block.style.top  = ( oY + e.clientY + document.documentElement.scrollTop )  + 'px';
			block.style.left = ( oX + e.clientX + document.documentElement.scrollLeft )  + 'px';
		}
		
		// Make sure box is not running off page
		if ( window.innerWidth ) {
			if ( ( diff = ( parseInt( block.style.left ) + boxWidth ) - window.innerWidth ) > 0 )
				block.style.left = ( parseInt( block.style.left ) - ( diff + 50 ) ) + 'px'; 
		} else if ( document.body ) {
			if ( ( diff = ( parseInt( block.style.left ) + boxWidth ) 
					- document.body.clientWidth > 0 ) )
				block.style.left = ( parseInt( block.style.left ) - ( diff + 120 ) ) + 'px'; 
		}
		
		block.style.display = 'block';
	//}
}

function hideCalendar( id ) {
	document.getElementById( id ).style.display = 'none';
}