// JavaScript Document
var opened;
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;

function showPopup(url, w, h){
	if (opened ){
		opened.close();
	}
	var config = 'height='+h+',width='+w+',';
	config += (arguments.length > 3)? arguments[3] : 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0';
	opened = window.open(url, '_popup', config);
	opened.focus();
}

function getBounds( obj ){
	var t = obj.offsetTop;
	var l = obj.offsetLeft;
	var w = obj.offsetWidth;
	var h = obj.offsetHeight;
	
	while ( obj=obj.offsetParent ){
		t += obj.offsetTop;
		l += obj.offsetLeft;
	}
	return {top:t, left:l, width:w, height:h}
}

/*====================================================================
 * Show Floating Panel
 *====================================================================*/
function showFloatPanel( content ){
	var shadowClose = true;
	if ( (arguments.length > 1) )
		shadowClose = arguments[1];
	
	var ieFix = document.getElementById('iefix_panel');
	if ( ieFix == null ){
		ieFix = document.createElement('div');
		ieFix.setAttribute('id', 'iefix_panel');
		document.body.appendChild( ieFix );
		
		ieFix.style.backgroundColor ='#000000';
		ieFix.style.opacity = 0.1;
		ieFix.style.filter = "alpha(opacity=10);";
		ieFix.style.position = 'absolute';
		ieFix.style.zIndex = 20;
		ieFix.style.top = 0;
		ieFix.style.left = 0;
	}
	
	var shadow = document.getElementById('float_panel_shadow');
	if ( shadow == null ){
		shadow = document.createElement('div');
		shadow.setAttribute('id', 'float_panel_shadow');
		document.body.appendChild( shadow );
		
		shadow.style.backgroundColor ='#000000';
		shadow.style.opacity = 0.5;
		shadow.style.filter = "alpha(opacity=50);";
		shadow.style.position = 'absolute';
		shadow.style.zIndex = 21;
		shadow.style.top = 0;
		shadow.style.left = 0;
		shadow.onclick = closeFloatPanel;
	}
//	var scrMaxH = ( document.body.scrollHeight > document.body.clientHeight ) ? document.body.scrollHeight : document.body.clientHeight;
	var scrMaxH = (window.innerHeight) ? window.innerHeight : ((document.documentElement) ? document.documentElement.clientHeight : document.body.clientHeight);
	var widthFix = 0;
	if( document.body.scrollHeight > scrMaxH ) {
		scrMaxH = document.body.scrollHeight;
		widthFix = 25;
	}

	shadow.style.height = scrMaxH + 'px';
	shadow.style.width = document.body.offsetWidth-widthFix+'px';
	shadow.style.display = 'block';
	
	if( shadowClose )
		shadow.onclick = closeFloatPanel;
	else
		shadow.onclick = '';
	
	var contentObj = document.getElementById('float_panel_content');
	if ( contentObj == null ){
		contentObj = document.createElement('div');
		contentObj.setAttribute('id', 'float_panel_content');
		document.body.appendChild( contentObj );
		contentObj.style.position = 'absolute';
		contentObj.style.backgroundColor ='#FFFFFF';
		contentObj.style.zIndex = 22;
		contentObj.style.top = 0;
		contentObj.style.left = 0;
	}
	contentObj.innerHTML = content;
	contentObj.style.display = 'block';

	resetPanelPosition();
}

/*====================================================================
 * Close Floating Panel
 *====================================================================*/
function closeFloatPanel(){
	var shadow = document.getElementById('float_panel_shadow');
	if ( shadow ){
		shadow.style.height = '0px';
		shadow.style.display = 'none';
	}
	var ieFix = document.getElementById('iefix_panel');
	if ( ieFix ){
		ieFix.style.height = '0px';
		ieFix.style.display = 'none';
	}
	var contentObj = document.getElementById('float_panel_content');
	if ( contentObj ){
		contentObj.style.display = 'none';
	}
	
}

/*====================================================================
 * Reset Floating Panel position
 *====================================================================*/
function resetPanelPosition(){
	var contentObj = document.getElementById('float_panel_content');
	if ( contentObj && (contentObj.style.display == 'block')){ 
		var bodyH = ( document.documentElement.clientHeight ) ? document.documentElement.clientHeight : document.body.clientHeight;
		
		var targetTop = 0;
		var targetLeft = 0;
		
		var top = ( contentObj.offsetHeight < document.body.clientHeight) ? ((document.body.clientHeight - contentObj.offsetHeight) / 2) : 0;
		var left = ( contentObj.offsetWidth < document.body.clientWidth ) ? ((document.body.clientWidth - contentObj.offsetWidth) / 2) : 0; 

		top = 0;
		left = ((document.body.clientWidth - contentObj.offsetWidth) / 2);
		
		targetTop = document.body.scrollTop + top + 'px';
		targetLeft = document.body.scrollLeft + left + 'px';

		contentObj.style.top = targetTop;
		contentObj.style.left = targetLeft;
	}
}


// Attach the event
if ( window.addEventListener ){	//W3C standard
	window.addEventListener('load', resetPanelPosition, false);
	window.addEventListener('scroll', resetPanelPosition, false);
} else if ( window.attachEvent ){	// Miscrosoft IE only
	window.attachEvent('onload', resetPanelPosition);
	window.attachEvent('onscroll', resetPanelPosition);
}
