	/////////////////////////////////////////////////
	var MozFox = false;
	if(document.implementation && document.implementation.createDocument)
	{
		MozFox = true;
		// Extend the Array to behave as a NodeList	
		Array.prototype.item = function(i)
		{
			return this[i];
		};
		// add IE's expr property
		Array.prototype.expr = "";
	    // dummy, used to accept IE's stuff without throwing errors
		XMLDocument.prototype.setProperty  = function(x,y){};
		// Emulate IE's selectNodes
		XMLDocument.prototype.selectNodes = function(sExpr, contextNode)
		{
			var oResult = this.evaluate(sExpr, (contextNode?contextNode:this), 
								this.createNSResolver(this.documentElement),
								XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
			var nodeList = new Array(oResult.snapshotLength);
			nodeList.expr = sExpr;
			for(i=0;i<nodeList.length;i++)
				nodeList[i] = oResult.snapshotItem(i);
			return nodeList;
		};
		Element.prototype.selectNodes = function(sExpr)
		{
			var doc = this.ownerDocument;
			if(doc.selectNodes)
				return doc.selectNodes(sExpr, this);
			else
				throw "SarissaXPathOperationException: Method selectNodes is only supported by XML Nodes";
		};
		XMLDocument.prototype.selectSingleNode = function(sExpr, contextNode){
			var ctx = contextNode?contextNode:null;
			sExpr = "("+sExpr+")[1]";
			var nodeList = this.selectNodes(sExpr, ctx);
			if(nodeList.length > 0)
			    return nodeList.item(0);
			else
			    return null;
		};
		/**
		* <p>Extends the Element to emulate IE's selectNodes.</p>
		* @argument sExpr the XPath expression to use
		* @returns the result of the XPath search as an (Sarissa)NodeList
		* @throws An error if invoked on an HTML Element as this is only be
		*             available to XML Elements.
		*/
		Element.prototype.selectSingleNode = function(sExpr){
			var doc = this.ownerDocument;
			if(doc.selectSingleNode)
			    return doc.selectSingleNode(sExpr, this);
			else
			    throw "Method selectNodes is only supported by XML Elements";
		};
	}
function eventObject(EventLoop, table, ContainerDiv)
{
	/////////////////////////////////////////////////
		this.GetRecordsPerPage = GetRecordsPerPage;
		this.SetRecordsPerPage = SetRecordsPerPage;
		this.showForm = showForm;
		////	Navigation
		this.getDataNext = getDataNext;
		this.getDataPrev = getDataPrev;
		this.JumpToRecord = JumpToRecord;
		this.gotoRecord = gotoRecord;
		////	CRUD
		this.updateLocal = updateLocal;
		this.deleteLocal = deleteLocal;
		this.addLocal = addLocal;
		this.doFind = doFind;
		//////////////////////////////////////////////
		this.GetTable = GetTable;
		this.clearForm = clearForm;
	/////////////////////////////////////////////////
	//		GLOBALS
		var debug = false;
		var showAlerts=true;
		var CurrentQuery="";
		var CRUDClear=true;  // do clear under normal circumstances
	//	Private Variables
		var initWhere="";  // this where is without the "where" word, just the constraints, i.e. "Active=1"
		var globalFormType="edit";
		var numrec = -1;  // the record number currently active
		var items;
		var types; // get the types
		var getAllRecords=true;
		var activeTable="";
		var lastWhere="";
		var navActive = false;
		var recordsPerPage=2;
		var numpages=0;
		var totalRecords=0; // totalRecords=recordsPerPage*(numpages-1) + 1
		var pageIndex=1;
		var orderby="";
		var showform=true;
		var values;  // these are the saved values
		
		this.debug = debug;
		this.showAlerts=showAlerts;
		this.CurrentQuery=CurrentQuery;
		this.CRUDClear = CRUDClear;
		/* Another way to get XML into the page is to use the following
		//		<XML ID="ivcRecord" SRC="order.xml"></XML>
		//	<XML ID="ivcRecord" SRC="http://localhost/_ivcworking/OrmIsland/order.xml"></XML>
		//----------------------------------------------------------------------------
		*/
		var ivcRecord = GetXmlObject();
		var ivcRecordChanged = GetXmlObject();
		var prefix="";  // the prefix used previously.  We want to set this to nothing.
		var odbc,pk,query,connstr,burl,s,useodbc=false;
		if(table != null) activeTable=table;
		else alert("No table specified");
		var databoundstr="";
	//	burl="http://localhost/ShapeXml/CustomersOrders.asmx/queryOrm"; // call the webservice
	//	query="SELECT CustomerID,Address,Country,Phone,Fax,city FROM Customers";
		function GetRecordsPerPage()
		{
			return recordsPerPage;
		}
		function SetRecordsPerPage(num)
		{
			recordsPerPage = num;
		}
		function getDbVal(s)
		{
			var flag=true;
			if(s == null) return s;
			for (var i = 0; i < s.length; i++){   
				var c = s.charAt(i);
				if (((c < "0") || (c > "9"))){ flag=false; break; }
			}
			if(!flag) 
			{
				s = "'"+s+"'";
				return s;
			} else return s;
		}
		function getWhereValues(nowire)  
		{
			if(types == null) return "";
			var name,val,islike=false,isGT,isLT; 
			var str="",equality="";
			for(var k=0; k < types.length; k++) 
			{
				name = types[k].firstChild.nodeValue.split(",");  
				islike=false;
				isLT=false;
				isGT=false;
				if(name[1].indexOf("text") > -1) continue;
				val = document.getElementById(prefix+name[0]).value;
				if(val == "") continue;
				var loc=val.indexOf("*");
				if(loc == -1) loc=val.indexOf("<");
				if(loc == -1) loc=val.indexOf(">");
				if(loc > -1) 
				{
					var tmp="",c;
					for(var j=0; j < val.length; j++)
					{
						c = val.charAt(j);
						if(c == '*')
						{ 
							if(nowire){ tmp += '%'; islike=true; }
							else{ tmp += '%25'; islike=true; }
						}  // since this has to go over the wire, encode % to %25
						else if(c == '<'){ isLT=true; }
						else if(c == '>'){ isGT=true; }
						else tmp += c;
					}
					val=tmp;
				}
				if(str.length > 1) 
				{
					str += " and ";
				}
				if(islike) equality=" like ";
				else if(isGT) equality=" > ";
				else if(isLT) equality=" < ";
				else equality="=";
	//			alert(name[1]);
				if(name[1].indexOf("char") > -1) str += name[0]+equality+"'"+val+"'";
				else if(name[1].indexOf("int") > -1 || name[1].indexOf("number") > -1 || name[1].indexOf("double") > -1 || name[1].indexOf("float") > -1) str += name[0]+equality+val;
				else str += name[0]+equality+getDbVal(val);
			}
			if(initWhere != "") 
			{
				if(str == "") str += initWhere;
				else str += " and "+initWhere;
			}
			if(str == "") return "";
			else return str;
	//		else return " where "+str;
		}
		function GetXmlValues(inxml)
		{
			 if (document.implementation.createDocument){ 
				// Mozilla, create a new DOMParser 
				var parser = new DOMParser(); 
				ivcRecordChanged = parser.parseFromString(s, "text/xml"); 
			 } else if (window.ActiveXObject){ 
				ivcRecordChanged.loadXML(s);
			 } 
			ivcRecord = ivcRecordChanged;
			items = ivcRecord.selectNodes("/ivcOrmRoot/ivcBaseData/ivcOrm");
			types = ivcRecord.selectNodes("/ivcOrmRoot/typesArray/type"); // get the types
			numpages = ivcRecord.selectNodes("/ivcOrmRoot/numPages")[0].firstChild.nodeValue;
			totalRecords = ivcRecord.selectNodes("/ivcOrmRoot/totalRecs")[0].firstChild.nodeValue;
			values=new Array(types.length);  // these are the saved values
		}
		function doFindAgain() // used internally, when there is no where clause
		{
			// spawn Event
			if(EventLoop == null) AppletEvent("before_find_again","");
			else EventLoop("before_find_again","");
			var names= GetQueryString(ContainerDiv).split(",");
			var table=activeTable;
			query = "select "+names+" from "+table;
			if(lastWhere == "") lastWhere = initWhere;
	//		alert(lastWhere); 	
			s = ExecutePostEvt("ivcGetIslandXml.aspx","fields="+names+"&pageIndex="+pageIndex+"&table="+table+"&query="+query+"&conn="+"&where="+lastWhere+"&recordsPerPage="+recordsPerPage+"&sortfield="+orderby);
			GetXmlValues(s);
	//		alert(pageIndex+"  :  "+s);
			// Cross Browser attempt
			var data="<table border='0'>", name="";
	//		var frmType="string"
	//		globalFormType = frmType;
			var sr = document.getElementById("StartRecord");
			if(sr != null && sr.value != "") numrec = parseInt(sr.value)-2;
			else numrec=-1;
			getDataNext();
		}
		function doFind()
		{
			if(EventLoop == null) AppletEvent("before_find","");
			else EventLoop("before_find","");
			var names= GetQueryString(ContainerDiv).split(",");
			var table=activeTable;
			query = "select "+names+" from "+table;
			lastWhere = getWhereValues(false);
				var alertCurQuery=false;
				var cwhere=getWhereValues(true);
				CurrentQuery = query;
				if(cwhere != "") CurrentQuery += " where "+cwhere;
				CurrentQuery += orderby;
				if(alertCurQuery) alert(CurrentQuery); 	
			pageIndex = 1;
			s = ExecutePostEvt("ivcGetIslandXml.aspx","fields="+names+"&pageIndex="+pageIndex+"&table="+table+"&query="+query+"&conn="+"&where="+lastWhere+"&recordsPerPage="+recordsPerPage+"&sortfield="+orderby);
			if(s.length < 100) 
			{
				if(showAlerts) alert("No Records Found");
				document.getElementById("statusinfo").innerText = "";
				navActive = false;
				if(EventLoop == null) AppletEvent("no_recs_found","");
				else EventLoop("no_recs_found","");
				return;
			}
			navActive = true;
	//		alert(s.length);
			GetXmlValues(s);
			var data="<table border='0'>", name="";
	//		var frmType="string"
	//		globalFormType = frmType;
			var sr = document.getElementById("StartRecord");
			if(sr != null && sr.value != "") numrec = parseInt(sr.value)-2;
			else numrec=-1;
			getDataNext();
			if(EventLoop == null) AppletEvent("after_find","");
			else EventLoop("after_find","");
		}
		function doFindFull()
		{
			var names= GetQueryString(ContainerDiv).split(",");
			var table=activeTable;
			query = "select "+names+" from "+table+getWhereValues(false);
	//		alert(query); return;
			s = ExecutePostEvt("ivcGetIslandXml.aspx","query="+query+"&conn=");
			if(s.length < 100) 
			{
				if(showAlerts) alert("No Records Found");
				navActive = false;
				document.getElementById("statusinfo").innerText = "";
				if(EventLoop == null) AppletEvent("no_recs_found","");
				else EventLoop("no_recs_found","");
				return;
			}
			navActive = true;
			GetXmlValues(s);
			var data="<table border='0'>", name="";
	//		var frmType="string"
	//		globalFormType = frmType;
			var sr = document.getElementById("StartRecord");
			if(sr != null && sr.value != "") numrec = parseInt(sr.value)-2;
			else numrec=-1;
			getDataNext();
		}
		function init()
		{
			var names= GetQueryString(ContainerDiv).split(",");
			var table=activeTable;
			if(getAllRecords) query = "select "+names+" from "+table;
			else  query = "select top 1 "+names+" from "+table;
			lastWhere="";
	//		s = queryServerForXml(burl, query, connstr, odbc, pk);  // the web service solution, but only works locally
	//		alert("fields="+names+"&pageIndex="+pageIndex+"&table="+table+"&query="+query+"&conn="+"&where="+"&recordsPerPage="+recordsPerPage); return;
			s = ExecutePostEvt("ivcGetIslandXml.aspx","fields="+names+"&pageIndex="+pageIndex+"&table="+table+"&query="+query+"&conn="+"&where="+initWhere+"&recordsPerPage="+recordsPerPage+"&sortfield="+orderby);
			if(s.length < 100) 
			{
				if(showAlerts) alert("No Records Found");
				navActive = false;
				document.getElementById("statusinfo").innerText = "";
				if(EventLoop == null) AppletEvent("no_recs_found","");
				else EventLoop("no_recs_found","");
				return false;
			}
			else if(s.indexOf("GetSortedPageQuery") > -1) 
			{
				navActive = false;
				document.getElementById("statusinfo").innerHTML = "<font color='#ff0000'>Error</font>";
				if(EventLoop == null) AppletEvent("no_recs_found","");
				else EventLoop("no_recs_found","");
				if(showAlerts) alert(s);
				return false;
			}
			navActive = true;
	//		alert(s);
	//		s = ExecutePostEvt("ivcGetIslandXml.aspx","query="+query+"&conn="+"&mode=single");
	//		ormOut.innerText=s; 
	//		alert(s); 
			//    var s = runRemoteScript("http://localhost/_ivcworking/OrmIsland/GetIslandXml.aspx");
			//    var s = runRemoteScript("http://localhost/_ivcworking/OrmIsland/order.xml");
			//   alert(s);
			 if (document.implementation.createDocument){ 
				// Mozilla, create a new DOMParser 
				var parser = new DOMParser(); 
				ivcRecordChanged = parser.parseFromString(s, "text/xml"); 
			 } else if (window.ActiveXObject){ 
				ivcRecordChanged.loadXML(s);
			 } 
			ivcRecord = ivcRecordChanged;
	//		alert(ivcRecord+"");
	//		ivcRecord.loadXML(s);
			//    ivcRecord.load("http://localhost/_ivcworking/OrmIsland/order.xml");  // not working
			items = ivcRecord.selectNodes("/ivcOrmRoot/ivcBaseData/ivcOrm");
			types = ivcRecord.selectNodes("/ivcOrmRoot/typesArray/type"); // get the types
			values=new Array(types.length);  // these are the saved values
			return true;
		}
	// ====================================================================
	// ====================================================================
		function URLEncode( inStr )
		{
			if(inStr == null) return "";
			// The Javascript escape and unescape functions do not correspond
			// with what browsers actually do...
			var SAFECHARS = "0123456789" +					// Numeric
							"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
							"abcdefghijklmnopqrstuvwxyz" +
							"-_.!~*'()";					// RFC2396 Mark characters
			var HEX = "0123456789ABCDEF";
		
			var plaintext = inStr; 
			var encoded = "";
			for (var i = 0; i < plaintext.length; i++ ) {
				var ch = plaintext.charAt(i);
			    if (ch == " ") {
				    encoded += "+";				// x-www-urlencoded, rather than %20
				} else if (SAFECHARS.indexOf(ch) != -1) {
				    encoded += ch;
				} else {
				    var charCode = ch.charCodeAt(0);
					if (charCode > 255) {
					    alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" +
							"(URL encoding only supports 8-bit characters.)\n" +
								"A space (+) will be substituted." );
						encoded += "+";
					} else {
						encoded += "%";
						encoded += HEX.charAt((charCode >> 4) & 0xF);
						encoded += HEX.charAt(charCode & 0xF);
					}
				}
			} // for
			return encoded;
		};
		
		function URLDecode( inStr )
		{
		   // Replace + with ' '
		   // Replace %xx with equivalent character
		   // Put [ERROR] in output if %xx is invalid.
		   var HEXCHARS = "0123456789ABCDEFabcdef"; 
		   var encoded = inStr;
		   var plaintext = "";
		   var i = 0;
		   while (i < encoded.length) {
		       var ch = encoded.charAt(i);
			   if (ch == "+") {
			       plaintext += " ";
				   i++;
			   } else if (ch == "%") {
					if (i < (encoded.length-2) 
							&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
							&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
						plaintext += unescape( encoded.substr(i,3) );
						i += 3;
					} else {
						alert( 'Bad escape combination near ...' + encoded.substr(i) );
						plaintext += "%[ERROR]";
						i++;
					}
				} else {
				   plaintext += ch;
				   i++;
				}
			} // while
		   return plaintext;
		}
		
		function queryServerForXml(baseUrl, query, connectionString, odbc, pk)  // non-working webservice post attempt
		{
			var qp="doOdbc="+odbc+"&pk="+pk+"&query="+query+"&connstr="+URLEncode(connectionString);
	//		alert(qp);
			return ExecutePostEvt(baseUrl, qp);
		}
		
		function GetXmlObject() 
		{
			if (typeof window.ActiveXObject != 'undefined' ) {
				return new ActiveXObject("MSXML2.DOMDocument.3.0");
			}
			else {
				return new XMLHttpRequest();
			}
		}
		function GetHttpObject() 
		{
			if (typeof window.ActiveXObject != 'undefined' ) {
				return new ActiveXObject("Microsoft.XMLHTTP");
			}
			else {
				return new XMLHttpRequest();
			}
		}
		function AsyncCallBack(ret,fid)
		{
			switch(fid) // execute a function somewhere
			{
				case 0:
					alert(fid+":  "+ret);
				break;
				case 1:
					alert(fid+":  "+ret);
				break;
				case 2:
					alert(fid+":  "+ret);
				break;
				case 3:
					alert(fid+":  "+ret);
				break;
			}
		}
		function ExecuteScriptAsync( rscript, params, fid )
		{
			var httpObj = GetHttpObject();
			httpObj.open("POST", rscript, true, "", "");
			httpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			httpObj.send(params); // if sending variables, omit the "?", i.e. if the get was url?name=max&day=now, then send only "name=max&day=now"
			httpObj.onreadystatechange = function () {
				if (httpObj.readyState == 4) AsyncCallBack(httpObj.responseText,fid); 
			}
		}
		function ExecutePostEvt( url, pars )
		{
			var httpObj = GetHttpObject();
			httpObj.open("POST", url, false, "", "");
			httpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			httpObj.send(pars); // if sending variables, omit the "?", i.e. if the get was url?name=max&day=now, then send only "name=max&day=now"
			return httpObj.responseText;	
		}
		function runRemoteScript( rscript )
		{
			var httpObj = GetHttpObject();
			httpObj.open("GET", rscript, false, "", "");
			httpObj.setRequestHeader("Content-Type","text/xml");
			httpObj.send(null);
			return httpObj.responseText;	
		}
	    
	    // build the form	//////////////////////////////////////////////////////////////////////////////////////////////////////
		function switchMode(mode)
		{
			var data="<table border='0'>", name="";
			globalFormType = mode;
			for(var k=0; k < types.length; k++) 
			{
				name = types[k].firstChild.nodeValue.split(",");
				if(mode == "edit")
					data += "<tr><td>"+name[0]+"</td><td><input type='text' id='"+prefix+name[0]+"' name='"+name[0]+"'></td></tr>";
				if(mode == "string")
					data += "<tr><td>"+name[0]+"</td><td><span id='"+prefix+name[0]+"'></span></td></tr>";
			}
			var tbl = document.getElementById("formContent");
			tbl.innerHTML = data+"</table>";
			if(numrec > -1) numrec--;
			getDataNext();
		}
		function showForm(frmType)
		{
			navActive = false;
			if(!init()) return;
			numpages = ivcRecord.selectNodes("/ivcOrmRoot/numPages")[0].firstChild.nodeValue;
			totalRecords = ivcRecord.selectNodes("/ivcOrmRoot/totalRecs")[0].firstChild.nodeValue;
			var data="<table border='0'>", name="";
			if(frmType == null) frmType="edit"
			globalFormType = frmType;
			var sr = document.getElementById("StartRecord");
			if(sr != null && sr.value != "") numrec = parseInt(sr.value)-2;
			else numrec=-1;
			if(getAllRecords) getDataNext();
			else clearForm();
			// spawn Event
			if(EventLoop == null) AppletEvent("initial_Load","");
			else EventLoop("initial_Load","");
			if(EventLoop == null) AppletEvent("update_table",null);
			else EventLoop("update_table",null);
			showform = false;
		}
		function getFormHtml()
		{
			return document.getElementById("formContent").innerHTML;
		}
		function setFormHtml(htmlTbl)
		{
			document.getElementById("formContent").innerHTML = htmlTbl;
			if(numrec > -1) numrec--;
			getDataNext();
		}
	//    alert(ivcRecord.selectSingleNode("/ivcOrmRoot/typesArray/type[1]").text);
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	        
	    function getNode(doc, xpath) {
	      return doc.selectSingleNode(xpath);
	    }
	    
	    function getNodeText(doc, xpath) {
	      var retval = "";
	      var value = doc.selectSingleNode(xpath);
	      if (value.firstChild) retval = value.firstChild.nodeValue;
	      return retval;
	    }
	    
	    function getXml(element)
	    {
		return element.xml;
	    }
	    
	    function clearForm()
	    {
		if(types == null) return;
		var name;
		for(var k=0; k < types.length; k++) 
		{
			name = types[k].firstChild.nodeValue.split(",");
			var aname = prefix+name[0];
			editor_obj = document.getElementById("_" +aname + "_editor");
			if(editor_obj != null) editor_setHTML(aname, "");
			else document.getElementById(prefix+name[0]).value = "";
		}
		document.getElementById("statusinfo").innerText = "";
	    }
	    // use this method to jump
	    function JumpToRecord(rec)
	    {
		pageIndex= parseInt((rec-1)/recordsPerPage)+1;
	//	numrec = pageIndex*recordsPerPage - rec;
		var newrec=rec-(pageIndex-1)*recordsPerPage-1;
	//	alert(numrec);
		doFindAgain();
		if(newrec > 0) gotoRecord(newrec)
			if(EventLoop == null) AppletEvent("update_table",null);
			else EventLoop("update_table",null);
	    }
	    // internal method
	    function gotoRecord(rec)
	    {
		    numrec = rec-1;
		    getDataNext();
	    }
	  
		function getdata(node)
		{
		    return (node ? (node.text ? node.text : "&nbsp;") : "&nbsp;"); 
		}

	    function getDataNext() {  
	    if(!navActive) return;
	        if (numrec > items.length-2) 
	        {
			if(pageIndex < numpages)
			{
				document.getElementById("statusinfo").innerText = "<font color='#ff0000'>Busy</font>";
				pageIndex++;
				doFindAgain();
				numrec=-1;
				if(EventLoop == null) AppletEvent("update_table",null);
				else EventLoop("update_table",null);
			}
			else return;
		}
	      numrec++;
	      var getrec;
	     if(MozFox) getrec = numrec+1;
	     else getrec = numrec;
			var name;
			var lnode=getNode(ivcRecord, "/ivcOrmRoot/ivcBaseData/ivcOrm[" + getrec + "]");
		var att = lnode.getAttribute("ops");  
	//	alert();
			for(var k=0; k < types.length; k++) 
			{
				name = types[k].firstChild.nodeValue.split(",");  
				values[k] = getNodeText(ivcRecord, "/ivcOrmRoot/ivcBaseData/ivcOrm[" + getrec + "]/"+name[0]);
				if(globalFormType == "edit")
				{ 
					var aname = prefix+name[0];
					editor_obj = document.getElementById("_" +aname + "_editor");
					if(!showform && editor_obj != null) editor_setHTML(aname, values[k]);
					else document.getElementById(prefix+name[0]).value = values[k];
				}
				else if(globalFormType == "string")
					document.getElementById(prefix+name[0]).innerText = values[k];
			}
		var numrecs = document.getElementById("statusinfo");
		
		numrecs.innerHTML = (pageIndex-1)*recordsPerPage+(numrec+1)+" of "+totalRecords;
		if(EventLoop == null) AppletEvent("record_changed",numrecs.innerHTML);
		else EventLoop("record_changed",numrecs.innerHTML);
	    }
	    
	    function getDataPrev() {
		    if(!navActive) return;
	        if (numrec < 1) 
	        {
	//		alert("numrec="+numrec+" rpp="+recordsPerPage+" idx="+pageIndex);
			if(pageIndex > 1)
			{
				document.getElementById("statusinfo").innerText = "<font color='#ff0000'>Busy</font>";
				pageIndex--;
				doFindAgain();
				numrec=recordsPerPage;
				if(EventLoop == null) AppletEvent("update_table",null);
				else EventLoop("update_table",null);
			}
			else return;
		}
	      numrec--;
	//      if (numrec < 0) numrec = items.length - 1;
	      
	      var getrec;
	     if(MozFox) getrec = numrec+1;
	     else getrec = numrec;
			var name;
		var lnode = getNode(ivcRecord, "/ivcOrmRoot/ivcBaseData/ivcOrm[" + getrec + "]");
		var att = lnode.getAttribute("ops");
			for(var k=0; k < types.length; k++) 
			{
				name = types[k].firstChild.nodeValue.split(",");
				values[k] = getNodeText(ivcRecord, "/ivcOrmRoot/ivcBaseData/ivcOrm[" + getrec + "]/"+name[0]);
				if(globalFormType == "edit")
				{
					var aname = prefix+name[0];
					editor_obj = document.getElementById("_" +aname + "_editor");
					if(editor_obj != null) editor_setHTML(aname, values[k]);
					else document.getElementById(prefix+name[0]).value = values[k];
				}
				else if(globalFormType == "string")
					document.getElementById(prefix+name[0]).innerText = values[k];
			}
		var numrecs = document.getElementById("statusinfo");
		
		numrecs.innerHTML = (pageIndex-1)*recordsPerPage+(numrec+1)+" of "+totalRecords;
		if(EventLoop == null) AppletEvent("record_changed",numrecs.innerHTML);
		else EventLoop("record_changed",numrecs.innerHTML);
	    }
	    
		// returns an array of the current values.  Use this method if the user changes the data.
		//  Use the valuse array to get the saved values.  This is usefull to test if the data has changed.
	    function getCurrentValues()  
	    {
		var name; 
		var array=new Array(types.length);
		for(var k=0; k < types.length; k++) 
		{
			name = types[k].firstChild.nodeValue.split(",");  
			array[k] = document.getElementById(prefix+name[0]).value;
		}
		return array;
	    }
	    
	    function showSavedValues()
	    {
		for(var k=0; k < values.length; k++) 
		{
			alert(values[k]);
		}
	    }
	    
	    function showValues()
	    {
		var array = getCurrentValues();
		for(var k=0; k < array.length; k++) 
		{
			alert(array[k]);
		}
	    }
	    
	    function doOp(op)
	    {
		alert("The operation "+op+" is not implemented yet");
	    }
	    
	    function updateLocal()
	    {
		var name,node;
	      var getrec;
	     if(MozFox) getrec = numrec+1;
	     else getrec = numrec;
		for(var k=0; k < types.length; k++) 
		{
			name = types[k].firstChild.nodeValue.split(",");
			node = getNode(ivcRecord, "/ivcOrmRoot/ivcBaseData/ivcOrm[" + getrec + "]/"+name[0]);
			node.text = document.getElementById(prefix+name[0]).value;
		}
		node = getNode(ivcRecord, "/ivcOrmRoot/ivcBaseData/ivcOrm[" + getrec + "]");
		node.setAttribute("ops","update");  // set the operation in the XML
	//	if(debug)alert("Record "+(numrec+1)+" - "+node.getAttribute("ops"));
		if(debug){alert(GetPagePost()+"&ivcUDMode=update"+"&ivcUDTable="+activeTable); return;}
		var ret=ExecutePostEvt("HandleFormForm.aspx",GetPagePost()+"&ivcUDMode=update"+"&ivcUDTable="+activeTable);
		if(ret != "success") alert("Failed to update this record: \n"+ret);
		else if(MozFox)
		{
			if(CRUDClear) clearForm();
			doFindFull();
			JumpToRecord(getrec)
		}
		if(EventLoop == null) AppletEvent("update_table","Updated Record");
		else EventLoop("update_table","Updated Record");
	    }
	    function updateRemote(op)
	    {
		alert("The operation "+op+" is not implemented yet");
	    }
	    
	    function deleteLocal()
	    {
	      var getrec;
	     if(MozFox) getrec = numrec+1;
	     else getrec = numrec;
		node = getNode(ivcRecord, "/ivcOrmRoot/ivcBaseData/ivcOrm[" + getrec + "]");
		node.setAttribute("ops","delete");  // set the operation in the XML so the server will know what to delete
	//	if(debug)alert("Record "+numrec+" - "+node.getAttribute("ops"));
		if(debug){alert(GetPagePost()+"&ivcUDMode=delete"+"&ivcUDTable="+activeTable); return;}
		var ret=ExecutePostEvt("HandleFormForm.aspx",GetPagePost()+"&ivcUDMode=delete"+"&ivcUDTable="+activeTable);	
		if(ret != "success") alert("Failed to delete this record: "+ret);
		removeLocal(); 
		if(CRUDClear) clearForm();
			if(totalRecords > 1) 
			{
				if(getrec == totalRecords) getrec -= 1;
				doFindFull();
				JumpToRecord(getrec);
			}
		if(EventLoop == null) AppletEvent("update_table","Deleted Record");
		else EventLoop("update_table","Deleted Record");
	   } 
	    // this function completely removes the data
	    function removeLocal()
	    {
	      var getrec;
	     if(MozFox) getrec = numrec+1;
	     else getrec = numrec;
		node = getNode(ivcRecord, "/ivcOrmRoot/ivcBaseData/ivcOrm[" + getrec + "]");
		node.parentNode.removeChild(node);
	//	alert("done");
	    }
	    function deleteRemote(op)
	    {
		alert("The operation "+op+" is not implemented yet");
	    }
		
	    function addLocal()
	    {
		    var arec;
		    if(arec == 0) arec=items.length;
		    else arec ++;
		    /*
		var ormroot = ivcRecord.getElementsByTagName("ivcBaseData");
		var ele = ivcRecord.createElement("ivcOrm");
		var att = ivcRecord.createAttribute("ops");
		ele.setAttributeNode(att);  
				
		att = ivcRecord.createAttribute("cnt");
		ele.setAttributeNode(att);  
				
		var name;
		var ele2;
		var tn;
		for(var k=0; k < types.length; k++) 
		{
			name = types[k].text.split(",");
			ele2 = ivcRecord.createElement(name[0]);
			tn = ivcRecord.createTextNode(document.getElementById(prefix+name[0]).value);
			ele2.appendChild(tn);
			ele.appendChild(ele2);
		}
	    	
		ormroot[0].appendChild(ele);
		items = ivcRecord.selectNodes("/ivcOrmRoot/ivcBaseData/ivcOrm");
	//	alert("fini:  "+items.length);
	//	alert(getXml(ormroot[0]));
	//	document.getElementById("ormOut").innerText = getXml(ivcRecord.getElementsByTagName("ivcBaseData")[0]);
		// update the server
		*/
		if(debug){alert(GetPagePost()+"&ivcUDMode=insert"+"&ivcUDTable="+activeTable); return;}
		var ret=ExecutePostEvt("HandleFormForm.aspx",GetPagePost()+"&ivcUDMode=insert"+"&ivcUDTable="+activeTable);
		if(ret != "success") alert("Failed to insert this record: "+ret);
		else{
			if(CRUDClear) clearForm();
			if(MozFox) doFindFull();
			else doFind();
			JumpToRecord(totalRecords)
		}
		if(EventLoop == null) AppletEvent("update_table","Inserted Record");
		else EventLoop("update_table","Inserted Record");
	    }
	    function addRemote(op)
	    {
		alert("The operation "+op+" is not implemented yet");
	    }
	    function getCurrentXml()
	    {
			if(numrec < 0){ alert("No record selected"); return ""; }
		    	return getXml(getNode(ivcRecord, "/ivcOrmRoot/ivcBaseData/ivcOrm[" + numrec + "]"));
	    }
	    function getAllXml()
	    {
		    	return getXml(getNode(ivcRecord, "/ivcOrmRoot"));
	    }
	    function ConvertHeaderTxt(name)
	    {
		    var len=name.length; var tout="",tmp="";
		    for(var j=0; j < len; j++)
		    {
			    ch=name.charAt(j);
			    if(j == 0) ch = ch.toUpperCase( );
			    else
			    {
				    if(ch == '_') 
				    {
					    ch=" "; tout += ch; j++;
					    ch=name.charAt(j);
					    ch = ch.toUpperCase( );
				    }
			    }
			    tout += ch;
		    }
		    return tout;
	    }
	    function GetPopupTable() {  
			var name,zout="<table style=\"color:rgb(255,255,255); width:100%; font-family:Verdana; font-size:8pt; background-color:rgb(192,192,225); border: rgb(92,92,92); \">";
			zout += "<tr><td nowrap>Rec #</td>";
			for(var k=0; k < types.length; k++) 
			{
				name = types[k].firstChild.nodeValue.split(",");
				zout += "<td>"+ConvertHeaderTxt(name[0])+"</td>";
			}
			zout += "</tr>";
		var increment=0;
		if(MozFox) increment = 1;
		for (z=0; z < items.length; z++) 
		{
			var lnode = getNode(ivcRecord, "/ivcOrmRoot/ivcBaseData/ivcOrm[" + (z+increment) + "]");
			zout += "<tr style=\"color:black; background-color: whitesmoke\" onmouseover=\"this.style.backgroundColor='lightyellow';\" onmousedown=\"opener.gotoRecord("+z+")\" onmouseout=\"this.style.backgroundColor='whitesmoke';\">";
			zout += "<td>"+(z+1)+"</td>";
			for(var k=0; k < types.length; k++) 
			{
				name = types[k].firstChild.nodeValue.split(",");
				values[k] = getNodeText(ivcRecord, "/ivcOrmRoot/ivcBaseData/ivcOrm[" + (z+increment) + "]/"+name[0]);
				if(values[k] != null && values[k] != "") zout += "<td>"+values[k]+"</td>";
				else  zout += "<td><br></td>";
			}
			zout += "</tr>";
		}
		zout += "</table>";
		my_window= window.open ("", "mywindow1","scrollbars=yes,status=1,width=350,height=150,resizable=yes"); 
		my_window.document.write( zout );  
	    }
	    function GetTable(tblDiv, header, fields) {  
			var name,zout="<span style='height:450; overflow:auto;overflow-x:hidden;'><table style=\"color:rgb(255,255,255); width:100%; font-family:Verdana; font-size:8pt; background-color:rgb(192,192,225); border: rgb(92,92,92); \">";
			zout += "<tr align='center'><td nowrap>Rec #</td>";
			var i,j,k,z,hidx;
			var usefields=null,usehead=null;
			if(header != null)
			{
				usehead = header.split(",");
			}
			if(fields != null)
			{
				usefields = fields.split(",");
			}
			var docontinue=false;
			for(k=0; k < types.length; k++) 
			{
				name = types[k].firstChild.nodeValue.split(",");
				if(usefields != null) 
				{
					for(i=0; i < usefields.length; i++)
					{
						if(name[0].toLowerCase() == usefields[i].toLowerCase()){hidx = i; docontinue=true; break;}
					}
					if(docontinue) docontinue=false;
					else continue;
				}
				if(usehead != null) zout += "<td nowrap>"+ConvertHeaderTxt(usehead[hidx])+"</td>";
				else zout += "<td nowrap>"+ConvertHeaderTxt(name[0])+"</td>";
			}
			zout += "</tr>";
		var increment=0;
		if(MozFox) increment = 1;
		docontinue=false;
		for (z=0; z < items.length; z++) 
		{
			var lnode = getNode(ivcRecord, "/ivcOrmRoot/ivcBaseData/ivcOrm[" + (z+increment) + "]");
			zout += "<tr style=\"color:black; background-color: whitesmoke\" onmouseover=\"this.style.backgroundColor='lightyellow';\" onmousedown=\"evtObj.gotoRecord("+z+")\" onmouseout=\"this.style.backgroundColor='whitesmoke';\">";
			zout += "<td nowrap>" + (z+1) + "</td>";
			if(lnode == null){ document.getElementById(tblDiv).innerHTML = "Error generating table"; return; }
			for(k=0; k < types.length; k++) 
			{
				name = types[k].firstChild.nodeValue.split(",");
				if(usefields != null) 
				{
					for(i=0; i < usefields.length; i++)
					{
						if(name[0].toLowerCase() == usefields[i].toLowerCase()){docontinue=true; break;}
					}
					if(docontinue) docontinue=false;
					else continue;
				}
				values[k] = getNodeText(ivcRecord, "/ivcOrmRoot/ivcBaseData/ivcOrm[" + (z+increment) + "]/"+name[0]);
				if(values[k] != null && values[k] != "") zout += "<td>"+values[k]+"</td>";
				else  zout += "<td><br></td>";
			}
			zout += "</tr>";
		}
		zout += "</table></span>";
		document.getElementById(tblDiv).innerHTML = zout;
	    }
	    
		function GetQueryString(ContainerName)
		{ 
			var root;
			if(ContainerName != null) root = document.getElementById(ContainerName);
			else root = document;
			var dbn;
			var QueryString="";
			// look for dropdowns(selects)
			var eles = root.getElementsByTagName("select") ;
			if(eles != null)
			{
				for(var i=0; i < eles.length; i++) 
				{
					if(eles[i].selectedIndex == -1) continue;
					dbn = eles[i].getAttribute("db");
					if(dbn == null || dbn == "false") continue;
					name = eles[i].getAttribute("name");
					if(QueryString == "") QueryString = name;
					else QueryString += ","+name;
				}
			}
			// look for inputs(text,checkboxes & radiobuttons)
			eles = root.getElementsByTagName("input") ;
			if(eles != null)
			{
				for(var i=0; i < eles.length; i++) 
				{
					if(eles[i] == null) continue;
					dbn = eles[i].getAttribute("db");
					if(dbn == null || dbn == "false") continue;
					name = eles[i].getAttribute("name");
					if(eles[i].getAttribute("type") == "text")// || eles[i].getAttribute("type") == "hidden")  // omit hiddens
					{ 
						if(QueryString == "") QueryString = name;
						else QueryString += ","+name;
					}
					else if(eles[i].getAttribute("type") == "radio") // atleast one of the radio's need to be selected
					{
						if(eles[i].checked) 
						{
							if(QueryString == "") QueryString = name;
							else QueryString += ","+name;
						}
					}
					else if(eles[i].getAttribute("type") == "checkbox") 
					{
						if(QueryString == "") QueryString = name;
						else QueryString += ","+name;
					}
				}
			}
			// look for textareas
			eles = root.getElementsByTagName("textarea") ;
			if(eles != null)
			{
				for(var i=0; i < eles.length; i++) 
				{
					dbn = eles[i].getAttribute("db");
					if(dbn == null || dbn == "false") continue;
					name = eles[i].getAttribute("name");
					if(QueryString == "") QueryString = name;
					else QueryString += ","+name;
				}
			}	 
			return QueryString;
		} 
	function GetPagePost(ContainerName)
	{ 
		var root;
		if(ContainerName != null) root = document.getElementById(ContainerName);
		else root = document;
		var dbn;
	 var PostString="",val="";
	 // look for dropdowns(selects)
	 var eles = root.getElementsByTagName("select") ;
	 if(eles != null)
	 {
	  for(var i=0; i < eles.length; i++) 
	  {
	if(eles[i].selectedIndex == -1) continue;
	dbn = eles[i].getAttribute("db");
	if(dbn == null || dbn == "false") continue;
	   name = eles[i].getAttribute("name");
	   val = eles[i].options[eles[i].selectedIndex].value;
	   if(val == null) val = eles[i].options[eles[i].selectedIndex].text;
	   val = URLEncode(val);
	   if(PostString == "") PostString = name+"="+val;
	   else PostString += "&"+name+"="+val;
	  }
	 }
	 // look for inputs(text,checkboxes & radiobuttons)
	 eles = root.getElementsByTagName("input") ;
	 if(eles != null)
	 {
	  for(var i=0; i < eles.length; i++) 
	  {
	   if(eles[i] == null) continue;
	dbn = eles[i].getAttribute("db");
	if(dbn == null || dbn == "false") continue;
	   name = eles[i].getAttribute("name");
	   if(eles[i].getAttribute("type") == "text")// || eles[i].getAttribute("type") == "hidden")  // omit hiddens
	   { 
	    val = eles[i].value;
	   val = URLEncode(val);
	    if(PostString == "") PostString = name+"="+val;
	    else PostString += "&"+name+"="+val;
	   }
	   else if(eles[i].getAttribute("type") == "radio") // atleast one of the radio's need to be selected
	   {
	    if(eles[i].checked) 
	    {
		    val=eles[i].getAttribute("value");
		    if(PostString == "") PostString = name+"="+val;
		    else PostString += "&"+name+"="+val;
	    }
	    else val=0;
	   }
	   else if(eles[i].getAttribute("type") == "checkbox") 
	   {
	    if(eles[i].checked) val=eles[i].value;
	    else val=0;
	    if(PostString == "") PostString = name+"="+val;
	    else PostString += "&"+name+"="+val;
	   }
	  }
	 }
	 // look for textareas
	 eles = root.getElementsByTagName("textarea") ;
	 if(eles != null)
	 {
	  for(var i=0; i < eles.length; i++) 
	  {
	   dbn = eles[i].getAttribute("db");
	   if(dbn == null || dbn == "false") continue;
	   name = eles[i].getAttribute("name");
	   val = eles[i].value;
	   val = URLEncode(val);
	   if(PostString == "") PostString = name+"="+val;
	   else PostString += "&"+name+"="+val;
	  }
	 }
	 
		return PostString;
	}
	return true;
}