////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Some search functions

// Turn advanced search on and off
function toggleSearchOptions()
{
   if ( document.getElementById('searchadvanced').style.display == "none" ) {
      document.getElementById('searchadvanced').style.display = "block";
   } else {
      document.getElementById('searchadvanced').style.display = "none";
   }
}

// Used to make sure the contents of the advanced search and simple search are synced
function syncSearch(src_str, dest_str)
{
   document.getElementById(dest_str).value = document.getElementById(src_str).value;
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
function OpenSeriesDirectory(root, sess, opt_page)
{
   var page = "null";
   if ( (opt_page != undefined) && (opt_page != "") )
   {
      page = opt_page;
   }

   // New system
	var sd_window = window.open(root+ "/ps.pl?sess=" + sess + "&t=toc&p=" + page, "sd", "resizable=yes,width=550,height=550,status=yes,scrollbars=yes");

   // Old system
   //	var sd_window = window.open(root+ "/ps.pl?sess=" + sess + "&t=sd&p=null", "sd", "resizable=yes,width=450,height=550,status=yes");

   sd_window.focus();
	self.name = "main";
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
function LoginInfo(form_login, help_text)
{

   // Set the local time variable
   var now = new Date();
   var user_time = now.toLocaleString();
   form_login.user_time.value = now.toLocaleString();

   // Open a temporary window
   var login_window = window.open("", "Login", "resizable=no,width=400,height=200,status=no");
   login_window.focus();

   // Write to it...
   var doc = login_window.window.document;

   doc.open();

   doc.writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">                                                     \n',
               '<html>                                                                                                             \n',
               '<head>                                                                                                             \n',
               '  <title>ESDU: Logging in...</title>                                                                               \n',
               '  <link href="/css/esdu2.css" rel="stylesheet" type="text/css">                                                    \n',
               '</head>                                                                                                            \n',
               '<body bgcolor="#FFFFFF" onLoad="setTimeout(\'self.close()\', 4000)">                                               \n',
               '<table width="100%" border="0" align="center">                                                                     \n',
               '<tr>                                                                                                               \n',
               '   <td width="50">&nbsp;</td>                                                                                      \n',
               '   <td width="100%" align="center" valign="middle">                                                                \n',
               '     <img src="/images/ihsblue/please_wait.gif" alt="" width="200" height="50" border="0">                         \n',
               '   </td>                                                                                                           \n',
               '   <td width="50">&nbsp;</td>                                                                                      \n',
               '</tr>                                                                                                              \n',
               '<tr>                                                                                                               \n',
               '   <td>&nbsp;</td>                                                                                                 \n',
               '   <td align="left" valign="middle">                                                                               \n',
               '     <p style="font-size: x-small">' + help_text + '</p>                                                           \n',
               '     <p style="font-size: x-small">' + user_time + '</p>                                                           \n',
               '   </td>                                                                                                           \n',
               '   <td>&nbsp;</td>                                                                                                 \n',
               '</tr>                                                                                                              \n',
               '</table>                                                                                                           \n',
               '</body>                                                                                                            \n',
               '</html>                                                                                                            \n'
              );


   doc.close();

   login_window.focus();
//   login_window.close();

   return true;

}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
function ShowHelpPopup(root_cgi, sess, help_page)
{

	var show_help_window = window.open(root_cgi + "/ps.pl?sess=" + sess + "&t=help&p=" + help_page, "show_help_window", "resizable=yes,width=500,height=500,status=no,scrollbars=yes");

	show_help_window.focus();

	return;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
function ShowLicPopup(root_cgi, sess, page_request)
{
   if ( page_request == 'null')
   {
      alert('No licences are required for any VIEWpacs in your subscription');
   }
   else
   {
      var lic = window.open(root_cgi + "/licence_key_generator.pl?sess=" + sess + "&t=vpgen&p=" + page_request, "lic", "resizable=yes,width=800,height=400,status=no,scrollbars=yes");
      lic.focus();
   }

   return;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
function ShowVPEVPopup(root_cgi, sess, page_request)
{
   if (vpev) {
      vpev = window.open(root_cgi + "/ps.pl?sess=" + sess + "&amp;t=vpev&amp;p=" + page_request, "vpev", "resizable=no,width=300,height=300,status=no,scrollbars=no");
      vpev.focus();
   } else {
      var vpev = window.open(root_cgi + "/ps.pl?sess=" + sess + "&amp;t=vpev&amp;p=" + page_request, "vpev", "resizable=no,width=300,height=300,status=no,scrollbars=no");
      vpev.focus();
   }
   return;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
function ShowInteractiveGraphHelpPopup()
{
	var ag_window = window.open("/activegraph/demo/demo.htm", "ag", "resizable=yes,width=800,height=600,status=yes");
	ag_window.focus();
	self.name = "main";
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
function ShowProductdemoPopup(demo)
{
	var pd_window = window.open("/productdemos/online/" + demo + "/index.html", "pd", "resizable=yes,width=850,height=650,status=yes");
	pd_window.focus();
	self.name = "main";
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
function OpenPP(root, sess)
{
   var pp_window = window.open("http://beta.esdu.com/webinterfaces/esdupp/default.aspx?&sess=" + sess, "pp", "resizable=yes,width=850,height=680,status=yes,scrollbars=yes");
   pp_window.focus();
	self.name = "main";

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
function OpenVPJ(root, sess, page, width, height)
{
	var vpj_window = window.open(root+ "/ps.pl?sess=" + sess + "&t=vpj&p=" + page, page, "resizable=yes,width=" + width + ",height=" + height + ",status=yes,scrollbars=yes");
	vpj_window.focus();
	self.name = "main";
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
function OpenWSEP(root, sess, page)
{
   var wsep_window = window.open("/webservices/public/" + page + "/" + page + ".aspx?&sess=" + sess, page, "resizable=yes,width=800,height=550,status=yes,scrollbars=yes");
   wsep_window.focus();
	self.name = "main";

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
function ShowWSEPKeyPopup(un, pw, email)
{

   // Open a temporary window
   var wsep_key_window = window.open("", "wsepkey", "resizable=yes,width=400,height=400,status=yes,scrollbars=yes");
   wsep_key_window.focus();

   // Write to it...
   var doc = wsep_key_window.window.document;

   doc.open();

   doc.writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">                                                                                          \n',
               '<html>                                                                                                                                                  \n',
               '<head>                                                                                                                                                  \n',
               '   <title>Connect key request</title>                                                                                                                   \n',
               '   <link href="/css/esdu2.css" rel="stylesheet" type="text/css">                                                                                        \n',
               '</head>                                                                                                                                                 \n',
               '<body onload="document.getElementById(\'form_main\').submit()">                                                                                         \n',
               '   <div style="margin: 50px 50px 50px 50px;">                                                                                                           \n',
               '      <h3>Requesting Connect key</h3>                                                                                                                   \n',
               '      User: ' + email + '<br /><br />                                                                                                                   \n',
               '      Please wait - this may take up to a minute...                                                                                                     \n',
               '   </div>                                                                                                                                               \n',
               '   <form action="http://connect.esdu.com/webinterfaces/getconnectkey/Default.aspx" method="post" id="form_main">                                        \n',
               '      <input type="hidden" name="un" id="un" value="' + un + '" />                                                                                      \n',
               '      <input type="hidden" name="pw" id="pw" value="' + pw + '" />                                                                                      \n',
               '      <input type="hidden" name="email" id="email" value="' + email + '" />                                                                             \n',
               '   </form>                                                                                                                                              \n',
               '</body>                                                                                                                                                 \n',
               '</html>                                                                                                                                                 \n'
               );

   doc.close();

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
function OpenAG(root, sess, page)
{
	var ag_window = window.open(root+ "/ps.pl?sess=" + sess + "&t=ag&p=" + page, page, "resizable=yes,width=850,height=670,status=yes,scrollbars=yes");
	ag_window.focus();
	self.name = "main";
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
function switchTabContentsContainer(target_id, tabsarray)
{

   // Turn off all the current tabs and set the tab style to default
   for (var i=0; i<tabsarray.length; i++)
   {
      if ( document.getElementById(tabsarray[i]) )
      {
         // Only turn 'off' what we can find
         document.getElementById(tabsarray[i]).style.display = "none";
         document.getElementById("menu_" + tabsarray[i]).className = "";  // Remove any class style
         document.getElementById("menu_" + tabsarray[i]).blur();          // Lose focus
      }
   }

   //... and display the requested one and style the tab a href
   document.getElementById(target_id).style.display = "block";
   document.getElementById("menu_" + target_id).className = "current"; // Set the class to current

}

function setDataItemTabContentsContainer(tabsarray)
{

   // select tab_target if URL has a named anchor...
   var myurl = document.URL;

   // PROGRAMS
   if (
         ( myurl.substring( myurl.length - '#PROGRAMS'.length ) == '#PROGRAMS' ) &&
         ( document.getElementById('conprograms') )
      )
   {
      switchTabContentsContainer('conprograms', tabsarray)
   }
   // GRAPHS
   else if (
              ( myurl.substring( myurl.length - '#GRAPHS'.length ) == '#GRAPHS' ) &&
              ( document.getElementById('congraphs') )
           )
   {
      switchTabContentsContainer('congraphs', tabsarray)
   }

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
function toggleDivPM(div_in, show_text, hide_text)
{
   // Toggle div_in
   var tdiv = document.getElementById(div_in);  // Shorthand

   if (tdiv.style.display == "block" ) {
      tdiv.style.display = "none";
      document.getElementById(div_in + '_plus').innerHTML = show_text;
   } else {
      tdiv.style.display = "block";
      document.getElementById(div_in + '_plus').innerHTML = hide_text;
   }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
function toggleDiv(div_in)
{
   // Toggle div_in
   var tdiv = document.getElementById(div_in);  // Shorthand

   if (tdiv.style.display == "block" )
   {
      tdiv.style.display = "none";
   }
   else
   {
      tdiv.style.display = "block";
   }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
function toggleDivVisibility(div_in, visible)
{
   // Toggle div_in
   var tdiv = document.getElementById(div_in);  // Shorthand

   if (visible == false )
   {
      tdiv.style.display = "none";
   }
   else
   {
      tdiv.style.display = "block";
   }
}



