<?
session_start();
$brcode = $_SESSION['brcode'];
$yr = $_SESSION['yr'];
if($yr!='2010-2011')
{
 print "<script> alert('You are already logged in  $yr'); </script>";
 print "<center>[<a href='logout.php'>Logout</a>] ";
 print "<br><font color=red><blink><b>Warning </b></font></blink><br>Logout properly in future <br> Multiple login is not allowed";
 return;
}
?>

<html>

<head>
<title>PSN Auto, Administration Software</title>
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">

<style>
    body {
      margin: 0px !important;
    }

    #globalSearchResults {
      position: absolute;
      background: white;
      border: 1px solid #ccc;
      border-radius: 6px;
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
      z-index: 9999;
      display: none;
      font-family: 'Segoe UI', sans-serif;
      max-height: 300px;
      overflow-y: auto;
    }

    #globalSearchResults a {
      display: block;
      padding: 10px;
      color: #2f4050;
      text-decoration: none;
      font-size: 14px;
    }

    #globalSearchResults a:hover {
      background-color: #e8f1ff;
    }
  </style>

  <script>
    let lastSearchBoxPos = null;

    function showGlobalSearchResults(html) {
      const container = document.getElementById("globalSearchResults");
      if (!container || !lastSearchBoxPos) return;

      container.style.left = lastSearchBoxPos.left + "px";
      container.style.top = lastSearchBoxPos.top + "px";
      container.style.width = lastSearchBoxPos.width + "px";
      container.innerHTML = html;
      container.style.display = 'block';
    }

    function hideGlobalSearchResults() {
      const resultDiv = document.getElementById("globalSearchResults");
      if (resultDiv) resultDiv.style.display = 'none';
    }

    // Listen for message from top.php iframe
    window.addEventListener("message", function(event) {
      if (event.data === "hideSearchDropdown") {
        hideGlobalSearchResults();
      }

      // Capture position from iframe
      if (event.data.type === "searchPosition") {
        lastSearchBoxPos = event.data;
      }
    });

    // Optional: Hide when clicking outside
    document.addEventListener("click", function(e) {
      const dropdown = document.getElementById("globalSearchResults");
      if (dropdown && !dropdown.contains(e.target)) {
        hideGlobalSearchResults();
      }
    });
  </script>
</head>

<body>
    <div id="top" style="height: 84px;">
    <iframe src="top.php" name="banner" scrolling="no" target="contents" noresize style="width:100%; height:100%; border:0;"></iframe>
  </div>
  <div style="display: flex; height: calc(100vh - 105px);">
    <iframe src="left.htm" name="contents" target="main" style="width:210px; border:0;"></iframe>
    <iframe src="main1.htm" name="main" scrolling="auto" style="flex:1; border:0;"></iframe>
  </div>

  <div id="globalSearchResults"></div>

  <script>
    window.addEventListener("message", function(event) {
      if (event.data === "hideSearchDropdown") {
        hideGlobalSearchResults();
      }

      if (event.data.type === "searchPosition") {
        lastSearchBoxPos = event.data;
      }
    });
    // Hide when clicking outside the dropdown
    document.addEventListener("click", function(e) {
      const dropdown = document.getElementById("globalSearchResults");
      if (dropdown && dropdown.style.display === "block" && !dropdown.contains(e.target)) {
        hideGlobalSearchResults();
      }
    });
  </script>

</body>

</html>
