/*
' ================================================================================
' Changes to file 'XMLData.js' for 'iknow_0517', generated 13/05/2004 6:37:03 AM
' ================================================================================
' 003 29/04/2004 Rayp     <No description available>
' 002 28/04/2004 Rayp     <No description available>
' ================================================================================
*/
function isoDate(dd){
	return(dd.replace(/(\d+).(\d+).(\d+)/, "$3-$2-$1"));
}
function escapeSingleQuote(sText){
	if (!sText){return sText;}
	//return sText.replace (/([^"])'([^"])/g, '$1"\'"$2');
	//sText = sText.replace(/\n/g, "<br>");
	return sText.replace(/'/g, "''");
}
function objectToDisplayString(x, d) {
	if (typeof(x) != "object") {return ""}	
	var txt = "<br>"
	for (prop in x) {
		if (prop != "xxfoInternalParent" &&
		    (typeof(x[prop]) == "number" || typeof(x[prop]) == "string" || typeof(x[prop]) == "object" || typeof(x[prop]) == "boolean")) {
			indent = "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp"
		    for (i=0; i<d; i++){txt += indent}
		    if (txt != "(") {txt += "<font style='color:black'>- </font>"}
			txt += "<font style='color:blue'>" + prop + "</font>" + ": " + typeof(x[prop]) + ":"
			if (typeof(x[prop]) == "object"){txt += objectToDisplayString(x[prop], d+1)} 
			else {
				var strProp = "" + x[prop]
				txt += "<font style='color:red'>" + strProp.replace(/\n/g, "<br>" + indent + indent + indent) + "</font><br>"
			}
		}
	}
	txt += ""
	return txt
}
function objectToString(x){
	if (typeof(x) != "object"){return ""}	
	var txt = ""
	for (var prop in x) {
		if(typeof(x[prop]) == "number" || typeof(x[prop]) == "string" || typeof(x[prop]) == "object" || typeof(x[prop]) == "boolean"){		    
			txt += "<x_" + prop + " type='" + typeof(x[prop]) + "'>"
			if (typeof(x[prop]) == "object"){txt += objectToString(x[prop])} 
			else{
				try{txt += escape(x[prop])} 
				catch(err){txt += ""}
			}
			txt += "</x_" + prop + ">"
		}			
	}
	return "<response>" + txt + "</response>"
}
function fireSQL(dataURL,sql,pageSize,page,varAsync,rtnType){

	try {	
		var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
		var oDoc	= new ActiveXObject("Microsoft.XMLDOM")
			oDoc.async = varAsync;
			oDoc.loadXML("<request><sql><![CDATA[" + escape(sql) + "]]></sql><pageSize>"+ pageSize +"</pageSize><page>"+ page +"</page></request>")
			xmlhttp.Open("POST",dataURL,varAsync)
			//alert("dataURL=" + dataURL);
			//xmlhttp.Open("POST",urlPath +"includes/XMLdata.asp?_ref="+ dbref,varAsync)			
			xmlhttp.Send(oDoc)
			//return stringToObject(unescape(xmlhttp.responseXML.xml))
			//xmlhttp.onreadystatechange = xmlDone = false;
			if(rtnType == 1){
				//alert(xmlhttp.readyState);
				//prompt("",xmlhttp.responseText);
				if(xmlhttp.readyState == 4){return stringToObject(unescape(xmlhttp.responseXML.firstChild.firstChild.xml))}
			}
			else{return(xmlhttp)};
	} 
	catch (error) {
		var err3 = new Array();
		err3.result = false;
		err3.name = String(error.name);
		err3.number = String(error.number);
		err3.message = String(error.message);
		err3.description = String(error.description);
		err3.query = sql;
		err3.pageSize = pageSize;
		err3.page = page;
		err3.URLrequest = dataURL;
		return err3	
	}
}
function stringToObject(str) {
	var xmlDoc	= new ActiveXObject("Microsoft.XMLDOM")
		xmlDoc.async = false
		xmlDoc.loadXML(str)
	var topObj = new Array()
	var topNode = xmlDoc.documentElement
	stringToObject2(topNode, topObj)
	return topObj
}
function stringToObject2(node, obj){
	if (node.hasChildNodes()) {
		var childNodes = node.selectNodes("*")
		var numberOfNodes = childNodes.length
		var currentChild = node.firstChild
		for (var i=0; i<numberOfNodes; i++) {
			var type = currentChild.getAttribute('type')
			if (type == 'string'){obj[currentChild.nodeName.substring(2)] = "" + unescape(currentChild.text)}
			if (type == 'number'){obj[currentChild.nodeName.substring(2)] = 1 * unescape(currentChild.text)}
			if (type == 'boolean'){obj[currentChild.nodeName.substring(2)] = (currentChild.text == "true" ? true : false)}
			if (type == 'object'){obj[currentChild.nodeName.substring(2)] = new Array();stringToObject2(currentChild, obj[currentChild.nodeName.substring(2)])}
			currentChild = currentChild.nextSibling
		}
	}
}
