var myVehicleQuestionRequest = null;

function setVehicleQuestionQueryString() {
    var queryString = '';
    var frm = document.vehicle_question;
    var numberElements = frm.elements.length;
    for( var i = 0; i < numberElements; i++ ) {
        if( i < numberElements - 1 ) {
            queryString += frm.elements[i].name + '=' +
            encodeURIComponent(frm.elements[i].value) + '&';
        } else {
            queryString += frm.elements[i].name + '=' +
            encodeURIComponent(frm.elements[i].value);
        }
    }
    return queryString;
}

function sendVehicleQuestionData() {
    document.getElementById('vehicle_question_loading').style.display = 'block';
    document.getElementById('vehicle_question_submit').style.display = 'none';
    var queryString = setVehicleQuestionQueryString();
    var url = '/cgi-bin/ajax';
    myVehicleQuestionRequest = initHttpRequest();
    httpRequest(myVehicleQuestionRequest,'POST',url,true,handleVehicleQuestionResponse,queryString);
}

function handleVehicleQuestionResponse() {
    if( myVehicleQuestionRequest.readyState == 4 ) {
        if( myVehicleQuestionRequest.status == 200 ) {
            var doc = myVehicleQuestionRequest.responseXML;

            writeVehicleQuestionDocument(doc);
        } else {
            alert('A problem occurred with the XMLHttpRequest Object');
        }
    }
}

function writeVehicleQuestionDocument(doc) {
    var root = doc.documentElement;
    var retArray = new Array();

    if( root.hasChildNodes() ) {
        var nodes = root.childNodes;
        for( var i = 0; i < nodes.length; i++ ) {
            retArray[i] = new Array();
            if( nodes[i].hasChildNodes() ) {
                var nodes2 = nodes[i].childNodes;
                for( var j = 0; j < nodes2.length; j++ ) {
                    retArray[i][j] = new Array();
                    retArray[i][j][0] = nodes2[j].nodeValue;
                }
            }
        }
    }

    if(retArray[1][0][0] == 'success') {
    	document.getElementById('vehicle_question_error').style.display = 'none';
        document.getElementById('vehicle_question_loading').style.display = 'none';
        document.getElementById('vehicle_question_thanks').style.display = 'block';
    } else {
    	document.getElementById('vehicle_question_error').style.display = 'block';
        document.getElementById('vehicle_question_loading').style.display = 'none';
        document.getElementById('vehicle_question_submit').style.display = 'block';
    }
}
