   // Get the HTTP Object

function getHTTPObject()
{
   if (window.ActiveXObject) 
      return new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
      return new XMLHttpRequest();
   else 
   {
      alert("Your browser does not support AJAX.");
      return null;
   }
}


function ajaxAddMarker(lat,lng,title,sev,add,com,callback)
{
   var httpObject = getHTTPObject();

   if (httpObject != null) 
   {
      httpObject.open("POST", "add.php", true);
      httpObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
      httpObject.send("lat="+lat+"&lng="+lng+"&tit="+title+"&sev="+sev+"&add="+add+"&com="+com);
      httpObject.onreadystatechange = function(){
	if(httpObject.readyState == 4){
		saveMarkerCallback(httpObject.responseText);

   	}};
   }
}

function ajaxAddComment(comment, pid, callback)
{
   var httpObject = getHTTPObject();

   if (httpObject != null) 
   {
      httpObject.open("POST", "addc.php", true);
      httpObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
      httpObject.send("c="+comment+"&p="+pid);
      httpObject.onreadystatechange = function(){
	if(httpObject.readyState == 4){
		callback(httpObject.responseText);
   	}};
   }
}

function ajaxUpdateMarker(id,lat,lng,title,sev,add,com,callback)
{
 var httpObject = getHTTPObject();

   if (httpObject != null)
   {
      httpObject.open("POST", "update.php", true);
      httpObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
      httpObject.send("id="+id+"&lat="+lat+"&lng="+lng+"&tit="+title+"&sev="+sev+"&add="+add+"&com="+com);
       httpObject.onreadystatechange = function(){
	if(httpObject.readyState == 4){
		updateMarkerCallback(httpObject.responseText);

   	}};
   }
}

function ajaxCreateUpdatePothole(id,lat,lng,title,sev,add,com,callback)
{
 var httpObject = getHTTPObject();

   if (httpObject != null)
   {
      httpObject.open("POST", id==0?"add.php":"update.php", true);
      httpObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
      httpObject.send("id="+id+"&lat="+lat+"&lng="+lng+"&tit="+title+"&sev="+sev+"&add="+add+"&com="+com);
       httpObject.onreadystatechange = function(){
	if(httpObject.readyState == 4){
		callback(httpObject.responseText);

   	}};
   }
}

//update reverse geocode properties ( address, pcode )
function ajaxUpdateRGC(id,add,pcode)
{
 var httpObject = getHTTPObject();

   if (httpObject != null)
   {
      httpObject.open("POST", "updateRGC.php", true);
      httpObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
      httpObject.send("id="+id+"&add="+add+"&pcode="+pcode);
   }
}


function ajaxUpdateRating(id,sev)
{
   //alert('id='+id+'sev='+sev);
 var httpObject = getHTTPObject();

   if (httpObject != null)
   {
      httpObject.open("POST", "updateRating.php", true);
      httpObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
      httpObject.send("id="+id+"&sev="+sev);
      httpObject.onreadystatechange = function(){
         if(httpObject.readyState == 4){
                updateRatingCallback(httpObject.responseText);
      }};

   }
}


function ajaxDeleteMarker(id)
{
   var httpObject = getHTTPObject();

   if (httpObject != null)
   {
      httpObject.open("POST", "delete.php", true);
      httpObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
      httpObject.send("id="+id);
      httpObject.onreadystatechange =  function(){
        if(httpObject.readyState == 4){
                deleteMarkerCallback(httpObject.responseText);
        }};

   }
}

function ajaxFixMarker(id)
{
   var httpObject = getHTTPObject();

   if (httpObject != null)
   {
      httpObject.open("POST", "fix.php", true);
      httpObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
      httpObject.send("id="+id);
      httpObject.onreadystatechange =  function(){
        if(httpObject.readyState == 4){
                fixMarkerCallback(httpObject.responseText);
        }};

   }
}


function ajaxClearDB()
{
 var httpObject = getHTTPObject();

   if (httpObject != null)
   {
      httpObject.open("GET", "clearDB.php", true);
      httpObject.send(null);
   }

}

function ajaxImageExists(id)
{
   var httpObject = getHTTPObject();

   if (httpObject != null)
   {
      httpObject.open("GET", "hasImage.php?id="+id, true);
      httpObject.send(null);
      httpObject.onreadystatechange =  function(){
        if(httpObject.readyState == 4){
                imageExistsCallback(httpObject.responseText);
        }};

   }
}

/*
function ajaxAddComment(name,comm)
{
   var httpObject = getHTTPObject();

   if (httpObject != null)
   { 
      var params = "name="+name+"&com="+comm;
      httpObject.open("POST", "addc.php", true);
      httpObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
      httpObject.send(params);
      httpObject.onreadystatechange =  function(){
        if(httpObject.readyState == 4){
                addCommentCallback(httpObject.responseText);
        }};

   }
}*/

function ajaxModerateImage(f,com)
{
   var httpObject = getHTTPObject();

   if (httpObject != null)
   {
      httpObject.open("POST", "moveImage.php", true);
      httpObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
      httpObject.send("f="+f+"&com="+com);
   }
}



function setOutput()
{
   if(httpObject.readyState == 4)
   {
      //document.getElementById('outputText').value = httpObject.responseText;
   }
}


