
//check in firefox

var _Xml = function(){

var xmlObj = null;
var xmlXsl = null;
var xmlClipboard = null;
var container = null;
	
//LoadFile("filename")
var LoadFile = function(){
	if(window.XMLHttpRequest)
		var xhttp = new XMLHttpRequest();
	else
		var xhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xhttp.open("GET", arguments[0], false);
	xhttp.send("");
	return xhttp.responseXML;
}

//Init("xml file")
var Init = function(){
	this.xmlObj = LoadFile(arguments[0]);
	return this;
}

//LoadXsl("xsl file", "container ID")
var LoadXsl = function(){
	this.xmlXsl = LoadFile(arguments[0]);
	this.container = arguments[1];
	return this;
}

//Refresh()
var Refresh = function(){
	if(window.ActiveXObject)
		document.getElementById(this.container).innerHTML = this.xmlObj.transformNode(this.xmlXsl);
	else{
		xsltProcessor = new XSLTProcessor();
		xsltProcessor.importStylesheet(this.xmlXsl);
		resultDocument = xsltProcessor.transformToFragment(this.xmlObj, document);
		document.getElementById(this.container).appendChild(resultDocument);
	}
}

//Move
var Move = function(){
	if(window.ActiveXObject)
		var node = this.xmlObj.selectSingleNode("//*[@id='"+ arguments[0] +"']");
	else
		var node = this.xmlObj.evaluate("//*[@id='"+ arguments[0] +"']", this.xmlObj, null, XPathResult.ANY_TYPE,null);
	switch(arguments[1]){
		case "+":		//Move Up
			node.parentNode.insertBefore(node, node.previousSibling);
			break;
		case "-":		//Move Down
			if(node.nextSibling)
				node.parentNode.insertBefore(node.nextSibling, node);
			break;
		case "first":	//Move first
			node.parentNode.insertBefore(node, node.parentNode.firstChild);
			break;
		case "last":	//Move last
			node.parentNode.insertBefore(node, null);
			break;
	}
	return this;
}

//Remove("node ID")
var Remove = function(){
	if(window.ActiveXObject)
		var node = this.xmlObj.selectSingleNode("//*[@id='"+ arguments[0] +"']");
	else
		var node = this.xmlObj.evaluate("//*[@id='"+ arguments[0] +"']", this.xmlObj, null, XPathResult.ANY_TYPE,null);
	node.parentNode.removeChild(node);
	return this;
}

//Copy("node ID")
var Copy = function(){
	if(window.ActiveXObject)
		this.xmlClipboard = this.xmlObj.selectSingleNode("//*[@id='"+ arguments[0] +"']");
	else
		this.xmlClipboard = this.xmlObj.evaluate("//*[@id='"+ arguments[0] +"']", this.xmlObj, null, XPathResult.ANY_TYPE,null);
	return this;
}

//Paste("parent node ID")
var Paste = function(){
	if(this.xmlClipboard == undefined)
		return false;
	if(window.ActiveXObject)
		var parentNode = this.xmlObj.selectSingleNode("//*[@id='"+ arguments[0] +"']");
	else
		var parentNode = this.xmlObj.evaluate("//*[@id='"+ arguments[0] +"']", this.xmlObj, null, XPathResult.ANY_TYPE,null);
	parentNode.appendChild(this.xmlClipboard.cloneNode(true));
	this.xmlClipboard = null;
	return this;
}

return{
	xmlObj : xmlObj,
	Init : Init,
	LoadXsl : LoadXsl,
	Refresh : Refresh,
	Move : Move,
	Remove : Remove,
	Copy : Copy,
	Paste : Paste
}

}
