// JavaScript Document
var _popupsLoaded = new Array();

function centerLayer(id) {		
	if (!_isW3C) 	
		return;

	var obj = getObject(id);
	var winh, winw, x, y, sx, sy;
	
	// get the dimensions of the window
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	
	// get the srolling of the page
	if (self.pageYOffset) // all except Explorer
	{
		sx = self.pageXOffset;
		sy = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		sx = document.documentElement.scrollLeft;
		sy = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		sx = document.body.scrollLeft;
		sy = document.body.scrollTop;
	}

	winh = y; // + sy;
	winw = x; // + sx;
	
	var w = parseInt(getStyle(obj, 'width'));
	var h = parseInt(getStyle(obj, 'height'));		
	
	var x = Math.round((winw - w) / 2) + sx;	
  var y = Math.round((winh - h) / 2) + sy;  		

	setStyleProperty(obj, "top", y + "px");
	setStyleProperty(obj, "left", x + "px");

}

function showLayer(obj) {	
	if (!_isW3C) 	
		return;

	var obj = getObject(obj);
	_popupsLoaded[obj.id] = true;	
	showObj(obj);
	//fadeIn(obj, 50);
}

function hideLayer(obj) {	
	if (!_isW3C) 	
		return;

	var obj = getObject(obj);
	_popupsLoaded[obj.id] = false;
	hideObj(obj);
	//fadeOut(obj, 30);
}

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

var _fadeTimer;

function fadeIn(obj, opacity) {
	clearTimeout(_fadeTimer);
	if (!_isW3C)
		return;

  obj = getObject(obj);
		
	setStyleProperty(obj, "visibility", "visible");
  if (opacity <= 100) {
    setOpacity(obj, opacity);
    opacity += 10;
    _fadeTimer = window.setTimeout("fadeIn('"+obj.id+"',"+opacity+")", 50);
  }
  
}

function fadeOut(obj, opacity, current) {
	clearTimeout(_fadeTimer);
	if (!_isW3C)
		return;
	
	if (!current)
		current = 100;

  obj = getObject(obj);
	
  if (current > opacity) {
    setOpacity(obj, current);
    current -= 10;
    _fadeTimer = window.setTimeout("fadeOut('"+obj.id+"',"+opacity+","+current+")", 50);
  }
	else
		setStyleProperty(obj, "visibility", "hidden");
  
}

function centerLayerRelative(layer, container)
{
	if (!_isW3C) 	
		return;

	layer = getObject(layer);
	container = getObject(container);
	
	var w = parseInt(getStyle(layer, 'width'));
	var h = parseInt(getStyle(layer, 'height'));		
	var cw = parseInt(getStyle(container, 'width'));
	var ch = parseInt(getStyle(container, 'height'));		
	
	var x = Math.round((cw - w) / 2);	
  var y = Math.round((ch - h) / 2);  		

	setStyleProperty(layer, "top", y + "px");
	setStyleProperty(layer, "left", x + "px");

}

/*
function showPopup(id, topSlide, leftSlide) {	
	if (!_isW3C) 	
		return;
	
	_popupsLoaded[id] = true;
	
	var obj = document.getElementById(id);
	var winh, winw, x, y, sx, sy;
	
	// get the dimensions of the window
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	
	// get the srolling of the page
	if (self.pageYOffset) // all except Explorer
	{
		sx = self.pageXOffset;
		sy = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		sx = document.documentElement.scrollLeft;
		sy = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		sx = document.body.scrollLeft;
		sy = document.body.scrollTop;
	}

	winh = y; // + sy;
	winw = x; // + sx;
	
	var w = parseInt(getStyle(obj, 'width'));
	var h = parseInt(getStyle(obj, 'height'));		
	
	var x = Math.round((winw - w) / 2) + sx;	
  var y = Math.round((winh - h) / 2) + sy;  		

	obj.style.visibility = "visible";	
	if (topSlide)
		slide(-550, y, id, "top");
	else
		obj.style.top = y + "px";
	if (leftSlide)
		slide(-500, x, id, "left");
	else
		obj.style.left = x + "px"; 	
}

function slide(x, target, id, attr) {
	var obj = document.getElementById(id);
	eval("obj.style." + attr + "= '" + x + "px';");
	if (x < target) {
		//alert(x);
		setTimeout("slide(" + (x + 50) + ", " + target + ", '" + id + "', '" + attr + "')", 1);
	} else
		eval("obj.style." + attr + "= '" + target + "px';");
}

function closePopup(id) {
	if (!document.getElementById)
		return;
	document.getElementById(id).style.visibility = "hidden";		
	_popupsLoaded[id] = false;

}*/

function getStyle(obj,cAttribute){
	//if IE
	if (obj.currentStyle){
	 return eval('obj.currentStyle.'+cAttribute)
	} else if (document.defaultView) {
	 //if Mozilla/FF
	 return eval('document.defaultView.getComputedStyle(obj, null).'+cAttribute)
	}	
}

function openCenteredWindowWithOptions(url, name, w, h, options) {      
  var screenh = window.screen.height;
  var screenw = window.screen.width;      
  var y = Math.round((screenh - h) / 2);
  var x = Math.round((screenw - w) / 2);
  var atts = "height=" + h + ",width=" + w + ",top=" + y + ",left=" + x + ",screenX=" + x + ",screenY=" + y + ",resizable"
  if (options != null)
    atts += "," + options;
  return window.open(url, name, atts);
}

//returns a window of specified url, height and width centered in the screen
function openCenteredWindow(url, name, w, h) {
  return openCenteredWindowWithOptions(url, name, w, h, null);
}

function rerender() 
{
	for (id in _popupsLoaded)
	{
		if (_popupsLoaded[id])
		{
			centerLayer(id);
		}
	}
}

function fade2Background(id) {
	try 
	{
		var obj = document.getElementById(id);
		obj.style.opacity = ".5";
		obj.style.filter = "alpha(opacity=50)";	
	} 
	catch (e)	{ }
	//obj = document.getElementById(popup);	
	//obj.style.opacity = "1";	
}


window.onresize = rerender;
try {
	//if (typeof window.onscroll != "undefined")
		window.onscroll = rerender;
} catch (e) { }

