var gsdlURL = '';
var gsdlServerURL = location.protocol + "//" + location.host;
var gsdlDefaults = { 
	args: { 
		clmd: 0,
		o: 50,
		t: 0,
		m: 0,
		k: 1,
		s: 0
	}
};
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, ' ');
	}
}

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)
		gsdl_goto(gsdlURL + 'd/' + weaID + sectionID + '/');
}

function gsdlTrimFieldValue(objField) {
	if (objField != null && objField.value != null) {
		objField.value = objField.value.gsdl_clean();
	}
}

function openWindow (address) {
	open(fix_url2(address), '_blank', 'width=600,height=400,menubar=yes,location=yes,status=yes,toolbar=yes,resizable=yes,scrollbars=yes');
}

function openWindow1 (address) {
	open(fix_url2(address), '_blank', 'width=600,height=400,menubar=yes,location=no,status=yes,toolbar=no,resizable=yes,scrollbars=yes');
}

function openWindow2 (address, width, height) {
	open(fix_url2(address), '_blank', 'width='+width+',height='+height+',menubar=no,location=no,status=yes,toolbar=no,resizable=yes,scrollbars=yes');
}

function openWindow3 (address, width, height) {
	open(fix_url2(address), '_blank', 'width='+width+',height='+height+',menubar=yes,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 openCourseWindow(address, width, height, title) {
	var offset = 25, posX, posY;
	if (screen.availHeight > height) height = screen.availHeight - 2*offset;
	if (screen.availWidth > width) width = screen.availWidth - 2*offset;
	posY = (screen.availHeight - height) / 2;
	posX = (screen.availWidth - width) / 2;
	open(address, '_blank', 'top='+posY+',left='+posX+',width='+width+',height='+height+',menubar=no,location=no,status=no,toolbar=no,resizable=yes,scrollbars=yes');
}

function openFixedWindow (address, width, height) {
	var posX, posY, nHeight, nWidth, offset = 10;
	nHeight = (screen.availHeight > height ? height :  screen.availHeight - 2*offset);
	nWidth = (screen.availWidth > width ? width : screen.availWidth - 2*offset);
	posY = (screen.availHeight - nHeight) / 2;
	posX = (screen.availWidth - nWidth) / 2;
	open(address, '_blank', 'top='+posY+',left='+posX+',width='+width+',height='+height+',menubar=no,location=no,status=no,toolbar=no,resizable=yes,scrollbars=no');
}

function resizeFixedWindow (width, height) {
	var posX, posY, nHeight, nWidth, offset = 10;
	nHeight = (screen.availHeight > height ? height :  screen.availHeight - 2*offset);
	nWidth = (screen.availWidth > width ? width : screen.availWidth - 2*offset);
	posY = (screen.availHeight - nHeight) / 2;
	posX = (screen.availWidth - nWidth) / 2;
	moveTo (posX, posY); resizeTo (nWidth, nHeight);
}

function openModalWindow (address, width, height) {
	if (isGecko) {
		window.open(address, '', 'chrome,modal');
	} else {
		var ret = window.showModalDialog(address, '', 'dialogWidth:'+width+'px;dialogHeight:'+height+'px;center:1;status:0;help:0');
		if (ret != null && typeof(ret) != 'undefined' && ret != "") {
			var idx = ret.indexOf(":");
			if (idx > -1) {
				var strAction = ret.substr(0, idx);
				if (strAction == "reload") {
					window.location.reload(true);
				} else if (strAction == "add") {
					var strURL = gsdlLocationAddParam(window.location, ret.substr(idx+1));
					window.setTimeout("window.location = '" + strURL + "'", 400);
				} else if (strAction == "new") {
					openWindow(ret.substr(idx+1));
				} else if (strAction == "addnew") {
					openWindow(window.location.href + ret.substr(idx+1));
				} else if (strAction == "go") {
					window.setTimeout("window.location = '" + ret.substr(idx+1) + "'", 400);
				} else {
					window.setTimeout("window.location = '" + ret + "'", 400);
				}
			}
		}
	}
}

function openPrintPreviewWindow(address, width, height) {
	if (IE4plus && !IE4) {
		var ampReg = new RegExp('&', 'g');
		address = address.replace(ampReg, "&" + "amp" + ";");
	} else {
		var 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 + 'p/exportmsg/?cl=' + cgiarg.cl + '&amp;d=' + cgiarg.d;
	strURL += '&amp;xf=' + format + '&amp;ew=' + encoding;
	openWindow2(fix_url(strURL), width, height);
}

//
// 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;
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;
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;
IE55plus = IE55 || IE6 || IE7 || IE8;
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(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 gsdlLocationAddParam(locationObj, strParams) {
	fix_location_hash(locationObj);
	var strArgs = locationObj.search.substr(1);

	var strNewURL = locationObj.protocol + "//" + locationObj.host;
	strNewURL += locationObj.pathname;
	if (strArgs.length) strArgs += '&';
	strArgs += strParams;

	strNewURL += "?" + strArgs;
	if (locationObj.hash.length) strNewURL += locationObj.hash;
	
 
	if (IE5plus) {
		var ampReg = new RegExp('&', 'g');
		strNewURL = strNewURL.replace(ampReg, "&" + "amp" + ";");
	}
	return strNewURL;
}

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, "");
		}
	}
}

var gLocationObj = null;
function clearForm2() { clearForm1(); }
function clearForm1() {
	var objTemp = gsdlGetElement('checkall');
	if (objTemp != 'undefined' && objTemp != null) objTemp.checked = false;
	
	var date = new Date();
	if (cgiarg.a == 'q') {
		var queryForm = gsdlGetElement('QueryPostForm');
		g_gsdlPreferenceState.SetFormArgs(queryForm);
		
		gsdlInitValue(queryForm.uq, '' + date.getTime());
		gsdlInitValue(queryForm.qu, '' + gsdlNewQueryUniqueId());
		gsdlInitValue(queryForm.r, '1');
		gsdlInitValue(queryForm.qe, '0');
		gsdlInitValue(queryForm.q, '');
		gsdlInitValue(queryForm.fqv, '');
		gsdlInitValue(queryForm.fqf, '');

		queryForm.submit();
		return;
	}
	
	if (!gsdlGetCookieBool('qe', false))
		return;
	gsdlSetCookie('qe', '0');
	updateClearLink();
	clearHighlight();

	var strURL = gsdlURL + 'q/';
	var strVars = 'q=&fqv=&fqu=&fqf=&fqc=&fqk=&fqs=&r=1&qe=0&qu=' + gsdlNewQueryUniqueId() + '&uq=' + date.getTime();
	var request = null;
	if (!IE4 && !NS4) request = gsdlGetHttpRequest();
	if (request == null) {
		gsdlGetElement('dataFrame').src = strURL + '?' + strVars;
	} else {
		request.open('POST', strURL, false);
		request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		request.send(strVars);
	}
	return;
}

function gsdlInitValue(field, value) {
	if (typeof(field.type) != 'undefined') {
		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') {
					if (value == field.value)
						field.checked = true;
				} else { // 'text', 'textarea', 'password', 'hidden'
					field.value = value;
				}
	} else if (typeof(field.length) != 'undefined') {
		var values = null;
		if (typeof(value) == 'string')
			values = value.split('||');
		if (values == null || values.length == 1) {
			for (var i = 0; i < field.length; ++i) {
				gsdlInitValue(field[i], value);
			}
		} else {
			for (var i = 0; i < field.length; ++i) {
				for (var j = 0; j < values.length; ++j) {
					gsdlInitValue(field[i], values[j]);
				}
			}
		}
	}
}

function gsdlInitRadioValue(field, value) {
	for(var i = 0; i < field.length; ++i) {
		field[i].checked = (field[i].value == value);
	}
}

function gsdlGetValue(field) {
	if (typeof(field.type) != 'undefined') {
		if (field.type == 'select-one') {
			if (field.selectedIndex < 0)
				return '';
			else
				return field.options[field.selectedIndex].value;
		} else if (field.type == 'checkbox' || field.type == 'radio'){
			return field.checked ? field.value : '';
		} else {
			return field.value;
		}
	} else if (typeof(field.length) != 'undefined')
	{
		var value = '', v;
		for (var i = 0; i < field.length; ++i)
		{
			v = gsdlGetValue(field[i]);
			if (v.length > 0 && value.length > 0)
				value += '||';
			value += v;
		}
		return value;
	}
}

function close_detach() {
	close();
}

var loaded = new Array();
function gbutton (image, onimage) {
	if (image && image.src && (image.out == null || typeof(image.out) == typeof(void(0)))) {
		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) {
		if (over) i = "over";
		else i = "out";
		image = loaded[imagename];
		if (image) image.src = eval("image."+i+".src");
	}
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i = 0; i < changeImages.arguments.length; i += 2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		preloadFlag = true;
	}
}


function xInsDoc(parent, text, jn)
{
	var doc = insDoc(parent, gLnk('S', text, 'javascript:display_doc(\\\'' + jn + '\\\')'));
	doc.xID = jn;
}

function xInsFld(parent, text, jn)
{
	var fld = insFld(parent, gFld(text, 'javascript:display_doc(' + String.fromCharCode(34) + jn + String.fromCharCode(34) + ')'));
	fld.xID = jn;
	return fld;
}

function synchPage(linkID)
{
	if (foldersTree == 'undefined' || foldersTree == null)
	{
		window.setTimeout('synchPage("'+ linkID + '")', 400);
	}
	var folderObj;
	docObj = findObj(linkID);
	if (docObj != "undefined")
	{
		docObj.forceOpeningOfAncestorFolders();

		if (typeof docObj.setState != "undefined")
		{ //is folder
			if (!docObj.isOpen)
				clickOnNodeObj(docObj);
		}
		highlightObjLink(docObj);

		//Scroll the tree window to show the selected node
		//Other code in these functions needs to be changed to work with
		//frameless pages, but this code should, I think, simply be removed
		if (typeof document.body != "undefined") //scroll doesn work with NS4, for example
			document.body.scrollTop = docObj.navObj.offsetTop
	}
}

function array_remove_at(arrObject, nIndex, nLength)
{
	if (arrObject.splice != null) {
		arrObject.splice(nIndex, nLength);
	} else {
		var carray = new Array();
		if (nIndex == 0) {
			if (nIndex+nLength > arrObject.length) {
			} else {
				carray = arrObject.slice(nLength);
			}
		} else {
			if (nIndex+nLength > arrObject.length) {
				carray = new Array().concat(arrObject.slice(0,nIndex));
			} else {
				carray = new Array().concat(arrObject.slice(0,nIndex), arrObject.slice(nIndex+nLength));
			}
		}
		arrObject.length = 0;
		var i=0;
		for(i=0; i < carray.length; ++i) {
			arrObject[i] = carray[i];
		}
	}
}

function gsdlGetElement(strName, doc) {
	if (typeof(doc) == 'undefined' || doc == null)
		doc = document;
	var elem = null;
	if (doc.getElementById) {
		elem = doc.getElementById(strName);
	} else if (doc.all) {
		elem = doc.all[strName];
	} else {
		eval('elem = doc.' + strName);
	}
	return elem;
}

function gsdlGetArrayElement(strName, max) {
	var elem, a = new Array();
	if (typeof(max) == 'undefined' || max == null)
		max = 1000;
	for (var i = 1; i < max; ++i)
	{
		elem = gsdlGetElement(strName + i);
		if (elem == null)
			break;
		a.push(elem);
	}
	return a;
}


function ChangeImageSource(strId, strSRC)
{
	var objImage = GetImageObject(strId);
	if (objImage != null)
		objImage.src = strSRC;
}

function GetImageObject (strId)
{
	var objImage = null;
	if (document.getElementById)
	{
		objImage = document.getElementById(strId);
	}
	else if (document.all)
	{
		objImage = document.all.item(strId);
	}
	else
	{
		objImage = document.images[strId];
		if (!objImage) objImage = eval('document.' + strId );
	}
	return objImage;
}

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 cancelEvent(e) {
	if(!e) e = window.event;
	if(!e) e = window.Event;
	if(e) {
		if (typeof(e.cancelBubble) != 'undefined')
			e.cancelBubble = true;
		if (typeof(e.returnValue) != 'undefined')
			e.returnValue = false;
		if (typeof(e.stopPropagation) != 'undefined' && e.stopPropagation)
			e.stopPropagation();
	}
	return false;
}

var nHideCountryAssociationsTimer = 0;
function DisplayCountryAssociations(nId) {
	cancelEvent();
	if (nHideCountryAssociationsTimer != 0)
		window.clearTimeout(nHideCountryAssociationsTimer);
	var objSpan, objLayer;
	var arrInfo = new Array();
	var isvisible = false;
	
	objSpan = GetObject(nId);
	objLayer = GetObject('ca_' + nId);

	if (objSpan && objLayer) {
		arrInfo = GetObjectInfo(objSpan);
		arrInfoLayer = GetObjectInfo(objLayer);
			MoveObjectTo(objLayer, arrInfo[0] - arrInfoLayer[2]/2, arrInfo[1] - 3);
		isvisible = !ShowObject(objLayer);
		if (isvisible) {
			g_aRegisteredLayerHide.Hide();
		}
	} else {
		alert ('Unknown object ' + nId + ' !');
	}
	if (isvisible) {
		g_aRegisteredLayerHide.Register(DisplayCountryAssociations, nId);
	} else {
		g_aRegisteredLayerHide.UnRegister(DisplayCountryAssociations, nId);
	}
	StartHideCountryAssociations(nId, '3000');
}

function StartHideCountryAssociations(nId, sec) {
	if (nHideCountryAssociationsTimer != 0)
		window.clearTimeout(nHideCountryAssociationsTimer);
	nHideCountryAssociationsTimer = window.setTimeout("HideCountryAssociations('" + nId + "')", sec);
}

function HideCountryAssociations(nId) {
	if (nHideCountryAssociationsTimer != 0)
		window.clearTimeout(nHideCountryAssociationsTimer);
	nHideCountryAssociationsTimer = 0;
	g_aRegisteredLayerHide.Hide();
}

function CancelHideCountryAssociations(nId) {
	if (nHideCountryAssociationsTimer != 0)
		window.clearTimeout(nHideCountryAssociationsTimer);
}

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();

function __coverErrorInit__() {
	var strImg = httpCollectionImage + '/blankcover\\.gif';
	var re = new RegExp('\\/', 'g');
	strImg = strImg.replace(re,'\\/');
	g_imgRegExp = new RegExp(strImg + '$', 'i');
}

var g_imgRegExp = 0;

function CoverError() {
	if (g_imgRegExp != 0 && this.src.search(g_imgRegExp) < 0)
		this.src = httpCollectionImage + '/blankcover.gif';
}

function closeDocument() {
	var strCL = gsdlGetCookie('cl', '');
	if (strCL.length == 0) {
		gsdl_goto(gsdlURL);
	} else if (strCL == 'search') {
		gsdl_goto(gsdlURL + 'q/');
	} else {
		gsdl_goto(gsdlURL + 'cl/' + strCL + '/');
	}

}

function expand_warning(strOID) {
	if (strOID == null) strOID = cgiarg.d;
	if (confirm(textDocumentExpandWarning2)) {
		gsdl_goto_ex(location, gsdlCGI + '/' + 'd/' + strOID + '/gt,2,gc,1.html');
	}
}

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] - 20);
		isvisible = !ShowObject(objLayer);
		if (isvisible) {
			g_aRegisteredLayerHide.Hide();
		}
	} else {
		alert ('Unknown object ' + nId + ' !');
	}
	if (IE55plus) {
		var modalFrame = GetObject('overLayer');
		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 (nId == 'near' && !IE55plus && IE4plus) {
		var problematicSelect = GetObject('orgselect');
		problematicSelect.style.display = isvisible ? 'none' : 'block';
	}
	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 eventTrigger (e) {
	if (! e)
		e = event;
	return e.target || e.srcElement;
}

function checkClick(evt) {
	var obj = eventTrigger (evt);
	if (obj.id != "ca_mesh" && obj.id != "meshLink" && obj.id != 'descriptionLink' && obj.id != 'descriptionImage')
		HideDescriptionBox('ca_mesh');
}

var nHideCountryAssociationsTimer = 0;
function DisplayBlock(nId) {
	if (nHideCountryAssociationsTimer != 0)
		window.clearTimeout(nHideCountryAssociationsTimer);
	var objSpan, objLayer;
	var arrInfo;
	var isvisible = false;
	
	objSpan = GetObject(nId);
	objLayer = GetObject('ca_' + nId);

	if (objSpan && objLayer) {
		arrInfo = GetObjectInfo(objSpan);
		var arrInfo2 = GetObjectInfo(objLayer);
		//alert(objSpan.id + ' ' + arrInfo);
		if (IE4 || IE8)
			MoveObjectTo(objLayer, arrInfo[1] + 497, arrInfo[1] + 163);
		else
			MoveObjectTo(objLayer, arrInfo[0] - arrInfo2[2] + 1, arrInfo[1] + 2);
		isvisible = !ShowObject(objLayer);
		if (isvisible) {
			g_aRegisteredLayerHide.Hide();
		}
	} else {
		alert ('Unknown object ' + nId + ' !');
	}
	if (isvisible) {
		g_aRegisteredLayerHide.Register(DisplayBlock, nId);
	} else {
		g_aRegisteredLayerHide.UnRegister(DisplayBlock, nId);
	}
}

function updateClearLink() {
	var clearFormLink = gsdlGetElement('clearFormLink');
	if (clearFormLink == null) return;
	var bHasQuery = gsdlGetCookieBool('qe', false);
	clearFormLink.className = 'clearmeniu' + (bHasQuery ? 'active' : 'inactive');
	//clearFormLink.disabled = !bHasQuery;
	if (bHasQuery)
		clearFormLink.href = 'javascript:clearForm2();';
	else
		clearFormLink.href = 'javascript:void(0);';
}

function clearHighlight() {
	if (cgiarg.a != 'd') return;
	var documentContent = gsdlGetElement('documentContent');
	if (documentContent == null) return;
	var elements = getElementsByClassName(documentContent, 'span', 'hl');
	if (elements == null && elements.length == 0) return;
	for(var i = 0; i < elements.length; ++i) {
		elements[i].className = 'hlnone';
	}
}

function gsdlGetHttpRequest() {return null;}
function globalPageInit() {
	if (gsdlCGI.length > 0 && gsdlCGI.substr(0, 1) != '/')
		gsdlCGI = '/' + gsdlCGI;
	gsdlURL = gsdlCGI + '/';
	if (typeof(cgiarg.l) == 'undefined' || cgiarg.l == null)
		cgiarg.l = 'en';
	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;}');

	__coverErrorInit__();
	if (typeof(g_gsdlPreferenceState) != 'undefined' && g_gsdlPreferenceState != null)
		g_gsdlPreferenceState.Initialize();
	if (cgiarg.a == 'p' && cgiarg.p == 'about') {
		onLoadPageAbout();
	}
	if (cgiarg.a == 'q') {
		gsdlSetCookie('cl', 'search');
		query_initialize();
	}
	if (!gsdlGetCookieBool('sd', true) && gsdlGetElement('pagedescription') != null) {
		showDescription();
	}
}

function getPageCLMD() {
	var pageCLMD = gsdlDefaults.args.clmd;
	var r = /\/clmd,([0-9]+)/;
	var a = r.exec(window.location.href);
	if (a != null && a.length > 1) {
		pageCLMD = parseInt(a[1], 10);
	}
	return pageCLMD;
}

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;
	}
	document.cookie = strCookie + ';path=' + escape(gsdlCGI) + ';expires=Fri, 31 Dec 2099 23:59:59 GMT;';
}

function gsdlUpdateLinksForCLMD(value) {
	if (typeof(value) == 'undefined' || value == null)
		value = gsdlGetCookieInt('clmd', 20);
	var re = new RegExp('x');
	re.compile('\\/clmd,[0-9]+(,clr,[0-9]+)?(,cldc,[0-9]+)?');
	var np = '/clmd,' + value;
	for (var i = 0; i < document.links.length; ++i) {
		document.links[i].href = document.links[i].href.replace(re, np);
	}
}

function gsdlGetQueryUniqueId() {
	return gsdlGetCookieInt('qu', 0);
}

function gsdlNewQueryUniqueId() {
	var queryUniqueId = 1 + gsdlGetCookieInt('qu', 0);
	if (queryUniqueId == 2147483646) queryUniqueId = 1;
	gsdlSetCookie('qu', queryUniqueId);
	return queryUniqueId;
}

////////////////////////////////////////////////////////////////////////////////
// For about page
////////////////////////////////////////////////////////////////////////////////
var gBookCoverTimeout;
var coverlinkindex = -1;
function onLoadPageAbout()
{
	var book = getBookElement();
	if (book != null) book.onError= CoverError;
	set_book();
}

var gBookCoverImage=null;
function setBookCoverImage(oImg) {
	if (!gBookCoverImage) {
		gBookCoverImage=oImg;
	}
}

function GoToBookCover() { gsdl_goto(thislink); }

function getBookElement() {
	var elem = null;
	if (document.getElementById) {
		elem = document.getElementById('book');
	} else if (document.all) {
		elem = document.all['book'];
	} else {
		elem = document.images['book'];
		if (!elem) elem = document.book;
	}
	return elem;
}

var thislink = '';
function set_book()
{
	if (typeof(books) == 'undefined' || books.length < 1) return;
	if (!gBookCoverImage) {
		gBookCoverImage = getBookElement();
		if (!gBookCoverImage) {
			return;
		}
	}
	var date = new Date();
	var t = ((date.getTime() % 9301) + (Math.round(Math.random() * 49297))) % books.length;
	if (t >= books.length) t = books.length - 1;
	var thisbook = httpCollectionAssocImage + '/' + hrefs[t] + '/cover.jpg';
	thislink  = httpCollectionAssocImage + '/' + hrefs[t] + '/' + hrefs[t] + '.pdf';

	var oBookLinkElem = null;
	if (document.getElementById) {
		oBookLinkElem = document.getElementById('coverlink');
	} else if (document.all) {
		oBookLinkElem = document.all['coverlink'];
	} else {
		if (coverlinkindex != -1)
			oBookLinkElem = document.links[coverlinkindex];
	}
	if (!oBookLinkElem) {
		// we failed to find the object
	} else if (oBookLinkElem.href) {
		gBookCoverImage.src = thisbook;
		oBookLinkElem.href = fix_url2(thislink);
		window.clearTimeout(gBookCoverTimeout);
		gBookCoverTimeout = window.setTimeout("set_book();", 5000);
	}
}

function showDescription() {
	var obj = gsdlGetElement('pagedescription');
	if (typeof(obj) == 'undefined' || obj == null)
		return;
	var bVisible;
	if (typeof(obj.style.display) != 'undefined' && obj.style.display == 'none')
		bVisible = true;
	else
		bVisible = false;
	obj.style.display = (bVisible ? '' : 'none');

	var iobj = gsdlGetElement('sdShowPageBtn');
	if (typeof(iobj) != 'undefined' && iobj != null)
	{
		iobj.src = httpCollectionImage + '/' + (bVisible ? 'sdclose.gif' : 'sdshow.gif');
		if (IE4) {
			gsdlGetElement('sdShowPageLink').innerHTML = '<img src="' + httpCollectionImage +  '/' + (bVisible ? 'sdclose.gif' : 'sdshow.gif') + '" alt="' + (bVisible ? texts.iconPageDescriptionOpen : texts.iconPageDescriptionClosed) + '" title="' + (bVisible ? texts.iconPageDescriptionOpen : texts.iconPageDescriptionClosed) + '" border="0" align="middle" id="sdShowPageBtn">';
		} else {
			iobj.title = bVisible ? texts.iconPageDescriptionOpen : texts.iconPageDescriptionClosed;
			iobj.alt = bVisible ? texts.iconPageDescriptionOpen : texts.iconPageDescriptionClosed;
		}
	}
	gsdlPrefUpdateArg('sd' , bVisible ? 1 : 0 );
	g_aRegisteredLayerHide.Hide();
}

function onCatalogClick(id, itemIndex) {
	var obj = gsdlGetElement('dcat' + itemIndex + '_' + id);
	if (typeof(obj) == 'undefined' || obj == null)
		return;
	var bVisible;
	if (typeof(obj.style.display) != 'undefined' && obj.style.display == 'none')
		bVisible = true;
	else
		bVisible = false;

	obj.style.display = (bVisible ? '' : 'none');
	var iobj = gsdlGetElement('idcat' + itemIndex + '_' + id);
	if (typeof(iobj) != 'undefined' && iobj != null)
	{
		if (id.indexOf('_') > -1)
			iobj.src = httpCollectionImage + '/' + (bVisible ? 'openfldr.gif' : 'clsdfldr.gif');
		else
			iobj.src = httpCollectionImage + '/' + (bVisible ? 'catalogopenbook.gif' : 'catalogclosebook.gif');
			iobj.title = bVisible ? texts.iconCatalogOpenBook : texts.iconCatalogCloseBook;
			iobj.alt = bVisible ? texts.iconCatalogOpenBook : texts.iconCatalogCloseBook;
	}
}

