var registryItemRequest = getHttpRequest();
var registryItemPopupDiv;
var registryItemPopup;
var checkIt;

function sendPopReq(registryID, itemNum, itemDesc, obj) {
   showRegistryItemPopup(itemNum, itemDesc, obj);
}

function checkUserPopInput() {
	checkIt = setTimeout('hideRegistryItemPopup()',20);
}

function hideRegistryItemPopup() {
   if(registryItemPopup != null) {
      registryItemPopup.style.visibility = 'hidden';
   }
}

function showRegistryItemPopup(itemNum, itemDesc, obj) {
   
   if (registryItemPopupDiv == null) {
		registryItemPopupDiv = document.createElement("DIV");
		document.body.appendChild(registryItemPopupDiv);		
   }

   var url = 
      '/lowes/lkn?action=grPopup' +
      '&itemNum=' + itemNum + 
      '&itemDesc=' + itemDesc;
    
   var timeoutId = 
      window.setTimeout(
         function() {
            if (isHttpRequestInProgress(registryItemRequest)) {
               registryItemRequest.abort();
            }
         }, 
         100
      );

   registryItemRequest.open('GET', url, true);

   registryItemRequest.onreadystatechange = 
      function() {
         if(registryItemRequest.readyState == 4){
        	registryItemPopupDiv.innerHTML = registryItemRequest.responseText;
            registryItemPopup = getElementByID('pop0');
            registryItemPopup.style.left= findPosX(obj) + 'px';
            registryItemPopup.style.top= findPosY(obj) + 'px';
            registryItemPopup.style.visibility = 'visible';           
         }
      };

   if (!isHttpRequestInProgress(registryItemRequest)) {
      registryItemRequest.send(null);
	}  
}

function getHttpRequest() {
   return (navigator.appName == "Microsoft Internet Explorer") ?  
      new ActiveXObject("Microsoft.XMLHTTP") :
      new XMLHttpRequest();
}

function getElementByID(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	} else if (document.all) {
		return document.all[id];
	} else if (document.layers) {
		return document.layers[id];
	} else return null;
}

function isHttpRequestInProgress(httpRequest) {
   switch (httpRequest.readyState) {
      case 1, 2, 3:
		   return true;
         break;
      default:
         return false;
         break;
   }
}

function findPosX(objXY) {
   var curleft = 0;
   if(objXY.offsetParent) {
   while(1) {
      curleft += objXY.offsetLeft;
      if(!objXY.offsetParent)
         break;
         objXY = objXY.offsetParent;
      }
   }
   else if(objXY.x) {
      curleft += objXY.x;
   }
   
   return curleft;
}

function findPosY(objXY) {
   var curtop = 0;
   if(objXY.offsetParent) {
      while(1) {
         curtop += objXY.offsetTop;
         if(!objXY.offsetParent)
            break;
         objXY = objXY.offsetParent;
      }
   }
   else if(objXY.y) {
      curtop += objXY.y;
   }

   return curtop + ((navigator.appName == "Microsoft Internet Explorer") ? 22 : 10);
}
