<!--;
/**
*
* Global constants
* 
*/
// var _HOST = 'http://192.168.0.131:1010';
if(typeof(window['_HOST']) == "undefined") { _HOST = 'http://comments.keymedia.info'; };
if(typeof(window['_STARMARKER']) == "undefined") { _STARMARKER = '*'; };
if(typeof(window['_MAX_COMMENTS']) == "undefined") { _MAX_COMMENTS = 20; };
var req = new Array();	// An array of request objects
var moz = false;		// A flag to say if we should try to get UniversalBrowserRead
var backEditHTML = new Array();	// Stores some HTML code temporarily
var allowedActions = 'updatecomment|authenticateresource|listroutes|deletebookmark|myfolder|readroute|readroutefull|deleteinfo|readinfo|writeinfo|recoverpass|login|logout|readbookmark|readcomment|readhistory|readnote|signup|writebookmark|writecomment|writehistory|writenote|writeroute|getgroups|userupdate'.split('|');
var historyXML;
var bookmarkXML;
var _PATHTOROOT = '_NONE_'; // This needs to be redefined in the page to point to the root directory of the CD
var _FORCEDEBUG = 0;
var _COMMENTCHARS = 80;
var _CANCOOKIE = -1;
/**
*
* These are all now defined in a separate, parsed JS file, mycookies.js
*
* var _USERNAME = '';
* var _PASSWORD = '';
* var _GROUPNAME = '';
*/
var resourceid;		/* Must be redefined locally */

/**
*
* Misc messages: these can be overriden by a local redefinition
*
*/

var _MISSING_USER_AND_PASS	= 'Error: You first need to log in\nbefore you can use this feature';
var _MISSING_COMMENT_DIV	= 'Error: there\'s nowhere to make the comment/note';
var _PLEASE_WAIT			= 'Please wait...';
var _BAD_CHARS				= 'Error: you have illegal characters in your input';
var _BAD_USERNAME			= 'Error: your username is invalid';
var _NO_EMAIL_USERNAME		= 'Error: your username is not a valid email address \n- no password recovery is possible';
var _CROSS_DOMAIN_AJAX		= 'Error: cross-domain AJAX calls will not work.';
var _NO_PATHTOROOT			= 'Error: _PATHTOROOT variable not specified.';
var _NO_ROUTE_INFO			= 'You have not yet created a route';
var _COOKIE_ERROR			= 'Error: please enable cookies';
var _ERROR_12029			= 'Error: your computer is temporarily unable to connect to the internet. Please try again.';

/**
*
* AJAX request and response handlers
*
*/
function doRequest(someXML){
	if(document.location && document.location.host && 'http://' + document.location.host != _HOST){
		// alert('http://' + document.location.host + '  !=  ' + _HOST);
		_tellUser(_CROSS_DOMAIN_AJAX); return '';
	};

	if(_CANCOOKIE != 1){
		if(! _testCookies()) {
			return false;
		};
	};

	_myDebug(someXML);
	/* check that the request has an action attibute */
	var requestaction = '';
	var re = eval('/<request[^>]*>/');
	var matches = someXML.match(re);
	if (matches[0]) {
		re = eval('/action="([^"]*)"/');
		var idmatches = matches[0].match(re);
		if(idmatches) {
			requestaction = idmatches[1];
		};
	};
	var reqIndex = _inArray(requestaction,allowedActions);
	if (! requestaction || reqIndex == -1) {
		return _tellUser('Error: request needs an allowed action attribute (you said <b>'+ requestaction +'</b>)');
	};

	/* now set the handler on the basis of the request id */
	handlerName = eval('handle_'+ requestaction);

	// _myDebug('function doRequest\n--\n'+someXML);
	var _URL = _HOST + '/enhancedcd.asp';
	if (window.XMLHttpRequest) {
		moz = true;
		try {
			netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
		} catch (e) {
			/* Harmless if it's Safari */
			// alert("Permission UniversalBrowserRead denied.");
		};
		req[reqIndex] = new XMLHttpRequest();
		req[reqIndex].onreadystatechange = handlerName; // processReqChange;
		req[reqIndex].open("POST",_URL, true);
		req[reqIndex].setRequestHeader('Content-Type', 'text/xml');
		req[reqIndex].send(someXML);

	// Or, for IE/Windows ActiveX:
	} else if (window.ActiveXObject) {
		req[reqIndex] = new ActiveXObject("Microsoft.XMLHTTP");
		if (req[reqIndex]) {
			req[reqIndex].onreadystatechange = handlerName; // processReqChange;
			req[reqIndex].open("POST",_URL, true);
			req[reqIndex].setRequestHeader('Content-Type', 'text/xml');
			req[reqIndex].send(someXML);
		};
	};
};


/**
*
* START of process_ACTION response handlers.
* You *MUST* have one of these for each action.
*
*/
function handlerTemplate(someInt) {
	myreq = req[someInt];
	if(moz){try { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");} catch (e) {};};
    if (myreq.readyState == 4) {
        if (myreq.status == 200) {
			_myDebug('responseText:\n'+myreq.responseText);
			response = myreq.responseXML.documentElement;
			if(response.getElementsByTagName('message')[0]
				&& response.getElementsByTagName('message')[0].getAttribute('text')){
				_tellUser(response.getElementsByTagName('message')[0].getAttribute('text'));
				eval('process_' + allowedActions[someInt] + '("'+ someInt +'")');
			} else {
				_tellUser('Error: there was a problem with the server response. Please try again later');
				alert(myreq.responseText);
			};
		} else {
			if(myreq.status && myreq.status == 12029){ 
				_tellUser(_ERROR_12029);
	        };
			if(myreq.status && myreq.status != 12029){ /* for otherwise you're just being impatient, probably */
				_tellUser("Error: there was a problem with the submission:\nreq[0].status: " + myreq.status + ' - ' + myreq.statusText);
	        };
        };
    };
};

for(j=0;j<allowedActions.length;j++){
	// alert(allowedActions[j] + ':' + j);
	eval('function handle_' + allowedActions[j] + '() { handlerTemplate('+j+'); };');
};


/**
*
* Display comments
*
*/
function process_readcomment(someInt,appendFlag){
	myreq = req[someInt];
	someResponse = myreq.responseXML.documentElement;
	// alert(myreq.responseText);
	// show the comments, but only if this page has a space for them
	if(! document.getElementById('comments')) {
		// _myDebug('Nowhere to write comments (<div id="comments">)');
		return false;
	};
	var commentHTML = '';

	if(appendFlag){ commentHTML = document.getElementById('comments').innerHTML; };
	for(i=0;i<someResponse.getElementsByTagName('comment').length;i++){
		if(i < _MAX_COMMENTS) {
			var randID = 'randomid' + Math.random(); randID = randID.replace('.','');
			commentHTML += '<div class="comment_or_note_body">\n';
			var commentBody = someResponse.getElementsByTagName('comment')[i].firstChild.data;
			if(someResponse.getElementsByTagName('comment')[i].firstChild){
				commentHTML += commentBody.substr(0,_COMMENTCHARS);
				if(commentBody.length > _COMMENTCHARS) {
					commentHTML += '...';
				};
			};
			commentHTML += '<code>';
			commentHTML += someResponse.getElementsByTagName('comment')[i].getAttribute('date');
			commentHTML += '</code>';
			commentHTML += '</div>\n';
			commentHTML += '<div id="'+ randID +'" style="display: none;">';
			commentHTML += commentBody;
			commentHTML += '<code>';
			commentHTML += someResponse.getElementsByTagName('comment')[i].getAttribute('date');
			commentHTML += '</code>';
			commentHTML += '</div>\n';
			commentHTML += '<div class="rating">\n';
			starRating = parseInt(someResponse.getElementsByTagName('comment')[i].getAttribute('rating'));

			for(r=0;r<starRating+1;r++){
				commentHTML += '<span class="ratingon">'+ _STARMARKER +'</span>';
			};
			for(r=starRating+1;r<5;r++){
				commentHTML += '<span class="ratingoff">'+ _STARMARKER +'</span>';
			};
			commentHTML += '</div>\n';
			commentHTML += '<br /><a href="#" onClick="_showCopy(\''+ randID +'\',this); return false;">view full item</a>';
		};
	};
	commentHTML += '\n<div id="newcomment" style="display: none"></div>\n\n';
	if(commentHTML){
		document.getElementById('comments').style.display = 'block';
		document.getElementById('comments').innerHTML = commentHTML;
	} else {
		document.getElementById('comments').style.display = 'none';
	};
};
function process_writecomment(someInt){ process_readcomment(someInt,1);};

function process_readnote(someInt,appendFlag){
	myreq = req[someInt];
	someResponse = myreq.responseXML.documentElement;
	// alert(myreq.responseText);
	// show the notes, but only if this page has a space for them
	if(! document.getElementById('notes')) {
		// _myDebug('Nowhere to write notes (<div id="notes">)');
		return false;
	};
	var commentHTML = '';
	if(appendFlag){ commentHTML = document.getElementById('notes').innerHTML; };
	var cId = '';
	for(i=0;i<someResponse.getElementsByTagName('comment').length;i++){
		cBody = someResponse.getElementsByTagName('comment')[i].firstChild.data;
		cRating = someResponse.getElementsByTagName('comment')[i].getAttribute('rating');
		cId = someResponse.getElementsByTagName('comment')[i].getAttribute('id');
		if(someResponse.getElementsByTagName('comment')[i].firstChild){
			commentHTML += cBody;
			// commentHTML += cBody.substr(0,_COMMENTCHARS);
		};
		commentHTML += '<code>';
		commentHTML += someResponse.getElementsByTagName('comment')[i].getAttribute('date');
		commentHTML += '</code>';
	};
	if(commentHTML){
		document.getElementById('notes').style.display = 'block';
		document.getElementById('notes').innerHTML = commentHTML;
	} else {
		document.getElementById('notes').style.display = 'none';
	};
};
function process_writenote(someInt){process_readnote(someInt,0);};

function process_readhistory(someInt){
	historyXML = req[someInt].responseXML.documentElement;
};
function process_readbookmark(someInt){
	bookmarkXML = req[someInt].responseXML.documentElement;
};
function process_writehistory(someInt){	/* no action needed, is there? */ };
function process_writebookmark(someInt){ /* no action needed, is there? */ };
function process_login(someInt){
	someResponse = req[someInt].responseXML.documentElement;
	if(someResponse.getElementsByTagName('identity')[0]){
		_USERNAME = someResponse.getElementsByTagName('identity')[0].getAttribute('username');
		_PASSWORD = someResponse.getElementsByTagName('identity')[0].getAttribute('password');
		_GROUPNAME = someResponse.getElementsByTagName('identity')[0].getAttribute('groupname') || '';
		_hideOrShow('','','loginform','none');
		_hideOrShow('','','loginlink','none');
		_hideOrShow('','','recoverpasslink','none');
		_hideOrShow('','','requestloginlink','none');
		_hideOrShow('','','signuplink','none');
		_hideOrShow('','','requestsignuplink','none');
		_hideOrShow('','','requestuserupdatelink','inline');
		_hideOrShow('','','userupdatelink','none');
		_hideOrShow('','','groupselectbox','none');
		_tellUser('Logged in successfully');
		_postLogin();
	};
};
function process_userupdate(someInt){ process_login(someInt); }

function process_logout(someInt){
	someResponse = req[someInt].responseXML.documentElement;
	_USERNAME = '';
	_PASSWORD = '';
	_GROUPNAME = '';
	_hideOrShow('','','requestuserupdatelink','none');
	_hideOrShow('','','requestloginlink','inline');
	_hideOrShow('','','recoverpasslink','inline');
	_tellUser('Logged out successfully');
	_postLogout();
};
function process_signup(someInt){ process_login(someInt); };
function process_getgroups(someInt){
	someResponse = req[someInt].responseXML.documentElement;
	if(document.getElementById('groupselect')){
		var tmpString = '<select name="groupname" id="groupnameselect" onChange="checkForNew(this)">';
		for(var g=0;g<someResponse.getElementsByTagName('group').length;g++){
			var tmpVal = someResponse.getElementsByTagName('group')[g].getAttribute('name');
			var tmpID = someResponse.getElementsByTagName('group')[g].getAttribute('id');
			var isPublic = someResponse.getElementsByTagName('group')[g].getAttribute('public') || 'false';
			var selectedstring = '';
			if(tmpVal == _GROUPNAME) {
				selectedstring = ' selected="1" ';
			};
			tmpString += '<option '+ selectedstring +' value="'+ tmpVal +'" id="'+ tmpID +'" public="'+ isPublic +'">'+ tmpVal +'</option>\n';
		};
		tmpString += '<option value="^new_group^" id="">[new group]</option>\n';
		tmpString += '</select>';
		if(someResponse.getElementsByTagName('group').length == 0) {
			tmpString = '<input type="text" name="groupname" value="mygroup" />';
		};
		document.getElementById('groupselect').innerHTML = tmpString;
		checkForNew(document.getElementById('groupnameselect'));
	};
};
function process_recoverpass(someInt){ /* Nothing need be done here */ };
function process_writeinfo(someInt){ };
function process_readinfo(someInt){ /* This will likely be  overridden locally */ };
function process_myfolder(someInt){
	if(_PATHTOROOT == '_NONE_') {
		_tellUser(_NO_PATHTOROOT);
		return '';
	};
	myreq = req[someInt];
	someResponse = myreq.responseXML.documentElement;
	if(someResponse.getElementsByTagName('message')[0] &&
		someResponse.getElementsByTagName('message')[0].getAttribute('text').indexOf('Error') > -1){
		/* user will already have received notification of problem, so do nothing */
		return '';
	};

	if(! document.getElementById('myfolder')) {
		_myDebug('Nowhere to write myfolder (<div id="myfolder">)');
		return false;
	};
	var myfolderTable = '';
	if(someResponse.getElementsByTagName('bookmark').length){
		myfolderTable += '<table id="myf">';
		myfolderTable += '<thead>\n';
		myfolderTable += '<tr>\n';
		myfolderTable += '<th id="dateheader" onClick="sortTable(\'myf\',0);"><a name="myfdate">Date</a></td>\n';
		myfolderTable += '<th id="titleheader" onClick="sortTable(\'myf\',1);"><a name="myftitle">Title</a></td>\n';
		myfolderTable += '<th id="unitheader" onClick="sortTable(\'myf\',2);"><a name="myfunit">Unit</a></td>\n';
		myfolderTable += '<th id="routesheader" onClick="sortTable(\'myf\',3);"><a name="myfroutes">Routes</a></td>\n';
		myfolderTable += '<th id="notesheader" onClick="sortTable(\'myf\',4);"><a name="myfnotes">My Notes</a></td>\n';
		myfolderTable += '<th id="deleteheader"><a name="myfdelete">Delete</a></td>\n';
		myfolderTable += '</tr>\n';
		myfolderTable += '</thead>\n';
		myfolderTable += '<tbody id="myfbody">\n';
		var rowClass = '0';
		for(var r=0;r<someResponse.getElementsByTagName('bookmark').length;r++){
			rowClass =  1 - rowClass;
			var bk = someResponse.getElementsByTagName('bookmark')[r];

			var routesIfAny = '&#160;';
			for(var p=0;p<bk.getElementsByTagName('route').length;p++){
				var rt = bk.getElementsByTagName('route')[p];
				routesIfAny += '<a href="viewroute.htm?routeid='+ rt.getAttribute('id') +'">' + rt.getAttribute('name') +'</a>&#160;\n';
			};
			if (! routesIfAny){ routesIfAny = '&#160;'; };

			var notesIfAny = '';
			for(var p=0;p<bk.getElementsByTagName('note').length;p++){
				var nt = bk.getElementsByTagName('note')[p];
				var nText = '' + nt.firstChild.nodeValue;
				var nTextShort = nText.substr(0,40) + '... ';
				var tmpNoteID = 'tmpnote'+ bk.getAttribute('id') + '_' + p;
				nText = '<span id="'+ tmpNoteID +'" style="display: none;">' + nText + '</span>\n';
				notesIfAny += '<a href="#" onClick="_showCopy(\''+tmpNoteID+'\',this); return false;">' + nTextShort + '</a>\n' + nText;
			};
			if (! notesIfAny){ notesIfAny = '&#160;'; };

			myfolderTable += '<tr id="bookmark' + bk.getAttribute('id') + '" class="row'+ rowClass +'">\n';
			myfolderTable += '<td>' + bk.getAttribute('date') + '</td>\n';
			myfolderTable += '<td><a href="'+ _PATHTOROOT + bk.getAttribute('pid').substr(1) +'">\n';
			myfolderTable += bk.getAttribute('pagetitle');
			myfolderTable += '</a></td>\n';
			myfolderTable += '<td>' + (bk.getAttribute('pagesubtitle') || '&#160;')+ '</td>\n';
			myfolderTable += '<td>' + routesIfAny + '</td>\n';
			myfolderTable += '<td>' + notesIfAny + '</td>\n';
			myfolderTable += '<td><div class="deletebookmark" onClick="deletebookmark(\'bookmark\',\''+ resourceid + '::' + bk.getAttribute('pid') +'\')">&#160</div></td>\n';
			myfolderTable += '</tr>\n';
		};
		myfolderTable += '</tbody>\n';
	} else {
		_tellUser('Sorry, you have no bookmarks');
	};
	document.getElementById('myfolder').innerHTML = myfolderTable;

};

function process_deletebookmark(someInt){
	myreq = req[someInt];
	someResponse = myreq.responseXML.documentElement;
	for(var r=0;r<someResponse.getElementsByTagName('bookmark').length;r++){
		var bk = someResponse.getElementsByTagName('bookmark')[r];
		if (bk.getAttribute('status') == 'deleted') {
			var deleteRow = document.getElementById('bookmark' + bk.getAttribute('id'));
			if(deleteRow){
				deleteRow.parentNode.removeChild(deleteRow);
			};
		};
	};
};

/**
*
* This turns the readroute reponse into a nice little
* XHTML document fragment and inserts it as innerHTML
* into all occurences of
* <div class="routereader"></div>
*/
function process_readroute(someInt){
	if(_PATHTOROOT == '_NONE_') {
		_tellUser(_NO_PATHTOROOT);
		return '';
	};
	myreq = req[someInt];
	someResponse = myreq.responseXML.documentElement;
	if(! someResponse.getElementsByTagName('a').length){
		_myDebug('nothing in path');
		_hideOrShow('div','routereader','','none');
		return '';
	};

	var linksXHTML = myreq.responseText;
	linksXHTML = linksXHTML.substr(linksXHTML.indexOf('<response'));
	re = eval('/' + '<response[^>]*>' + '/');	linksXHTML = linksXHTML.replace(re,'');
	re = eval('/' + '<message.*' + '/');		linksXHTML = linksXHTML.replace(re,'');
	re = eval('/' + '<\\/response>' + '/');		linksXHTML = linksXHTML.replace(re,'');
	re = eval('/<a href="\\//g');				linksXHTML = linksXHTML.replace(re,'<a href="' + _PATHTOROOT);
	linksXHTML += '<br />';
	_hideOrShow('div','routereader','','block');
	_dropins('div','routereader',linksXHTML);
};

/**
*
* This reads the details for a specific route and displays the results in
* <div id="routedetails></div>
*
*/
function process_readroutefull(someInt){
	if(_PATHTOROOT == '_NONE_') {
		_tellUser(_NO_PATHTOROOT);
		return '';
	};
	myreq = req[someInt];
	someResponse = myreq.responseXML.documentElement;
	var routeHTML = _NO_ROUTE_INFO;
	if(someResponse.getElementsByTagName('questionnaire') &&
		someResponse.getElementsByTagName('questionnaire')[0]) {
		var myQset = someResponse.getElementsByTagName('questionnaire')[0];
		routeHTML = '';
		routeHTML += '<h1>'+ myQset.getAttribute('name') +'</h1>\n';
		for (var q=0; q<myQset.getElementsByTagName('question').length;q++){
			var myQ = myQset.getElementsByTagName('question')[q];
			if(myQ.getElementsByTagName('page') && myQ.getElementsByTagName('page')[0]){
				var mylink = myQ.getElementsByTagName('page')[0].getAttribute('id');
				mylink = mylink.replace('/',_PATHTOROOT);
				routeHTML += '<div id="q'+ (q+1) +'"><a href="'+ mylink +'" class="complete'+ myQ.getAttribute('completestatus') +'">'+ myQ.getElementsByTagName('text')[0].firstChild.data +'</a></div>\n';
			};
		};
	} else {
		_tellUser(_NO_ROUTE_INFO);
		_myDebug('No questionnaire info returned');
		_noRoute();
		return '';
	};

	_dropins('','routedetails',routeHTML);
};


/**
*
* Process list of routes, and drop a list into
* <div id="routedetails></div>
*
*/
function process_listroutes(someInt){
	myreq = req[someInt];
	someResponse = myreq.responseXML.documentElement;
	var routeList = _NO_ROUTE_INFO;
	for (var r=0; r<someResponse.getElementsByTagName('route').length;r++){
		if(routeList == _NO_ROUTE_INFO) { routeList = ''; };
		rt = someResponse.getElementsByTagName('route')[r];
		routeList += '<div class="listroutes"><a href="viewroute.htm?routeid='+ rt.getAttribute('id') +'">'+ rt.firstChild.data +'</a></div>\n';
	};
	_dropins('','routedetails',routeList);
};

/**
*
* Process comment update
*
*/
function process_updatecomment(someInt){
	myreq = req[someInt];
	someResponse = myreq.responseXML.documentElement;
	var updatedComment = someResponse.getElementsByTagName('comment').item(0);
	document.getElementById('comment' + updatedComment.getAttribute("id")).setAttribute('class','status' + updatedComment.getAttribute('status'));
	document.getElementById('comment' + updatedComment.getAttribute("id")).setAttribute('className','status' + updatedComment.getAttribute('class'));
	document.getElementById('message').innerHTML = response.getElementsByTagName('message').item(0).getAttribute('text');
};

/**
*
* END of process_ACTION response handlers
*
*/

function checkForNew(someSelect){
	if (! someSelect.selectedIndex) { someSelect.selectedIndex = 0; };
	if(someSelect.options[someSelect.selectedIndex].getAttribute('public') == 'true'){
		_hideOrShow('','','needgrouppass','none');
	} else {
		_hideOrShow('','','needgrouppass','block');
	};
	if(someSelect.options[someSelect.selectedIndex].value == '^new_group^'){
		document.getElementById('groupselect').innerHTML = '<input type="text" name="groupname" value="newgroup" />';
	};
};



/**
*
* START of ACTION request functions.
*
*/

/**
*
* Basic function for pullnig stuff out of database. May be overriden
* EG: getCommentsOrNotes('readcomment','/index.htm',1,'',1,'','',1);
*
*/
function getCommentsOrNotes(actionName,somePageID,groupCall,note,comment,status,summary){
	var resultDiv = 'comments';
	if(actionName != 'readcomment') { resultDiv = 'notes'; };
	if(! document.getElementById(resultDiv)){
		// Don't perform action, as there's nowhere to show the results
		return '';
	};

	var mySql = '';
	if('a' + note != 'a')			{ mySql = " comments.note="+ note +" "; };
	if('a' + comment != 'a')		{ if(mySql) { mySql += ' AND '; }; mySql += " comments.comment="+ comment +" "; };
	if(mySql) { mySql += ' AND '; }; mySql += " comments.status='"+ status +"' ";

	var reqXML = '';
	reqXML += '<request action="'+ actionName +'">';
	reqXML += '\n<identity rid="'+ resourceid +'" pid="'+ somePageID +'" username="'+ _USERNAME +'"  password="'+ _PASSWORD +'" />';
	reqXML += '\n<comment sql="'+ mySql +'" ';
	if(summary) { reqXML += ' summary="1" '; };
	if(groupCall) { reqXML += ' groupcall="1" '; };
	reqXML += ' />';
	reqXML += '\n</request>';
	doRequest(reqXML);
};


/**
*
* Assembles all the given parameters in an XML request.
*
* Main difference between a note and a comment is that
* each user can have only one note per page, but many
* comments.
*
*/
function postCommentsOrNotes(somePageID,somePageTitle,note,comment,commentBody,rating){
	_tellUser(_PLEASE_WAIT);
	var reqXML  = '';
	var action = 'writenote';
	if(comment > 0){
		action = 'writecomment';
	};
	reqXML += '<request action="'+ action +'">';
	reqXML += '\n<identity rid="'+ resourceid +'" pid="'+ somePageID +'" pagetitle="'+ somePageTitle +'" username="'+ _USERNAME +'"  password="'+ _PASSWORD +'" />';
	reqXML += '<comment rating="'+ rating +'" comment="' + comment + '" note="'+ note +'"><![CDATA['+ commentBody +']]></comment>';
	reqXML += '\n</request>';
	// _myDebug(reqXML);
	doRequest(reqXML);
};

function editNote(notesdivid,pageid,pagetitle){
	if(! document.getElementById(notesdivid)){ _tellUser('Error: No place to edit note!'); return ''; };
	commentBody = document.getElementById(notesdivid).innerHTML;
	commentBody = commentBody.replace(eval('/' + 'CODE>' + '/g'),'code>');
	commentBody = commentBody.substr(0,commentBody.indexOf('<code>'));
	makeComment('notes',pageid,pagetitle,1,0,commentBody,0);
};


/**
*
* Collects all the parameters needed to make a request
*
*/
function makeComment(editDivName,somePageID,somePageTitle,note,comment,commentBody,rating){
	if(! _USERNAME || ! _PASSWORD ) { alert(_MISSING_USER_AND_PASS); return ''; };

	if(! editDivName || ! document.getElementById(editDivName)){ alert(_MISSING_COMMENT_DIV); return '';};
	backEditHTML[editDivName] = document.getElementById(editDivName).innerHTML;

	if(document.getElementById('notepadeditor')) {
		/* wysiwyg notepad editor loaded */
		customEditorExtra = '<form id="commenteditform" style="display: inline;">';
		if(comment){
			customEditorExtra += '<span style="font-size: 10px;">rating:';
			customEditorExtra += '1:<input type="radio"  name="rating" value="0" />';
			customEditorExtra += '2:<input type="radio"  name="rating" value="1" />';
			customEditorExtra += '3:<input type="radio"  name="rating" value="2" />';
			customEditorExtra += '4:<input type="radio"  name="rating" value="3" />';
			customEditorExtra += '5:<input type="radio"  name="rating" value="4" /></span>';
		};
		customEditorExtra += '<input type="hidden" name="commentbody" />';
		customEditorExtra += '<input type="hidden" name="pageid" value="'+ somePageID +'" />';
		customEditorExtra += '<input type="hidden" name="pagetitle" value="'+ somePageTitle +'" />';
		customEditorExtra += '<input type="hidden" name="note" value="'+ note +'" />';
		customEditorExtra += '<input type="hidden" name="comment" value="'+ comment +'" />';
		customEditorExtra += '</form>';
		document.getElementById('customeditorextra').innerHTML = customEditorExtra;
		// if(document.getElementById(editDivName).innerHTML) {
			document.getElementById(editDivName).innerHTML = commentBody;
		// };
		notepadEditor(editDivName);
		// _moveLevelWith(document.getElementById(editDivName),'notepadeditor');

	} else {
		editorHTML = '';
		editorHTML += '<form id="commenteditform"><textarea id="commentbody" name="commentbody">'+ commentBody +'</textarea><br />';
		editorHTML += '<input type="hidden" name="pageid" value="'		+ somePageID +'">';
		editorHTML += '<input type="hidden" name="pagetitle" value="'	+ somePageTitle +'">';
		editorHTML += '<input type="hidden" name="note" value="'		+ note +'">';
		editorHTML += '<input type="hidden" name="comment" value="'		+ comment +'">';
		if(comment){
			editorHTML += '<input type="radio"  name="rating" value="0" />';
			editorHTML += '<input type="radio"  name="rating" value="1" />';
			editorHTML += '<input type="radio"  name="rating" value="2" />';
			editorHTML += '<input type="radio"  name="rating" value="3" />';
			editorHTML += '<input type="radio"  name="rating" value="4" />';
		};
		editorHTML += '<br /><a href="#" onClick="completeComment(\''+ editDivName +'\',document.forms[\'commenteditform\']); return false;">done</a>';
		editorHTML += '      <a href="#" onClick="completeComment(\''+ editDivName +'\'); return false;">cancel</a>';
		editorHTML += '</form>';
		document.getElementById(editDivName).innerHTML = editorHTML;
		if(rating != '') {
			document.getElementById('commenteditform').elements['rating'][rating].checked=true;
		};
	};
};
/**
*
* Overrides definition from wysiwyg editor
*
*/
function postNotepadCall(someDivId){
	if(! document.forms['commenteditform']) {
		alert("ERROR: can't find 'commenteditform'");
		return false;
	};
	document.forms['commenteditform'].elements['commentbody'].value = document.getElementById(someDivId).innerHTML;
	completeComment(someDivId, document.forms['commenteditform']);
};

/**
*
* Requests the XML to be sent and restores the HTML page
*
*/
function completeComment(someDivName, someForm){
	if(! someForm) {
		document.getElementById(someDivName).innerHTML = backEditHTML[someDivName];
		return false;
	};

	somePageID = someForm.elements['pageid'].value;
	somePageTitle = someForm.elements['pagetitle'].value;
	note = someForm.elements['note'].value;
	comment = someForm.elements['comment'].value;
	commentBody=someForm.elements['commentbody'].value;
	rating = -1;
	if(someForm.elements['rating']){
		for (k=0;k<someForm.elements['rating'].length;k++){
			if(someForm.elements['rating'][k].checked){ rating = someForm.elements['rating'][k].value; };
		};
	};
	document.getElementById(someDivName).innerHTML = backEditHTML[someDivName];
	// postCommentsOrNotes(somePageID,somePageTitle,note,comment,commentBody,rating);
	postCommentsOrNotes(somePageID,somePageTitle,note,comment,commentBody,rating);
};

/**
*
* Updates a comment status: requires super user (and user) account
*
*/
function updateComment(someId,someStatus){
	var reqXML  = '';
	var action = 'updatecomment';
	reqXML += '<request action="'+ action +'">';
	reqXML += '\n<identity rid="'+ resourceid +'" username="'+ _USERNAME +'"  password="'+ _PASSWORD +'" />';
	reqXML += '<comment id="'+ someId +'" status="'+ someStatus +'" />';
	reqXML += '\n</request>';
	doRequest(reqXML);
};

/**
*
* Assembles all the given parameters for a bookmark or history record in an XML request
*
*/
function bookmarkOrHistory(bookGroup,somePageID,somePageTitle,somePageSubTitle){
	if(! _USERNAME || ! _PASSWORD ) { alert(_MISSING_USER_AND_PASS); return ''; };
	var reqXML  = '';
	var action = 'writebookmark';

	if(bookGroup != 'bookmark'){
		action = 'writehistory';
	} else {
		if(document.getElementById('bookmarklink')){
			document.getElementById('bookmarklink').setAttribute('class','bookmarked');
			document.getElementById('bookmarklink').className = 'bookmarked';
		};
	};
	reqXML += '<request action="'+ action +'">';
	reqXML += '\n<identity rid="'+ resourceid +'" pid="'+ somePageID +'" pagetitle="'+ somePageTitle +'" pagesubtitle="'+ somePageSubTitle +'" username="'+ _USERNAME +'"  password="'+ _PASSWORD +'" />';
	reqXML += '<bookmark bookgroup="'+ bookGroup +'" />';
	reqXML += '\n</request>';
	doRequest(reqXML);
};

function readBookmarkOrHistory(bookGroup,somePageID,somePageTitle){
	var reqXML  = '';
	var action = 'readbookmark';
	if(bookGroup != 'bookmark'){ action = 'readhistory'; };
	reqXML += '<request action="'+ action +'">';
	reqXML += '\n<identity rid="'+ resourceid +'" pid="'+ somePageID +'" pagetitle="'+ somePageTitle +'" username="'+ _USERNAME +'"  password="'+ _PASSWORD +'" />';
	reqXML += '<bookmark bookgroup="'+ bookGroup +'" />';
	reqXML += '\n</request>';
	doRequest(reqXML);
};

/**
*
* Assembles all the given parameters for login in an XML request
*
*/
function login(someForm){
	if(! (someForm && someForm.elements['username'].value && someForm.elements['password'].value)) {
		_tellUser('Error: Full login details not specified'); return '';
	};
	someUser = someForm.elements['username'].value;
	somePass = someForm.elements['password'].value;
	if(! _isValid(someUser)){
		_tellUser(_BAD_CHARS);
		_flagField(someForm.elements['username']);
		return '';
	};
	if(! _isValid(somePass)){
		_tellUser(_BAD_CHARS);
		_flagField(someForm.elements['password']);
		return '';
	};
	_tellUser(_PLEASE_WAIT);
	var reqXML  = '';
	var action = 'login';
	reqXML += '<request action="'+ action +'">';
	reqXML += '\n<identity rid="'+ resourceid +'" username="'+ someUser +'"  password="'+ somePass +'" />';
	reqXML += '\n</request>';
	doRequest(reqXML);
};

/**
*
* Assembles all the given parameters for signup/userupdate in an XML request
*
*/
function signup(someForm,action){

	if(! someForm) {
		_tellUser('Error: No form completed'); return '';
	};

	var stuffNeeded = 'username|password|groupname|grouppass'.split('|');
	var formVals = new Array();
	var flagged = 0;
	for (var i=0;i<stuffNeeded.length;i++){
		if(someForm.elements[stuffNeeded[i]]){
			formVals[stuffNeeded[i]] = someForm.elements[stuffNeeded[i]].value;
			if(someForm.elements[stuffNeeded[i]].name == 'select') {
				formVals[stuffNeeded[i]] = someForm.elements[stuffNeeded[i]].options[someForm.elements[stuffNeeded[i]].selectedIndex].value;
			};
		} else {
			formVals[stuffNeeded[i]] = undefined;
		};

		/* If we're looking to signup to a public group, no password is needed */
		if(stuffNeeded[i] == 'grouppass' && someForm.elements['groupname'] && someForm.elements['groupname'].options &&
			someForm.elements['groupname'].options[someForm.elements['groupname'].selectedIndex].getAttribute('public') == 'true'
		) {
			formVals[stuffNeeded[i]] = '';
		};

		if(! someForm.elements['groupname']){
			_tellUser('Error: Please wait for the page to load fully before trying to log in');
			return '';
		};
		if(! formVals[stuffNeeded[i]] || ! _isValid(formVals[stuffNeeded[i]])) {
			if(stuffNeeded[i] == 'grouppass' &&
				(
				someForm.elements['groupname'].options &&
				someForm.elements['groupname'].options[someForm.elements['groupname'].selectedIndex].getAttribute('public') == 'true'
				) ||
				someForm.elements['groupname'].value.indexOf('catchall') > 1
			) {
				formVals[stuffNeeded[i]] = '';
			} else {
				flagged = 1;
				_tellUser('Error: Please check the indicated field('+ stuffNeeded[i] +')');
				_flagField(someForm.elements[stuffNeeded[i]]);
			};
		};
	};
	if (flagged){ return ''; };

	_tellUser(_PLEASE_WAIT);
	var reqXML  = '';
	reqXML += '<request action="'+ action +'">';
	reqXML += '\n<identity rid="'+ resourceid +'" username="'+ formVals['username'] +'" password="'+ formVals['password'] +'" groupname="'+ formVals['groupname'] +'" grouppass="'+ formVals['grouppass'] +'" />';
	reqXML += '\n</request>';
	doRequest(reqXML);
};

function recoverpass(someForm){
	if(! someForm) {
		_tellUser('Error: No form completed'); return '';
	};
	var testusername = someForm.elements['username'].value;
	if(! testusername) { _tellUser(_BAD_USERNAME); return ''; };
	if(testusername.indexOf('@') == -1) { _tellUser(_NO_EMAIL_USERNAME); return ''; };
	var reqXML  = '';
	reqXML += '<request action="recoverpass">';
	reqXML += '\n<identity rid="'+ resourceid +'" username="'+ testusername +'" />';
	reqXML += '\n</request>';
	doRequest(reqXML);
};


/**
*
* modifies login form, making the signup form
*
*/
function prepSignupForm(loginType){
	if(loginType == 'login') {
		/* need only username and password */
		_hideOrShow('','','loginform','block');
		_hideOrShow('','','loginlink','inline');
		_hideOrShow('','','recoverpasslink','inline');
		_hideOrShow('','','requestloginlink','none');
		_hideOrShow('','','signuplink','none');
		_hideOrShow('','','requestsignuplink','inline');
		_hideOrShow('','','requestuserupdatelink','none');
		_hideOrShow('','','userupdatelink','none');
		_hideOrShow('','','groupselectbox','none');

	};
	if(loginType == 'signup') {
		/* need username and password  and groups */
		getgroups();
		_hideOrShow('','','loginform','block');
		_hideOrShow('','','loginlink','none');
		_hideOrShow('','','recoverpasslink','none');
		_hideOrShow('','','requestloginlink','none');
		_hideOrShow('','','signuplink','inline');
		_hideOrShow('','','requestsignuplink','none');
		_hideOrShow('','','requestuserupdatelink','none');
		_hideOrShow('','','userupdatelink','none');
		_hideOrShow('','','groupselectbox','block');
	};
	if(loginType == 'userupdate') {
		/* need username and password  and groups */
		getgroups();
		_hideOrShow('','','loginform','block');
		_hideOrShow('','','loginlink','none');
		_hideOrShow('','','recoverpasslink','none');
		_hideOrShow('','','requestloginlink','none');
		_hideOrShow('','','signuplink','none');
		_hideOrShow('','','requestsignuplink','none');
		_hideOrShow('','','requestuserupdatelink','none');
		_hideOrShow('','','userupdatelink','inline');
		_hideOrShow('','','groupselectbox','block');
		document.getElementById('usernamefield').innerHTML='<input type="hidden" name="username" value="'+ _USERNAME +'" />' + _USERNAME;
		document.forms['loginform'].elements['password'].value=_PASSWORD;

	};
	if(loginType == 'loggedin') {
		_hideOrShow('','','loginform','none');
		_hideOrShow('','','loginlink','none');
		_hideOrShow('','','recoverpasslink','none');
		_hideOrShow('','','requestloginlink','none');
		_hideOrShow('','','signuplink','none');
		_hideOrShow('','','requestsignuplink','none');
		_hideOrShow('','','requestuserupdatelink','inline');
		_hideOrShow('','','userupdatelink','none');
		_hideOrShow('','','groupselectbox','none');
	};
	if(loginType == 'loggedout') {
		_hideOrShow('','','loginform','none');
		_hideOrShow('','','loginlink','none');
		_hideOrShow('','','recoverpasslink','none');
		_hideOrShow('','','requestloginlink','inline');
		_hideOrShow('','','signuplink','none');
		_hideOrShow('','','requestsignuplink','none');
		_hideOrShow('','','requestuserupdatelink','none');
		_hideOrShow('','','userupdatelink','none');
		_hideOrShow('','','groupselectbox','none');
	};
};

/**
*
* Gets all group infor for the current resource
*
*/
function getgroups(){
	var reqXML  = '';
	var action = 'getgroups';
	reqXML += '<request action="'+ action +'">';
	reqXML += '\n<identity rid="'+ resourceid +'" />';
	reqXML += '\n</request>';
	doRequest(reqXML);
};

/**
*
* Send logout request
*
*/
function logout(){
	var reqXML  = '';
	var action = 'logout';
	reqXML += '<request action="'+ action +'">';
	reqXML += '\n<identity rid="'+ resourceid +'" username="'+ _USERNAME +'"  password="'+ _PASSWORD +'" />';
	reqXML += '\n</request>';
	doRequest(reqXML);
};

function writeinfo(someForm){
	if(! someForm) { _tellUser('Error: No login form specified'); return ''; };

	var questionsets = '';
	questionsets += '<questionset name="'+ (someForm.elements['name'].value || '') +'">\n';
	for (var q=0;q<someForm.elements.length;q++){
		if(someForm.elements[q].name.match(/q\d*/) && someForm.elements[q].checked){
			questionsets += '<question id="'+ someForm.elements[q].name +'" response="'+ parseInt(someForm.elements[q].value) +'" />\n';
		};
	};

	questionsets += '</questionset>\n';

	var reqXML  = '';
	reqXML += '<request action="writeinfo">';
	reqXML += '\n<identity rid="'+ resourceid +'" username="'+ _USERNAME +'"  password="'+ _PASSWORD +'" />';
	reqXML += questionsets;
	reqXML += '\n</request>';
	doRequest(reqXML);
};

function readinfo(){
	var reqXML  = '';
	reqXML += '<request action="readinfo">';
	reqXML += '\n<identity rid="'+ resourceid +'"  username="'+ _USERNAME +'"  password="'+ _PASSWORD +'" />';
	reqXML += '\n</request>';
	doRequest(reqXML);
};

/* the cleanest of calls, but runs the ugliest of code on the server */
function myfolder(){
	var reqXML  = '';
	reqXML += '<request action="myfolder">';
	reqXML += '\n<identity rid="'+ resourceid +'" username="'+ _USERNAME +'"  password="'+ _PASSWORD +'" />';
	reqXML += '\n</request>';
	doRequest(reqXML);
};


function deletebookmark(bookgroup,resourcepid){
	var pageid = resourcepid.substring(resourcepid.indexOf('::')+2,resourcepid.length);
	var resourceid = resourcepid.substring(0,resourcepid.indexOf('::'));
	if(! confirm('Delete this bookmark?\n'+ pageid)){
		return '';
	};
	var reqXML  = '';
	reqXML += '<request action="deletebookmark">';
	reqXML += '\n<identity rid="'+ resourceid +'" username="'+ _USERNAME +'"  password="'+ _PASSWORD +'" pid="'+ pageid +'" />';
	reqXML += '\n<bookmark bookgroup="'+ bookgroup +'" />';
	reqXML += '\n</request>';
	doRequest(reqXML);
};


/**
*
* Takes one optional parameter: routename If not supplied,
* we assume that you just want the current route cookie
* trail. If a routename is gicven explicitly, it is assumed
* you want the full XML of the route.
*
*/

function readroute(somePageID,optionalRouteID){
	var reqXML  = '';
	actionname = 'readroute';
	if(optionalRouteID) {
		actionname = 'readroutefull';
	};
	reqXML += '<request action="'+ actionname +'">';
	reqXML += '\n<identity pid="'+ somePageID +'" rid="'+ resourceid +'" username="'+ _USERNAME +'"  password="'+ _PASSWORD +'" />';
	if(optionalRouteID) {
		reqXML += '\n<route id="'+ optionalRouteID +'" />';
	};
	reqXML += '\n</request>';
	doRequest(reqXML);
};

/**
*
* List your routes. Takes one parameter 
* - an href for the page to be used in the 
* response.
*
*/
function listroutes(){
	
	var reqXML  = '';
	reqXML += '<request action="listroutes">';
	reqXML += '\n<identity rid="'+ resourceid +'" username="'+ _USERNAME +'"  password="'+ _PASSWORD +'" />';
	reqXML += '\n</request>';
	doRequest(reqXML);
};

function readroutefull(somePageID,optionalRouteID){
	var reqXML  = '';
	reqXML += '<request action="readroutefull">';
	reqXML += '\n<identity pid="'+ somePageID +'" rid="'+ resourceid +'" username="'+ _USERNAME +'"  password="'+ _PASSWORD +'" />';
	if(optionalRouteID) {
		reqXML += '\n<route id="'+ optionalRouteID +'" />';
	};
	reqXML += '\n</request>';
	doRequest(reqXML);
};


/**
*
* END actions
*
*/

/**
*
* Some basic cookie reading and writing
*
*/
function setCookieOld(name, value, expires, path, domain, secure) {
	/* ovveride any date preference - just ave cookie last a long time */
	var d = new Date(); /* now */
	expires = new Date(d.getTime() + 12960000000); /* 150 days from now */
	var curCookie = name + "=" + value + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "");
	document.cookie = curCookie;
};
function setCookie(name, value, expires, path, domain, secure) { 
	var curCookie = name + "=" + escape(value) + 
		((expires) ? "; expires=" + expires.toGMTString() : "") + 
		((path) ? "; path=" + path : "") + 
		((domain) ? "; domain=" + domain : "") + 
		((secure) ? "; secure" : ""); 
	document.cookie = curCookie; 
};
function _testCookies() { 
	if (navigator.userAgent.toLowerCase().indexOf('safari') > -1) {
		/* we can't tell till we try setting cookies from the server... */
		_CANCOOKIE = 1;
		return _CANCOOKIE;
	};
	var d = new Date(); 
	d.setTime(d.getTime() + 1800000); 
	setCookie("cookies", "cookies", d, false, false, false);
	_CANCOOKIE = 0;
	if (document.cookie.indexOf('cookies') != -1) { _CANCOOKIE = 1; };
	d = new Date(); 
	d.setTime(d.getTime() - 1800000); 
	setCookie("cookies", "cookies", d, false, false, false);
	if(! _CANCOOKIE){
		_tellUser(_COOKIE_ERROR);
	};
	return _CANCOOKIE;
};

function getCookie(Name) {
	var search = Name + "=";
	if (document.cookie.length > 0) { // if there are any cookies
		offset = document.cookie.indexOf(search)
		if (offset != -1) { // if cookie exists
			offset += search.length;
			end = document.cookie.indexOf(";", offset)
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(offset, end));
		};
	};
	return '';
};

function show_props(obj, obj_name) {
	var result = "";
	for (var i in obj) {
		try {
			result += obj_name + "." + i + " = " + obj[i] + "\n";
		} catch(er) {
			alert('error:' + er);
		};
	};
	return result
};

/**
* START: script to sort the contents of any table, so long as it's
* identified correctly and has a tbody and thead.
*
* Unfortunately, any ID or class attributes on td are lost.
* All class and id tags on tr are however preserved, except for
* class="row0" and class="row1", which are redefined after the 
* table is sorted (to preserve stripes!)
* 
*/
var _SORTCOL = 0;
var _SORTSENSE = 1;
function sortTable(someTableID,someColCount){
	_SORTCOL = someColCount;
	_SORTSENSE = -_SORTSENSE;
	if(! document.getElementById(someTableID) && document.getElementById(someTableID +'body')){
		alert('No such table or tbody:' + someTableID);
		return '';
	};
	var mytab = document.getElementById(someTableID);
	var tabData = new Array();

	for(r=1;r<mytab.getElementsByTagName('tr').length;r++){
		tabData[r-1] = new tabRow(mytab.getElementsByTagName('tr')[r]);
	};


	var newTabBody = '<table id="'+ someTableID +'">\n';
	newTabBody += mytab.getElementsByTagName('tr')[0].innerHTML;
	tabData = tabData.sort(sortBy);
	var newClass = 0;
	for(var i=0;i<tabData.length;i++){
		newClass = 1 - newClass;
		var newClassTag = 'class="row'+ newClass +'"';
		var extraInf = tabData[i].pop();
		var re = /class="row\d"/i;
		extraInf = extraInf.replace(re,newClassTag);
		newTabBody += '<tr'+ extraInf +'>\n';
		for(var j=0;j<tabData[i].length;j++){
			newTabBody += '<td>' + tabData[i][j] + '</td>\n';
		};
		newTabBody += '</tr>\n';
	};
	newTabBody += '</table>\n';
	document.getElementById(someTableID).parentNode.innerHTML = newTabBody;
};

function tabRow (someRow){
	var newRow = new Array();
	for(var j=0;j<someRow.getElementsByTagName('td').length;j++){
		newRow[j] = someRow.getElementsByTagName('td')[j].innerHTML;
	};
	/* and use the last element in the array to store any class and ID info */
	var extraInf = ' ';
	if (someRow.getAttribute('id')){ extraInf += 'id="'+ someRow.getAttribute('id') +'"' };
	if (someRow.getAttribute('class')){ extraInf += ' class="'+ someRow.getAttribute('class') +'"' };
	newRow[j] = extraInf;
	return newRow;
};

function sortBy(a,b){
	var tmpArray = new Array(a[_SORTCOL],b[_SORTCOL]);
	if(a[_SORTCOL] == tmpArray.sort()[1]){
		return _SORTSENSE;
	} else {
		return - _SORTSENSE;
	};
};
/**
* END: script to sort the contents of any table, so long as it's
* identified correctly and has a tbody and thead
*/


/**
*
* Little admin functions
*
*/
function _myDebug(someMessage,refresh){
	var newMsg = someMessage;
	var d = new Date();
	re = eval('/</g'); newMsg = newMsg.replace(re,'&lt;');
	re = eval('/>/g'); newMsg = newMsg.replace(re,'&gt;');
	newMsg  = '\n<code>' + d.toUTCString() + '</code>\n' + newMsg;
	var forced = 0;
	if(_FORCEDEBUG && ! document.getElementById('debug')) {
		document.getElementsByTagName('body')[0].innerHTML = document.getElementsByTagName('body')[0].innerHTML + '\n<div id="debug"></div>\n';
		forced = 1;
	};
	if(document.getElementById('debug')) {
		var tmp = '';
		if(! document.getElementById('debug').innerHTML){
			tmp = '<a href="#" onClick="_myDebug(\'\',1); return false;">[clear debug]</a>\n';
			tmp += '<a href="#" onClick="alert(document.getElementById(\'debug\').innerHTML); return false;">[show debug]</a>\n';
		};
		if(refresh) {
			tmp = '';
		} else {
			tmp += document.getElementById('debug').innerHTML + '<pre>' + newMsg + '</pre>';
		};
		document.getElementById('debug').innerHTML = tmp;
		if(forced && document.getElementById('notepad')){
			notepad = document.getElementById('notepad');
			if(notepad.document) {notepad.document.designMode= "On"; };
		};
		return false;
	};
};

function _tellUser(someMessage) {
	if(document.getElementById('message')) {
		if(someMessage && someMessage != ' ') {
			_hideOrShow('','','message','block');
			document.getElementById('message').innerHTML = someMessage;
		} else {
			// _hideOrShow('','','message','none');
		};
	} else {
		/* if it's really urgent! */
		if(someMessage.match('Error')) {
			alert(someMessage);
		};
	};
};

function _inArray(someName,someArray){
	for(i=0;i<someArray.length;i++){
		if(someArray[i] == someName) return i;
	};
	return -1;
};

function _isValid (someString,checkString){
	if(! someString){ return 0; };
	if (! checkString){ checkString = ' 0123456789-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@.'; };
	var counter = 0;
	while (counter < someString.length) {
		if (checkString.indexOf(someString.charAt(counter)) == -1 ){ return 0;};
		counter++;
	};
	return 1;
};

function _hideOrShow(tagName,className,thingID,hideOrShow){
	// _myDebug('tagName:' + tagName + '\nclassName:' + className + '\nthingID:' + thingID + '\nhideOrShow:' + hideOrShow);
	if(thingID && document.getElementById(thingID)) {
			document.getElementById(thingID).style.display=hideOrShow;
	} else {
		for(var i=0;i<document.getElementsByTagName(tagName).length;i++){
			if(
				document.getElementsByTagName(tagName)[i].getAttribute('class') == className
			||	document.getElementsByTagName(tagName)[i].className == className){
				document.getElementsByTagName(tagName)[i].style.display=hideOrShow;
			};
		};
	};
};

function _dropins(tagName,className,replacevar){
	// _myDebug('_dropins:' + replacevar);
	var foundItem = '';
	if(tagName) {
		for(var k=0;k<document.getElementsByTagName(tagName).length;k++){
			if(		document.getElementsByTagName(tagName)[k].getAttribute('class')	== className
				||	document.getElementsByTagName(tagName)[k].className				== className ) {
				// document.getElementsByTagName(tagName)[k].innerHTML = replacevar;
				foundItem = document.getElementsByTagName(tagName)[k];
			};
		};
	} else {
		/* assume className is an element id */
		if(document.getElementById(className)){
			// document.getElementById(className).innerHTML = replacevar;
			foundItem = document.getElementById(className);
		};
	};
	if(foundItem) {
		if (replacevar) {
			foundItem.innerHTML = replacevar;
		} else {
			foundItem.style.display = 'hidden';
		};
	};
};


function _flagField (someFormEle){
	warnFlag		= document.createElement("b");
	warnFlagText	= document.createTextNode("*");
	warnFlag.appendChild(warnFlagText);
	warnFlag.style.color='#FF0000';
	warnFlag.setAttribute('style','color: #FF0000;');
	if(someFormEle) {
		someFormEle.parentNode.insertBefore(warnFlag,someFormEle);
	};
};

function _showCopy(someDivID, someLink){
	_myDebug(show_props(someLink,'someLink'));
	if(! document.getElementById(someDivID)) {
		_myDebug("ERROR: can't find element: " + someDivID);
		return '';
	};
	newDivObject = document.getElementById('fullcomment');
	if(! newDivObject) {
		newDivObject = document.createElement('div');
		newDivObject.setAttribute('id','fullcomment');
		newDivObject.setAttribute('style','width: 400px; background-color: #FFFFFF;');
		var newDiv = '';
		// newDiv += '\n<div id="fullcomment" style="width: 400px; background-color: #FFFFFF; border: 3px; border-style: solid; border-color: #336600;">';
		newDiv += '<div id="fullcommentheader" style="background-color: #D4D0C8; text-align: right; padding: 5px;">';
		newDiv += '<a href="#" style="color:#000000; text-decoration: none; font-family: sans-serif; font-weight: bold; " onClick="_removeElement(\'fullcomment\'); return false;">X</a>';
		newDiv += '</div>\n';
		newDiv += '<div id="fullcommentbody" style="background-color: #FFFFFF;">';
		newDiv += document.getElementById(someDivID).innerHTML;
		newDiv += '</div>\n';
		// newDiv += '</div>\n';
		newDivObject.innerHTML = newDiv;
		// document.getElementsByTagName('body')[0].innerHTML = document.getElementsByTagName('body')[0].innerHTML + newDiv;
		var linkParent = someLink.parentNode;
		linkParent.insertBefore(newDivObject,someLink);
	} else {
		document.getElementById('fullcomment').style.display = 'block';
		document.getElementById('fullcommentbody').innerHTML = document.getElementById(someDivID).innerHTML;
	};
	_moveLevelWith(someLink,'fullcomment');
	// document.getElementById('fullcomment').style.position = 'absolute';
	// document.getElementById('fullcomment').style.left = '25%';
};


/**
* 
* Use with caution - seems to upset rendering of divs in IE
*
*/
function _moveLevelWith(someLink,someElementId){
	// _myDebug('_moveLevelWith:' + someLink + ':' + someElementId);
	someElement = document.getElementById(someElementId);
	if (! someElement) { alert('can\'t find  element' + someElementId); return ''; };
	someElement.style.position='absolute';
	someElement.style.left='25%';

	var eleParent = someElement.parentNode;
	eleParent.removeChild(someElement);

	var linkParent = someLink.parentNode;
	linkParent.insertBefore(someElement,someLink);
};

function _removeElement(someElementId){
	someElement = document.getElementById(someElementId);
	if (! someElement){ return ''; };

	var eleParent = someElement.parentNode;
	eleParent.removeChild(someElement);
};

function _postLogin(){}; /* I assume this wil be overwritten client-side */
function _postLogout(){}; /* I assume this wil be overwritten client-side */
function _noRoute(){}; /* I assume this wil be overwritten client-side */

//-->
