/* CONSTANTS */
var NN_INTERVAL = 100; // polling interval
var NN_MAX_POLLS = 30; // maximum times Netscape will poll for document to be loaded
var NN_POLL_TRIES = 0; // the number of times we have polled so far
var SEARCH_FORM_NAME = "webcm_search";
var SEARCH_QUERY_ELEMENT = "query";
var SEARCH_RESULTS_PAGE = "/projects/satair/webcm/satair_webcm.nsf/search_results";
var XML_DATA = "webcm_xml";
var SEARCH_RESULTS_DIV = "webcm_search_results";
var SEARCH_URL_BASE = "http://itix200.iti.it-inspiration.dk/servlet/WebcmSearchServlet";
var SEARCH_PAGE_SIZE = "10";
var SPOT_URL_BASE = "http://itix200.iti.it-inspiration.dk/servlet/SpotServlet";
var USING_TOMCAT = false; // setting this to true will append the jsessionid to the servlet request
// global declarations
var gXML_handler = null;
/* *******************************************************************
SearchResult object: Object representing a search result with accessors
for the main data (title, link and abstract).
******************************************************************* */
function SearchResult_setTitle(v) {
this.pTitle = v;
}
function SearchResult_getTitle() {
return this.pTitle;
}
function SearchResult_setLink(v) {
this.pLink = v;
}
function SearchResult_getLink() {
return this.pLink;
}
function SearchResult_setAbstract(v) {
this.pAbstract = v;
}
function SearchResult_getAbstract() {
return this.pAbstract;
}
function SearchResult() {
// pointers to functions
this.setTitle = SearchResult_setTitle;
this.setLink = SearchResult_setLink;
this.setAbstract = SearchResult_setAbstract;
this.getTitle = SearchResult_getTitle;
this.getLink = SearchResult_getLink;
this.getAbstract = SearchResult_getAbstract;
}
/* *******************************************************************
ResultSetInfo object: Object giving information about the result set such
as the actual query, the number of results found etc.
******************************************************************* */
function ResultSetInfo_setQuery(v) {
this.pQuery = v;
}
function ResultSetInfo_setStart(v) {
this.pStart = v;
}
function ResultSetInfo_setStop(v) {
this.pStop = v;
}
function ResultSetInfo_setCount(v) {
this.pCount = v;
}
function ResultSetInfo_setPage(v) {
this.pPage = v;
}
function ResultSetInfo_setPages(v) {
this.pPages = v;
}
function ResultSetInfo_setSessionId(v) {
this.pSessionId = v;
}
function ResultSetInfo_getQuery() {
return this.pQuery;
}
function ResultSetInfo_getStart() {
return this.pStart;
}
function ResultSetInfo_getStop() {
return this.pStop;
}
function ResultSetInfo_getCount() {
return this.pCount;
}
function ResultSetInfo_getPage() {
return this.pPage;
}
function ResultSetInfo_getPages() {
return this.pPages;
}
function ResultSetInfo_getSessionId() {
return this.pSessionId;
}
function ResultSetInfo_hasNextPage() {
try {
if (this.pPages > 1 && this.pPage != this.pPages) {
return true;
} else {
return false;
}
} catch (exception) {
window.status = "An error occured in hasNextPage(): " + e.message;
return false;
}
}
function ResultSetInfo_hasPrevPage() {
try {
return (this.pPage != 1);
} catch (exception) {
window.status = "An error occured in hasNextPage(): " + e.message;
return false;
}
}
function ResultSetInfo_getNextPageLink() {
var link = "gXML_handler.getNextPage('" + this.pSessionId + "'); return false;";
return link;
}
function ResultSetInfo_getPrevPageLink() {
return "gXML_handler.getPrevPage('" + this.pSessionId + "'); return false;";
}
function ResultSetInfo() {
// pointer to functions
this.hasNextPage = ResultSetInfo_hasNextPage;
this.hasPrevPage = ResultSetInfo_hasPrevPage;
this.getPrevPageLink = ResultSetInfo_getPrevPageLink;
this.getNextPageLink = ResultSetInfo_getNextPageLink;
// pointers to getter / setter functions
this.setQuery = ResultSetInfo_setQuery;
this.setStart = ResultSetInfo_setStart;
this.setStop = ResultSetInfo_setStop;
this.setCount = ResultSetInfo_setCount;
this.setPage = ResultSetInfo_setPage;
this.setPages = ResultSetInfo_setPages;
this.setSessionId = ResultSetInfo_setSessionId;
this.getQuery = ResultSetInfo_getQuery;
this.getStart = ResultSetInfo_getStart;
this.getStop = ResultSetInfo_getStop;
this.getCount = ResultSetInfo_getCount;
this.getPage = ResultSetInfo_getPage;
this.getPages = ResultSetInfo_getPages;
this.getSessionId = ResultSetInfo_getSessionId;
}
/* *******************************************************************
XMLHandler object: Object to handle XML retrieval - decides the method
to use based on the browser version.
******************************************************************* */
/**
* CLASS: Definition for the XMLHandler object.
* The object defines the following callbacks to objects overriding the prototype:
* - processXML(): Called when the XML has been fetched and the object should act on it.
*/
function XMLHandler() {
}
XMLHandler.prototype.init = function() {
// create new data to get milliseconds
var temp_date = new Date();
// declarations
this.pID = XML_DATA + "_" + temp_date.getMinutes() + temp_date.getSeconds() + temp_date.getMilliseconds();
this.pXML_data = null;
this.pIE5 = false;
this.pNAV6 = false;
this.pXMLCapable = false;
}
/**
* Dummy method. This method is meant to be overridden by "sub-classes".
*/
XMLHandler.prototype.processXML = function(success) {}
/**
* This method retrieves the XML from the servlet and forwards control
* to the processXML() method.
*/
XMLHandler.prototype.getXML = function(url) {
try {
if (this.pXMLCapable) {
// reset poll and data
NN_POLL_TRIES = 0;
if (this.pIE5) {
// we're dealing with Internet Explorer
this.pXML_data = document.all[this.pID];
// get resulting XML from servlet
this.pXML_data.async = false;
var success = this.pXML_data.load(url);
// call XML processing method (should be implemented in subclasses)
this.processXML(success);
} else if (this.pNAV6) {
// we're dealing with Netscape - get handle to document
this.pXML_data = window.frames[this.pID];
// clear any results we might already have
this.pXML_data.location = null;
// set the URL to the XML
this.pXML_data.location.href = url;
// store a reference to the holder
gXML_handler = this;
// poll to see when we are done loading the xml
setTimeout("XML_Poll('" + this.pRootElement + "')", NN_INTERVAL * 3);
}
} else {
alert("Browser not XML capable...");
}
} catch (exception) {
// some error occured
window.status = "Exception caught in XMLHandler.getXML(): " + exception.message;
}
}
/**
* This method writes either an IFRAME or a XML island to the document.
*/
XMLHandler.prototype.createXmlHolder = function() {
// use an XML island if IE 5 or up - otherwise use an IFRAME
if (is_ie5up) {
document.write('');
this.pXMLCapable = true;
this.pIE5 = true;
} else if (is_nav6up) {
document.write('');
this.pXMLCapable = true;
this.pNAV6 = true;
}
}
/**
* Returns the XML document for the object.
*/
XMLHandler.prototype.getXMLDocument = function() {
return this.pXML_data;
}
/**
* Utility method to get the value of a tag given a XML fragment.
*/
XMLHandler.prototype.getTagValue = function(xml, tagname) {
for (var i=0; i -1) {
var stop = location.href.indexOf("&", start);
query = location.href.substring(start+6, stop);
}
} else {
var query = form.elements[SEARCH_QUERY_ELEMENT].value;
}
return query;
}
/* *************************************************
* Function to forward the user to the search page.
*/
function forwardSearch() {
var page_name = location.pathname;
if (page_name.indexOf(SEARCH_RESULTS_PAGE) > -1) {
// we're already on the search page - do search from here
// if a query is specified
if (getQuery() != "") {
var xml_handler = new SearchXMLHandler();
xml_handler.createXmlHolder();
xml_handler.search(getQuery());
}
} else {
// not on the search page - go there first...
document.location.href = SEARCH_RESULTS_PAGE + "?readform&query=" + getQuery() + "&";
}
}
/* *************************************************
* Since Netscape 6 doesn't support the asynchroneous fetching of the
* XML we need to poll to find out when it is done fetching. Once the
* XML has been fetched the control is dispatched to the processXML() method
* of the XMLHandler.
*/
function XML_Poll(name) {
// this is used for NN6 only. We need to wait for the iframe to load the xml data
// get the loaded document
var aObj = gXML_handler.getXMLDocument().document.getElementsByTagName(name);
// should we poll again
if (!aObj || !aObj.length) {
NN_POLL_TRIES++;
if (NN_POLL_TRIES < NN_MAX_POLLS) {
setTimeout("XML_Poll('" + name + "')", NN_INTERVAL);
}
return;
}
// done ... call the onload handler
gXML_handler.processXML(true);
}