function OpenTSRWindow(NewWay) {
  if (NewWay) {
    fcnShowPopup('TSRIframe', 20);
  } else {
    openTechSupport();
  }
}

function fcnResizePopups() {
  if (document.getElementById("TSRIframe").style.display == "block") {
    fcnReducePopup("TSRIframe");
  }
  //  if(document.getElementById("DefectSupplierIframe")){
  //  alert("resize defect supplier")
  //    fcnReducePopupBySize("DefectSupplierIframe", 600, 300);
  //  }
}

function fcnFocusOnPopup(PopupID) {
    var fr = document.getElementById(PopupID);
    fr.document.getElementById("hiddentext").value = "alex";
}

function fcnShowPopup(PopupID, Pcent) {
  setPopupByPcent(PopupID, Pcent);
  document.getElementById("divPageCover").style.height = fcnGetScrollPageHeight() + "px";
  document.getElementById("divPageCover").style.width = fcnGetPageWidth() + "px";
  document.getElementById(PopupID).style.display = "block";
  document.getElementById("divPageCover").className = "FadedBlack";
  document.getElementById("divPageCover").style.display = "block";
}

function fcnShowPopupBySize(PopupID, Wid, Hei) {
  setPopupBySize(PopupID, Wid, Hei);
  document.getElementById("divPageCover").style.height = fcnGetScrollPageHeight() + "px";
  document.getElementById("divPageCover").style.width = fcnGetPageWidth() + "px";
  document.getElementById(PopupID).style.display = "block";
  document.getElementById("divPageCover").className = "FadedBlack";
  document.getElementById("divPageCover").style.display = "block";
}

function fcnShowPopupBySize2(PopupID, Wid, Hei, strURL) {
    document.getElementById(PopupID).src = strURL;
    setPopupBySize(PopupID, Wid, Hei);
    document.getElementById("divPageCover").style.height = fcnGetScrollPageHeight() + "px";
    document.getElementById("divPageCover").style.width = fcnGetPageWidth() + "px";
    document.getElementById(PopupID).style.display = "block";
    document.getElementById("divPageCover").style.display = "block";
}

function fcnShowPopupBySize3(PopupID, Wid, Hei, strURL, strClassName) {
    document.getElementById(PopupID).src = strURL;
    setPopupBySize(PopupID, Wid, Hei);
    document.getElementById("divPageCover").style.height = fcnGetScrollPageHeight() + "px";
    document.getElementById("divPageCover").style.width = fcnGetPageWidth() + "px";
    document.getElementById(PopupID).style.display = "block";
    document.getElementById("divPageCover").style.display = "block";
    document.getElementById("divPageCover").className = strClassName;
}

function fcnEnlargePopup(PopupID) {
  document.getElementById("divPageCover").style.height = fcnGetScrollPageHeight() + "px";
  document.getElementById("divPageCover").style.width = fcnGetPageWidth() + "px";
  setPopupByPcent(PopupID, 75);
}

function fcnReducePopup(PopupID) {
  document.getElementById("divPageCover").style.height = fcnGetScrollPageHeight() + "px";
  document.getElementById("divPageCover").style.width = fcnGetPageWidth() + "px";
  setPopupByPcent(PopupID, 30);
}

function fcnReducePopupBySize(PopupID, Wid, Hei) {
  document.getElementById("divPageCover").style.height = fcnGetScrollPageHeight() + "px";
  document.getElementById("divPageCover").style.width = fcnGetPageWidth() + "px";
  setPopupBySize(PopupID, Wid, Hei);
}

function fcnClosePopup(PopupID, strRedirectURL) {
  if (strRedirectURL != "") { document.getElementById(PopupID).src = strRedirectURL }
  document.getElementById(PopupID).style.display = "none";
  document.getElementById("divPageCover").style.display = "none";
}

function fcnGetPageHeight() {
    var D = document;
    var val = 0;
    if (document.all) {
        val = D.documentElement.offsetHeight;
    } else {
        val = D.documentElement.clientHeight;
    }
    return val;
}

function fcnGetPageWidth() {
    var D = document;
    var val = 0;
    if (document.all) {
        val = D.documentElement.offsetWidth;
    } else {
        val = D.documentElement.clientWidth;
    }
    return val-20;
}

function fcnGetScrollPageHeight() {
  return document.body.scrollHeight;
}

function fcnGetScrollPageWidth() {
  return document.body.scrollWidth;
}

function setPopupByPcent(PopupID, Pcent) {
  Pcent = Pcent / 100;
  var PageHeight = fcnGetPageHeight();
  var PageWidth = fcnGetPageWidth();
  var intPopUpHeight = (PageHeight - (PageHeight / 10) / Pcent);
  var intPopUpWidth = (PageWidth - (PageWidth / 10) / Pcent);
  var intTop = (PageHeight - intPopUpHeight) / 2;
  var intLeft = (PageWidth - intPopUpWidth) / 2;

  document.getElementById(PopupID).style.height = intPopUpHeight + "px";
  document.getElementById(PopupID).style.width = intPopUpWidth + "px";
  document.getElementById(PopupID).style.left = intLeft + "px";
  document.getElementById(PopupID).style.top = intTop + "px";
  document.getElementById(PopupID).src = document.getElementById(PopupID).src;
}

function setPopupBySize(PopupID, Wid, Hei) {
  var PageHeight = fcnGetPageHeight();
  var PageWidth = fcnGetPageWidth();
  var intPopUpHeight = Hei
  var intPopUpWidth = Wid
  var intTop = (PageHeight - intPopUpHeight) / 2;
  var intLeft = (PageWidth - intPopUpWidth) / 2;

  document.getElementById(PopupID).style.height = intPopUpHeight + "px";
  document.getElementById(PopupID).style.width = intPopUpWidth + "px";
  document.getElementById(PopupID).style.left = intLeft + "px";
  document.getElementById(PopupID).style.top = intTop + "px";
  document.getElementById(PopupID).src = document.getElementById(PopupID).src;
}
