
function XMLOP(elementID,xmlFile,xslFile) {
  	this.xmlDoc	 	 = null;
    this.xslDoc	 	 = null;
    this.xmlFile	 = xmlFile;
    this.xslFile	 = xslFile;
    this.elementID 	 = elementID;
    this.elementPtr	 = document.getElementById(elementID);
    this.editMode   = false;

}



XMLOP.prototype.setEditMode = function(mode){
  this.editMode=mode;
}

XMLOP.prototype.loadXML = function (filename) {
	var xmlDoc;
	//  IE
    if (window.ActiveXObject) {
    	xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
	}
	// Mozilla, Firefox, Opera
    else if (document.implementation &&
    	document.implementation.createDocument) {
        xmlDoc = document.implementation.createDocument("","",null);
	} else {
    	alert('Your browser cannot handle this script');
 	}
    xmlDoc.async = false;
    xmlDoc.load(filename);
	return xmlDoc;
}

XMLOP.prototype.loadXSL = function (filename) {
	var xmlDoc;
	//  IE
    if (window.ActiveXObject) {
    	xmlDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
	}
	// Mozilla, Firefox, Opera
    else if (document.implementation &&
    	document.implementation.createDocument) {
        xmlDoc = document.implementation.createDocument("","",null);
	} else {
    	alert('Your browser cannot handle this script');
 	}
    xmlDoc.async = false;
    xmlDoc.load(filename);
	return xmlDoc;
}

XMLOP.prototype.displayResult = function (params) {
	this.xmlDoc = this.loadXML(this.xmlFile);
    this.xslDoc = this.loadXSL(this.xslFile);


	 this.transformXSLT(params);
}

XMLOP.prototype.transformXSLT = function(params){
	//  IE
	if (window.ActiveXObject) {
    	//var htmlCode = this.xmlDoc.transformNode(this.xslDoc);
		xslTemp = new ActiveXObject("Msxml2.XSLTemplate");
     	xslTemp.stylesheet = this.xslDoc;
	    xslProc = xslTemp.createProcessor();
     	xslProc.input = this.xmlDoc;
		if (params) {
			for(i=0;i<params[0].length;i++){
				xslProc.addParameter(params[0][i], params[1][i]);
			}
		}
	  	xslProc.transform;
     	this.elementPtr.innerHTML = "";
        this.elementPtr.innerHTML = xslProc.output;//(new String(xslProc.output)).replace(/<strong>/gi, '<B>').replace(/<\/strong>/gi, '</B>');
	}//Mozilla, Firefox, Opera
    else if (document.implementation &&
    	document.implementation.createDocument) {
        xsltProcessor = new XSLTProcessor();
        xsltProcessor.importStylesheet(this.xslDoc);
        var resultDocument = xsltProcessor.transformToFragment(this.xmlDoc,document);
        while ( this.elementPtr.childNodes.length >= 1 )
    	{
       		this.elementPtr.removeChild(this.elementPtr.firstChild);
    	}
        this.elementPtr.appendChild(resultDocument);
	}
}

XMLOP.prototype.sendAJAXData = function(fileName, paramname, paramvalue, data){
	if (!data||data=='') return false;
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/


	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		}
		catch (e) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		}
		catch (e) {
			xmlhttp = false;
		}
	}
	if (xmlhttp) {
	//XMLactionStore.push("data/saveXML.asp?pname=" + paramname + "&pvalue=" + paramvalue);
	//XMLactionStore.push("data/saveXML.asp?pname=" + paramname + "&pvalue=" + paramvalue);
	//alert(window.XMLactionStore.length);
	//alert(XMLOP.storedActions);
	//XMLOP.storedActions='dddd';
	//alert(XMLOP.storedActions);

		xmlhttp.open("POST", "data/saveXML.asp?pname=" + paramname + "&pvalue=" + paramvalue, true);
		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4) {
				//ok
				// alert(xmlhttp.responseText);
				if (xmlhttp.responseText == '[OK]') {
					var OBrowser = new BrowserOP();
					OBrowser.removeDIV('edit');
					document.location = window.location.href;
				}

			}
		}
		if (data) {
			xmlhttp.send('data=' + data);
		}
		else
			xmlhttp.send(null);
	}
}

