var browserName=navigator.appName;  

if (browserName=="Microsoft Internet Explorer") 
{ 
  var agt=navigator.userAgent.toLowerCase();
  var iePos  = agt.indexOf('msie');
  var browserVer = parseFloat(agt.substring(iePos+5,agt.indexOf(';',iePos)));

  if(browserVer < 7)   window.isIE6=true;
}
else 
  window.isIE6=false; 



function getPageSize() {
	
 var xScroll, yScroll;

if (window.innerHeight && window.scrollMaxY) {	
	xScroll = window.innerWidth + window.scrollMaxX;
	yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
	xScroll = document.body.scrollWidth;
	yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	xScroll = document.body.offsetWidth;
	yScroll = document.body.offsetHeight;
}

var windowWidth, windowHeight;

if (self.innerHeight) {	// all except Explorer
	if(document.documentElement.clientWidth){
		windowWidth = document.documentElement.clientWidth; 
	} else {
		windowWidth = self.innerWidth;
	}
	windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
	windowWidth = document.documentElement.clientWidth;
	windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
	windowWidth = document.body.clientWidth;
	windowHeight = document.body.clientHeight;
}	

// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
	pageHeight = windowHeight;
} else { 
	pageHeight = yScroll;
}

// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){	
	pageWidth = xScroll;		
} else {
	pageWidth = windowWidth;
}

return [pageWidth,pageHeight];
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function getWindowSize()
{
	var w = 0;
	var h = 0;

	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else
		{
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}
	//w3c
	else
	{
		w = window.innerWidth;
		h = window.innerHeight;
	}
	return [w,h];
}


function showSimple(id)
{
	var arrayPageSize = this.getPageSize();
	$('popup_overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
	
	$('popup_overlay').show();
	$(id).show();
	
	if(getScrollXY()[1] > 0)
	{
	 var myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	  }
		$(id).style.top = getScrollXY()[1] + myHeight/2 + 'px';
		$(id).style.marginLeft = '-'+$(id+'_holder').getWidth()/2 + 'px';
		$(id).style.marginTop = '-'+$(id+'_holder').getHeight()/2 + 'px';
	}
	else
	{
		$(id).style.top = "50%";
		$(id).style.marginLeft = '-'+$(id+'_holder').getWidth()/2 + 'px';
		$(id).style.marginTop = '-'+$(id+'_holder').getHeight()/2 + 'px';
	}
}

function popupShow(elemId,href,cost,isKeywords, yesId)
{		
	if(href)
	{
		if(typeof(yesId) == 'undefined')
		$('yes').href = href;
		else
		$(yesId).href = href;
	}
	if(cost) $('warning_cost').update(cost);
	
	var arrayPageSize = this.getPageSize();
	$('popup_overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
	
	if($(elemId+'_holder') && $(elemId+'_holder').innerHTML != "")
	{
		$(elemId).update($(elemId+'_holder').innerHTML);
		$('popup_window').update("");
	}
	
	$('popup_window').appendChild(Builder.node('div',{id:elemId+'_holder'}));
	
	$(elemId+'_holder').update($(elemId).innerHTML);
	$(elemId).update("");
	
	
	$('popup_window').style.top = "50%";
	$('popup_window').style.marginLeft = '-'+$('popup_window').getWidth()/2 + 'px';
	$('popup_window').style.marginTop = '-'+$('popup_window').getHeight()/2 + 'px';
	$('popup_window').style.position= 'fixed';
	
	if($('popup_window').getHeight() > getWindowSize()[1])
	{
		$('popup_window').style.top = getScrollXY()[1]+"px";
		$('popup_window').style.marginTop = '0px';
		$('popup_window').style.position= 'absolute';
	}
	
	$('popup_overlay').show();
	$('popup_window').show();
	
	if(isIE6)
	{
		$$('select').each(function(sel){
			if(typeof(sel.up('.popup_wnd')) == 'undefined') sel.style.visibility = 'hidden';
		});
	}
}

function popupCloseSimple(elemId)
{
	$('popup_overlay').hide();
	$(elemId).hide();	
}

function popupClose(elemId)
{	
if($(elemId+'_holder') && $(elemId+'_holder').innerHTML != "")
{
	$(elemId).update($(elemId+'_holder').innerHTML);
	$('popup_window').update("");
}

$('popup_overlay').hide();
$('popup_window').hide();

if(isIE6)
{
	$$('select').each(function(sel){
	   if(typeof(sel.up('.popup_wnd')) == 'undefined') sel.style.visibility = 'visible';
	});
}

}

function showTab(tabID, obj)
{
$$('#tab_nav a').each(function(it){
	it.className = '';
});

$$('.tabCont').each(function(it){
	it.style.display = 'none';
});

$(obj).className = 'sel';
$(tabID).style.display = 'block';
}


Event.observe(window, 'load', function () {
new Insertion.Bottom(document.body,'<div id="popup_overlay"></div>');
new Insertion.Bottom(document.body,'<div id="popup_window"></div>');
document.body.appendChild(Builder.node('div',{id:'popup_overlay'}));
document.body.appendChild(Builder.node('div',{id:'popup_window', className:'popup_wnd'}));

$('popup_overlay').setStyle({'position': 'absolute', 'top': '0', 'left': '0', 'z-index': '90', 'width': '100%', 'height': '500px', 'background': '#000', 'display':'none', 'opacity':'0.8'});

$('popup_window').setStyle({'position':'fixed', 'top':'50%', 'left':'50%', 'z-index':'100', 'display':'none'});

});