//****************************
// httpConnection Object:
// http object to send/request data over internet
//****************************
httpConnection = function(url, dataHandler, altUrl) {
    this.url = url;
    this.altUrl = altUrl;
    this.dataHandler = dataHandler;
    this.method = "GET";
    this.async = true;
    this.connected = false;
    this.pageFound = false;

    this.connect();
    if(!this.connected) {
    	if(altUrl)
    		window.location.href = altUrl;
    	else
    		this.dataHandler("browserNotEnabled", this);
    }
}

htp = httpConnection.prototype;

//****************************
// http Object creation
//****************************
htp.connect = function() {
	var cn;

	/*@cc_on
	@if (@_jscript_version >= 5)
		try {
			cn = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				cn = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {}
		}
	@end @*/

	if (!cn && typeof XMLHttpRequest != 'undefined') {
		try {
			cn = new XMLHttpRequest();
		} catch (e) {}
	}

	if(cn) {
		this.connected = true;
		this.cn = cn;
	}
}

//****************************
// Asinchronicous Connection
//****************************
htp.getUrl = function() {
    var cn = this.cn;
    var obj = this;

    cn.onreadystatechange = function() {
        if(cn.readyState == 4) {
            obj.pageFound = (cn.status == "200");

            if(obj.pageFound)
                obj.dataHandler("success", obj);
            else
                obj.dataHandler("error", obj);
        }
    }

    cn.open(this.method, this.url, this.async);
    obj.dataHandler("loading", obj);
    cn.send(null);
}
