function replace(id, url) {
  //document.getElementById(id).innerHTML     = 'Espere...';
  //document.getElementById(id).style.display = 'block';
  loadXMLDoc(url + '&ajax=1&id_replace=' + id, replaceId);
}

function php_session_register(id, variable, valor)
{
  loadXMLDoc('../Default/SessionRegister?id='+id+'&var='+variable+'&val='+valor+'&ajax=1', bogus);
}

function replaceId()
{
  if (req.readyState == 4) {
    if (req.status == 200) {
      response   = req.responseXML.documentElement;
      id_replace = response.getElementsByTagName('id')[0].firstChild.data;
      new_html   = response.getElementsByTagName('new_html')[0].firstChild.data;
      document.getElementById(id_replace).innerHTML     = new_html;
      document.getElementById(id_replace).style.display = 'block';
      Behaviour.apply();
    } else {
      alert("There was a problem retrieving the XML data:\n" + req.statusText);
    }
  }
}

function bogus ()
{

}

function loadXMLDoc(url, callback)
{
  // branch for native XMLHttpRequest object
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
    req.onreadystatechange = callback;
    req.open("GET", url, true);
    req.send(null);
    // branch for IE/Windows ActiveX version
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    if (req) {
      req.onreadystatechange = callback;
      req.open("GET", url, true);
      req.send();
    }
  }
}

function processReqChange()
{
  //alert (reg.readyState);
  // only if req shows "complete"
  if (req.readyState == 4) {
    // only if "OK"
    if (req.status == 200) {
      response  = req.responseXML.documentElement;
      method    = response.getElementsByTagName('method')[0].firstChild.data;
      eval(method + '(response)');
    } else {
      alert("There was a problem retrieving the XML data:\n" + req.statusText);
    }
  }
}    

function eliminarElegidosDeSelect (id_select) 
{
  var acum_rms = '';
  if (confirm('¿Está seguro de eliminar los ítems seleccionados?')) {
    options = document.getElementById(id_select).options;
    for (i = 0; i < options.length; i++) {
      if (options[i].selected) {
      	acum_rms += '' + options[i].value + '&';
        options[i] = null;
        i--;
      }
    }
  }
  return acum_rms;
}

function seleccionarTodo (id_select)
{
  options = document.getElementById(id_select).options;
  for (i = 0; i < options.length; i++) {
    options[i].selected = true;
  }
  return true;
}

