var xmlHttp;
var divretorno;
var valexterno;

function Pagina(page_name,valdiv_,externo)
{ 
valexterno=externo;
divretorno=valdiv_;
xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 


if (divretorno == '' )
{
document.getElementById("mainframe").innerHTML="<html><br><br><br><br><br><center><img src='images/wait.gif'><br><strong style='font-family:Trebuchet MS;font-size:10pt;color:#999999'>Cargando, Espere un momento...</strong></center></html>";

}
else
{
  if (valexterno > 0) 
  {
opener.document.getElementById(divretorno).innerHTML="<html><br><center><img src='images/wait.gif'><br><strong style='font-family:Trebuchet MS;font-size:10pt;color:#999999'>Cargando, Espere un momento...</strong></center></html>";

 }
  else
  {
document.getElementById(divretorno).innerHTML="<html><br><center><img src='images/wait.gif'><br><strong style='font-family:Trebuchet MS;font-size:10pt;color:#999999'>Cargando, Espere un momento...</strong></center></html>";
  
  }
}

var url;


url=page_name;

//document.getElementById("contiene").innerHTML="<html><br><br><br><center><img src='img/indicator.gif'><br><strong style='font-family:Trebuchet MS;font-size:14pt;color:#0049b7'>Cargando...</strong></center></html>";
xmlHttp.onreadystatechange=stateChange;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

}



function stateChange() 
{ 

if (xmlHttp.readyState==4)
{ 
   if (divretorno == '' )
      {
       document.getElementById("mainframe").innerHTML=xmlHttp.responseText;	
      }
   else
      {
       if (valexterno > 0) 
          {
          opener.document.getElementById(divretorno).innerHTML=xmlHttp.responseText;		  
          }
       else
	      {
          document.getElementById(divretorno).innerHTML=xmlHttp.responseText;	
		  }
      }
   
   if (divretorno=="no_items")
     {
     alert("Articulo Agregado a Pedido");	
     } 
}

}

function GetXmlHttpObject()
{
var xmlHttp=null;

try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }


return xmlHttp;
} 
