var gsdlURL = '';
var gsdlServerURL = location.protocol + "//" + location.host;
window.onload= globalPageInit;
if (typeof(Array.prototype.push) == 'undefined')
{
	Array.prototype.push = function(v) {
		this[this.length] = v;
	}
}

if (typeof(Array.prototype.splice) == 'undefined')
{
	Array.prototype.splice = function(start, deleteCount) {
		var i;
		for(i = start + deleteCount; i < this.length; ++i) {
			this[i - deleteCount] = this[i];
		}
		this.length = this.length - deleteCount;
	}
}

if (typeof(String.prototype.trim) == 'undefined')
{
	String.prototype.trim = function() {
		var rs = new RegExp('^\\s+', '');
		var re = new RegExp('\\s+$', '');
		return this.replace(re, '').replace(rs, '');
	}
}

if (typeof(String.prototype.gsdl_clean) == 'undefined')
{
	String.prototype.gsdl_clean = function() {
		var rs = new RegExp('^\\s+', '');
		var re = new RegExp('\\s+$', '');
		var rd = new RegExp('\\s{2,}', 'g');
		return this.replace(re, '').replace(rs, '').replace(rd, ' ');
	}
}

//
// Browser Detection
//
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(navigator.appVersion.indexOf("MSIE")!=-1)&&(isMac)) ? true : false;
IE4plus = ((document.all)&&(navigator.appVersion.indexOf("MSIE")!=-1)) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
IE50 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.0")!=-1)) ? true : false;
IE55 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.5")!=-1)) ? true : false;
IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
IE7 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)) ? true : false;
IE8 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 8.")!=-1)) ? true : false;
IE9 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 9.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;
isGecko = (navigator.userAgent.indexOf(' Gecko/')!=-1)?true:false;
IE5plus = IE5 || IE6 || IE7 || IE8 || IE9;
IE55plus = IE55 || IE6 || IE7 || IE8 || IE9;
IEMajor = 0;

if (IE4plus)
{
	var start = navigator.appVersion.indexOf("MSIE");
	var end = navigator.appVersion.indexOf(".",start);
	IEMajor = parseInt(navigator.appVersion.substring(start+5,end));
	IE5plus = (IEMajor>=5) ? true : false;
	IE55plus = (IE55 || ((IEMajor>5) ? true : false));
}

function gsdl_encode(parString) {
	if (NS4 || NS6) {
		return escape(parString);
	}
	var str = "";
	for(var i=0; i < parString.length; i++) {
		if(parString.charCodeAt(i) < 0x80) {
			str += String.fromCharCode(parString.charCodeAt(i));
		}
		else if (parString.charCodeAt(i) < 0x0800) {
			str += String.fromCharCode(parString.charCodeAt(i)>> 6 | 0xC0);
			str += String.fromCharCode(parString.charCodeAt(i) & 0x3F | 0x80);
		}
		else if (parString.charCodeAt(i) < 0x10000) {
			str += String.fromCharCode(parString.charCodeAt(i)>> 12 | 0xE0);
			str += String.fromCharCode(parString.charCodeAt(i)>> 6 & 0x3F | 0x80);
			str += String.fromCharCode(parString.charCodeAt(i) & 0x3F | 0x80);
		}
		else {
			str += String.fromCharCode(parString.charCodeAt(i)>> 18 | 0xF0);
			str += String.fromCharCode(parString.charCodeAt(i)>> 12 & 0x3F | 0x80);
			str += String.fromCharCode(parString.charCodeAt(i)>> 6 & 0x3F | 0x80);
			str += String.fromCharCode(parString.charCodeAt(i) & 0x3F | 0x80);
		}
	}
	return escape(str);
}

function gsdl_goto(strURL) {
	var ampReg = new RegExp('&' + 'amp' + ';', 'g');
	strURL = strURL.replace(ampReg, "&");
	if (IE5plus) {
		var ampReg2 = new RegExp('&', 'g');
		strURL = strURL.replace(ampReg2, "&" + "amp" + ";");
	}
	window.location = strURL;
	return false;
}

function gsdl_goto_ex(obj, strURL) {
	var ampReg = new RegExp('&' + 'amp' + ';', 'g');
	strURL = strURL.replace(ampReg, "&");
	if (IE5plus) {
		var ampReg2 = new RegExp('&', 'g');
		strURL = strURL.replace(ampReg2, "&" + "amp" + ";");
	}
	obj.href = strURL;
	return false;
}

function fix_url(strURL) {
	var ampReg = new RegExp('&' + 'amp' + ';', 'g');
	strURL = strURL.replace(ampReg, "&");
	if  (IE5plus) {
		var ampReg2 = new RegExp('&', 'g');
		strURL = strURL.replace(ampReg2, "&" + "amp" + ";");
	}
	return strURL;
}

function fix_url2(strURL) {
	var ampReg = new RegExp('&' + 'amp' + ';', 'g');
	strURL = strURL.replace(ampReg, "&");
	return strURL;
}

function fix_location_hash (oLocationObj) {
	if (IE4 && oLocationObj.search !== null) {
		var re = new RegExp ('#.*$');
		var arrMatch = oLocationObj.search.match(re);

		if (arrMatch !== null && arrMatch.length) {
			oLocationObj.hash = arrMatch[0];
			oLocationObj.search = oLocationObj.search.replace(re, "");
		}
	}
}

function getUnixTime() {
	var date = new Date();
	return date.getTime();
}

function gsdlGetElement(strName, doc) {
	if (doc === null || typeof(doc) == 'undefined') { doc = document; }
	var elem = null;
	if (doc.getElementById) {
		elem = doc.getElementById(strName);
	} else if (doc.all) {
		elem = doc.all[strName];
	} else {
		eval('elem = document.' + strName);
	}
	if (typeof(elem) == 'undefined') { elem = null; }
	return elem;
}

function gsdlInitValue(field, value) {
	if (field.type == "select-one") {
		var i;
		for (i=0; i < field.options.length;i++) {
			if (value == field.options[i].value) {
				field.options[i].selected = true;
				break;
			}
		}
	} else if (field.type == "checkbox" || field.type == "radio") {
		field.checked = (value == "1"?true:false);
	} else { // "text", "textarea", "password", "hidden"
		field.value = value;
	}
}

function gsdlGetValue(field) {
	if (field.type == "select-one") {
		return field.options[field.selectedIndex].value;
	} else if (field.type == "checkbox" || field.type == "radio"){
		return field.checked ? "1" : "0";
	} else {
		return field.value;
	}
}

function changeSection(objSelect) {
	if (!objSelect) { return; }
	var index = objSelect.selectedIndex;
	var sectionID = objSelect.options[index].value;
	var weaID = "HASH6731e5b341863c8b95d12c";
	if (sectionID.length) { sectionID = "." + sectionID; }
	if (index > 0) {
		window.location = gsdlURL + cgiarg.l + '/d/' + weaID + sectionID + '/';
	}
}
function openWindow (address) {
	open(address, '_blank', 'width=600,height=400,menubar=yes,location=yes,status=yes,toolbar=yes,resizable=yes,scrollbars=yes');
}

function openWindow2 (address, width, height) {
	open(address, '_blank', 'width='+width+',height='+height+',menubar=no,location=no,status=yes,toolbar=no,resizable=yes,scrollbars=yes');
}

function openExtLink(address) {
	open(address, '_blank', 'width=600,height=400,menubar=yes,location=yes,status=yes,toolbar=yes,resizable=yes,scrollbars=yes');
}

function openPrintPreviewWindow(address, width, height) {
	var ampReg;
	if (IE4plus && !IE4) {
		ampReg = new RegExp('&', 'g');
		address = address.replace(ampReg, "&" + "amp" + ";");
	} else {
		ampReg = new RegExp('&amp;', 'g');
		address = address.replace(ampReg, "&");
	}
	open(address, '_blank', 'width='+width+',height='+height+',menubar=yes,location=no,status=yes,toolbar=yes,resizable=yes,scrollbars=yes');
}

function openExportWindow(format, encoding, width, height) {
	var strURL = gsdlURL + cgiarg.l + '/p/exportmsg/?cl=' + cgiarg.cl + '&amp;d=' + cgiarg.d;
	strURL += '&amp;xf=' + format + '&amp;ew=' + encoding;
	openWindow2(fix_url(strURL), width, height);
}

var gLocationObj = null;
function clearForm1() {
	if (gsdlGetCookieBool('qe', false)) {
		strNewURL = gsdlURL + cgiarg.l + '/q/page/docfr/uq,1.html?qe=0&q=&fqv=&chka=1&r=1&uq=' + getUnixTime();
		if (IE5plus) {
			var ampReg = new RegExp('&', 'g');
			strNewURL = strNewURL.replace(ampReg, "&" + "amp" + ";");
		}
		gsdl_goto_ex(top.location, strNewURL);
	} else if (cgiarg.a == 'q' || (cgiarg.a == 'p' && cgiarg.p == 'docb')) {
		document.QueryForm.reset();
		argfqv = '';
		query_initialize();
	}
}

function close_detach() {
	close();
}

var loaded = [];
function gbutton (image, onimage) {
	if (image && image.src && image.out === null) {
		var s = image.src;
		image.out = new Image();
		image.out.src = s;
		image.over = new Image();
		image.over.src = onimage;
		loaded[image.name] = image;
	}
}

function roll (imagename, over) {
	if (document.images) {
		var i = 'out';
		if (over) { i = 'over'; }
		var image = loaded[imagename];
		if (image) { image.src = eval("image."+i+".src"); }
	}
}

function OpenDoc(section) {
	if (typeof(gsdlURL) == 'undefined' || gsdlURL.length == 0)
		gsdlInitURL();
	top.docf.location.href = gsdlURL + cgiarg.l + '/d/Jb.' + section + '/';
	//var idx = section.indexOf('&');
	//if (idx != -1) {
	//	section = section.substr(0,idx);
	//}
	//top.doctree.synchPage('Jb.' + section);
}

function updateDocButtons(oid) {
	var section = '';
	if (oid !== null && typeof(oid) != 'undefined' && oid.length > 0)
	{
		var regex = new RegExp('^Jb\\.([0-9]+)', '');
		var arr = oid.match(regex);
		if (arr !== null && arr.length > 0) {
			section = arr[1];
		}
	}
	var obj = gsdlGetElement('toc' + section);
	var i;
	var obj2 = null;

	for (i=1; i < 13; ++i)
	{
		obj2 = gsdlGetElement('toc' + i);
		if (obj2 !== null && typeof(obj2) != 'undefined' && obj2 != obj) {
			obj2.className = 'topmenu';
		}
	}

	if (obj !== null && typeof(obj) != 'undefined') {
		obj.className = 'topmenuactiv';
	}
}

function updatesd (value) {
	argsd = "&sd=" + value;
	var newUrl = location.href;
	var re = new RegExp("&sd=[^&]*", "ig");
	
	// remove any bookmark before adding any new argument ...
	var reHash = new RegExp("\#.*", "i");
	newUrl = newUrl.replace (reHash, '');

	// remove any existing 'gca' argument ...
	newUrl = newUrl.replace(re, '');

	newUrl += argsd;

	location.href = newUrl;
}

function updateBannerButtons(page, currentIdx, foundWords, currentOID) {
	if (typeof(top.banner) != 'undefined' && typeof(top.banner.updateBannerButtonsX) != 'undefined' && gsdlGetElement('mnuRead', top.banner.document) !== null) {
			top.banner.updateBannerButtonsX(page, currentIdx, foundWords, currentOID);
	} else {
		window.setTimeout('updateBannerButtons("' + page + '", ' + currentIdx + ', ' + foundWords + ', "' + currentOID + '");', 400);
	}
}

function updateBannerButtonsX(page, currentIdx, foundWords, currentOID) {
	if (currentIdx === null) { currentIdx = 1; }
	if (foundWords === null) { foundWords = 0; }
	if (currentOID === null) { currentOID = ''; }
	updateButtons(currentIdx, foundWords, currentOID);
	updateDocButtons(currentOID);

	gsdlGetElement('mnuSearch').className = (page == 'search' ? 'meniuactiv' : 'meniu');
	gsdlGetElement('mnuRead').className = (page == 'doc' ? 'meniuactiv' : 'meniu');
	gsdlGetElement('mnuHelp').className = (page == 'help' ? 'meniuactiv' : 'meniu');
}

function GetObject (strId)
{
	var objLayer = null;

	if (document.getElementById)
	{
		objLayer = document.getElementById(strId);
	}
	else if (document.all)
	{
		objLayer = document.all.item(strId);
	}
	else
	{
		objLayer = eval('document.' + strId );
	}
	return objLayer;
}

/* MoveObjectTo():
	moves the objLayer object to (nLeft,nTop) absolute coordinates ...
 */

function MoveObjectTo(objLayer, nLeft, nTop) {
	if (document.getElementById || document.all) {
		objLayer.style.left = nLeft + 'px';
		objLayer.style.top = nTop + 'px';
	} else {
		objLayer.left = nLeft;
		objLayer.top = nTop;
	}
}

/* GetObjectInfo():
	returns an array containing : 0-left, 1-top, 2-width, 3-height ...
 */

function GetObjectInfo(objLayer) {
	var arrInfo = new Array();
	var TempTop, TempHeight;
	if (document.getElementById || document.all)
	{
		arrInfo[0] = objLayer.offsetLeft;
		TempTop = objLayer.offsetTop;
		TempHeight = objLayer.offsetHeight;
		arrInfo[1] = TempTop + TempHeight;
		arrInfo[2] = objLayer.offsetWidth;
		arrInfo[3] = objLayer.offsetHeight;
	}
	else
	{
		arrInfo[0] = objLayer.pageX;
		arrInfo[1] = objLayer.pageY + 14;
	}
	return arrInfo;
}

function ShowObject(objLayer, bShow) {
	if (! objLayer) return false;
	var bVisible, bOldVisible;

	// get current state ...
	if (document.getElementById || document.all)
		bOldVisible = (objLayer.style.visibility == 'visible');
	else
		bOldVisible = (objLayer.visibility == 'show');

	// see if the object should be visible or hidden ...
	if (typeof(bShow) == 'undefined' || bShow == null) {
		bVisible = ! bOldVisible;
	}
	else
		bVisible = bShow;

	// set new state ...
	if (document.getElementById || document.all)
		objLayer.style.visibility = (bVisible ? 'visible' : 'hidden');
	else
		objLayer.visibility = (bVisible ? 'show' : 'hide');
	return bOldVisible;
}

function isGoodNumericKey(evt) {
	//var charCode = (evt.charCode) ? evt.charCode : event.keyCode
	var charCode = evt.keyCode ? evt.keyCode : evt.charCode ? evt.charCode : evt.which;

	if ((charCode >= 48 && charCode <= 57) || charCode == 13 || charCode == 37 || charCode == 39 || charCode == 8 || charCode == 46) { // numeric
		return true;
	} else {
		return false;
	}
}


function gsdlInitURL() {
	if (gsdlCGI.length > 0 && gsdlCGI.substr(0, 1) != '/')
		gsdlCGI = '/' + gsdlCGI;
	gsdlURL = gsdlCGI + '/';
}

function gsdlGetHttpRequest() {return null;}
function globalPageInit() {
	if (typeof(cgiarg) != 'undefined' && typeof(cgiarg.gt) == 'undefined')
		cgiarg.gt = 0;
	if (typeof(gsdlQueryIsPage) == 'undefined' || gsdlQueryIsPage != null)
		gsdlQueryIsPage = false;
	gsdlInitURL();
	if (!IE4 && !NS4)
		eval('gsdlGetHttpRequest = function() {var obj = null;if (window.XMLHttpRequest) {obj = new XMLHttpRequest();if (obj.overrideMimeType)obj.overrideMimeType("text/xml");} else if (window.ActiveXObject) {try {obj = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) {try {obj = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {}}}return obj;}');
	if (cgiarg.a == 'p') {
		if (cgiarg.p == 'doctree') {
			OnTreePageLoad();
		} else if (cgiarg.p == 'docb') {
			onDocumentInit();
		} else if (cgiarg.p == 'help') {
			gsdlSetCookie('docfl', 'help');
			if (typeof(top.banner) == 'undefined') {
				top.location = gsdlURL + cgiarg.l + '/p/docfr/docfl,help.html';
				return;
			}
			onHelpPageInit();
			updateBannerButtons('help');
		} else if (cgiarg.p == 'firstpage') {
			onFirstPageInit();
		} else if (cgiarg.p == 'docfr') {
			gsdlSetCookie('docfl', cgiarg.docfl);
			gsdl_goto(docURL);
		}
	}
	if (cgiarg.a == 'd') {
		gsdlSetCookie('docfl', 'doc');
		gsdlSetCookie('d', cgiarg.d);
		if (typeof(top.banner) == 'undefined') {
			if (gsdlURL == '/gsdl-whopharm/')
				top.location = gsdlURL + cgiarg.l + '/p/docfr/docfl,doc,d,' + cgiarg.d + '.html';
			else
				top.location = gsdlURL + cgiarg.l + '/p/docfr/docfl,doc,d,Jb.1.html';
			return;
		}
		if (cgiarg.htoc == '1' && !NS4)
			document_initialize();
	}
	//updateClearLink();
	//__coverErrorInit__();
	//g_gsdlPreferenceState.Initialize();
	if (cgiarg.a == 'q' && !gsdlQueryIsPage) {
		gsdlSetCookie('docfl', 'search');
		if (typeof(top.banner) == 'undefined') {
			top.location = gsdlURL + cgiarg.l + '/p/docfr/docfl,search.html';
			return;
		}
		query_initialize();
	}
}

var g_hCookies = {
	'init': false
};

function gsdlGetCookie(name, defaultValue) {
	if (!g_hCookies.init)
		gsdlParseCookies();
	var value = g_hCookies['__' + name];
	if (typeof(value) == 'undefined') {
		if (typeof(defaultValue) == 'undefined' || defaultValue == null)
			return null;
		return '' + defaultValue;
	} else {
		return value;
	}
}

function gsdlGetCookieInt(name, defaultValue) {
	if (!g_hCookies.init)
		gsdlParseCookies();
	var value = g_hCookies['__' + name];
	if (typeof(value) == 'undefined') {
		if (typeof(defaultValue) == 'undefined' || defaultValue == null)
			return null;
		if (typeof(defaultValue) == 'number')
			return defaultValue;
		if (typeof(defaultValue) == 'boolean')
			return defaultValue ? 1 : 0;
		return parseInt('' + defaultValue, 10);
	} else {
		return parseInt(value, 10);
	}
}

function gsdlGetCookieBool(name, defaultValue) {
	if (!g_hCookies.init)
		gsdlParseCookies();
	var value = g_hCookies['__' + name];
	if (typeof(value) == 'undefined') {
		if (typeof(defaultValue) == 'undefined' || defaultValue == null)
			return null;
		if (typeof(defaultValue) == 'number')
			return defaultValue != 0;
		if (typeof(defaultValue) == 'boolean')
			return defaultValue;
		defaultValue = '' + defaultValue;
		return (defaultValue == 'yes' || defaultValue == '1' || defaultValue == 'true');
	} else {
		return (value == 'yes' || value == '1' || value == 'true');
	}
}

function gsdlSetCookie(name, value) {
	if (!g_hCookies.init)
		gsdlParseCookies();
	if (value == null)
		g_hCookies['__' + name] = value;
	else
		g_hCookies['__' + name] = '' + value;
	gsdlBuildCookies();
}

//GSDL-ARGS=bo|0/pr|6/sid|XQAWEJ3I2130706433X00000664X4804A896
function gsdlParseCookies() {
	g_hCookies.init = true;
	if (document.cookie == null || document.cookie.length == 0)
		return;
	var i, aCookies, gsdlArgs = null, name, value, nPos;
	aCookies = document.cookie.split(';');
	for(i = 0; i < aCookies.length; ++i) {
		aCookies[i] = aCookies[i].trim();
		if (aCookies[i].indexOf('GSDL-ARGS=') == 0) {
			gsdlArgs = aCookies[i].substr(10).trim();
			break;
		}
	}
	if (gsdlArgs == null || gsdlArgs.length == 0)
		return;
	aCookies = gsdlArgs.split('/');
	for(i = 0; i < aCookies.length; ++i) {
		aCookies[i] = aCookies[i].trim();
		nPos = aCookies[i].indexOf('|');
		if (nPos > -1) {
			name  = unescape(aCookies[i].substr(0, nPos)).trim();
			value = unescape(aCookies[i].substr(nPos + 1)).trim();
			g_hCookies['__' + name] = value;
		}
	}
}

function gsdlBuildCookies() {
	if (!g_hCookies.init)
		return;
	var i, aCookies, gsdlArgs = '', strArg, strCookie = '', value;
	for (strArg in g_hCookies) {
		if (strArg.length > 2 && strArg.substr(0, 2) == '__') {
			value = g_hCookies[strArg];
			if (value != null && value.length > 0) {
				if (gsdlArgs.length > 0) gsdlArgs += '/';
				gsdlArgs += escape(strArg.substr(2)) + '|' + escape(value);
			}
		}
	}
	if (gsdlArgs.length > 0) {
		strCookie += 'GSDL-ARGS=' + gsdlArgs;
	}
	
	/*
	if (document.cookie != null && document.cookie.length > 0) {
		aCookies = document.cookie.split(';');
		for(i = 0; i < aCookies.length; ++i) {
			aCookies[i] = aCookies[i].trim();
			if (aCookies[i].indexOf('GSDL-ARGS=') != 0 && aCookies[i].indexOf('path=') != 0) {
				if (strCookie.length > 0) strCookie += ';';
				strCookie += aCookies[i];
			}
		}
	}
	*/
	document.cookie = strCookie + ';path=' + escape(gsdlCGI) + ';expires=Fri, 31 Dec 2099 23:59:59 GMT;';
}

function showNearBox() {
	var strValue = gsdlGetValue(document.QueryForm.fqv[fqvtextidx]).trim();
	if (strValue.length > 0) {
		document.ProxyForm.proxy.value = cgiarg.pr.length == 0 ? 0 : cgiarg.pr;
		var isVisible = PositionBox('near')
		if (isVisible){
			document.ProxyForm.proxy.focus();
			document.ProxyForm.proxy.select();
		} else {
			document.QueryForm.fqv[fqvtextidx].focus();
		}
	}
}

function PositionBox(nId) {
	var objSpan, objLayer;
	var arrInfo = new Array();
	var arrInfoLayer =  new Array();
	var isvisible = false;

	objSpan = GetObject(nId + 'Bookmark');
	objLayer = GetObject(nId + 'Box');

	if (objSpan && objLayer) {
		arrInfo = GetObjectInfo(objSpan);
		arrInfoLayer = GetObjectInfo(objLayer);
		MoveObjectTo(objLayer, arrInfo[0] - arrInfoLayer[2] / 2, arrInfo[1]);
		isvisible = !ShowObject(objLayer);
	} else {
		alert ('Unknown object ' + nId + ' !');
	}
	if (IE55plus) {
		var modalFrame = GetObject('overLayer');
		if (modalFrame) {
			modalFrame.style.top = objLayer.style.top;
			modalFrame.style.left = objLayer.style.left;
			modalFrame.style.width = arrInfoLayer[2];
			modalFrame.style.height = arrInfoLayer[3];
			modalFrame.style.zIndex = objLayer.style.zIndex + 1;
			modalFrame.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
			modalFrame.style.display = isvisible ? 'block' : 'none';
		}
	}
	if (isvisible) {
		g_aRegisteredLayerHide.Register(PositionBox, nId);
	} else {
		g_aRegisteredLayerHide.UnRegister(PositionBox, nId);
	}
	return isvisible;
}

function HideDescriptionBox(nId) {
	g_aRegisteredLayerHide.Hide();
	if (nId == 'near') {
		document.QueryForm.fqv[fqvtextidx].focus();
	}
}

function updateFrames() {
	window.setTimeout('updateFramesX()', 50);
}

function updateFramesX() {
	if (parent.banner == null || parent.banner.location == null) {
		window.setTimeout('updateFramesX()', 50);
		return;
	}
	gsdl_goto_ex(parent.banner.location, gsdlURL + cgiarg.l + '/p/docb/?qnew=1&amp;activesearch=1&amp;uq=' + getUnixTime());
}

var strColumnsCurrent = "200,*";
function hideTOC() {
	var obj = gsdlGetElement('navigare', top.document);
	if (obj === null) {
		var re = new RegExp ('&htoc=[0|1]', '');
		var currURL = top.location.href.replace(re, '');
		top.location.href = currURL + '&htoc=0';
		return;
	}
	strColumnsCurrent = obj.cols;
	obj.cols = "0,*";
	obj = gsdlGetElement('docf', top.document);
	obj.noResize = true;
	obj = gsdlGetElement('showtoctd', top.banner.document);
	obj.innerHTML = '<a href="javascript:void(0);" onClick="showTOC();" class="color1" style="margin-left: 5px; width: 14px; display: block;"><img src="' + httpCollectionImage + '/show-toc.gif" width="14" height="15" border="0" alt="Show TOC" title="Show TOC">';
}

function showLoading(bShow) {
	var obj = gsdlGetElement('loading');
	if (obj !== null) {
		obj.style.display = bShow ? 'block' : 'none';
	}
}

var g_queryResultIndex = -1;
var g_currentDocView = '';

function onDocumentInit() {
	obj = gsdlGetElement('docf', top.document);
	obj1 = gsdlGetElement('showtoctd', top.banner.document);
	if (!obj.noResize) {
		obj1.innerHTML = '<img src="' + httpCollectionImage + '/spacer.gif" width="19">';
	} else {
		obj1.innerHTML = '<a href="javascript:void(0);" onClick="showTOC();" class="color1" style="padding-left: 5px;"><img src="' + httpCollectionImage + '/show-toc.gif" width="14" height="15" border="0" alt="Show TOC" title="Show TOC">';
	}

	query_initialize();
	g_queryResultIndex = -1;
	updateResultButtons();
}

function updateResultIndex(docOID) {
	var i = 0;
	for(; i < g_queryResult.length; ++i) {
		if (g_queryResult[i] == docOID) {
			g_queryResultIndex = i;
			updateResultButtons();
			break;
		}
	}
}

function goNextResult(dir) {
	if (g_queryResult.length == 0)
		return;
	g_queryResultIndex += dir;
	if (g_queryResultIndex < 0)
		g_queryResultIndex = 0;
	else if (g_queryResultIndex >= g_queryResult.length)
		g_queryResultIndex = g_queryResult.length - 1;
	updateResultButtons();
	gsdl_goto_ex(top.docf.location, gsdlURL + cgiarg.l + '/d/' + g_queryResult[g_queryResultIndex] + '/?docfl=doc#docfirsthighlight');
}

function updateResultButtons() {
	if (g_queryResult.length == 0) {
		document.images['btnnextr'].src = httpCollectionImage + '/btndown.gif';
		document.images['btnprevr'].src = httpCollectionImage + '/btnup.gif';
	} else {
		if (g_queryResultIndex < g_queryResult.length - 1)
			document.images['btnnextr'].src = httpCollectionImage + '/btndown_activ.gif';
		else
			document.images['btnnextr'].src = httpCollectionImage + '/btndown.gif';
		if (g_queryResultIndex > 0)
			document.images['btnprevr'].src = httpCollectionImage + '/btnup_activ.gif';
		else
			document.images['btnprevr'].src = httpCollectionImage + '/btnup.gif';
	}
}

function updateButtons(currentIndex, foundWords, currentDocView) {
	g_currentDocView = currentDocView;
	if (document.images['btnnext'] == null || document.images["btnprev"] == null) {
		window.setTimeout('updateButtons(' + currentIndex + ', ' + foundWords + ');', 400);
		return;
	}
	if (foundWords != 0) {
		if (currentIndex < foundWords)
			document.images['btnnext'].src = httpCollectionImage + '/btnnext.gif';
		else
			document.images['btnnext'].src = httpCollectionImage + '/btnnextoff.gif';
		if (currentIndex > 1)
			document.images['btnprev'].src = httpCollectionImage + '/btnprev.gif';
		else
			document.images['btnprev'].src = httpCollectionImage + '/btnprevoff.gif';
	} else {
		document.images['btnnext'].src = httpCollectionImage + '/btnnextoff.gif';
		document.images['btnprev'].src = httpCollectionImage + '/btnprevoff.gif';
	}
}

function xchangeLanguage(lang) {
	window.setTimeout("xchangeLanguage2('" + lang + "');", 400);
}

function xchangeLanguage2(lang) {
	top.location.href = gsdlURL + lang + '/p/docf/?d=' + g_currentDocView;
}

function showTOC() {
	var obj = gsdlGetElement('navigare', top.document);
	if (obj === null) {
		var re = new RegExp ('&htoc=[0|1]', '');
		var currURL = top.location.href.replace(re, '');
		top.location.href = currURL + '&htoc=1';
		return;
	}
	obj.cols = top.searchnav.strColumnsCurrent;
	obj = gsdlGetElement('docf', top.document);
	obj.noResize = false;
	obj = gsdlGetElement('showtoctd', top.banner.document);
	obj.innerHTML = '<img src="' + httpCollectionImage + '/spacer.gif" width="19">';
}

function onFirstPageInit() {
	var bShowHome = gsdlGetCookieBool('showhome', true);
	var strURL = gsdlURL + cgiarg.l;
	if (bShowHome)
		strURL += '/p/about/';
	else
		strURL += '/p/docfr/docfl,doc,d,Jb.html';
	window.location = strURL;
}

function onHelpPageInit() {
	document.PrefForm.showhome.checked = !gsdlGetCookieBool('showhome', true);
	gsdlInitValue(document.PrefForm.m, gsdlGetCookie('m', '0'));
	gsdlInitValue(document.PrefForm.o, gsdlGetCookie('o', '50'));
	if (gsdlGetCookieBool('s', false)) {
		document.PrefForm.s[0].checked = true;
		document.PrefForm.s[1].checked = false;
	} else {
		document.PrefForm.s[0].checked = false;
		document.PrefForm.s[1].checked = true;
	}
	if (gsdlGetCookieBool('k', true)) {
		document.PrefForm.k[0].checked = true;
		document.PrefForm.k[1].checked = false;
	} else {
		document.PrefForm.k[0].checked = false;
		document.PrefForm.k[1].checked = true;
	}
}

function updateShowHomePage() {
//  alert(document.PrefForm.showhome.checked ? '0' : '1');
	gsdlSetCookie('showhome', document.PrefForm.showhome.checked ? '0' : '1');
}

function updatek(value) {
	gsdlSetCookie('k', value);
}

function updates(value) {
	gsdlSetCookie('s', value);
	gsdlSetCookie('fqs', '0,' + value);
}

function updatem() {
	var value = gsdlGetValue(document.PrefForm.m);
	gsdlSetCookie('m', value);
	gsdlSetCookie('r', '1');
}

function updateo() {
	var value = gsdlGetValue(document.PrefForm.o);
	gsdlSetCookie('o', value);
	gsdlSetCookie('r', '1');
}

function RegisteredLayersHide() {
	this.functions = new Array();
	this.parameters = new Array();
	this.Register = RegisteredLayersHide_Register;
	this.UnRegister = RegisteredLayersHide_UnRegister;
	this.Hide = RegisteredLayersHide_Hide;
}

function RegisteredLayersHide_Register(func, param) {
	this.functions.push(func);
	this.parameters.push(param);
}

function RegisteredLayersHide_UnRegister(func, param) {
	var i;
	for(i = 0; i < this.functions.length; ++i) {
		if (this.functions[i] == func && this.parameters[i] == param) {
			this.functions.splice(i, 1);
			this.parameters.splice(i, 1);
			break;
		}
	}
}

function RegisteredLayersHide_Hide() {
	while (this.functions.length) {
		this.functions[0](this.parameters[0]);
	}
}

var g_aRegisteredLayerHide = new RegisteredLayersHide();

