    
/******************************************************************************
 *AJAX FUNCTIONS
 */
var http;

// Handles all AJAX requests to the server
function doPost(url, params, func) {
    http = createRequestObject();
    if (http) {
        http.onreadystatechange = func;
        http.open('POST', url, true);
        http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        http.setRequestHeader("Content-length", params.length);
        http.setRequestHeader("Connection", "close");
        http.send(params);
    }
}

//Do Post Quick!
/**
 *FUNC
 *----
 *innerHTML         - uses responseText and puts in an element defined in by ID
 *flashGreenInner   - flash green with passed id (second), and fill the innerHTML
 *flashGreen        - flash green w/ no response
 *flashRedInner     - same as Green version
 *flashGreenInner   - same as Green version
 *alert             - display alert w/ responseText (good for debugging)
 *noResponse        - does nothing w/ response
 *
 *id                - where the response will go, or which item will flash
 *flashId           - the object to flash
 */
function doPostQ(url, params, func, id, flashId) {
    http = createRequestObject();
    if (http) {
        http.onreadystatechange = function(){
            if(http.readyState == 4){
                handleAjax(http, func, id, flashId);
                
                //Display Default Cursor because we've processed request
                pointer();
            }else{
                //Display Wait Cursor while waiting for AJAX response
                wait();
            }
        };
        http.open('POST', url, true);
        http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        http.setRequestHeader("Content-length", params.length);
        http.setRequestHeader("Connection", "close");
        http.send(params);
    }
}


/******************************************************
 * THIS STILL NEEDS WORK - FLASH RED STILL WONKY
 *****************************************************/
function handleAjax(http, func, id){
    //we got a response so handle it!
    switch(func){
        case "innerHTML":
            //Only update the innerHTML
            inner(http, id);
            break;
        case "flashGreenInner":
            //Flash Green then update innerHTML
            inner(http, id); 
        case "flashGreen":
            //Duh?
            //alert("FlashGreen");
            if(document.getElementById('flashGreen')){
                flashId = document.getElementById('flashGreen').value;
                fadeIt(flashId, '#FFFFFF', '#77EE77', 1600, 2, true);
                //alert(document.getElementById('currentPage').value);
                setTimeout("loadContent(document.getElementById('currentPage').value, 'step1/index.php')", 3200);
            }
            break;
        case "flashRedInner":
            //Flash Red then update innerHTML after time period
            fadeIt(flashId, '#EE7777', '#FFFFFF', 1600, 2, true);
            //setTimeout("inner('"+http+"','"+id+"')", 2400);
            inner(http.responseText, id);
            break;
        case "flashRed":
            //Duh?
            fadeIt(flashId, '#EE7777', '#FFFFFF', 2400, 2, true);
            break;
        case "alert":
            //alert the response, good for debug
            alert(http.responseText);
            break;
        default:
        case "noResponse":
            //We really don't care
            break;
    }
}

//Replace innerHTML
function inner(http, id){
    //check if the element exists before replacing it's innerHTML
    if(document.getElementById(id)){
        document.getElementById(id).innerHTML = http.responseText;
    }else{
        alert("Couldn't find element");
    }
}

function pointer(){
    document.body.style.cursor = '';
}

function wait(){
   document.body.style.cursor = 'wait';
}

//keeps doPost happy
function noFunction(){
     return;
}


// creates an AJAX HTTP object
function createRequestObject() {
    var xmlHttp=null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    } catch (e) {
        // Internet Explorer
        try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e){
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    
    if (xmlHttp==null){
        alert ("Your browser does not support AJAX. Please use Internet Explorer 6.0+ or Mozilla Firefox 1.5+.");
        return false;
    }
    return xmlHttp;
}
