// NaviXML Class
// Writer: I Sung, 2010-03-24

function NaviXML( )
{
	this.xmlHttp = null;
	this.results = null;
	this.count = 0;
	this.callfunction = function call(){var a=1; }

	this.Init = function(type){
		var	ret;
		if ( typeof XMLHttpRequest != 'undefined' ) {
			ret = new XMLHttpRequest();
		// check the dom to see if this is IE or not
		} else {
			if (typeof window.XMLHttpRequest != 'undefined') {
				// Not IE
				ret = new XMLHttpRequest();
			} else {
					if (window.ActiveXObject) {
						// Hello IE!
						// Instantiate the latest MS ActiveX Objects
						if ( typeof dm_xmlhttprequest_type != 'undefined' ) {
							ret = new ActiveXObject(dm_xmlhttprequest_type);
						} else {
							// loops through the various versions of XMLHTTP to ensure we're using the latest
							var versions = ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
							for (var i = 0; i < versions.length ; i++) {
								try {
									// try to create the object
										// if it doesn't work, we'll try again
										// if it does work, we'll save a reference to the proper one to speed up future instantiations
									ret = new ActiveXObject(versions[i]);
									if (ret) {
										dm_xmlhttprequest_type = versions[i];
										break;
									}
								}
								catch (objException) {
									// trap; try next one
								};
							};
						}
				}
			}
		}
		this.xmlHttp = ret;
		return ret;
	};
	
	this.ReadXMLPage = function(path, tag_name){
		var me = this;

		me.xmlHttp.onreadystatechange = function()
		{
			if(me.xmlHttp.readyState == 4)
			{
		
				switch(me.xmlHttp.status){
		
					case 404:
						alert('Not Found');
						break;
					case 500:
						alert('Internal Server Error'+me.xmlHttp.responseText);
						break;
					default:
						if(me.xmlHttp.responseXML != undefined && me.xmlHttp.responseXML.documentElement != undefined){
							me.results = me.xmlHttp.responseXML.documentElement.getElementsByTagName(tag_name);
							me.count = me.results.length;
						}else{
							me.count = 0;
						}
						me.callfunction();
						break;
				}
			}
		
		};
		me.xmlHttp.open("POST", path, true);
		me.xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		me.xmlHttp.send("");
	};
	
	this.GetElementsByTagName = function(tag){
		if(this.xmlHttp == undefined) return null;
		
		if(this.xmlHttp.responseXML == undefined || this.xmlHttp.responseXML.documentElement == undefined) return null;
		
		return this.xmlHttp.responseXML.documentElement.getElementsByTagName(tag);
	};

	this.GetPageValue = function(row, col_name){
		if(col_name){
			//alert(col_name);
			return this.results[row].getElementsByTagName(col_name)[0].childNodes[0].nodeValue;
		}else{
			//alert("no col");
			return this.results[row].childNodes[0].nodeValue;
		}
	};
	
	this.GetResultValue = function(row, col){
		return this.results[row].getElementsByTagName("col"+col)[0].childNodes[0].nodeValue;
	};

	this.Init();
}

//Definition for DOMParser
if (typeof DOMParser == "undefined") {
   DOMParser = function () {}

   DOMParser.prototype.parseFromString = function (str, contentType) {
      if (typeof ActiveXObject != "undefined") {
         var d = new ActiveXObject("MSXML.DomDocument");
         d.loadXML(str);
         return d;
      } else if (typeof XMLHttpRequest != "undefined") {
         var req = new XMLHttpRequest;
         req.open("GET", "data:" + (contentType || "application/xml") +
                         ";charset=utf-8," + encodeURIComponent(str), false);
         if (req.overrideMimeType) {
            req.overrideMimeType(contentType);
         }
         req.send(null);
         return req.responseXML;
      }
   }
}

