var gDocumentTOC = null;

function DocumentTree(id) {
	this.id = id;
	this.root = new DocumentTreeItem(id, null);
	this.root.tree = this;
	this.list = [];
	this.expanded = false;
	this.depth = 1;
	this.updateCurrentId(cgiarg.d);
}

function DocumentTreeItem(id, parent) {
	this.id = id;
	this.parent = parent;
	this.children = [];
	this.tree = null;
	this.isOpened = false;
	if (parent) {
		this.tree = parent.tree;
		if (this.id == this.tree.currentId) {
			this.isOpened = true;
		} else {
			var ids = id.split('_');
			var level = ids.length - 1;
			if (level < this.tree.currentIdParents.length && this.id == this.tree.currentIdParents[level]) {
				this.isOpened = true;
			}
		}
	} else {
		this.isOpened = true;
	}
}

DocumentTree.prototype.updateCurrentId = function(oid) {
	this.currentId = cgiarg.d.substring(1).replace(OID.oidToSafeIdRegExp, '_');
	this.currentIdParents = OID.getParents(this.currentId, '_');
}

DocumentTree.prototype.openTo = function(id) {
	var section = this.getItem(id);
	if (section != null)
		section.show();
}

DocumentTree.prototype.getItem = function(id) {
	var ids = id.split('_');
	var item = this.root;
	var idx = 0;
	for(var i = 1; i < ids.length; ++i) {
		idx = parseInt(ids[i], 0) - 1;
		item = item.children[idx];
	}
	return item;
}

DocumentTree.prototype.getParent = function(id) {
	var ids = id.split('_');
	// this is the root
	if (ids.length == 1)
		return null;
	// we have only the root and this children.
	if (ids.length == 2)
		return this.root;
	var parent = this.root;
	var idx = 0;
	for(var i = 1; i < ids.length - 1; ++i) {
		idx = parseInt(ids[i], 0) - 1;
		parent = parent.children[idx];
	}
	return parent;
}

DocumentTree.prototype.add = function(id) {
	var item = new DocumentTreeItem(id, this.getParent(id));
	if (typeof(item.parent) != 'undefined' && item.parent != null)
		item.parent.children.push(item);
	this.list.push(item);
	var depth = OID.getLevel(id, '_');
	if (depth > this.depth)
		this.depth = depth;
	return item;
}

DocumentTree.prototype.closeAll = function() {
	for (var i = 0; i < this.root.children.length; ++i)
		this.root.children[i].show(false);
	this.expanded = false;
}

DocumentTree.prototype.openAll = function() {
	for (var i = 0; i < this.list.length; ++i)
		this.list[i].show();
	this.expanded = true;
}

DocumentTreeItem.prototype.getOID = function() {
	return 'J' + this.id.replace(OID.safeIdToOIDRegExp,'.');
}

DocumentTreeItem.prototype.hasChildren = function() {
	return this.children != null && this.children.length > 0;
}

DocumentTreeItem.prototype.show = function(show) {
	if (typeof(show) == 'undefined' || show == null) show = true;
	if (show)
	{
		if (this.parent != null)
			this.parent.show(true);
		if (this.children.length > 0) {
			if (this.parent != null) {
				var elem = gsdlGetElement('i' + this.id);
				elem.src = httpCollectionImage + '/openfldr.gif';
				elem.alt = elem.title = texts.iconopenfolder;
			}
			for(var i = 0; i < this.children.length; ++i) {
				elem = gsdlGetElement('d' + this.children[i].id);
				elem.style.display = '';
			}
		}
		this.isOpened = true;
	} else {
		if (this.children.length > 0) {
			var elem = gsdlGetElement('i' + this.id);
			elem.src = httpCollectionImage + '/clsdfldr.gif';
			elem.alt = elem.title = texts.iconclosedfolder;
			for(var i = 0; i < this.children.length; ++i) {
				this.children[i].show(false);
				var elem = gsdlGetElement('d' + this.children[i].id);
				elem.style.display = 'none';
			}
		}
		this.isOpened = false;
	}
}

DocumentTreeItem.prototype.open = function() {
	var oid = 'J' + this.id.replace(OID.safeIdToOIDRegExp, '.');
	if (gsdlGetElement('exJ' + this.id) != null) {
		window.location = '#' + oid;
	} else if (cgiarg.a == 'd') {
		var url = gsdl.url + cgiarg.l + '/d/';
		var pos = oid.indexOf('.');
		if (pos > -1) {
			url += oid.substr(0, pos) + '/' + oid.substr(pos + 1) + '.html';
		} else {
			url += oid + '/'
		}
		gsdl_goto(url);
	}
}

function buildDocumentTree(tableId, hasTitle, changeState) {
	if (typeof(changeState) == 'undefined' || changeState == null)
		changeState = true;
	if (typeof(hasTitle) == 'undefined' || hasTitle == null)
		hasTitle = true;
	if (DocumentLoader.Instance == null)
		DocumentLoader.Instance = new DocumentLoader();
	var tableTOC = gsdlGetElement(tableId);
	if (typeof(tableTOC) == 'undefined' || tableTOC == null) return null;

	var currentId = cgiarg.d.substring(1).replace(OID.oidToSafeIdRegExp, '_');
	var documentId = currentId;
	if (documentId.indexOf('_') > 0) 
		documentId = documentId.substr(0, documentId.indexOf('_'));
	var documentTOC = new DocumentTree(documentId);

	var rows = tableTOC.rows;
	var i = 0, length = rows.length - 1;
	if (hasTitle) i = 1;
	for (; i < length; i++) {
		documentTOC.add(rows[i].id.substr(1));
	}
	for (i=0; i < documentTOC.list.length; ++i)
		setDocumentTreeEvent(documentTOC.list[i]);
	if (documentTOC.depth < 3)
	{
		var tocBtn = gsdlGetElement('toggleTOC');
		if (tocBtn != null) {
			tocBtn.className = 'docbuttons1';
			tocBtn.disabled = true;
			tocBtn.title = '';
		}
	}
	if (getTOCState() && changeState) {
		documentTOC.openAll();
	}
	return documentTOC;
}

DocumentTree.create = buildDocumentTree;

DocumentTree.installDocumentHandlers = function() {
	var topDocumentId = OID.getTop(cgiarg.d.substr(1));
	var obj = gsdlGetElement('l' + topDocumentId);
	if (obj != null) {
		obj.onclick = function(e) {
			closeDocument();
			return cancelEvent(e);
		}
	}
	obj = gsdlGetElement('i' + topDocumentId);
	if (obj != null) {
		obj.onclick = function(e) {
			closeDocument();
			return cancelEvent(e);
		}
	}
}

DocumentTree.prototype.installHandlers = function() {
	DocumentTree.installDocumentHandlers();
	obj = gsdlGetElement('closeDoc');
	if (obj != null) {
		obj.onclick = function(e) {
			closeDocument();
			return cancelEvent(e);
		}
	}
	obj = gsdlGetElement('documentPreviousLink');
	if (obj != null) {
		obj.onclick = function(e) {
			navigateToPreviousDocument();
			return cancelEvent(e);
		}
	}
	obj = gsdlGetElement('documentNextLink');
	if (obj != null) {
		obj.onclick = function(e) {
			navigateToNextDocument();
			return cancelEvent(e);
		}
	}
}

function setDocumentTreeEvent(item) {
		var elem = gsdlGetElement('i' + item.id);
		if (elem != null) {
			if (item.hasChildren()) {
				elem.onclick = function (e) {
					item.show(!item.isOpened);
					return cancelEvent(e);
				}
			} else if (!gsdlExport) {
				elem.onclick = function (e) {
					item.open();
					return cancelEvent(e);
				}
			}
		}
		if (!gsdlExport) {
			elem = gsdlGetElement('l' + item.id);
			if (elem != null) {
				elem.onclick = function (e) {
					item.open();
					return cancelEvent(e);
				}
			}
		}
}

function getTOCState() {
	return gsdlGetCookieBool('gca', false);
}

function toggleTOC() {
	if (typeof(gDocumentTOC) == 'undefined' || gDocumentTOC == null)
		return;
	if (gDocumentTOC.depth < 3) return;
	var tocBtn = gsdlGetElement('toggleTOC');
	if (typeof(tocBtn) != 'undefined' && tocBtn != null) {
		if (gDocumentTOC.expanded) {
			gDocumentTOC.closeAll();
				gDocumentTOC.openTo(cgiarg.d.substring(1).replace(OID.oidToSafeIdRegExp, '\_'));
			tocBtn.innerHTML = texts.expand_toc;
			tocBtn.title = texts.expand_toc_title;
		}
		else {
			gDocumentTOC.openAll();
			tocBtn.innerHTML = texts.contract_toc;
			tocBtn.title = texts.contract_toc_title;
		}
	}
}

function refreshTOCState(state) {
	gsdlSetCookie('gca', state);
	if (state) {
		gDocumentTOC.openAll();
	} else {
		gDocumentTOC.closeAll();
		gDocumentTOC.openTo(cgiarg.d.substring(1).replace(OID.oidToSafeIdRegExp, '\_'));
	}
	updateDocumentButtons();
}

function DocumentLoader() {
	this.loader = null;
	this.documentIndex = -1;
	this.queue = [];
	this.loaderIsAJAX = true;
	this._oidregex = new RegExp('\\.', 'g');
	this.loading = false;
	this.loadingMessage = new FloatTopDiv('loading');

	// events
	this.onFirstDocumentLoaded = null;
	this.onLastDocumentLoaded = null;
	this.onDocumentLoaded = null;
	this.onDocumentProcess = DocumentLoader_onDocumentDefaultProcess;
	this.onError = null;
}

DocumentLoader.prototype.updateNavigation = function(response) {
	var documentNavigation = gsdlGetElement('documentNavigation');
	if (response.error)
		return;
	if (response.docs.length > 0) {
		cgiarg.d = response.docs[0].oid;
	}
	gPreviousDocument = response.prev;
	gNextDocument = response.next;
	var elements = getElementsByClassName(gsdlGetElement('docToc'), 'a', 'hlchapopenlink');
	if (elements != null && elements.length > 0) {
		for(var i = 0; i < elements.length; ++i) {
			elements[i].className = 'chapopenlink';
		}
	}
	elements = getElementsByClassName(gsdlGetElement('docToc'), 'a', 'hlseclink');
	if (elements != null && elements.length > 0) {
		for(var i = 0; i < elements.length; ++i) {
			elements[i].className = 'seclink';
		}
	}
	if (OID.getParent(cgiarg.d).length > 0) {
		var element = gsdlGetElement('l' + cgiarg.d.substring(1).replace(OID.oidToSafeIdRegExp, '_'));
		element.className = 'hl' + element.className;
	}

	if (response.prev.length == 0 && response.next.length == 0) {
		if (documentNavigation == 'undefined' || documentNavigation == null)
			return;
	} else {
		if (documentNavigation == 'undefined' || documentNavigation == null)
			return;
		else {
			documentNavigation.style.display = 'block';
			DocumentLoader_updateNavigationLink(gsdlGetElement('documentPreviousLink'), response.prev);
			DocumentLoader_updateNavigationLink(gsdlGetElement('documentNextLink'), response.next);
		}
	}
}

function DocumentLoader_updateNavigationLink(linkElement, oid) {
	if (linkElement == null)
		return;
	if (oid.length == 0) {
		linkElement.style.display = 'none';
	} else {
		linkElement.style.display = 'block';
		var url = gsdl.url + cgiarg.l + '/d/';
		var pos = oid.indexOf('.');
		if (pos > -1) {
			url += oid.substr(0, pos) + '/' + oid.substr(pos + 1) + '.html';
		} else {
			url += oid + '/'
		}
		linkElement.href = url;
	}
}

function DocumentLoader_onDocumentDefaultProcess(response) {
	var documentContent = gsdlGetElement('documentContent');
	var contentNew = '';
	if (this.documentIndex > 0) {
		contentNew += documentContent.innerHTML;
			}
	if (response.error) {
		contentNew = response.message;
		} else {
		var data;
		for(var i = 0; i < response.docs.length; ++i) {
			data = response.docs[i];
			contentNew += '<a class="chaptertitle" id="' + data.oid + '" name="' + data.oid + '"></a>';
			contentNew += '<h1 id="ex' + data.oid.replace(this._oidregex, '_') + '" class="booksectitle\">' + data.title + '</h1>';
			contentNew += '<div class="booktext">' + data.text + '</div>';
			if (gsdlGetCookieBool('qe', false) && gsdlGetCookieBool('hl',false)) {
				var h = getHighlightObject();
				if (h != null && (h.doHighlightTerms || h.phrases.length > 0)) {
					contentNew = h.highlight(contentNew);
				}
		}
	}
		}
	documentContent.innerHTML = contentNew;
}

DocumentLoader.prototype.createLoader = function() {
	this.loaderIsAJAX = true;
	this.loader = gsdlGetHttpRequest();
	if (this.loader == null) {
		this.loader = gsdlGetElement('dataFrame');
		this.loaderIsAJAX = false;
	}
}

DocumentLoader.prototype.clearQueue = function() {
	this.queue = [];
	this.documentIndex = -1;
}

DocumentLoader.prototype.addDocumentToQueue = function(oid, expand) {
	if (typeof(expand) == 'undefined' || expand == null) expand = false;
	this.queue.push({'oid':oid,'expand':expand});
}

DocumentLoader.prototype.loadBatch = function() {
	if (this.loading) return false;
	this.documentIndex = -1;
	this.loadNextDocument();
	return true;
}

DocumentLoader.prototype.loadDocument = function(oid) {
	if (this.loading) return false;
	this.clearQueue();
	this.queue.push({'oid':oid,'expand':false});
	this.loadNextDocument();
	return true;
}

function setDocumentLoaderCallBack(documentLoader) {
	documentLoader.loader.onreadystatechange = function() {
		if (documentLoader.loader == null) return;
		if (documentLoader.loader.readyState == 4) {
			if (documentLoader.loader.status == 200) {
				var responseText = documentLoader.loader.responseText;
				documentLoader.loader = null;
				documentLoader.processDocument(responseText);
			} else {
				if (documentLoader.onError != null) {
					documentLoader.onError();
				}
				if (documentLoader.loadingMessage != null)
					documentLoader.loadingMessage.stop();
				documentLoader.loading = false;
				documentLoader.loader = null;
			}
		}
	}
}

DocumentLoader.prototype.loadNextDocument = function() {
	if (this.queue.length == 0) {
		this.loading = false;
		return false;
	}
	if (this.loadingMessage != null)
		this.loadingMessage.start();
	this.loading = true;
	var oid = this.queue[0].oid;
	var expand = this.queue[0].expand;
	this.queue.splice(0, 1);
	var url = gsdl.url + 'en/d/';
	var pos = oid.indexOf('.');
	if (pos > -1) {
		url += oid.substr(0, pos) + '/' + oid.substr(pos + 1) + ',';
	} else {
		url += oid + '/'
	}
	url += 'of,json';
	if (expand) url += ',gt,2';
	this.createLoader();
	if (this.loaderIsAJAX) {
		this.loader.open('GET', url + '.json', true);
		this.loader.setRequestHeader("X-Requested-With", "XMLHttpRequest");
		this.loader.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		setDocumentLoaderCallBack(this);
		this.loader.send(null);
	} else {
		this.loader.src = url + ',wrap,1.html';
	}
}

DocumentLoader.prototype.processDocument = function(content) {
	++this.documentIndex;
	var response = null;
	if (typeof(content) == 'undefined' || content.length == 0) {
		response = {error:true,message:"ERROR: Failed to get content!!!!",docs:[]};
	} else {
		response = eval('(' + content + ')');
				}
	if (this.onDocumentLoaded != null)
		this.onDocumentLoaded(response);
	this.onDocumentProcess(response);
	if (this.documentIndex == 0) {
		this.updateNavigation(response);
		if (!response.error && response.docs.length > 0) {
			gDocumentTOC.updateCurrentId(response.docs[0].oid);
			gDocumentTOC.openTo(cgiarg.d.substring(1).replace(OID.oidToSafeIdRegExp, '\_'));
			location.href = '#' + response.docs[0].oid;
		}
		if (this.onFirstDocumentLoaded != null) {
			this.onFirstDocumentLoaded(response);
			}
		if (this.queue.length == 0) {
			if (this.loadingMessage != null)
				this.loadingMessage.stop();
			if (this.onLastDocumentLoaded != null) {
				this.onLastDocumentLoaded(response);
			}
		}
	}
	this.loadNextDocument();
}

DocumentLoader.Instance = null;
function onOldBackgroundDocumentResponse(win) {
	var jscontent = gsdlGetElement('jscontent', win.document);
	DocumentLoader.Instance.processDocument(typeof(jscontent.innerText) != 'undefined' ? jscontent.innerText : jscontent.textContent);
}

function updateDocumentButtons() {
	var linkExpandDoc = gsdlGetElement('linkExpandDoc');
	var linkExpandChap = gsdlGetElement('linkExpandChap');
	if (linkExpandDoc != null) {
		linkExpandDoc.title = texts.expand_doc_title;
		linkExpandDoc.innerHTML = texts.expand_doc;
	}
	if (linkExpandChap != null) {
		linkExpandChap.title = texts.expand_chapter_title;
		linkExpandChap.innerHTML = texts.expand_chapter;
	}
	if (cgiarg.gt == 0) {
	} else if (cgiarg.gt == 1) {
		if (linkExpandChap != null) {
			linkExpandChap.title = texts.contract_chapter_title;
			linkExpandChap.innerHTML = texts.contract_chapter;
		}
	} else {
		if (linkExpandDoc != null) {
			linkExpandDoc.title = texts.contract_doc_title;
			linkExpandDoc.innerHTML = texts.contract_doc;
		}
	}
}

function navigateToDocument(strOID) {
	if (typeof(strOID) == 'undefined' || strOID == null || strOID.length == 0) return;
	cgiarg.gt = 0;
	updateDocumentButtons();
	DocumentLoader.Instance.loadDocument(strOID);
}

function navigateToPreviousDocument() {
	if (gPreviousDocument != null || gPreviousDocument.length > 0) {
		navigateToDocument(gPreviousDocument);
	}
}

function navigateToNextDocument() {
	if (gNextDocument != null || gNextDocument.length > 0) {
		navigateToDocument(gNextDocument);
	}
}

function expandDocument() {
	if (typeof(cgiarg.gt) == 'undefined') cgiarg.gt = 0;
	if (cgiarg.gt == 2) {
		cgiarg.gt = 0;
		updateDocumentButtons();
		DocumentLoader.Instance.loadDocument(cgiarg.d);
		return;
	}
	if (confirm(texts.expand_warning)) {
		if (gDocumentTOC.list.length > 0) {
			var i, list = gDocumentTOC.list;
			cgiarg.gt = 2;
			updateDocumentButtons();
			DocumentLoader.Instance.addDocumentToQueue('J' + gDocumentTOC.id.replace(OID.safeIdToOIDRegExp,'.'), true);
			DocumentLoader.Instance.loadBatch();
		}
	}
}

function expandTextSection(sections) {
	var i;
	for (i = 0; i < sections.length; ++i) {
		DocumentLoader.Instance.addDocumentToQueue('J' + sections[i].id.replace(OID.safeIdToOIDRegExp,'.'));
		if (sections[i].hasChildren())
			expandTextSection(sections[i].children);
	}
}

function expandChapter() {
	if (typeof(cgiarg.gt) == 'undefined') cgiarg.gt = 0;
	if (cgiarg.gt != 0) {
		cgiarg.gt = 0;
		updateDocumentButtons();
		DocumentLoader.Instance.loadDocument(cgiarg.d);
		return;
	}
	var item = gDocumentTOC.getItem(gDocumentTOC.currentId);
	if (item != null) {
		if (item.parent == null || (item.parent.parent == null && !item.hasChildren())) {
			expandDocument();
			return;
		}
		if (confirm(texts.expand_warning)) {
			if (!item.hasChildren())
				item = item.parent;
			cgiarg.gt = 1;
			updateDocumentButtons();
			DocumentLoader.Instance.addDocumentToQueue('J' + item.id.replace(OID.safeIdToOIDRegExp,'.'), true);
			DocumentLoader.Instance.loadBatch();
		}
	}
}

function printableDocument() {
	window.open(gsdl.url + cgiarg.l + '/p/printable.html', '_blank', 'width=700,height=400,menubar=yes,location=no,status=yes,toolbar=yes,resizable=yes,scrollbars=yes');
}

function onPrintablePageLoad() {
	if (typeof(window.opener) == 'undefined' || window.opener == null) return;
	var i, r, documentContainer, strHTML;
	cgiarg.d = window.opener.cgiarg.d;
	documentContainer = gsdlGetElement('documentContainer', window.opener.document);
	if (documentContainer == null) return;
	if (typeof(document.title) != 'undefined' && document.title != null) {
		document.title.innerHTML =  window.opener.document.title.innerHTML;
		document.title = window.opener.document.title;
	}
	strHTML = documentContainer.innerHTML;
	//strHTML = strHTML.replace(new RegExp('<a([.]+) href="[^"]+"', 'gi'), '<a$1 href="javascript:void(0);"');
	r = new RegExp('javascript:[df]doc\\(\'([a-zA-Z0-9_\\.]+)\',[0-9]+\\)', 'g');
	strHTML = strHTML.replace(r, '#$1');
	documentContainer = gsdlGetElement('documentContainer');
	documentContainer.innerHTML = strHTML;
	for(i = 0; i < document.links.length; ++i) {
		var pathname = document.links[i].pathname;
		if (pathname.charAt(0) != '/')
			pathname = '/' + pathname;
		if (document.links[i].href.charAt(0) == '#' || pathname == window.location.pathname) {
		} else {
			document.links[i].href = '#TopOfPage';
			if (typeof(document.links[i].target) != 'undefined')
				document.links[i].target = '_self';
		}
	}
	var documentNavigation = gsdlGetElement('documentNavigation');
	if (documentNavigation != null) {
		documentNavigation.style.display = 'none';
	}
	var documentButtons = gsdlGetElement('documentButtons');
	if (documentButtons != null) {
		documentButtons.style.display = 'none';
	}
	globalPageInit();
	gDocumentTOC = DocumentTree.create('docToc', false, false);
	var topDocumentId = OID.getTop(cgiarg.d.substr(1));
	var obj = gsdlGetElement('l' + topDocumentId);
	if (obj != null) {
		obj.onclick = function(e) {
			window.close();
			return cancelEvent(e);
		}
	}
	obj = gsdlGetElement('i' + topDocumentId);
	if (obj != null) {
		obj.onclick = function(e) {
			window.close();
			return cancelEvent(e);
		}
	}
}

var g_oTextHighlight = null;
var g_queryHighlight = null;
function getHighlightObject() {
	if (g_oTextHighlight == null && g_queryHighlight != null) {
		g_oTextHighlight = new TextHighlight(g_queryHighlight.terms, g_queryHighlight.hasTerms);
		g_oTextHighlight.config.highlightBefore = '<span class="hl" id="hl${i}">'
		if (g_queryHighlight.hasPhrases)
			g_oTextHighlight.setQueryString(g_queryHighlight.queryString);
	}
	return g_oTextHighlight;
}

function highlightDocument() {
	var h = getHighlightObject();
	var o = gsdlGetElement('documentContent');
	if (h != null && o != null && (h.doHighlightTerms || h.phrases.length > 0)) {
		o.innerHTML = h.highlight(o.innerHTML);
	}
}

function onLoadHighlightDataResponse() {
	if (g_highlightDataRequest.readyState == 4) {
		if (g_highlightDataRequest.status == 200) {
			eval('g_queryHighlight = ' + g_highlightDataRequest.responseText + ';');
			highlightDocument();
		} else {
			// should we handle an error here???
		}
	} else {
		// should we handle an error here???
	}
}

function onOldLoadHighlightDataResponse(win) {
	var jscontent = gsdlGetElement('jscontent', win.document);
	eval('g_queryHighlight = ' + (typeof(jscontent.innerText) != 'undefined' ? jscontent.innerText : jscontent.textContent) + ';');
	highlightDocument();
}

function loadHighlightData() {
	g_highlightDataRequest = gsdlGetHttpRequest();
	if (g_highlightDataRequest == null) {
		g_highlightDataRequest = gsdlGetElement('dataFrame');
		g_highlightDataRequest.src = gsdl.url + cgiarg.l + '/q/oldterms.html?uq=' + gsdlGetQueryUniqueId();
		return;
	}
	if (g_highlightDataRequest.overrideMimeType) g_highlightDataRequest.overrideMimeType("application/json");
	g_highlightDataRequest.open('GET', gsdl.url + cgiarg.l + '/q/terms.json?uq=' + gsdlGetQueryUniqueId(), true);
	g_highlightDataRequest.setRequestHeader("X-Requested-With", "XMLHttpRequest");
	g_highlightDataRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	g_highlightDataRequest.onreadystatechange = onLoadHighlightDataResponse;
	g_highlightDataRequest.send(null);
}

