var req;

function loadXMLDoc(url) 
{
  if (window.XMLHttpRequest)  // branch for native XMLHttpRequest object
  {
    req = new XMLHttpRequest();
    req.onreadystatechange = processReqChange;
    req.open("GET", url, true);
    req.send(null);
  } 
  else if (window.ActiveXObject)  // branch for IE/Windows ActiveX version
  {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    if (req) 
    {
      req.onreadystatechange = processReqChange;
      req.open("GET", url, true);
      req.send(1);
    }
  }
}


function processReqChange() 
{
  if (req.readyState == 4)    // only if req shows "complete"
  {
    if (req.status == 200)  // only if "OK"
    {
      //alert(req.responseText);
      response  = req.responseXML.documentElement;
      if (response)
      {
        noitems = response.getElementsByTagName('noitems')[0].firstChild.data;
        
        if (noitems!='true')
        {
          method = response.getElementsByTagName('method')[0].firstChild.data;
          brand = response.getElementsByTagName('brand')[0].firstChild.data;
          desc = response.getElementsByTagName('description')[0].firstChild.data;
          price = response.getElementsByTagName('price')[0].firstChild.data;
          size = response.getElementsByTagName('size')[0].firstChild.data;
          star = response.getElementsByTagName('star')[0].firstChild.data;
          store = response.getElementsByTagName('store')[0].firstChild.data;
          sid = response.getElementsByTagName('sid')[0].firstChild.data;
          eval(method+"(brand, desc, price, size, star, store, sid)");
        }
        else
        {
          showNoItems();
        }
      }
      else
      {
        //alert("There was a problem retrieving the XML data:\n Server response is 'null'");
      }
    } 
    else
    {
      //alert("There was a problem retrieving the XML data:\n" + req.statusText);
    }
  }
}

function showItem(brand, desc, price, size, star, store, sid)
{
  in_html='<table align="center" width="100%" height="100%" border="0" style="cursor: pointer;"  onmouseover=\'status="Best Buys"\'  onmouseout=\'status=""\' onclick="window.location=\'/grocery/sto/showstore.asp?sid='+setID(sid)+'&bb=1\';">';  
  if (brand!='null') in_html+=' <tr><td colspan="2" style="font-size: 11px;"  align="center"><b>'+brand+'</b></td></tr>';
  if (desc!='null') in_html+=' <tr><td colspan="2" style="font-size: 11px;">'+desc+'</td></tr>';
  if (price!='null') in_html+=' <tr><td style="font-size: 11px;"><b>Price:</b></td><td style="font-size: 11px;">$'+price+'</td></tr>';
  if (size!='null') in_html+=' <tr><td style="font-size: 11px;"><b>Size:</b></td><td style="font-size: 11px;">'+size+'</td></tr>';
  if (star!='null') in_html+=' <tr><td style="font-size: 11px;"><b>Rank:</b></td><td><img src="/images/'+star+'_star.gif" /></td></tr>';
  if (store!='null') in_html+=' <tr><td valign="top" style="font-size: 11px;"><b>Store:</b></td><td style="font-size: 11px;">'+store+'</td></tr>';
  in_html+=' <tr><td colspan="2" style="font-size: 11px;color: #0000ff;text-decoration:underline;" align="center" height="15"><b>Click For Info</b></td></tr>';
  in_html+='</table>';
  document.getElementById('hot_item_holder').innerHTML=in_html;
}

function showNoItems()
{
  document.getElementById('hot_item_holder').innerHTML="<b>No Items</b>";
}

function setID(id)
{
  var prefix=Math.round(Math.random()*100);
  if (prefix==0)
  {
    prefix="10";
  }
  else if (prefix<10)
  {
    prefix=prefix.toString()+"0";
  }
  
  var suffix=Math.round(Math.random()*100);
  if (suffix==0)
  {
    suffix="10";
  }
  else if (suffix<10)
  {
    suffix=suffix.toString()+"0";
  }
  return prefix+id.toString()+suffix;
}
