   //// Создаем ссылку
 var xmlHttp = createXmlHttpRequestObject();
 

function set_tovar()
   {
   

    document.getElementById("id_tovar").innerHTML = '<option value="">--Выберите товар--</option>';
     
     document.getElementById("id_tovar").outerHTML = '<select id="id_tovar" name="id_tovar"><option value="">--Выберите товар--</option></select>';
   
   
   var category=document.getElementById("id_category").value; 
    document.body.style.cursor = "wait"; 
  
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  { 

    xmlHttp.open("GET", "ajax/php/get_tovar.php?category_id="+category, true);     
    xmlHttp.onreadystatechange = handleServerResponse_tov;   
    xmlHttp.send(null);
    
      
    
  }
 
 }
 
 




/////Создаем обьект аякс
  function createXmlHttpRequestObject() 
 {
   var xmlHttp;
   try
  {
    
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
       var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
   
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
    {
      try 
      { 
        
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {} // ignore potential error
    }
  }
  if (!xmlHttp)
    displayError("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
 }
 
 
 ////отрабатываем ответ  
 function handleServerResponse_tov() 
{

  if (xmlHttp.readyState == 4) 
  {
   
    if (xmlHttp.status == 200) 
    {
     
      txtResponse = xmlHttp.responseText;
   
  //alert(txtResponse); 
   
     document.getElementById("id_tovar").innerHTML = txtResponse;
     
     document.getElementById("id_tovar").outerHTML = '<select id="id_category"  name="id_category">'+txtResponse+'</select>';
     
     //document.getElementById("select_city").innerHTML ='<option value="">- empty -</option>';
      document.body.style.cursor = "default"; 
    } 
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
       document.body.style.cursor = "default";
    }
  }
}




function displayError(message)
{
  // display error message, with more technical details if debugMode is true
  displayMessage("Error accessing the server! "+
                 (debugMode ? "<br/>" + message : ""));
}
 
 
