var xmlhttp
var xmlhttpResult

var browserName=navigator.appName;
var browserVer=parseInt(navigator.appVersion);

IE = false;

if ( browserName != "Netscape" ) {
	IE = true;
}

function getViaHTTP( parameters ) {

	if ( browserName == "Microsoft Internet Explorer") {

		if ( typeof document.body.style.maxHeight != "undefined") {
			var xmlhttp=null
			if (window.XMLHttpRequest) {
				xmlhttp=new XMLHttpRequest()
			} else if (window.ActiveXObject) {
				var progIDs = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "microsoft.xmlhttp" ];
				for( var currentProgID = 0 ; currentProgID < progIDs.length ; currentProgID++) {
					try{ xmlhttp = new ActiveXobject(progIDs[currentProgID]); } catch(ex){}
				} 
			}

			// Ajax Internet Explorer 7
			if (xmlhttp!=null) {
				if ( !window.XMLHttpRequest) {
					xmlhttp.onreadystatechange = state_Change;
				}
				xmlhttp.open("GET", "api.asp?" + parameters, false);
				if ( window.XMLHttpRequest) {
					xmlhttp.onreadystatechange = function() {

						if (xmlhttp.readyState==4) {
							if (xmlhttp.status==200) {
								xmlhttpResult = xmlhttp.responseText;
							} else {
								alert("Problem retrieving XML data")
							}
						}
					}
				}
				xmlhttp.send(null)
				return ( xmlhttpResult );
			} else {
				alert("Your browser does not support XMLHTTP.")
			}
		} else {
			var xmlhttp=null
			if (window.XMLHttpRequest) {
				xmlhttp=new XMLHttpRequest()
			} else if (window.ActiveXObject) {
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
				var progIDs = ["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","microsoft.xmlhttp"];
				for( var currentProgID = 0 ; currentProgID < progIDs.length ; currentProgID++) {
					try{ xmlhttp = new ActiveXobject(progIDs[currentProgID]); } catch(ex){}
				} 
			}
			if (xmlhttp!=null) {
				if ( !window.XMLHttpRequest) {
					xmlhttp.onreadystatechange = function () {
						if (xmlhttp.readyState==4) {
							if (xmlhttp.status==200) {
								xmlhttpResult = xmlhttp.responseText;
							} else {
								alert("Problem retrieving XML data")
							}
						}
					}
				}
				xmlhttp.open("GET", "api.asp?" + parameters, false);
				xmlhttp.send(null)
				if ( window.XMLHttpRequest) {
					xmlhttp.onreadystatechange = function () {
						if (xmlhttp.readyState==4) {
							if (xmlhttp.status==200) {
								xmlhttpResult = xmlhttp.responseText;
							} else {
								alert("Problem retrieving XML data")
							}
						}
					}
				}
				return ( xmlhttpResult );
			} else {
				alert("Your browser does not support XMLHTTP.")
			}
		}
	} else {
//		if ( browserName == "Netscape" ) {

			xmlhttp = new XMLHttpRequest();     // Firefox, Safari, ...
			xmlhttp.open("GET", "api.asp?" + parameters, false);

//			xmlhttp.onreadystatechange = function () {
//			alert(xmlhttp.readyState);
//				if (xmlhttp.readyState==4) {
//					if (xmlhttp.status==200) {
//						 xmlhttpResult = "101";//xmlhttp.responseText + "";
//						return xmlhttpResult;
//					} else {
//						alert("Problem retrieving XML data")
//						return xmlhttpResult;
//					}
//				}
//			}
			xmlhttp.send(null);

			return xmlhttp.responseText;

//		}
	}
}

UTF8 = {
	encode: function(s){
		for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
			s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
		);
		return s.join("");
	},
	decode: function(s){
		for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
			((a = s[i][c](0)) & 0x80) &&
			(s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
			o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
		);
		return s.join("");
	}
};
