﻿$(document).ready(function() {
});

function showPopup(inventoryitemid, ele, action, thisElement, offsetTop, offsetLeft) {
  if ($(ele).css('display') == "none" && action == 'open') {
    var top = getYPosOnPage(thisElement);
    var left = getXPosOnPage(thisElement);
    $('.shipPopClass').css('display', 'none');
    $(ele).css('display', 'block').css('top', top + 10 + offsetTop).css('left', left - 5 + offsetLeft);
    $.ajax({
      type: 'POST',
      url: '/services/EstShipDate.asmx/GetShipDate',
      contentType: 'application/json; charset=utf-8',
      data: "{'inventoryitemid':'" + inventoryitemid + "'}",
      dataType: 'json',
      success: function(estdate) {
        $(ele).children('#loading').css('display', 'none');
        $(ele).css('display', 'block');
        $(ele).children('#shipDate').html(estdate.d);
      },
      error: function(estdate) { }
    });
  } else if (action == 'close') {
    $(ele).parent('.shipPopClass').css('display', 'none');
  }
}

function getYPosOnPage(element) {
  var iReturnValue = 0;
  while (element != null) {
    iReturnValue += element.offsetTop;
    element = element.offsetParent;
  }
  return iReturnValue;
}

function getXPosOnPage(element) {
  var iReturnValue = 0;
  while (element != null) {
    iReturnValue += element.offsetLeft;
    element = element.offsetParent;
  }
  return iReturnValue;
}