
function createXML(){
var xmlhttp=false;
if (window.XMLHttpRequest)
    {
      xmlhttp=new XMLHttpRequest();       
    }
    else{
        try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          }
        catch (E){
            xmlhttp = false;
        }
    }   
}
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
    {
    xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

function send_query (data_processor,method,query)//data_processor is your php script, method should usually be POST and the query is string that is form/url-encoded - ie: id=34&width=100&height=400
{
    //alert("URL = : " + data_processor + query);   
   
    xmlhttp=createXML();
    xmlhttp.open(method, data_processor);
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   
       
        xmlhttp.onreadystatechange =function()
        {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
           
            //alert(xmlhttp.responseText);
            process_xml_response(xmlhttp);
           
        }
        }   
    xmlhttp.send(query);
}


//Next we have the handlers that deal with the response from the script.

function process_xml_response(xml){
    var caller = xml.getResponseHeader("ajax_script_name");//I set this in the php script as header("ajax_script_name: <script_name>");
    var output = xml.responseText;//all the output from the script
    var call_back = xml.getResponseHeader("ajax_call_back");//use this to call something after the main ajax request - ie form-submit - can be a function name including arguments.
   
  //alert("caller = " + caller + " data = " + output);
    //alert("Callback = " + call_back);
   
    if(caller == "set_blind_price"){
        set_blind_cost(output);
        eval(call_back);
        return;
        }

}

function breakdown_data(data){
    data = data.split(":&:");
    var em_len = data.length;
    var breakdown = new Array();
    for(var x=0; x < em_len; x++){
        var t_str = data[x];
        //alert("value pair = " + t_str);
        var response_pairs = t_str.split(":=:");
        //alert("key name = " + response_pairs[0] + " key value = " + response_pairs[1]);
        breakdown["" + response_pairs[0] + ""] = response_pairs[1];
        }
    //alert("breakdown width = " + breakdown["width"]);
    return breakdown;
    }
