﻿function testcho() {
    alert("test");
}
//create a httprequest object
function cHo() {var conn = false; try {conn = new XMLHttpRequest();} catch (trymicrosoft) {try {conn = new ActiveXObject("Msxml2.XMLHTTP");} catch (othermicrosoft) {try {conn = new ActiveXObject("Microsoft.XMLHTTP");} catch (failed) {conn = false;}}}return conn;}
//default path for sync request calls
var cBAxPath = "";
//create a sync request shell object - takes a passed callback method
function reqShell(callBack) {
    this.Path = cBAxPath; this.Page = ""; this.Query = ""; this.Form = null; 
    this.Conn = cHo(); this.Call = callBack; var _this = this;
    this.Send = function() {
		var cachekillerkey = ""; var cachekillervalue = "";
		if(this.Query=="") {
			cachekillerkey = "?iecck=";
		} else {
			cachekillerkey = "&iecck=";
		}
		var ccdt = new Date;
		cachekillervalue =
		ccdt.getDate() + "" + 
		ccdt.getDay() + "" + 
		ccdt.getFullYear() + "" + 
		ccdt.getHours() + "" + 
		ccdt.getMinutes() + "" + 
		ccdt.getSeconds() + "" + 
		ccdt.getMilliseconds()
	    if(this.Conn&&this.Page!="") {
		    var url = this.Path + this.Page + this.Query + cachekillerkey + cachekillervalue;
		    this.Conn.onreadystatechange = function() {
                if(_this.Conn.readyState==4) {
                    if(_this.Conn.status==200) {
                        _this.Call(_this.Conn.responseText);
                        delete _this.Conn;
                    } else {
                        _this.Call('<!--err_status ' + _this.Conn.status + '-->');
                        delete _this.Conn;
                    }
                }
		    }
            if(this.Form==null) {
		        //call using get request
		        this.Conn.open("GET", url, true);
		        this.Conn.send(null);
            } else {
                var params = getFormParameters(this.Form);
                //pass form using post request
                this.Conn.open('POST', url, true);
                this.Conn.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                this.Conn.setRequestHeader("Content-length", params.length);
                this.Conn.setRequestHeader("Connection", "close");
                this.Conn.send(params);
            }
	    }
    }
}
//build a parameter string from form object
function getFormParameters(Form) {
    var params = ""; var loop = 0; var delim = "";
    while(loop<Form.elements.length) {
        formElem = Form.elements[loop];
        if(formElem.type=="text"||formElem.type=="hidden"||formElem.type=="password"||formElem.type=="select-one"||formElem.type=="textarea"||formElem.type=="button"||formElem.type=="submit") {
            if(formElem.name!="") {
                params = params + delim + formElem.name + "=" + escape(formElem.value);
            }
            delim = "&";
        } else if (formElem.type=="checkbox") {
            if(formElem.name!="") {
                if(formElem.checked==true) {
                    params = params + delim + formElem.name + "=on";
                }
            }
        } else if (formElem.type=="radio") {
            if(formElem.name!="") {
                if(formElem.checked==true) {
                    params = params + delim + formElem.name + "=" + escape(formElem.value);
                }
            }
        }
        loop++;
    }
    return params;
}
//array to contain event functions
var loadEvents = new Array();
//method to add event functions to the event function array
function addLoadEvent(Method) {
    loadEvents[loadEvents.length] = Method;        
}
//return the event function from the event array
function getLoadEvent(Index) {
    var ret;
    if(Index<loadEvents.length) {
        ret = loadEvents[Index];
    } else {
        ret = null;
    }
    return ret;
}
//called when the document loads and process all event functions in the load event array
function bodyLoaded() {
    var loop = 0;
    var ev;
    while(loop<loadEvents.length) {
        ev = getLoadEvent(loop);
        if(ev!=null) {
            ev();
        }        
        loop++;
    }
}
//set the onload event for the document
function setBodyOnload() {
	window.onload = bodyLoaded;
}