// JavaScript Document

function getajax()

{

            var ajaxRequest;

            try

            {

                        ajaxRequest=new XMLHttpRequest();

            }

            catch(e)

            {

                        // Internet Explorer

            try

                        {

                                    ajaxRequest=new ActiveXObject("Msxml2.XMLHTTP");

                        }

                        catch(e)

                        {

                                    try

                                    {

                                                ajaxRequest=new ActiveXObject("Microsoft.XMLHTTP");

                                    }

                                    catch(e)

                                    {

                                                //alert("Your browser does not support AJAX!");

                                                return false;

                                    }

                        }

            }

            return ajaxRequest;

}

 

function callAHAH(url, pageElement, callMessage)

{

            document.getElementById(pageElement).innerHTML = callMessage;

            var req = getajax();

            req.onreadystatechange = function() { responseAHAH(pageElement); };

            req.open("GET", url, true);

            req.send(null);

}

 

function responseAHAH(pageElement)

{

            var output = "";

            if(req.readyState == 4)

            {

                        if(req.status == 200)

                        {

                                    output = req.responseText;

                                    document.getElementById(pageElement).innerHTML = output;

                        }

            }

}

 

function requestGET(url, query, req)

{

            myRand = parseInt(Math.random()*99999999999999999);

            req.open("GET", url+'?'+query+'&rand='+myRand,true);

            req.send(null);

}

 

function requestPOST(url, query, req)

{

            req.open("POST", url, true);

            req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

            req.send(query);

}

 

function doCallback(callback, item)

{

            eval(callback + '(item)');

}

 

function doAjax(url, query, callback, reqtype, getxml)

{

            var myreq = getajax();

            myreq.onreadystatechange=function()

            {

                        if(myreq.readyState == 4)

                        {

                                    if(myreq.status == 200)

                                    {

                                                var item = myreq.responseText;

                                                if(getxml==1)

                                                {

                                                            item = myreq.responseXML;

                                                }

                                                doCallback(callback, item);

                                    }

                        }

            }

            if(reqtype='post')

            {

                        requestPOST(url, query, myreq);

            }

            else

            {

                        requestGET(url, query, myreq);

            }

}

 

 

/*************************************

// AJAX METHODS AND PROPERTIES

 

// properties:

// onreadystatechange: determines which event handler will be called when the object's readyState property changes

// readyState: reports status of the request.  0 = uninitialized, 1 = loading, 2 = loaded, 3 = interactive, 4 = completed

// responseText: data returned by the server in a text string form

// responseXML: data returned by the server expressed as a document object

// status: HTTP status code returned by the server

// statusText: HTTP reason phrase returned by the server

 

// methods:

// abort(): stops the current request

// getAllResponseHeaders(): returns all headers as a string

// getResponseHeader(x): returns the value of header x as a string

// open('method', 'URL', 'a'):  specifies the HTTP method (GET or POST), the target URL, and whether the request should be handled asynchronously (If yes, a='true'--the default; if no, a='false'.)

// send(content): sends the request, optionally with POST data

// setRequestHeader('x','y'): sets a parameter and value pair x=y and assigns it to the header to be sent with the request

 

// Send via POST

// objectname.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

// objectname.send(var1=value1&var2=value2);

 

// responseText: represents the information returned by the server as a text string (read only value)

// responseXML: used when an XML document is returned

// getElementsByTagName(): allows you to build a JavaScript array of all the elements having a particular tagname

 

// JavaScript DOM Methods

// createTextNode(): creates a text node

// appendChild(): appends a text node to an element

// createElement(): 

 

// Node Properties:

// childNodes: array of child nodes

// firstChild: the first child node

// lastChild: the last child node

// nodeName: the name of the node

// nodeType: type of node

// nodeValue: value contained in the node

// nextSibling: next node sharing the same parent

// previousSibling: previous node sharing the same parent

// parentNode: parent of this node

 

// Node Methods:

// appendChild(): add a new child node

// hasChildNodes(): TRUE if this node has children

// removeChild(): deletes a child node

 

// Document Methods:

// createAttribute(): make a new attribute for an element

// createElement(): create a new document element

// createTextNode(): make a text item

// getElementsByTagName(): create an array of tagnames

// getElementById(): find an element by its ID

**************************************/
