var current_el = null;

var began = false;
var xsltloaded = false;

// global request and XML document objects
// and call back page
var ajaxReq;

var callBackUrl;


// Load the XSLT for menus once
//menuXsl = loadXSLTDoc("menu.xsl");

// retrieve XML document (reusable generic function);
// parameter is URL string (relative or complete) to
// an .xml file whose Content-Type is a valid XML
// type, such as text/xml; XML source must be from
// same domain as HTML file
function loadXMLDoc(url, callBackFunction) {	
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        ajaxReq = new XMLHttpRequest();
        ajaxReq.onreadystatechange = callBackFunction;
        ajaxReq.open("GET", url, true);
        ajaxReq.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        //isIE = true;
        ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
        if (ajaxReq) {
            ajaxReq.onreadystatechange = callBackFunction;
            ajaxReq.open("GET", url, true);
            ajaxReq.send();
        }
    }
}

function loadXSLTDoc(url, xslLoadedCallBack)
{
    var xsldoc;
    
    if (window.XSLTProcessor)
    {
        // support Mozilla/Gecko based browsers
        xsldoc = document.implementation.createDocument("", "", null);
        xsldoc.addEventListener("load", xslLoadedCallBack, false);
        xsldoc.load(url);
    }
    else if(window.ActiveXObject)
    {
        // support Windows / ActiveX
        xsldoc = new ActiveXObject("Microsoft.XMLDOM");
        xsldoc.ondataavailable = xslLoadedCallBack;
        xsldoc.load(url);
    }
    
    return xsldoc;
}

function loadXSLTDoc(url)
{
    var xsldoc;
    if(window.ActiveXObject)
    {
        // support Windows / ActiveX
        xsldoc = new ActiveXObject("Microsoft.XMLDOM");
        //xsldoc.ondataavailable = xslLoadedCallBack;
        xsldoc.async = false;
        xsldoc.load(url);
    }
    
    else if (window.XSLTProcessor)
    {
        // support Mozilla/Gecko based browsers
        xsldoc = document.implementation.createDocument("", "", null);
        //xsldoc.addEventListener("load", xslLoadedCallBack, false);
        xsldoc.load(url);
    }
    
    return xsldoc;
}

// handle onreadystatechange event of req object
/*function processReqChange(){
	// only if req shows "complete"
	if (ajaxReq.readyState == 4) {
		// only if "OK"
		//alert(req.status)		
		if (ajaxReq.status == 200) {		
			//alert(req.responseText.substring(req.responseText.indexOf('<div>')))			
			// ...processing statements go here...
			
			
			response  = ajaxReq.responseXML;
			
			transformXml(response, menuXsl, current_el);
        
            loading.style.display = 'none';
			
			//alert(response);

			//method = req.responseXML.getElementsByTagName('method')[0].firstChild.data;
			//result = response.getElementsByTagName('result')[0].firstChild.data;
			//var start = req.responseText.indexOf('<result>') + 8
			//var stop = req.responseText.indexOf('</result>')
			//result = req.responseText.substring(start,stop);
			
			//result = req.responseXML;

			//eval(method + '(\'\', result)');
		} else {
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}*/

function transformXml(xml, xsl, theDiv)
{
	//alert(xsl);
	// code for Mozilla, Firefox, Opera, etc.
	if (window.XSLTProcessor)
    {
        xsltProcessor=new XSLTProcessor();
        xsltProcessor.importStylesheet(xsl);
        ex = xsltProcessor.transformToFragment(xml,document);
        
       // alert(ex);
        
        //alert(ex.toString());
        theDiv.innerHTML = "";
        theDiv.appendChild(ex);
        
        //alert(theDiv.innerHTML);
    }
    else if (window.ActiveXObject)
    {
        ex=xml.transformNode(xsl);
        
        //alert(ex);
        
        theDiv.innerHTML=ex;
    }
    alert(theDiv.innerHTML);
}

/*function loadItems(id,c){ 
	var img = null;
	if(arguments.length<2){
		c = "C" + id;
		img = document.getElementById("I"+id);
	}
	//alert(c)
	current_el = document.getElementById(c);
	if(current_el.style.display == 'none'){
		current_el.style.display = ''
		if(img)img.src = "images/minus.gif";
	}else{
		current_el.style.display = 'none'
		if(img)img.src = "images/plus.gif";
	}
	if(current_el.innerHTML == ''){
		loading.style.display = ''
		getItems(id,'');		
	}
}

function buildTree(id){
	if (!began){
		loading = document.getElementById("Loading")
		document.getElementById(id).style.display = 'none';
		began = true;
	}
	loadItems(0,id)
}*/


