﻿// JScript File

function rblCompraChange(valor)
{
  var requestUrl = "webCtrl/AjaxServer.aspx?tipo=" + encodeURIComponent(valor);
  CreateXmlHttp();
  if(XmlHttp)
  {
    XmlHttp.onreadystatechange = HandleResponseDP;
    XmlHttp.open("GET", requestUrl, true);
    XmlHttp.send(null);
  }
}

var XmlHttp;

function CreateXmlHttp()
{
  try
  {
    XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  }  
  catch(e)
  {
    try
    {
      XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    catch(oc)
    {
      XmlHttp = null;
    }
  }
  if(!XmlHttp && typeof XMLHttpRequest != "undefined")
  {
   XmlHttp = new XMLHttpRequest();
  }
}

function HandleResponseDP()
  {
   if(XmlHttp.readyState == 4)
   {
     if(XmlHttp.status == 200)
     {
       LlenarPrecios(XmlHttp.responseXML.documentElement);
     }
     else
     {
        alert("Problemas con el servidor Ajax.");
     }
   }
}

function LlenarPrecios(NodoPrecios)
{
   var listaPrecios = document.getElementById("ddlPrecio");
   for (var count = listaPrecios.options.length-1; count >-1; count--)
   {
     listaPrecios.options[count] = null;
   }
   var NodoPrecio = NodoPrecios.getElementsByTagName('precio');
   var textValue;
   var textTitulo;
   var optionItem;
   for (var count = 0; count < NodoPrecio.length; count++)
   {
     var NodoValor=NodoPrecio[count].getElementsByTagName('valor')[0].childNodes[0].nodeValue;
     var NodoTitulo=NodoPrecio[count].getElementsByTagName('texto')[0].childNodes[0].nodeValue;
     optionItem = new Option( NodoTitulo, NodoValor, false, false);
     listaPrecios.options[listaPrecios.length] = optionItem;
   }
   
   //alert(NodoPrecios + document.getElementById("ddlPrecio").items.count);
   alert(listaPrecios.options.length);
}
