﻿/*------------------------------*/


function serializeXml(oNode) {

    var oSerializer = new XMLSerializer();

    return oSerializer.serializeToString(oNode);

}


function Browser()
{
    var ua, s, i;
    this.isIE = false;
    this.isNS = false;
    this.isOP = false;
    this.isSF = false;
    ua = navigator.userAgent.toLowerCase();
    s = "opera";
    if ((i = ua.indexOf(s)) >= 0) {
       this.isOP = true;return;
    }
    s = "msie";
    if ((i = ua.indexOf(s)) >= 0) {
       this.isIE = true;return;
    }
    s = "netscape6/";
    if ((i = ua.indexOf(s)) >= 0) {
       this.isNS = true;return;
    }
    s = "gecko";
    if ((i = ua.indexOf(s)) >= 0) {
       this.isNS = true;return;
    }
    s = "safari";
    if ((i = ua.indexOf(s)) >= 0) {
       this.isSF = true;return;
    }
}

function loadXMLFromFile(path)
{
	var doc;
	if (window.ActiveXObject){
		try { 
			doc = new ActiveXObject("Msxml2.DOMDocument.3.0");
			doc.async=false; 
			doc.load(path); 
			return doc;
		}
		catch(ex) {
			alert("Msxml2.DOMDocument.3.0 throws exception:"+ex);
		};
		
		try { 
			doc = new ActiveXObject("Msxml2.DOMDocument.4.0"); 
			doc.async=false; 

			doc.load(path); 
			return doc;
		}
		catch(ex) {
			alert("Msxml2.DOMDocument.4.0 throws exception:"+ex);
		}
		
		try { 
			doc = new ActiveXObject("MSXML2.DOMDocument"); 
			doc.async=false; 

			doc.load(path);  
			return doc; 
		}
		catch(ex) {
			alert("MSXML2.DOMDocument throws exception:"+ex);
		}
		
		try { 
			doc = new ActiveXObject("Microsoft.DOMDocument"); 
			doc.async=false; 

			doc.load(path);  
			return doc;
		}
		catch(ex) {
			alert("Microsoft.DOMDocument throws exception:"+ex);
		}
	}
	else if (window.XMLHttpRequest){
		try { 
			//var domParser =new DOMParser();	
			var doc = document.implementation.createDocument("","",null);
			
			doc.async=false;
			doc.load(path);
			//doc.onload = function(){return doc;};			
			return doc;
		}
		catch(ex) {
			alert("DOMParser throws exception:"+ex);
		}	
	}
	return null;
}


function loadXML(xml)
{
	var doc;
	if (window.ActiveXObject){
		try { 
			doc = new ActiveXObject("Msxml2.DOMDocument.3.0"); 
			doc.async=false; 

			doc.loadXML(xml); 
			return doc;
		}
		catch(ex) {
			alert("Msxml2.DOMDocument.3.0 throws exception:"+ex);
		};
		
		try { 
			doc = new ActiveXObject("Msxml2.DOMDocument.4.0"); 
			doc.async=false; 

			doc.loadXML(xml); 
			return doc;
		}
		catch(ex) {
			alert("Msxml2.DOMDocument.4.0 throws exception:"+ex);
		}
		
		try { 
			doc = new ActiveXObject("MSXML2.DOMDocument"); 
			doc.async=false; 

			doc.loadXML(xml); 
			return doc; 
		}
		catch(ex) {
			alert("MSXML2.DOMDocument throws exception:"+ex);
		}
		
		try { 
			doc = new ActiveXObject("Microsoft.DOMDocument"); 
			doc.async=false; 

			doc.loadXML(xml); 
			return doc;
		}
		catch(ex) {
			alert("Microsoft.DOMDocument throws exception:"+ex);
		}
	}
	else if (window.XMLHttpRequest){
		try { 
			var domParser =new DOMParser();	
			var doc = domParser.parseFromString(xml,'text/xml');
			doc.async=false; 

			return doc;
		}
		catch(ex) {
			alert("DOMParser throws exception:"+ex);
		}	
	}
	return null;
}

function getLocationData(locationName)
{	
	if(locationName == null || locationName == "" || locationName == "no location")
	{
		return;
	}
	var xmlhttp;
	var _url = "/_layouts/pages/getlocationinfo.aspx?r=" + Math.random() + "&locationName=" + escape(locationName);
	//var _url = "/_layouts/pages/getlocationinfo.aspx?locationName=" + escape(locationName);

	//var _url = "getLocationInfo.xml";
	//alert(_url);
	browser = new Browser();
	
	if (browser.isIE)
	{
	    xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	    xmlhttp.open("GET",_url,true);
	    xmlhttp.onreadystatechange = function(){checkRequestStatus(xmlhttp);};
	}
	else
	{
	    xmlhttp=new XMLHttpRequest();
	    xmlhttp.open("GET",_url,true);
		xmlhttp.onload = function(){checkRequestStatus(xmlhttp);};
	}
	xmlhttp.send(null);
}

function checkRequestStatus(http_request)
{
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
        
        //alert(http_request.responseText);
        
		    renderHTML(http_request.responseText,"/xslt/aboutus_location.xslt");
        } else {
            alert('xml http request exception. status code:' + http_request.status);
        }
    }
}


function transferXML(xmldoc,xsldoc)
{
	if(document.implementation && document.implementation.createDocument)
	{
		try
		{
			var xsltProcessor = new XSLTProcessor();
		   	xsltProcessor.importStylesheet(xsldoc);
		    // transformToDocument
		    var result = xsltProcessor.transformToDocument(xmldoc);
		    
			return serializeXml(result);
		}
		catch(e)
  		{
   			alert("Unable to do xml/xsl processing");
  		} 
 	}
 	else if(typeof window.ActiveXObject != 'undefined')
 	{
		try
		{
			return xmldoc.transformNode(xsldoc);
		}
		catch(e)
		{
			alert("Unable to do xml/xsl processing");
		}	
	}
	else
	{
		alert("Browser unknown!");
	}


}

function renderHTML(xmlString,xslpath)
{
	var xmldoc = loadXML(xmlString);
	
	
	
	

	
	
	if(xmldoc != null && xsldoc != null)
	document.getElementById("detail_info").innerHTML = transferXML(xmldoc,xsldoc);	
	//alert(document.getElementById("detail_info").innerHTML);
}


function loadxslt(path)
{
	var xslt;
	var xmlhttp;
	var _url = path;
		
		browser = new Browser();
		
		if (browser.isIE)
		{
		    xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		    xmlhttp.open("GET",_url,false);
		    //xmlhttp.onreadystatechange = function(){ReturnExpertName(xmlhttp);};
		}
		else
		{
		    xmlhttp=new XMLHttpRequest();
		    xmlhttp.open("GET",_url,false);
			//xmlhttp.onload = function(){ReturnExpertName(xmlhttp);};
		}
		
		xmlhttp.send(null);
		
		var result = xmlhttp.status;		
		if(result==200)
			xslt = xmlhttp.responseText;				
		if(xslt  != null && xslt  != "")
			xmlhttp = null;
			return xslt;
}

/*------------------------------*/
