// global variables
var browser = new objBrowserCheck();
var widthWBC = 1012;
var heightWBC = 709;

// initialization
if (browser.ie)
{
	widthWBC += 2;
	heightWBC += 2;
}
else if (browser.ns6 || browser.ns7 || browser.mz)
{
	widthWBC += 6;
	heightWBC += 6;
}


function objRectangle(x, y, width, height)
{
	this.x = x;
	this.y = y;
	this.width = width;
	this.height = height;
}

function objSize(width, height)
{
	this.width = width;
	this.height = height;
}

function objBrowserCheck()
{
	var ua = navigator.userAgent;

	if (ua.indexOf('Opera') >= 0)
	{
		this.b = 'op';
		this.vd = ua.substr(ua.indexOf('Opera') + 6, ua.length);
		this.vd = this.vd.substring(0, this.vd.indexOf(' '));
	}
	else if (ua.indexOf('MSIE') >= 0)
	{
		this.b = 'ie';
		this.vd = ua.substr(ua.indexOf('MSIE ') + 5, ua.length);
		this.vd = this.vd.substring(0, this.vd.indexOf(';'));
	}
	else if (ua.indexOf('Netscape') >= 0)
	{
		this.b = 'ns';
		if (ua.indexOf('Netscape6/') >= 0)
			this.vd = ua.substr(ua.indexOf('Netscape6/') + 10, ua.length);
		else if (ua.indexOf('Netscape/') >= 0)
			this.vd = ua.substr(ua.indexOf('Netscape/') + 9, ua.length);
	}
	else if (ua.indexOf('Mozilla') >= 0 && ua.indexOf('Gecko') >= 0)
	{
		this.b = 'mz';
		this.vd = ua.substr(ua.indexOf('rv:') + 3, ua.length);
		this.vd = this.vd.substring(0, this.vd.indexOf(')'));
	}
	else if (ua.indexOf('Mozilla') >= 0 && ua.indexOf('Konqueror') == -1)
	{
		this.b = 'ns';
		this.vd = ua.substr(ua.indexOf('Mozilla/') + 8, ua.length);
		this.vd = this.vd.substring(0, this.vd.indexOf(' '));
	}
	else
	{
		this.b = navigator.appName;
		this.vd = String(parseFloat(navigator.appVersion));
	}

	this.v    = this.vd.substr(0, 1);
	this.ie   = (this.b == 'ie');
	this.ie4  = (this.b == 'ie' && this.v == 4);
	this.ie5  = (this.b == 'ie' && this.v == 5);
	this.ie6  = (this.b == 'ie' && this.v == 6);
	this.ns   = (this.b == 'ns');
	this.ns4  = (this.b == 'ns' && this.v == 4);
	this.ns6  = (this.b == 'ns' && this.v == 6);
	this.ns7  = (this.b == 'ns' && this.v == 7);
	this.mz   = (this.b == 'mz');
	this.mz1  = (this.b == 'mz' && this.v == 1);
	this.op   = (this.b == 'op');
	this.op4  = (this.b == 'op' && this.v == 4);
	this.op5  = (this.b == 'op' && this.v == 5);
	this.op6  = (this.b == 'op' && this.v == 6);
	this.op7  = (this.b == 'op' && this.v == 7);

	ua = ua.toLowerCase();
	if (ua.indexOf('win') >= 0)
	{
		this.os = 'win';
		if (ua.indexOf('windows nt 5.1') >= 0 || ua.indexOf('windows xp') >= 0)
			this.os = 'win xp';
		else if (ua.indexOf('windows nt 5.0') >= 0 || ua.indexOf('windows 2000') >= 0)
			this.os = 'win 2000';
		else if (ua.indexOf('windows nt 4.0') >= 0 || ua.indexOf('windows nt') >= 0 || ua.indexOf('winnt4.0') >= 0)
			this.os = 'win nt';
		else if (ua.indexOf('winme') >= 0 || ua.indexOf('windows me') >= 0 || ua.indexOf('win 9x') >= 0 || ua.indexOf('windows 9x') >= 0)
			this.os = 'win me';
		else if (ua.indexOf('win98') >= 0 || ua.indexOf('windows 98') >= 0)
			this.os = 'win 98';
		else if (ua.indexOf('win95') >= 0 || ua.indexOf('windows 95') >= 0)
			this.os = 'win 95';
	}
	else if (ua.indexOf('mac') >= 0)
		this.os = 'mac';
	else if (ua.indexOf('linux') >= 0)
		this.os = 'linux';
	else if (ua.indexOf('os/2') >= 0)
		this.os = 'os/2';
	else if (ua.indexOf('unix') >= 0 || ua.indexOf('sun') >= 0)
		this.os = 'unix';
	else
		this.os = 'other';

	this.dhtml = (this.ie || this.ns || this.mz);
	this.dom = (document.createElement && document.appendChild && document.getElementsByTagName) ? true : false;
}

function openWin(innerWidth, innerHeight, file, name, relative, scrollbars)
{
	var win;
	var x, y, outerWidth, outerHeight;
	var settings = "resizable=no,toolbar=no,directories=no,status=no,scrollbars=" + (scrollbars == true ? "yes" : "no") + ",menubar=no";

	if (relative)
	{
		x = getWindowLeft() + (getWidthOfWBC() - innerWidth) / 2;
		y = getWindowTop() + (getHeightOfWBC() - innerHeight) / 2;
	}
	else
	{
		x = (getOuterWidth(innerWidth) < screen.availWidth) ? (screen.availWidth - getOuterWidth(innerWidth)) / 2 : 0;
		y = (getOuterHeight(innerHeight) < screen.availHeight) ? (screen.availHeight - getOuterHeight(innerHeight)) / 2 : 0;
	}

	if (x<0)
		x=0;
	if (y<0)
		y=0;

	win = window.open(file,name,"width=" + innerWidth + ",height=" + innerHeight + ",left=" + x + ",top=" + y + "," + settings);
	return win;
}

function getBaseURL()
{
	if (location.href.toLowerCase().indexOf('/html/') >= 0)
		return location.href.substring(0, location.href.toLowerCase().indexOf('/html/') + 1);
	else
		return '';
}

function getGUID()
{
	var guid;
	
	if (parent.mainnav.document.mainnav && parent.mainnav.isLoadedData())
		guid = parent.mainnav.document.mainnav.getWBCData('wbc_GUID');

	return (guid) ? guid : '';
}

function getWidthOfWBC()
{
	return widthWBC;
}

function getHeightOfWBC()
{
	return heightWBC;
}

function getWindowLeft()
{
	var pt;

	if (self.screenX != null)
		return top.screenX;
	else if (browser.ie)
		return top.screenLeft - 3;
	else if (parent.mainnav && parent.mainnav.document.mainnav && parent.mainnav.isLoadedActive() && parent.mainnav.document.mainnav.isShowing())
	{
		pt = parent.mainnav.document.mainnav.getLocationOnScreen();
		return pt.x - 4;
	}
	else
		return -1;
}

function getWindowTop()
{
	var pt;

	if (self.screenY != null)
		return top.screenY;
	else if (browser.ie)
		return top.screenTop - 22;
	else if (parent.mainnav && parent.mainnav.document.mainnav && parent.mainnav.isLoadedActive() && parent.mainnav.document.mainnav.isShowing())
	{
		pt = parent.mainnav.document.mainnav.getLocationOnScreen();
		return pt.y - 137;
	}
	else
		return -1;
}

function getOuterWidth(innerWidth)
{
	if (browser.ie)
		return innerWidth + 10;
	if (browser.ns4)
		return innerWidth + 12;
	if (browser.ns6 || browser.ns7 || browser.mz)
		return innerWidth + 6;
	else
		return innerWidth + 10;
}

function getOuterHeight(innerHeight)
{
	if (browser.ie)
		return innerHeight + 29;
	if (browser.ns4)
		return innerHeight + 31;
	if (browser.ns6 || browser.ns7 || browser.mz)
		return innerHeight + 25;
	else
		return innerHeight + 28;
}

function getActiveContentMaxSize()
{
	return new objSize(990, 690);
}

function getWBCOffsetRect()
{
	return new objRectangle(0, -114, getWidthOfWBC(), getHeightOfWBC());
}

function getPageOffsetRect()
{
	return new objRectangle(173, 0, getWidthOfWBC() - 173, getHeightOfWBC() - 157);
}

function getScreenRect(rect)
{
	var pt;

	if (rect && parent.mainnav && parent.mainnav.document.mainnav && parent.mainnav.isLoadedActive() && parent.mainnav.document.mainnav.isShowing())
	{
		pt = parent.mainnav.document.mainnav.getLocationOnScreen();
		rect.x += pt.x;
		rect.y += pt.y;
		return rect;
	}
	else
	{
		return new objRectangle(0, 0, screen.availWidth, screen.availHeight);
	}
}

function getGlossary()
{
	if (parent.mainnav && parent.mainnav.document.glossary && parent.mainnav.document.glossary.isActive())
		return parent.mainnav.document.glossary;
	else
		return null;
}

function getGlossaryRect()
{
	return getScreenRect(getPageOffsetRect());
}

function getSearch()
{
	if (parent.mainnav && parent.mainnav.document.search && parent.mainnav.document.search.isActive())
		return parent.mainnav.document.search;
	else
		return null;
}

function getDiary()
{
	if (parent.mainnav && parent.mainnav.document.diary && parent.mainnav.document.diary.isActive())
		return parent.mainnav.document.diary;
	else
		return null;
}

function getDiaryRect()
{
	return getScreenRect(getPageOffsetRect());
}

function getSacRect()
{
	return getScreenRect(getWBCOffsetRect());
}

function getACGroup()
{
	if (parent.mainnav && parent.mainnav.document.acgroup && parent.mainnav.document.acgroup.isActive())
		return parent.mainnav.document.acgroup;
	else
		return null;
}

function getACGroupRect()
{
	return getScreenRect(getWBCOffsetRect());
}

