﻿// JScript File
var span;
var checking;
function checkInv(xref,pno)
{
    span = document.getElementById('txtInv');
    span.className = '';
    setText(span,'Checking...');
    ajaxRead('../getinv.aspx?pno=' + pno + '&xref=' + xref);
    //setTimeout("span.innerText='In Stock';","1000");
}

function setText(item,text)
{
    text = '<span style="font-color: red;color:red; font-size:11px; font-weight:bold">' + text + '</span>';
    item.innerHTML = text;
    item.hmtlContent = text;
}

function pageload(xref,pno)
{
    checkInv(xref,pno);
}

function checkStatus()
{
    span = document.getElementById('txtInv');
    if (checking)
        setText(span,'FACTORY STOCK');
}

function ajaxRead(file)
{
    checking = true;
    setTimeout('checkStatus();','15000');  
  var xmlObj = null;
  if(window.XMLHttpRequest)
  {
      xmlObj = new XMLHttpRequest();
  } 
  else if(window.ActiveXObject)
  {
      xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
  } 
  else 
  {
      return;
  }
  
  xmlObj.onreadystatechange = function()
  {
    if(xmlObj.readyState == 4)
    {
        if (xmlObj.status == 200) 
        {
            //updateObj('txtInv', xmlObj.responseXML.getElementsByTagName('res')[0].firstChild.data);
            updateObj('txtInv', xmlObj.responseText);
            
        } 
        else 
        {
            updateObj('txtInv', '<a href="mailto:sales@wbds.com">EMAIL</a> SALES TO CHECK MANUFACTURER AVAILABILITY.');
        }
        checking = false;
    }
  }
  
  xmlObj.open ('GET', file, true);
  xmlObj.send ('');
  
  }
  
function updateObj(obj, data)
{
   setText(document.getElementById(obj),data);
}