function js(myself) {
	this.me=myself;
	this.vid=null;
	this.gentime=null;
	this.loadtime=null;
	this.ok=true;
	this.ie=(document.all)?true:false;
	this.classname=(document.all)?'className':'class';
	this.scripts=Array();
	this.searchtype;
	this.searchresults=null;
	this.displaySearchResultDescription = true;
	this.displaySearchResultContent = false;
	this.displaySearchResultDate = true;
}
function script(src,vars,sid,trash) {this.src=src;this.vars=vars;this.sid=sid;this.trash=trash;this.add();}
script.prototype.add=function() {myscript = document.createElement('script');if (!this.sid.match(/\d$/)) this.sid += '0';while (client.get(this.sid)!==null) {var sidcount=this.sid.replace(/^[a-zA-Z]+(\d)$/, '$1');this.sid = this.sid.replace(/(\d)$/, sidcount+1);};if (this.sid!==null){myscript.id = this.sid;};myscript.type = 'text/javascript';myscript.src = "contentactivator.evanta.co.nz"+this.src+"?"+this.vars;document.getElementsByTagName("head")[0].appendChild(myscript);}
script.prototype.remove=function() {var myscript = client.get(this.sid);myscript.parentNode.removeChild(myscript);myscript=null;return true;}

js.prototype.make = 		function(nodetype, xid, xname, xclass, xcontent) {var x = document.createElement(nodetype);if (xid!=null) x.setAttribute('id', xid);if (xname!=null) x.setAttribute('name', xname);if (xclass!=null) x.setAttribute(this.classname, xclass);if (xcontent!=null) {if (typeof(xcontent)=='element') {x.appendChild(xcontent);} else if (typeof(xcontent)=='string') {x.innerHTML = xcontent;};};return x;}
js.prototype.addEvent = 	function(myelement, eventName, functionToCall) {if (typeof(myelement)==String) myelement = document.getElementById(myelement);if (typeof(myelement)!='object') {return false;};if (myelement.addEventListener) {myelement.addEventListener(eventName, functionToCall, false);return true;} else if (myelement.attachEvent) {myelement.attachEvent('on'+ eventName, functionToCall);return true;} else {alert('on '+functionToCall);return true;};}
js.prototype.clean = 		function() {for (var i=0;i<this.scripts.length;i++) {if (this.scripts[i]===null) continue;if (this.scripts[i].trash===true) {if (this.scripts[i].remove()===true) this.scripts[i]=null;};};}
js.prototype.get = 			function(myid) {if (document.getElementById){return document.getElementById(myid);}else{return null;};}
js.prototype.json = 		function(url,vars,sid,trash) {this.scripts[this.scripts.length] = new script(url, vars,sid,trash);}
js.prototype.startload = 	function() {this.addEvent(window,'load',new Function('client.loaded()'));}
js.prototype.loaded = 		function() {edocsig = this.get('documentsignature');if (edocsig!==null) {docsig=edocsig.value;var d=new Date();currenttime=d.getTime();this.gentime=(docsig.match(/^(\d+)/))?docsig.replace(/^(\d+).*/, '$1'):null;this.vid=(docsig.match(/(\d+)$/))?this.vid=docsig.replace(/^.*?(\d+)$/, '$1'):null;if (this.gentime!==null){this.loadtime=currenttime-this.gentime;};if (this.vid!==null&&this.loadtime!==null){this.json('/loadtime.js', 'vid='+this.vid+'&ms='+this.loadtime, 'loadtime', true);};};}
js.prototype.runsearch = 	function() {
	this.clean();
	this.searchresults=null;
	searchfield = this.get('search');
	searchtype = this.get('search_type');
	docidfield = this.get('docid');
	if (searchfield!=null&&docidfield!=null) {
		var searchstr = searchfield.value;
		var docid = docidfield.value;
		searchtype = (searchtype===null)?'site':'catalogue';
		this.searchtype = searchtype;
		this.json('/search.js', 's='+escape(searchstr)+'&doc='+docid+'&type='+searchtype+'&vid='+this.vid, 'search', true);
	};
}
js.prototype.displaySearchResults = function() {
	if (this.get('searchresults')===null) return false;
	var container = this.get('searchresults');
	while (container.childNodes.length>0) {container.removeChild(container.childNodes[0]);};
	var rdiv = this.make('div', 'mysearchresults', null, 'mysearchresults', "<h1>Search Results</h1>")
	for (var i=0;i<this.searchresults.results.length;i++) {
		var result = this.searchresults.results[i];
		var r2div = this.make('div', null, null, 'searchresult', null);
		r2div.appendChild(this.make('p', null, null, 'documentname', "<a href='"+result.link+"'>"+result.name+"</a>"));
		if (this.displaySearchResultDescription==true) r2div.appendChild(this.make('p', null, null, 'documentdesc', "Description: "+result.description));
		if (this.displaySearchResultContent==true) r2div.appendChild(this.make('p', null, null, 'documentcontent', "Content: "+result.content));
		if (this.searchtype=='site') r2div.appendChild(this.make('p', null, null, 'documentlast', "Last Updated: "+result.lastupdated));
		if (this.searchtype!='site' && this.displaySearchResultDate==true) r2div.appendChild(this.make('p', null, null, 'documentlast', "Date/Time: "+result.lastupdated));
		if (this.searchtype=='site') r2div.appendChild(this.make('p', null, null, 'documentlink', "Link: <a href='"+result.link+"'>"+result.link+"</a>"));
		rdiv.appendChild(r2div);
	}
	var pagediv = this.make('p', null, null, 'resultpages', null);
	for (var i=0;i<this.searchresults.pages.length;i++) {
		var sp = this.searchresults.pages[i];
		var myclass = null;
		if (sp.myclass!='') myclass='currentpage'
		pagediv.appendChild(this.make('span', null, null, myclass, "<a href=\""+sp.link+"\">&nbsp;&nbsp;"+sp.page+"&nbsp;&nbsp;</a>"));
	}
	if (this.searchresults.results.length==0) rdiv.appendChild(this.make('p', null,null,'noresults','No Results Were Found'));
	rdiv.appendChild(pagediv);
	container.appendChild(rdiv);
}
client = new js('client');
client.startload();