// JavaScript Document

function getSearchObjXML(inParams, inVA){
	var key2;
	var key3;
	var outXML;
	
	outXML		=		'';
	
	for(key2 in inParams){
		if(typeof(inParams[key2]) == "string"){
			outXML	+=	'<' + key2 + '  va="' + inVA + '" >';
		}else{
			outXML	+=	'<' + key2 + ' >';
		}
		
		if(typeof(inParams[key2]) == "string"){
			outXML	+=	inParams[key2];
		}else{
			for(key3 in inParams[key2]){
				outXML	+=	'<' + key3 + ' va="' + inVA + '" >';
				outXML	+=	inParams[key2][key3];
				outXML	+=	'</' + key3 + '>';
			}
		}
		outXML	+=	'</' + key2 + '>';
	};
	
	return outXML;
};

function getSearchXML(inParams,inVA){
	var outXML;
	var key1;
	var key2;
	var key3;
	var isArr;
	var i;
	
	outXML		=		'';
	
	if(!inParams) return outXML;
	
	isArr		=		isArray(inParams);
	
	if(!isArr){
		for(key1 in inParams){
			
			outXML	+=	'<' + key1 + '>';
			outXML	+=	getSearchObjXML(inParams[key1],inVA);
			outXML	+=	'</' + key1 + '>';
			
		}
	}else{
		for(i=0;i<inParams.length;i++){
			
			for(key1 in inParams[i]){
				outXML	+=	'<' + key1 + '>';
				outXML	+=	getSearchObjXML(inParams[i][key1],inVA);
				outXML	+=	'</' + key1 + '>';
			}
			
		}
	}
	
	return outXML;
}

function setNodeValue(inID,inValue){
	var theNode;
	
	theNode		=		document.getElementById(inID);
	if(!theNode) return;
	theNode.innerHTML		=		String(inValue);
	
}

function setInputValue(inID,inValue){
	var theNode;
	
	theNode				=		document.getElementById(inID);
	if(!theNode) return;
	theNode.value		=		String(inValue);
	
}

function getInputValue(inID){
	var theNode;
	
	theNode				=		document.getElementById(inID);
	if(!theNode) return "";
	return theNode.value;
}

function addText(inText,inTarget){

	var theTextNode;
	var theDiv;
	
	theDiv			=		document.createElement('div');
	
	theTextNode		=		document.createTextNode(inText);
	theDiv.appendChild(theTextNode);
	inTarget.appendChild(theDiv);
}

function setText(inText,inTarget){
	var theDiv;
	
	theDiv			=		document.createElement('div');
	theDiv.innerHTML	=		inText;
	inTarget.appendChild(theDiv);
}


function tagValue(inTagName,inXML){
	var thisArr;
		
	thisArr			=		inXML.getElementsByTagName(inTagName);
	if(thisArr.length){
		
		if(thisArr[0].firstChild) return		thisArr[0].firstChild.nodeValue;
	}
	return '';
}

function parseXML(inXML){
	var 	theXMLDoc;
	var 	theParser;
	var 	nodes;
	
	if (document.implementation.createDocument) {
		theParser 	= 	new DOMParser()
		theXMLDoc 	= 	theParser.parseFromString(inXML, "text/xml")
	} else if (window.ActiveXObject) {
		theXMLDoc = new ActiveXObject("Microsoft.XMLDOM")
		theXMLDoc.async="false"
		theXMLDoc.loadXML(inXML)
	}
	
	return theXMLDoc;

};

function xdrParseOutput(inNode,inTargets){
	var		nodes;
	var		nodeCnt;
	var		thisNode;
	var		thisNodeName;
	var		thisWidget;
	var		theParams;
	var		i;
	
	if(!inNode) return;
	
	nodes			=		inNode.childNodes;
			
	if(!nodes) return;
	
	nodeCnt			=		nodes.length;

	if(!nodeCnt) return;
	for(i=0;i<nodeCnt;i++){
		
		thisNode		=		nodes[i];
		
		switch(thisNode.nodeType){
			
			case 1:
				thisNodeName	=		thisNode.nodeName;
				
				switch(thisNodeName){
					
					case "s":
					
					break;
					
					case "record":
						xdrParseRecord(thisNode,inTargets);
					break;
					
					case "js":
						xdrExecuteJS(thisNode);
					break;
					
					default:
						xdrParseOutput(thisNode,inTargets);
					break;
				};
			
			break;
			
			default:
			break;
			
		};
	}
};


function xdrParseRecord(inNode,inTargets){
	var		nodes;
	var		nodeCnt;
	var		thisNode;
	var		thisNodeName;
	var		thisWidget;
	var		theParams;
	var		i;
	var 	thisTarget;
	var 	thisDiv;
	var 	key;
	var 	thisFieldName;
	
	nodes			=		inNode.childNodes;
			
	if(!nodes) return;
	
	nodeCnt			=		nodes.length;
			
	if(!nodeCnt) return;
	for(i=0;i<nodeCnt;i++){
		thisNode		=		nodes[i];
		
		thisNodeName	=		thisNode.nodeName.toLowerCase();
		
		for(key in inTargets){
			thisFieldName	=	inTargets[key];
			if(thisFieldName == thisNodeName){
				
								
				thisDiv			=		document.getElementById(key);
								
				if(!thisDiv) continue;
				if(!thisNode.firstChild){
					if(key.substr(0,3) == "fld"){
						
						thisDiv.value			=		'';
					}else if(key.substr(0,3) == "edi"){
						CKEDITOR.instances[key].setData('');
						
					}else{
						
						thisDiv.innerHTML = '';
					}
				}else{
								
					if(key.substr(0,3) == "fld"){
						
						thisDiv.value			=		thisNode.firstChild.nodeValue;
					}else if(key.substr(0,3) == "edi"){
						CKEDITOR.instances[key].setData(thisNode.firstChild.nodeValue);
						
					}else{
						
						thisDiv.innerHTML		=		thisNode.firstChild.nodeValue;
					}
				}

			}
			setFields();
		}
	}
};

