var request = false;
     try {
        request = new XMLHttpRequest();
     } catch (trymicrosoft) {
        try {
          request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (othermicrosoft) {
          try {
            request = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (failed) {
            request = false;
          } 
        }
     }
if (!request)
     alert("Error initializing XMLHttpRequest!");
function ajax_update_counter(counter, $ripple_id, $action_id){ 
    var url="/inc/counter.php?counter="+counter+"&ripple_id="+$ripple_id+"&action_id="+$action_id;
	request.open("GET", url, true);
	request.onreadystatechange = function(){updateCounter(counter);};
    request.send(null);
    return;
}
function updateCounter(counter){
   if (request.readyState == 4){
     var counter_clicked = document.getElementById(counter+'_counter');
	 counter_clicked.innerHTML = request.responseText;
	 var total_counter = document.getElementById('total_counter');
	 var total_connection_counter = document.getElementById('connect_counter');
	 var total_action_counter = document.getElementById('action_counter');
	 var old_total = total_counter.getAttribute('value');
	 var old_connection_total = total_connection_counter.getAttribute('value');
	 var old_action_counter_total = total_action_counter.getAttribute('value');
	 var new_total = (+old_total) + (+1);
	 total_counter.setAttribute('value', new_total);
	 total_counter.innerHTML = new_total;
	 document.getElementById('total_counter_buttom').innerHTML = new_total;
	 if(counter == 'counter1' || counter == 'counter2' || counter == 'counter3' || counter == 'counter4' || counter == 'counter5'){
	     var new_connection_total = (+old_connection_total) + (+1);
	     total_connection_counter.setAttribute('value', new_connection_total);
	     total_connection_counter.innerHTML = new_connection_total;
	 }
	 if(counter == 'action_segment1' || counter == 'action_segment2' || counter == 'action_segment3'){
	     var new_action_total = (+old_action_counter_total) + (+1);
		 total_action_counter.setAttribute('value', new_action_total);
		 total_action_counter.innerHTML = new_action_total;
	 }
   }
}

