//********************************************************
// include_main.js
//
// Purpose: Add the css files, header, and scripts to the 
//          web page. Makes use of the title and instrument 
//          page variables.
//
// 2007-Jul-11 MK Original version.
// 2007-Dec-28 MK Removed the Date information and
//                formatted the page to have three regions
// 2008-Jan-04 MK/JM Added database query functions and moved
//                   instrument master and email vars from the
//                   template to this include file.
// 2008-Oct-27 MK Added options for MAGIQ pages.
//********************************************************

//*******************************************************
// Add more instruments by editing the array below 
// by adding the name of the new instrument.
//*******************************************************

var instr = ["LRIS","HIRES","OSIRIS","NIRC","NIRC2","ADC","DEIMOS","NIRES","MOSFIRE","SHARC","ESI","NIRSPEC","AO","MAGIQ"];


//**********************************************************
// Function to query the database for appropriate info.
//**********************************************************
function getIM(instr,field)
{
  var queryName = new AjaxClass ();
  var query = "../web_docs/scripts/mkDB.php?instr="+instr+"&field="+field;
  var tmp = queryName.sendRequest (query);
  return tmp;
}
//**********************************************************
// Function to set up error handling and request handshakes.
//**********************************************************
function AjaxClass ()
{
  var xmlhttp=false;
  if (typeof XMLHttpRequest != 'undefined')
  {
    xmlhttp = new XMLHttpRequest();
  }
  else
  {
    try
    {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e1)
    {
      try
      {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e2)
      {
        xmlhttp = false;
      }
    }
  }
  this.xmlHttp = xmlhttp;
} // AjaxClass
//*******************************************************
// Function to send a database query request.
//*******************************************************
AjaxClass.prototype.sendRequest = function (query)
{
  var xmlhttp = this.xmlHttp;
  try { xmlhttp.abort (); } catch (e) {}
  xmlhttp.open("GET", query, false);
  xmlhttp.send ("");
  var data = xmlhttp.responseText;
  return data;
} // sendRequest

//*******************************************************
// Set page variables after database query.
// Email contact is used in the includ_end.js script.
//*******************************************************
var masterLast =  getIM( instrument ,"MasterLast");
var masterFirst = getIM( instrument ,"MasterFirst");
var secondaryLast = getIM( instrument,"SecondaryLast");
var secondaryFirst = getIM( instrument,"SecondaryFirst");
var contact =     getIM( instrument ,"Name");
var email =       getIM( instrument ,"Email");
var emailHost =   getIM( instrument ,"Domain");

//*******************************************************
//default behavior for CSS and side menues
//*******************************************************
var menu_common = '<script type="text/javascript"src="../web_docs/SideMenus/common_menu.js"></script>';
var css_file='<link rel=stylesheet href="../web_docs/CSS/general.css" type="text/css">';


//*******************************************************
// Instrument specific file selection for CSS and Side Menu
//*******************************************************
var menu_name=''
var tmp = ''
for (i = 0 ; i < instr.length ; ++i)
{
  tmp = instr[i]
  if ( instrument.toUpperCase() == tmp) {
       menu_name='<script type="text/javascript"src="../web_docs/SideMenus/'+tmp.toLowerCase()+'_menu.js"></script>';
       css_file='<link rel=stylesheet href="../web_docs/CSS/'+tmp.toLowerCase()+'.css" type="text/css">';
  }
}

//*******************************************************
// string variable defined that has in it all the page
// header information. It uses the page variable title
// and the two variables defined above.
//*******************************************************
add_start = '<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>'+title+'</title>'
+'<script type="text/javascript" src="../web_docs/scripts/zoom.js"></script>     <!-- Image zoom functions    --> '
+'<script type="text/javascript" src="../web_docs/scripts/overlib.js"> <!-- overLIB (c) Erik Bosrup--></script> '
+'<!-- Next three lines are used to add the *.css files for page style -->'
+'<link rel=stylesheet href="../web_docs/CSS/general.css" type="text/css">'
+'<link rel=stylesheet media="print" href="../web_docs/CSS/print.css" type="text/css">'
+css_file
+'</head> '
+'<body> '
+'<!-- ================== Page format ================== --> '
+'<!-- The document consists of a 2x2 table --> '
+'<!-- The first row is the title body      --> '
+'<table width=100%> '
+'  <tr> '
+'      <!-- Add the page title -->'
+'     <td class=logo></td>'
+'     <td class=titlebarfontcolor><div class=mytitle><div id="TitleLayer">'
+    title  +'   </div></div>'
+'     </td> '
+'  </tr>'
+'  <tr>  '
+'    <!-- Add the side menu -->'
+'    <td class=menubackground valign="top"><div id="MenuLayer">\n'
+menu_name
+'<script type="text/javascript"src="../web_docs/scripts/Menu_Choose.js"></script>'
+menu_common
+'<script type="text/javascript"src="../web_docs/scripts/Menu_Choose_Common.js"></script>';

//*******************************************************
// Note: The close tags for the div and the td are in the
// common_menu.js file to accomodate how MSIE processes
// java script. MK & JL 6 March 2009
//*******************************************************

//*******************************************************
// Writes the header information
//*******************************************************
document.write(add_start);

