// =========== XML Functions ==========//Defines xmlFile as a variable var xmlFile;//Defines HTMLresults as a variable var HTMLresults;//Defines source as a variablevar source;//Defines XPath key as a variablevar key;//Defines the Notes fieldname as a variablevar field;//Defines loadDefaultXML() as a functionfunction loadDefaultXML(xmlpath, xmlFile, start, record, flag){	//Creates a new ActiveXObject called source which is the Microsoft.XMLDOM parser that is part of IE 5.5		source = new ActiveXObject("Microsoft.XMLDOM");	//source = new ActiveXObject("MSXML.DOMDocument");	source.async = false;		//Sets the validateOnParse property to false		source.validateOnParse = false;	//Loads the xml into the parser using the openPage URL command	//path = xmlpath + "/" + xmlFile + "?ReadViewEntries&count=-1"		if (flag== "new")	{	path = xmlpath + "/" + xmlFile + "?ReadViewEntries&start=" + start + "&count="+ record	}	else	{	path = xmlpath + "/" + xmlFile + "?ReadViewEntries&count=-1"	}			source.load(path);	//alert(path)	//Error handler. If there is an error, call the showError() function	if(source.parseError.errorCode != 0) 		showError();}function loadDefaultXMLRestrictToCategory(xmlpath, xmlFile, key){	//Creates a new ActiveXObject called source which is the Microsoft.XMLDOM parser that is part of IE 5.5		source = new ActiveXObject("Microsoft.XMLDOM");	//source = new ActiveXObject("MSXML.DOMDocument");	source.async = false;	//Sets the validateOnParse property to false		source.validateOnParse = false;	//Loads the xml into the parser using the openPage URL command	path = xmlpath + "/" + xmlFile + "?ReadViewEntries&RestrictToCategory=" + key + "&count=-1"	source.load(path);		//Error handler. If there is an error, call the showError() function	if(source.parseError.errorCode != 0) 		showError();}//Define loadXSL functionfunction loadXSL(xmlpath, xslFile, designElement ) {	//Creates a new ActiveXObject called source which is the Microsoft.XMLDOM parser that is part of IE 5.5		style = new ActiveXObject("Microsoft.XMLDOM");	style.async = false;	//Loads the xsl into the parser using the openPage URL command	path = xmlpath + "/" + xslFile + "?openPage"    	style.load(path);	//Error handler. If there is an error, call the showError() function	if(source.parseError.errorCode != 0) 		showError();}//Defines doTransform() as a functionfunction doTransform() {		//If the getReadyState() function returns true, then put the results into the HTML.	if (getReadyState())	{		resulting = source.transformNode(style);		document.all.item("HTMLresults").innerHTML = resulting;	}	self.refresh;}//Defines retrieveNodes() as a function//key => XPath syntax//field => Notes field name//unique => to make value uniquefunction retrieveNodes(key, field, unik, append) {		var oldcount;	var intstart;	var intmax;	var intNo;	//If the getReadyState() function returns true, then put the results into the combobox.	if (getReadyState())	{		source.setProperty("SelectionLanguage", "XPath");		//added by cynthia (if not added then the contains() can't recognise    		var node = source.selectNodes(key);		if (unik == "yes") 		{			x = new Array(0);			m = 0			flag = "false"			for(i = 0; i <= node.length -1; i++)			{				var key = trim(node.item(i).text)				//if value is not empty put in an array and flag as true				if (key != "") {						x[m] = key					m += 1					flag = "true"				}						}		//if the array has value/not empty, make the list unique			if (flag == "true")			{				tmp = unique(x).toString()				ArrTemp = tmp.split(",")				rLen = ArrTemp.length	  				eval ("document.forms[0]." + field + ".length = rLen")					for(i = 0; i <= rLen-1; i++)				{					value = new Option(ArrTemp[i],ArrTemp[i])					eval("document.forms[0]." + field + ".options[" + i + "] = value")										}			}			else			{				eval("document.forms[0]." + field + ".options.length = 0")				value = new Option("","")				eval("document.forms[0]." + field + ".options[0] = value")						}		}			else // unik = no		{ 		//-----------				if (append == "yes")		{		oldcount = eval("document.forms[0]." + field + ".options.length")		intstart=parseInt(oldcount);		intmax=parseInt(oldcount) + node.length -1 ;		eval ("document.forms[0]." + field + ".length = parseInt(oldcount) + node.length")		}		else		{		oldcount = 0;		intstart=0;		intmax=node.length -1 ;		eval ("document.forms[0]." + field + ".length = node.length")		}		//alert(eval ("document.forms[0]." + field + ".length"))		//alert(node.length)			for(i = intstart; i <= intmax; i++)			{				intNo = i - parseInt(oldcount)				//var position = Instr(node.item(i).text, "|")				//var key = trim(left(node.item(i).text, position))				//var synonym = trim(right(node.item(i).text, position))				//value = new Option(key, synonym)				value = new Option(node.item(intNo).text, node.item(intNo).text)   	    			eval ("document.forms[0]." + field + ".options[" + i + "] = value")			}		}	}	//If the getReadyState() function doesn't return true, then refresh.	self.refresh;}//Defines retrieveNodes() as a function//key => XPath syntax//field => Notes field namefunction retrieveNodesToField( key, field ){		//If the getReadyState() function returns true, then put the results into the combobox.	if (getReadyState())	{			source.setProperty("SelectionLanguage", "XPath");		//added by cynthia (if not added then the contains() can't recognise		var node = source.selectNodes( key );		var verifynode = ""		if (node.length >0) {			verifynode = node.item(0).text		}						eval ("document.forms[0]." + field + ".value = verifynode")						}	//If the getReadyState() function doesn't return true, then refresh.	self.refresh;}//Defines retrieveNodesMultivalue() as a function//Use when the field contains multi value//key => XPath syntax//field => Notes field namefunction retrieveNodesMultivalue( key, field ){			//If the getReadyState() function returns true, then put the results into the field.	if (getReadyState())	{		source.setProperty("SelectionLanguage", "XPath");		//added by cynthia (if not added then the contains() can't recognise		var node = source.selectNodes( key );		var fldvalue = "";		if (node.length >0) {			for(i = 0; i < node.length -1; i++) {				fldvalue += node.item(i).text + "; ";			}					fldvalue += node.item(i).text;		}		eval ("document.forms[0]." + field + ".value = fldvalue")	}	//If the getReadyState() function doesn't return true, then refresh.	self.refresh;}//Defines the getReadyState function// 0 Object is not initialized// 1 Loading object is loading data // 2 Loaded object has loaded data // 3 Data from object can be worked with // 4 Object completely initialized  function getReadyState() {	if (source.readyState == 4) 		return true;	setTimeout("getReadyState()", 100);}//Defines the showError() function		function showError() {	var strError = new String;	var err = source.parseError;	strError = 'Error!\n' +	'file url: '+err.url +' \n'+	'line no.:'+err.line +'\n'+	'char: '+ err.linepos + '\n' +	'source: '+err.srcText+'\n'+	'code: '+err.errorCode+'\n'+	'description: '+err.reason+'\n';	//document.all.item("HTMLresults").innerHTML = strError;	alert(strError);}// ## To extract unique value from xmlfunction retrieveUniqueElement(key, field, includeAll) {		//If the getReadyState() function returns true, then put the results into the combobox.	if (getReadyState())	{	    	var node = source.selectNodes(key);		x = new Array(0);		m = 0		flag = "false"		for(i = 0; i <= node.length -1; i++)		{			var key = trim(node.item(i).text)			//if value is not empty put in an array and flag as true			if (key != "") 			{					x[m] = key				m += 1				flag = "true"			}					}		//if the array has value/not empty, make the list unique		if (flag == "true")		{			tmp = unique(x).toString()			ArrTemp = tmp.split(",")			rLen = ArrTemp.length							if (includeAll == "true") 			{		     	strSemua = "----Semua----"				rLen += 1						eval ("document.forms[0]." + field + ".length = rLen")								y = new Array(0)				for(i = 0; i <= rLen-1; i++)				{					if (i == 0)						y[i] = strSemua					else						y[i] = ArrTemp[i-1]					value = new Option(y[i],y[i])					eval("document.forms[0]." + field + ".options[" + i + "] = value")										}			} // end if-includeAll				else if (includeAll == "false") 			{				eval ("document.forms[0]." + field + ".length = rLen")						for(i = 0; i <= rLen-1; i++)				{					value = new Option(ArrTemp[i],ArrTemp[i])					eval("document.forms[0]." + field + ".options[" + i + "] = value")							}			}		} // end if flag==true		else if (flag != "true")		{			eval("document.forms[0]." + field + ".options.length = 0")			value = new Option("","")			eval("document.forms[0]." + field + ".options[0] = value")							}				}			//If the getReadyState() function doesn't return true, then refresh.	self.refresh;}// ===========================================================//================ XML Functions ====================function readViewEntries( server, database, viewName, category ){	var serverPath 	var databasePath	var categoryPath	if( server == 'undefined' || server == '' || server == null )		serverPath = document.forms[0].Server_Name.value	else		serverPath = server		if( database == 'undefined' || database == '' || database == null )		databasePath = document.forms[0].DBPath.value	else		databasePath = database	if( category == 'undefined' || category == '' || category == null )		categoryPath = ''	else		categoryPath = '&RestrictToCategory=' + category 	xmlpath = 'http://' + serverPath + '/' + databasePath + '/' + viewName + '?ReadViewEntries' + categoryPath + '&count=-1';	return loadXML(xmlpath)   //returns xmlDoc}function loadXML(xmlFile){  	var xmlObj = new ActiveXObject("Microsoft.XMLDOM");	xmlObj.async="false";	xmlObj.onreadystatechange = verify;	xmlObj.load(xmlFile);	var xmlDoc=xmlObj.documentElement;	return xmlDoc}// 0 Object is not initialized  // 1 Loading object is loading data  // 2 Loaded object has loaded data  // 3 Data from object can be worked with  // 4 Object completely initialized  function verify(){ 	if (XML.readyState != 4)		return false;  }function getFirstRecord( server, database, view, category ){	if( view == 'undefined' || view == '' || view == null )	{		alert( 'missing parameter error: 3rd for getFirstRecord' )		return -1 	}	if( category == 'undefined' || category == '' || category == null )		xmlDoc = readViewEntries( server, database, view, '' )		else		xmlDoc = readViewEntries( server, database, view, category )				xmlRecord = xmlDoc.firstChild	return xmlRecord}function getNextRecord( view, xmlRecord ){	if( view.nodeName != 'viewentries' )		alert( 'parameter type error: 1st for getNextRecord must be <viewentries>' )	var curPtr = xmlRecord.getAttribute('position')	entries = view.childNodes	if( curPtr >= entries.length )		return 'end of view'	else	{		for( var i=0; i<entries.length; i++ )		{			var tmpNode = entries.item(i)			if( tmpNode.getAttribute('position') == curPtr )			{				if( i == entries.length ) return 'end of view'				else return entries.item(i + 1)			}		}	}}function getRecordValue( xmlRecord, column ){	var nl = xmlRecord.childNodes	for(var i=0; i<nl.length; i++ )	{		if( eval( val/1 ) == val ) 	colName = nl.item(i).getAttribute('columnnumber')		else 	colName = nl.item(i).getAttribute('name')		if( colName.toUpperCase() == column.toUpperCase() )			var val = getText(nl.item(i))	}	return val}		function getRecordByKey( node, key, column ){	var datePat = /^(\d{8})$/;	var str = key.toString( )	var matchArray = str.match(datePat)	var curNode 		if( matchArray != null )		var nodeList = node.getElementsByTagName('datetime')	else if( eval( key/1 ) == key )		var nodeList = node.getElementsByTagName('number')	else		var nodeList = node.getElementsByTagName('text')		for( var k=0; k<nodeList.length; k++)	{		curNode = nodeList.item(k)		if( curNode.firstChild == null )		{			//	alert('empty node'); //found <text/>				}		else if( (curNode.firstChild.nodeValue == key) && inColumn(curNode, column) )		{ 			do			{				curNode = curNode.parentNode			} while( curNode.nodeName != 'viewentry' )			return curNode		}		}	return null}function inColumn( curNode, column ){	do	{		curNode = curNode.parentNode; 		var val = curNode.getAttribute( 'name' )		if( val == column ) 		{ 			return true 		}	} while( curNode.nodeName != 'entrydata' )	return false}function getText(node) {	if(node.nodeName == "#text")		return node.nodeValue	else	{		var nl = node.childNodes		var s = ""		for(var i=0; i<nl.length; ++i)			s += getText(nl.item(i))	}	return s}function myNameIs( xmlRecord ){	var value 	if( xmlRecord == null)	{		prompt( 'No value returned' )		 return 0	}			if( xmlRecord.nodeType == null || xmlRecord.nodeType == 'unspecified' || xmlRecord.nodeType == '' )		prompt( 'My Name Is...', 'not a node & value:' + xmlRecord)	else	{		 if(xmlRecord.firstChild == null) 			value = 'NULL'		else 			value = xmlRecord.firstChild.nodeValue		prompt( 'My Name Is...', 'type:' + xmlRecord.nodeType + ' name:' + xmlRecord.nodeName + ' position:' + xmlRecord.getAttribute('position') + ' value:' + value )	}}function retrieveNodesWithEmptyValue(key, field) {	// return unique values and empty value in the first element 	//If the getReadyState() function returns true, then put the results into the combobox.	if (getReadyState())	{		source.setProperty("SelectionLanguage", "XPath");		//added by cynthia (if not added then the contains() can't recognise		    var node = source.selectNodes(key);				x = new Array(0);			m = 0			flag = "false"			for(i = 0; i <= node.length -1; i++)			{				var key = trim(node.item(i).text)				//if value is not empty put in an array and flag as true				if (key != "") {						x[m] = key					m += 1					flag = "true"				}						}		//if the array has value/not empty, make the list unique			if (flag == "true")			{				tmp = unique(x).toString()				ArrTemp = tmp.split(",")				rLen = ArrTemp.length	  				eval ("document.forms[0]." + field + ".length = rLen")				for(i = 0; i <= rLen; i++)				{				if (i == 0)					value = new Option("", "")				else				//value = new Option(node.item(i-1).text, node.item(i-1).text)				value = new Option(ArrTemp[i-1], ArrTemp[i-1])				   	    			eval ("document.forms[0]." + field + ".options[" + i + "] = value")				}			}		}	//If the getReadyState() function doesn't return true, then refresh.	self.refresh;}//Defines retrieveNodesMultivalueand make it Unique() as a function//Use when the field contains multi value//key => XPath syntax//field => Notes field namefunction retrieveNodesMultivalueAndUnique( key, field ){		//If the getReadyState() function returns true, then put the results into the field.	if (getReadyState())	{		source.setProperty("SelectionLanguage", "XPath");		//added by cynthia (if not added then the contains() can't recognise				var node = source.selectNodes( key );		var fldvalue = "";		x = new Array(0);		m = 0			flag = "false"			for(i = 0; i <= node.length -1; i++)			{				var key = trim(node.item(i).text)				//if value is not empty put in an array and flag as true				if (key != "") {						x[m] = key					m += 1					flag = "true"				}						}		//if the array has value/not empty, make the list unique			if (flag == "true")			{				tmp = unique(x).toString()				ArrTemp = tmp.split(";")							eval ("document.forms[0]." + field + ".value = ArrTemp")			}				}	//If the getReadyState() function doesn't return true, then refresh.	self.refresh;}