function webDBLookup(sDBPath,sView,sKey,vResultColumns,nMaxResults){/*	this function performs an @dbcolumn equivalent on the web. It has been extended to create more flexibility in what data is retrieved when and how.   	Arguments:	sDBPath - string  - this is the path to the database that contains the sView; Use full paths ( http://server/db.nsf ) or absolute paths(/dir/db.nsf). required	sView - string  - this is the name or the alias of the sView you are trying to reference. Works best with non-categorized lookup sViews. required	vResultColumns - string or array - the column numbers you want returned as result. required. If the string 'unid' is supplied, the returnvalue is the unid of the found document in the sView	nMaxResults - numerical - maximum amount of returned results. optional; default value is 9999  		Result:	Multiple dimension Array of strings*/  	var vError = new Array(0);	var noResults = new Array(0);	var vResult= new Array()	vError[0] = 'dblookup not configured properly:';  	//cleaning up the passed parameters	if (!sDBPath){vError.push( 'sDBPath not specified')};	if (!sView) { vError.push( 'sView not specified')};	if (!sKey) { vError.push( 'sKey not specified')};	if (!vResultColumns) { vError.push( 'result column not specified')};	if (!nMaxResults){ nMaxResults = 9999};  	if (vError.length != 0){    		//Create a xmlDocument control for communicating with the server		var xmlDoc = false;		if(window.XMLHttpRequest) {		// branch for native XMLHttpRequest object (eg Mozilla, IE7)			try {				xmlDoc = new XMLHttpRequest();			} catch(e) {				xmlDoc = false;			}		} else if(window.ActiveXObject) {			// branch for IE/Windows ActiveX version (IE5, 5.5 and 6.x)			try {				xmlDoc = new ActiveXObject("Msxml2.XMLHTTP");			} catch(e) {				try {					xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");				} catch(e) {					xmlDoc = false;				}			}		}    		//If we have the object, go and work with it		if (typeof xmlDoc == 'object'){			//Prepare the caller url			if (sDBPath.substr(sDBPath.length-1)=='/') {sDBPath.substr(0,sDBPath.length-1)}			if (sDBPath.substr(0,4)!='http') {				if (sDBPath.substr(0,1)!='/') {sDBPath='/' + sDBPath}			}						var ranNo = Math.random().toString();			var sUrl = sDBPath + '/' + sView + '?readviewentries&count='+ nMaxResults + '&startkey='+sKey + '&random='+ranNo;     	       	  			//Load the XML from the view. wait for the result			xmlDoc.open("GET", sUrl, false);			xmlDoc.send('');			//If the XML has arrived then work the collection. If <html> exists in the responseText then 			if (xmlDoc.status==200){										//Browser compatible trick to get the viewentries collection from the dom object (IE & Moz tested):				var vViewEntries=xmlDoc.responseXML.childNodes[xmlDoc.responseXML.childNodes.length-1];				if (vViewEntries.childNodes.length==0) {					noResults[0] = null;					return(noResults)				}								//Make sure the resultcolumns is always an array				if (vResultColumns.constructor != Array){					vResultColumns=new Array(vResultColumns.toString())				}				//Mozilla may think that the LF's between the view nodes are text nodes. compensate for that				var bLFSkip=false;				if (vViewEntries.childNodes[0].nodeName=='#text'){					bLFSkip=true;				}				//Squeeze the info out of the XML				for (var e=0;e<vViewEntries.childNodes.length;e++){					//Do the #text tricks					if (bLFSkip==true){						if (e!=0){							var vViewEntry=vViewEntries.childNodes[(e*2)-1];						}					} else {						var vViewEntry=vViewEntries.childNodes[e]					}										if (vViewEntry!=null){											var vRowResult=new Array(vResultColumns.length)						for (var n=0;n<vResultColumns.length;n++){							vRowResult[n]=new Array()									if (isNaN(vResultColumns[n]) && vResultColumns[n].toLowerCase()=='unid'){								vRowResult[n].push(vViewEntry.getAttribute('unid'))							} else {								//Get the header								var headerKey;								if (bLFSkip==true){									var vNodeHeader=vViewEntry.childNodes[1].childNodes[1];								} else {									var vNodeHeader=vViewEntry.childNodes[0].childNodes[0];								}								if (bLFSkip==false && vNodeHeader.childNodes.length==1){									//IE 									headerKey = vNodeHeader.text;								} else {									//Moz									headerKey = vNodeHeader.childNodes[0].textContent;												}								if(headerKey.toLowerCase()==sKey.toLowerCase()) {									if (bLFSkip==true){										var vNodeContent=vViewEntry.childNodes[(2*parseFloat(vResultColumns[n]))-1].childNodes[1];									} else {										var vNodeContent=vViewEntry.childNodes[(parseFloat(vResultColumns[n]))-1].childNodes[0];									}																	if (bLFSkip==false && vNodeContent.childNodes.length==1){										//Single value field, IE style										vRowResult[n].push(vNodeContent.text)									} else if (bLFSkip==true && vNodeContent.childNodes.length==1){										//Single value field, Moz style										vRowResult[n].push(vNodeContent.childNodes[0].textContent)																} else {										//Multiple value field										for (var c=0;c<vNodeContent.childNodes.length;c++){											if (vNodeContent.childNodes[c].nodeName!='#text'){												if (vNodeContent.childNodes[c].text!=null){													vRowResult[n].push(vNodeContent.childNodes[c].text)												} 												else {													vRowResult[n].push(vNodeContent.childNodes[c].textContent)																							}											}										}									}								}							}						}											//Add the result to the end resutl set								if (vRowResult.length==1){							if (vRowResult[0]!='') {								vResult.push(vRowResult[0]) //Parse only the first element of the array							}						} else {							if (vRowResult!='') {								vResult.push(vRowResult) //Parse the array							}						}					}				}			}		}	}	//Parse the result back to the caller  	if (vError.length==0){		return(vError)	} else {		return(vResult); 	}}function trim(str) {	return str.replace(/^s+/g, '').replace(/s+$/g, '');} function replace(str, from, to) {	var i = str.indexOf(from);	if (!from || !str || i == -1) return str;	var newstr = str.substring(0, i) + to;	f (i+from.length < str.length)	newstr += replace(str.substring(i+from.length,str.length),from,to);	return newstr;}function setCookie(sName, sValue){	document.cookie = sName + "=" + escape(sValue) + "; expires=Tue, 1 Jan 2015 23:59:59 GMT;";	}function getCookie(sName){	if (document.cookie) {		var start = document.cookie.indexOf(' ' + sName + '=');	  	if (start == -1) { 			start = document.cookie.indexOf(sName + '=');	  		if (start == -1) {return null; }			}	  	var end = document.cookie.indexOf(";", start);	  	if (end == -1) { end = document.cookie.length; }	  	end -= start;	  	var cookie = document.cookie.substr(start,end);	  	return unescape(cookie.substr(cookie.indexOf('=') + 1, cookie.length - cookie.indexOf('=') + 1));	}else{		return null;	}}function openPageinNewWindow(strUrl, runInsideApp, width, height){	if (width == undefined){width='650'}	if (height == undefined){height='650'}	specs = 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width='+width+', height='+height;	window.open(strUrl,'_blank',specs) }//Author: Phillip Roberts - phillroberts@yahoo.com//Released under GNU General Public License : http://www.gnu.org/copyleft/gpl.htmlfunction getLeft(sourceStr, keyStr){	return (sourceStr.indexOf(keyStr) == -1 | keyStr=='') ? '' : sourceStr.split(keyStr)[0];}function getRight(sourceStr, keyStr){	idx = sourceStr.indexOf(keyStr);	return (idx == -1 | keyStr=='') ? '' : sourceStr.substr(idx+ keyStr.length);}function getRightBack(sourceStr, keyStr){	arr = sourceStr.split(keyStr);	return (sourceStr.indexOf(keyStr) == -1 | keyStr=='') ? '' : arr.pop()}function getLeftBack(sourceStr, keyStr){	arr = sourceStr.split(keyStr)	arr.pop();	return (keyStr==null | keyStr=='') ? '' : arr.join(keyStr)}function getMiddle(sourceStr, keyStrLeft, keyStrRight){ 	return xiLeft(xiRight(sourceStr,keyStrLeft), keyStrRight);} //End of code by Phillip Roberts - phillroberts@yahoo.comfunction getTrim(str) {	return str.replace(/^\s+|\s+$/g,'');}function getTimeStr(tDate, clockType) {	hour = tDate.getHours();	min = tDate.getMinutes();	sec = tDate.getSeconds();	if (clockType == "12") {		if (min <= 9) {			min = "0" + min;		}		if (sec <= 9) {			sec = "0" + sec;		}		if (hour > 12) {			hour = hour - 12;			add = " p.m.";		} else {			hour = hour;			add = " a.m.";		}		if (hour == 12) {			add = " p.m.";		}		if (hour == 00) {			hour = "12";		}		return ((hour<=9) ? "0" + hour : hour) + ":" + min + ":" + sec + add;	} else {		if (min <= 9) {			min = "0" + min		}		if (sec <= 9) {			sec = "0" + sec		}		if (hour < 10) {			hour = "0" + hour		}		return hour + ':' + min + ':' + sec;  	}}function getDateStr(tDate) {	var d = tDate.getDate();	var day = (d < 10) ? '0' + d : d;	var m = tDate.getMonth() + 1;	var month = (m < 10) ? '0' + m : m;	var yy = tDate.getYear();	var year = (yy < 1000) ? yy + 1900 : yy;	return day + "/" + month + "/" + year;}function xmlRPCHandler(){}xmlRPCHandler.prototype.XMLreq = Object;	xmlRPCHandler.prototype.loadXMLDoc = function(url, functionObject) {	if (functionObject){		xmlRPCHandler.prototype.doFunction = functionObject;		xmlRPCHandler.prototype.runFunction = true;	} else {		xmlRPCHandler.prototype.doFunction = undefined;		xmlRPCHandler.prototype.runFunction = false;				}			this.XMLreq = Object;	// branch for native XMLHttpRequest object	if(window.XMLHttpRequest) {		try {			this.XMLreq = new XMLHttpRequest();		} catch(e) {			this.XMLreq = false;		}	// branch for IE/Windows ActiveX version	} else if(window.ActiveXObject) {		try {			this.XMLreq = new ActiveXObject("Msxml2.XMLHTTP");		} catch(e) {			try {				this.XMLreq = new ActiveXObject("Microsoft.XMLHTTP");			} catch(e) {				this.XMLreq = false;			}		}	}			var _this = this;	if(this.XMLreq) {		this.XMLreq.onreadystatechange=function(){_this.onData()};		this.XMLreq.open("GET", url, true);		this.XMLreq.send("");	}}	//Handles the actions resulting from the XML HTTP objectxmlRPCHandler.prototype.onData = function(){	if (this.XMLreq.readyState==4){		if (this.XMLreq.status == 200) {									if(this.runFunction){				this.doFunction(this.XMLreq);			} else {				eval(this.XMLreq.responseText)			}		}	}}// Modal Dialog Box// copyright 8th July 2006 by Stephen Chapman// http://javascript.about.com/// permission to use this Javascript on your web page is granted// provided that all of the code in this script (including these// comments) is used without any alterationfunction pageWidth() {	return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}function pageHeight() {	return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}function posLeft() {	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}function posTop() {	return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}function scrollFix(){	var obol=document.getElementById('ol');obol.style.top=posTop()+'px';obol.style.left=posLeft()+'px'}function sizeFix(){	var obol=document.getElementById('ol');obol.style.height=pageHeight()+'px';obol.style.width=pageWidth()+'px';}function kp(e){	ky=e?e.which:event.keyCode;	if(ky==88||ky==120)hm();	return false}function inf(h){	tag=document.getElementsByTagName('select');	//for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;	if (h=='visible') {		for(i=tag.length-1;i>=0;i--)tag[i].disabled=false;	}	else {		for(i=tag.length-1;i>=0;i--)tag[i].disabled=true;	}		tag=document.getElementsByTagName('iframe');	for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;	tag=document.getElementsByTagName('object');	for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;}function sm(obl, wd, ht, focusTo){	var h='hidden';	var b='block';	var p='px';	var obol=document.getElementById('ol'); 	var obbxd = document.getElementById('mbd');	obbxd.innerHTML = document.getElementById(obl).innerHTML;	obol.style.height=pageHeight()+p;	obol.style.width=pageWidth()+p;	obol.style.top=posTop()+p;	obol.style.left=posLeft()+p;	obol.style.display=b;	var tp=posTop()+((pageHeight()-ht)/2)-12;	var lt=posLeft()+((pageWidth()-wd)/2)-12;	var obbx=document.getElementById('mbox');	obbx.style.top=(tp<0?0:tp)+p;	obbx.style.left=(lt<0?0:lt)+p;	obbx.style.width=wd+p;	obbx.style.height=ht+p;inf(h);	obbx.style.display=b;	if (focusTo!=null) {		document.getElementById(focusTo).focus();	}	//return false;}function hm(){	var v='visible';	var n='none';	document.getElementById('ol').style.display=n;	document.getElementById('mbox').style.display=n;	inf(v);		document.onkeypress='';}function initmb(){	var ab='absolute';	var n='none';	var obody=document.getElementsByTagName('body')[0];	var frag=document.createDocumentFragment();	var obol=document.createElement('div');	obol.setAttribute('id','ol');	obol.style.display=n;	obol.style.position=ab;	obol.style.top=0;	obol.style.left=0;	obol.style.zIndex=998;	obol.style.width='100%';	frag.appendChild(obol);	var obbx=document.createElement('div');	obbx.setAttribute('id','mbox');	obbx.style.display=n;	obbx.style.position=ab;	obbx.style.zIndex=999;	var obl=document.createElement('span');	obbx.appendChild(obl);	var obbxd=document.createElement('div');	obbxd.setAttribute('id','mbd');	obl.appendChild(obbxd);	frag.insertBefore(obbx,obol.nextSibling);	obody.insertBefore(frag,obody.firstChild);	window.onscroll = scrollFix; 	window.onresize = sizeFix;}
