function MostrarBanner ( img ) {
  FAjax ('img_ajax.php','banners','img='+img,'POST');
  //FAjax ('ofr_ajax.php','offers','offer='+offer,'POST');
}
function MostrarOffer ( offer) {
  //FAjax ('img_ajax.php','banners','img='+img,'POST');
  FAjax ('ofr_ajax.php','offers','offer='+offer,'POST');
}
function random(desde,hasta){
  posibles = hasta - desde;
  aleatorio = Math.random() * posibles;
  aleatorio = Math.floor(aleatorio);
  return parseInt(desde) + aleatorio;
}
function crearXMLHttpRequest()
{
  var xmlHttp=null;
  if (window.ActiveXObject)
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  else
    if (window.XMLHttpRequest)
      xmlHttp = new XMLHttpRequest();
  return xmlHttp;
}

function FAjax (url,capa,valores,metodo){
  var ajax=crearXMLHttpRequest();
  var capaContenedora = document.getElementById(capa);

  /*Creamos y ejecutamos la instancia si el metodo elegido es POST*/
  if(metodo.toUpperCase()=='POST'){
    ajax.open ('POST', url, true);
    ajax.onreadystatechange = function() {
      if (ajax.readyState==1) {
        capaContenedora.innerHTML="";
      }else if (ajax.readyState==4){
        if(ajax.status==200){
          document.getElementById(capa).innerHTML=ajax.responseText;
        }else if(ajax.status==404){
          capaContenedora.innerHTML = "La direccion no existe";
        }else{
        capaContenedora.innerHTML = "Error: ".ajax.status;
        }
      }
    }
    ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    ajax.send(valores);
    return;
  }
  /*Creamos y ejecutamos la instancia si el metodo elegido es GET*/
  if (metodo.toUpperCase()=='GET'){
    ajax.open ('GET', url, true);
    ajax.onreadystatechange = function() {
      if (ajax.readyState==1) {
        capaContenedora.innerHTML="";
      }else if (ajax.readyState==4){
        if(ajax.status==200){
          document.getElementById(capa).innerHTML=ajax.responseText;
        }else if(ajax.status==404){
          capaContenedora.innerHTML = "La direccion no existe";
        }else{
          capaContenedora.innerHTML = "Error: ".ajax.status;
        }
      }
    }
    ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    ajax.send(null);
    return
  }
}

function testtimeout()
{
  MostrarBanner(random(1,3));
  //MostrarOffer(random(1,4));
  setTimeout("testtimeout()",7000);
}

function testtimeout2()
{
  //MostrarBanner(random(1,3));
  MostrarOffer(random(1,4));
  setTimeout("testtimeout2()",20000);
}

testtimeout();
testtimeout2();