// gSitePath must be changed when the site goes live.
var gSitePath;
var gFrontSitePath;

if (location.hostname == "www.bookings.showbiz.com.au") {
    gSitePath = location.protocol + "//www.bookings.showbiz.com.au/tickets/";
    gFrontSitePath = location.protocol + "//www.bookings.showbiz.com.au/";
}
else {
    gFrontSitePath = location.protocol + "//" + location.host + "/www/";
    gSitePath = location.protocol + "//" + location.host + "/www/tickets/";
    //alert("gFrontSitePath: " + gFrontSitePath + ", gSitePath: " + gSitePath);
    //alert("hostname: " + location.hostname + "\n" + "hash: " + location.hash + "\n" + "host: " + location.host + "\n" + "href: " + location.href + "\n" + "pathname: " + location.pathname + "\n" + "port: " + location.port + "\n" + "protocol: " + location.protocol + "\n" + "search: " + location.search);
    /*
    hash: Returns the anchor portion of a URL
    host: Returns the hostname and port of a URL
    hostname: Returns the hostname of a URL
    href: Returns the entire URL
    pathname: Returns the path name of a URL
    port: Returns the port number the server uses for a URL
    protocol: Returns the protocol of a URL
    search: Returns the query portion of a URL
    */
}

var net = new Object();
net.READY_STATE_UNINITIALIZED = 0;
net.READY_STATE_LOADING = 1;
net.READY_STATE_LOADED = 2;
net.READY_STATE_INTERACTIVE = 3;
net.READY_STATE_COMPLETE = 4;
net.ContentLoader = function (url, blnGET, onload, parameters, onerror) {
    this.url = url;
    this.req = null;
    this.onload = onload;
    this.onerror = (onerror) ? onerror : this.defaultError;
    this.loadXMLDoc(url, blnGET, parameters);
}

net.ContentLoader.prototype = {
    loadXMLDoc: function(url, blnGET, parameters) {
        if (window.XMLHttpRequest) {
            this.req = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            this.req = new ActiveXObject("Microsoft.XMLHTTP");
        }
        if (this.req) {
            try {
                var loader = this;
                this.req.onreadystatechange = function() {
                    loader.onReadyState.call(loader);
                }
                if (blnGET) {
                    if (location.protocol == "https:") {
                        url = url.replace("http://", "https://")
                    }
                    this.req.open("GET", url, true);
                    this.req.send(null);
                }
                else {
                    this.req.open("POST", url, true);
                    this.req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                    this.req.setRequestHeader("Content-length", parameters.length);
                    this.req.setRequestHeader("Connection", "close");
                    this.req.send(parameters);
                }
            } catch (err) {
                this.onerror.call(this);
            }
        }
    },
    onReadyState: function() {
        var req = this.req;
        var ready = req.readyState;
        if (ready == net.READY_STATE_COMPLETE) {
            var httpStatus = req.status;
            if (httpStatus == 200 || httpStatus == 0) {
                this.onload.call(this);
            } else {
                this.onerror.call(this);
            }
        }
    },
    defaultError: function() {
        alert("error fetching data!\n\nreadyState: " + this.req.readyState + "\nstatus: " + this.req.status + "\nheaders: " + this.req.getAllResponseHeaders());
    }
};


