//------------------------------------------------------------------
// This script checks that the browser is a Netscape or Microsoft version 4 or above
//------------------------------------------------------------------
var ns4 = (document.layers)? true:false;
var ns6 = document.getElementById&&!document.all;
var ie4 = (document.all)? true:false;
var ie5 = (navigator.userAgent.indexOf('MSIE 5') > 0)? true : false;
var ie55 = (navigator.userAgent.indexOf('MSIE 5.5') > 0)? true : false;
var ie6 = (navigator.userAgent.indexOf('MSIE 6') > 0)? true : false;
if (!ie4 && !ns4 && !ns6)
   window.location = 'http://www.nottinghamcvs.co.uk/sorry.htm';

var TheIndent = '';
var newIndent = '';
var tablehead = '<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">\n';
var tablerow = '</TR>\n<TR>\n';
var tableleft = '';
var tableright = '';
var tablefoot = '</TR>\n</TABLE>\n\n';


//-HEADER-AND-FOOTER-TABLE-FUNCTIONS------------------------------------------------------------------------------------------------

//------------------------------------------------------------------
// Writes out the header table at the top of the page
// Takes indent (within Site), section name, section link, article name.
//------------------------------------------------------------------
function WriteHeader()
{
   var header = '';

   // Store the indent and workout constants
   TheIndent = WriteHeader.arguments[0];
   tableleft += '  <TD CLASS="borderLeft1"><IMG ALT="" HEIGHT="1" SRC="' + TheIndent + 'images/blank.gif" WIDTH="1"></TD>\n';
   tableright += '  <TD CLASS="borderRight1"><IMG ALT="" HEIGHT="1" SRC="' + TheIndent + 'images/blank.gif" WIDTH="1"></TD>\n';

   // Top logo table
   header += '<SPAN CLASS="hidden">Page Header</SPAN>';
   header += tablehead;
   header += '<TR BGCOLOR="#B0B0AF">\n';
   header += '  <TD><IMG TITLE="" HEIGHT="26" SRC="' + TheIndent + 'images/black.gif" WIDTH="138"></TD>\n';
   header += '  <TD ALIGN="CENTER">' + CreateLink(TheIndent + 'index.htm', 'Click here to get back to the NCVS home page.', '', '<IMG TITLE="Click here to get back to the NCVS home page." BORDER="0" HEIGHT="26" SRC="' + TheIndent + 'images/ncvs.gif" WIDTH="394">') + '</TD>\n';
   header += '  <TD ALIGN="RIGHT"><IMG TITLE="" HEIGHT="26" SRC="' + TheIndent + 'images/black.gif" WIDTH="138"></TD>\n';
   header += tablefoot;

   // Middle breadcrumb and bottom curve table
   header += tablehead;
   header += '<TR CLASS="orange">\n';
   header += '  <TD CLASS="borderBottom1" VALIGN="BOTTOM"><IMG TITLE="" HEIGHT="11" SRC="' + TheIndent + 'images/header_bottom_left.gif" WIDTH="11"></TD>\n';
   header += '  <TD ALIGN="CENTER" CLASS="borderBottom1"><SPAN CLASS="header">';

   // Work out the new indent to the current snippets issues
   newIndent = TheIndent.substring(6, TheIndent.length);

   // Work out the breadcrumb text
   if (WriteHeader.arguments.length > 1)
   {
      //header += CreateLink(TheIndent + 'index.htm', 'Click here to go to the home page.', '', 'NCVS') + '\n';
      if (WriteHeader.arguments.length == 6)
      {
         header += CreateTitleLink(WriteHeader.arguments[2], 'Click here to get to the ' + WriteHeader.arguments[1] + ' section main page.', '', WriteHeader.arguments[1]);
         header += '<B> > </B> ' + CreateTitleLink(WriteHeader.arguments[4], 'Click here to get to the ' + WriteHeader.arguments[3] + ' section main page.', '', WriteHeader.arguments[3]);
         header += '<B> > ' + WriteHeader.arguments[5] + '</B>';
      }
      else
      {
         if (WriteHeader.arguments.length == 4)
         {
            header += CreateTitleLink(WriteHeader.arguments[2], 'Click here to get to the ' + WriteHeader.arguments[1] + ' section main page.', '', WriteHeader.arguments[1]);
            header += '<B> > ' + WriteHeader.arguments[3] + '</B>';
         }
         else
            header += '<B>' + WriteHeader.arguments[1] + '</B>';
      }
   }
   else
      header += '<B>Home Page</B>';

   header += '</SPAN></TD>\n';
   header += '  <TD ALIGN="RIGHT" CLASS="borderBottom1" VALIGN="BOTTOM"><IMG TITLE="" HEIGHT="11" SRC="' + TheIndent + 'images/header_bottom_right.gif" WIDTH="11"></TD>\n';
   header += tablerow;
   header += '  <TD COLSPAN="2"><IMG TITLE="" HEIGHT="11" SRC="' + TheIndent + 'images/header_top_left.gif" WIDTH="11"></TD>\n';
   header += '  <TD ALIGN="RIGHT"><IMG TITLE="" HEIGHT="11" SRC="' + TheIndent + 'images/header_top_right.gif" WIDTH="11"></TD>\n';
   header += tablefoot;

   // Write the header table
   document.write(header);

   // Use the cookie settings for the colour scheme
   if (ie4 && getCookieValue('Scheme') != null)
   {
      // Get the scheme colours
      var scheme = getCookieValue('Scheme');
      var stylesheet = document.styleSheets(0);

      // Set the scheme colours
      document.body.style.backgroundColor = scheme.substring(1, 8);
      document.body.style.color = scheme.substring(8, 17);

      // Remove the existing .header .orange and A rules
      stylesheet.removeRule(6); // was 5
      stylesheet.removeRule(6);
      stylesheet.removeRule(6);

      // Add a stylesheet rules for textonly format
      stylesheet.addRule('A', 'color: ' + scheme.substring(8, 17) + '; font-size: x-large; font-weight: bold;');
      stylesheet.addRule('H3', 'font-size: large;');
      stylesheet.addRule('IMG.image', 'display: none;');
      stylesheet.addRule('TD', 'font-size: large;');
   }
}

//------------------------------------------------------------------
// Writes out the header part at the top on option tables on the left
// Takes indent (within Snippets), option title
//------------------------------------------------------------------
function WriteFooter(date)
{
   var footer = '';

   footer += '<SPAN CLASS="hidden">Page Footer</SPAN>';
   footer += '<HR NOSHADE>\n';
   footer += tablehead;
   footer += '<TR>\n';
   footer += '  <TD>' + CreateLink('#top', 'Click here to go to the top of the page.', '', '<SMALL>Back to top</SMALL>') + '</TD>\n';
   footer += '  <TD ALIGN="RIGHT">';

   if (date != '')
      footer += '<SMALL>(Date Written: ' + date + ')</SMALL>';

   // Toggle the navbar
   footer += '</TD>';
   footer += tablerow;
   footer += '  <TD ALIGN="MIDDLE" COLSPAN="2" ALIGN="MIDDLE">\n';
   footer += '  <IFRAME BORDER="0" FRAMEBORDER="0" HEIGHT="0" ID="Frame1" SCROLLING="NO" SRC="' + TheIndent + 'save_cookie.htm" WIDTH="0"></IFRAME>\n';
   if (ie4)
   {
      footer += '  <A ID="wide" HREF="JavaScript:toggleNavbarTable();" TITLE="Click here to hide the NCVS Toolbar." ONMOUSEMOVE="window.status=this.title" ONMOUSEOUT="window.status=\'\'"><B>W</B>idescree<B>N</B></A>\n';
   }
   footer += '  </TD>\n';

   footer += tablefoot;
   footer += '<HR NOSHADE>\n\n';
   footer += '</TD>\n';
   footer += tablefoot;

   document.write(footer);

   // Use the cookie settings for the navbar
   if (ie4 && getCookieValue('ShowNavBar') != null)
   {
      if (getCookieValue('ShowNavBar') == '00' || (getCookieValue('ShowNavBar') == '10' && getCookieValue('Scheme') != null) || (getCookieValue('ShowNavBar') == '01' && getCookieValue('Scheme') == null))
         toggleNavbarTable();
   }
}

//-OPTION-TABLE-FUNCTIONS----------------------------------------------------------------------------------------------------------

//------------------------------------------------------------------
// Writes out all the options tables on the left
// Takes code (S = Snippets)
//------------------------------------------------------------------
function WriteOptions(Code)
{
   var options = '';

   // Table header
   options += '<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="5" WIDTH="100%">\n';
   options += '<TR>\n';
   options += '  <TD ID="navbar" VALIGN="TOP" WIDTH="170px">\n';
   options += '  <SPAN CLASS="hidden">NCVS Toolbar</SPAN>';
   options += '\n';
   options += tablehead;
   options += '<TR>\n';
   options += '  <TD WIDTH="11px"><IMG ALT="" HEIGHT="11" SRC="' + TheIndent + 'images/navbar_top_left.gif" WIDTH="11"></TD>\n';
   options += '  <TD CLASS="borderTop1" WIDTH="148px"><IMG ALT="" HEIGHT="1" SRC="' + TheIndent + 'images/blank.gif" WIDTH="1"></TD>\n';
   options += '  <TD WIDTH="11px"><IMG ALT="" HEIGHT="11" SRC="' + TheIndent + 'images/navbar_top_right.gif" WIDTH="11"></TD>\n';

   // Search table
   options += WriteOptionHeader('Search NCVS');
   options += '    <FORM METHOD="get" ACTION="http://search.atomz.com/search/">\n';
   options += '      <INPUT ACCESSKEY="s" NAME="sp-q" SIZE="14" TITLE="Enter the words you want to search for." TYPE="text">&nbsp;\n';
   options += '      <INPUT TITLE="Click to search NCVS for matching articles." TYPE="submit" VALUE="GO">\n';
   options += '      <INPUT NAME="sp-a" TYPE="hidden" VALUE="sp0910ea00">\n';
   options += '      <INPUT NAME="sp-advanced" TYPE="hidden" VALUE="1">\n';
   options += '      <INPUT NAME="sp-p" TYPE="hidden" VALUE="all">\n';
   options += '    </FORM>\n';
   options += '  </TD>\n';
   options += tableright;

   // Sections table
   options += WriteOptionHeader('NCVS Sections');
   options += writeMenu('mnuHome', "");
   options += '<BR>\n';
   options += tableright;

   // Extras (IE only)
   if (ie4)
   {
      options += WriteOptionHeader('<SPAN CLASS="hidden">Optional</SPAN> Extras');

      // Use the cookie settings for the colour scheme
      if (ie4 && getCookieValue('Scheme') == null)
      {
         options += '    ' + CreateLink('#none', 'Click here to enlarge the text size on this page.', 'JavaScript:toggleLargePrint(); return false;', 'BIG / LITTLE TEXT') + '<BR><BR>\n';
      }

      options += '    ' + CreateLink('JavaScript:window.external.AddFavorite(document.location, document.title)', 'Click here to add this page to your favourites folder.', '', 'Add to favourites') + '<BR><BR>\n';

      if (ie55 || ie6)
      {
         options += '    <B>Magnify the Page</B><BR>\n';
         options += '    ' + CreateLink('#none', 'Click here to zoom back to normal size.', 'document.body.style.zoom = \'100%\'; return false;', 'Zoom to x1') + '<BR>\n';
         options += '    ' + CreateLink('#none', 'Click here to zoom to x1.5 magnification.', 'document.body.style.zoom = \'150%\'; return false;', 'Zoom to x1.5') + '<BR>\n';
         options += '    ' + CreateLink('#none', 'Click here to zoom to x2 magnification.', 'document.body.style.zoom = \'200%\'; return false;', 'Zoom to x2') + '<BR>\n';
         options += '    ' + CreateLink('#none', 'Click here to zoom to x4 magnification.', 'document.body.style.zoom = \'400%\'; return false;', 'Zoom to x4') + '<BR>\n';
         options += '  <BR>\n';
      }


      if (Code != 'SR')
      {
         options += '    ' + CreateLink('#none', 'Click here to hide the NCVS Toolbar.', 'JavaScript:toggleNavbarTable(); return false;', '<B>W</B>idescree<B>N</B>') + '<BR>\n';
         options += '  <BR>\n';
      }
      options += '  </TD>\n';
      options += tableright;
   }

   // Services table (for Snippets  or search results)
   if (Code == 'S' || Code == 'SR')
   {
      options += WriteOptionHeader('<SPAN CLASS="hidden">NCVS</SPAN> Services');
      options += '    ' + CreateLink('mailto:&#110;&#099;&#118;&#115;&#064;&#110;&#111;&#116;&#116;&#105;&#110;&#103;&#104;&#097;&#109;&#099;&#118;&#115;&#046;&#099;&#111;&#046;&#117;&#107;?Subject=Website feedback', 'Click here to contact us.', '', 'Contact us') + '<BR><BR>\n';
      options += '    ' + CreateLink(TheIndent + '\index.htm', 'Click here to get back to the NCVS home page.', '', 'NCVS Homepage') + '<BR>\n';
      options += '  </TD>\n';
      options += tableright;
   }


   // Extra stuff for the rest of the site
   if (Code == 'X')
   {
      options += WriteOptionHeader(' ');
      options += '    ' + CreateLink('mailto:&#110;&#099;&#118;&#115;&#064;&#110;&#111;&#116;&#116;&#105;&#110;&#103;&#104;&#097;&#109;&#099;&#118;&#115;&#046;&#099;&#111;&#046;&#117;&#107;?Subject=Website feedback', 'Click here to contact us.', '', 'Contact us') + '<BR><BR>\n';
      options += '  </TD>\n';
      options += tableright;
   }



   // Write options table footer and beginning of main text cell
   options += '  </TD>\n';
   options += tablerow;
   options += '  <TD><IMG ALT="" HEIGHT="11" SRC="' + TheIndent + 'images/navbar_bottom_left.gif" WIDTH="11"></TD>\n';
   options += '  <TD CLASS="borderBottom1"><IMG ALT="" HEIGHT="1" SRC="' + TheIndent + 'images/blank.gif" WIDTH="1"></TD>\n';
   options += '  <TD><IMG ALT="" HEIGHT="11" SRC="' + TheIndent + 'images/navbar_bottom_right.gif" WIDTH="11"></TD>\n';
   options += tablefoot;
   options += '  </TD>\n';
   options += '  <TD VALIGN="TOP" STYLE="word-wrap: break-word;">\n';
   options += '<SPAN CLASS="hidden">Page Contents</SPAN>';

   // Write the options tables
   document.write(options);

   // Make the main menu visible
   mnuHomediv.style.display = "block";
}

//------------------------------------------------------------------
// Writes out the header part at the top on option tables on the left
// Takes title
//------------------------------------------------------------------
function WriteOptionHeader(title)
{
   var tableHeader = '';
   tableHeader += tablerow;
   tableHeader += tableleft;
   tableHeader += '  <TD CLASS="borderBottom"><SPAN CLASS="blue"><BIG>' + title + '</BIG></SPAN></TD>\n';
   tableHeader += tableright;
   tableHeader += tablerow;
   tableHeader += tableleft;
   tableHeader += '  <TD>&nbsp;</TD>\n';
   tableHeader += tableright;
   tableHeader += tablerow;
   tableHeader += tableleft;
   tableHeader += '  <TD>\n';
   return tableHeader;
}

//-MISC-FUNCTIONS------------------------------------------------------------------------------------------------------------------

//------------------------------------------------------------------
// Create a hyperlink to a page including status text
// Takes URL, description for use as tooltip and status bar, click code and page text
//------------------------------------------------------------------
function CreateLink(URL, description, click, text)
{
   return '<A HREF="' + URL + '" TITLE="' + description + '" ONCLICK="' + click + '" ONMOUSEMOVE="window.status=\'' + description + '\' " ONMOUSEOUT="window.status=\'\'">' + text + '</A>';
}

//------------------------------------------------------------------
// Create a title hyperlink to a page including status text
// Takes URL, description for use as tooltip and status bar, click code and page text
//------------------------------------------------------------------
function CreateTitleLink(URL, description, click, text)
{
   return '<A CLASS="title" HREF="' + URL + '" TITLE="' + description + '" ONCLICK="' + click + '" ONMOUSEMOVE="window.status=\'' + description + '\' " ONMOUSEOUT="window.status=\'\'">' + text + '</A>';
}

//------------------------------------------------------------------
// Gets a cookie value
// Takes cookie name
//------------------------------------------------------------------
function getCookieValue(name)
{
   var cookieName = name + '=';
   var cookie = document.cookie;

   if (cookie.length > 0)
   {
      begin = cookie.indexOf(cookieName);
      if (begin != -1)
      {
         begin += cookieName.length;
         end = cookie.indexOf(';', begin);
         if (end == -1)
            end = cookie.length;
         return unescape(cookie.substring(begin, end));
      }
   }
   return null;
}

//------------------------------------------------------------------
// Hides or shows the side navbar table
//------------------------------------------------------------------
function toggleNavbarTable()
{
   var frameDoc = document.frames("Frame1").document;

   if (navbar.style.display == 'none')
   {
      navbar.style.display = 'block';
      navbar.innerHTML = navbar.navText;
      navbar.navText = '';
      wide.innerHTML = "<B>W</B>idescree<B>N</B>";
      wide.title = 'Click here to hide the NCVS Toolbar.';

      if (getCookieValue('Scheme') == null)
         frameDoc.body.onclick();
      else
         frameDoc.body.onmousedown();
   }
   else
   {
      navbar.style.display = 'none';
      navbar.navText = navbar.innerHTML;
      navbar.innerHTML = '';
      wide.innerHTML = "Show NCVS Toolbar";
      wide.title = 'Click here to show the NCVS Toolbar.';

      if (frameDoc.body != null)
      {
         if (getCookieValue('Scheme') == null)
            frameDoc.body.ondblclick();
         else
            frameDoc.body.onmouseup();
      }
   }
}

//------------------------------------------------------------------
// Hides or shows the side navbar table
//------------------------------------------------------------------
function toggleLargePrint()
{
   // Get a reference to the stylesheet
   var stylesheet = document.styleSheets(0);

   if (stylesheet.rules.length == 13)
   {
      stylesheet.addRule('A', 'font-size: x-large; font-weight: bold;');
      stylesheet.addRule('H3', 'font-size: large;');
      stylesheet.addRule('TD', 'font-size: large;');
   }
   else
   {
      stylesheet.removeRule(13);
      stylesheet.removeRule(13);
      stylesheet.removeRule(13);
   }
}