var http = null; //make global
var tID = null; //make global

//contact functions (from cp_contact_notes_shell.php)

function addPeriod(){
    var search_button = document.getElementById("search_button");
    search_button.value +=" .";
}

function updateCount(){
    var search_button = document.getElementById("search_button");
    search_button.value = "Counting";
    
    //tID = window.setTimeout(addPeriod, 1);
    //tID = window.setTimeout(addPeriod, 10);
    
    var search_form = document.getElementById("search_form");
    var params = "";
    
    for(var i=0;i < search_form.length;i++){
        input = search_form.elements[i];
        if(input.value!="all"){
            switch(input.type){
                case "select-one":  params+=input.name+"="+input.value+"&"; break;
                case "radio": 
                case "checkbox": if(input.checked) params+=input.name+"="+input.value+"&"; break;
                default: break;
            }
            //alert(params);

        }
    }
    
    http = getHTTPObject(); // We create the HTTP Object 
    http.onreadystatechange = handleUpdateCountHttpResponse;
    var url = "num_results.php";
    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);
}
function handleUpdateCountHttpResponse(){
  
    var search_button = document.getElementById("search_button");
    if(http.readyState == 4) {
        //prompt(http.responseText,http.responseText);
        //clearTimeout(tID);
        search_button.value = "Submit Search Now ("+http.responseText+")";  
    }
}
