/*
 * Common.js
 *
 * JavaScript to provide a common place
 *  for maniuplation of stuff that is common
 *  to pages on the site.
 *
 * Some access is restricted, this is provided
 *  by the host, by requiring a username and
 *  password for access to a directory.  This
 *  directory is named Restriced, and contains
 *  all the files that need to be protected.
 *
 *
 * WFH OnTarget  7/2005
 * -EdA-
 */


// Paths to local files
var ImagePath = "Images/";
var ButtonImagePath = "Images/btn/";
var BannerImagePath = "Images/bnr/";

// Some files require restricted access.
//  These are placed into a subdirectory,
//  and protected by the host.
var RestrictedPath = "Restricted/";

var clockcolor = "";

// Trick to see if a variable has been assigned a value.
//  Test for equality to the following.
var undefined;

//////////////////////////////////////////////////////////////////////////
// Routine for clocks
function displayTime() {

document.frmTucsonTime.txtTucsonTime.value = calcTime('-7', 'Tucson');
//document.frmTucsonTime.txtTucsonTime.style.backgroundColor = clockcolor;
    if (clockcolor == 'day')
	{document.frmTucsonTime.txtTucsonTime.style.backgroundImage="url(http://www.otsscorp.com/Images/day2.jpg)";
	document.frmTucsonTime.txtTucsonTime.style.color="black";}
    else		
	{document.frmTucsonTime.txtTucsonTime.style.backgroundImage="url(http://www.otsscorp.com/Images/night2.jpg)";
	document.frmTucsonTime.txtTucsonTime.style.color="fuchsia";}

document.frmCRTime.txtCRTime.value = calcTime('-6', 'CR');
//document.frmCRTime.txtCRTime.style.backgroundColor = clockcolor;
    if (clockcolor == 'day')
	{document.frmCRTime.txtCRTime.style.backgroundImage="url(http://www.otsscorp.com/Images/day2.jpg)";
	document.frmCRTime.txtCRTime.style.color="black";}
    else		
	{document.frmCRTime.txtCRTime.style.backgroundImage="url(http://www.otsscorp.com/Images/night2.jpg)";
	document.frmCRTime.txtCRTime.style.color="fuchsia";}

document.frmEuropeTime.txtEuropeTime.value=nd = calcTime('1', 'Europe');
//document.frmEuropeTime.txtEuropeTime.style.backgroundColor = clockcolor;
    if (clockcolor == 'day')
	{document.frmEuropeTime.txtEuropeTime.style.backgroundImage="url(http://www.otsscorp.com/Images/day2.jpg)";
	document.frmEuropeTime.txtEuropeTime.style.color="black";}
    else		
	{document.frmEuropeTime.txtEuropeTime.style.backgroundImage="url(http://www.otsscorp.com/Images/night2.jpg)";
	document.frmEuropeTime.txtEuropeTime.style.color="fuchsia";}



document.frmPenangTime.txtPenangTime.value = calcTime('8', 'Penang');
//document.frmPenangTime.txtPenangTime.style.backgroundColor = clockcolor;
    if (clockcolor == 'day')
	{document.frmPenangTime.txtPenangTime.style.backgroundImage="url(http://www.otsscorp.com/Images/day2.jpg)";
	document.frmPenangTime.txtPenangTime.style.color="black";}
    else		
	{document.frmPenangTime.txtPenangTime.style.backgroundImage="url(http://www.otsscorp.com/Images/night2.jpg)";
	document.frmPenangTime.txtPenangTime.style.color="fuchsia";}



document.frmShanghaiTime.txtShanghaiTime.value = calcTime('8', 'Shanghai');
//document.frmShanghaiTime.txtShanghaiTime.style.backgroundColor = clockcolor;
    if (clockcolor == 'day')
	{document.frmShanghaiTime.txtShanghaiTime.style.backgroundImage="url(http://www.otsscorp.com/Images/day2.jpg)";
	document.frmShanghaiTime.txtShanghaiTime.style.color="black";}
    else		
	{document.frmShanghaiTime.txtShanghaiTime.style.backgroundImage="url(http://www.otsscorp.com/Images/night2.jpg)";
	document.frmShanghaiTime.txtShanghaiTime.style.color="fuchsia";}



document.frmCaviteTime.txtCaviteTime.value = calcTime('8', 'Cavite');
    if (clockcolor == 'day')
	{document.frmCaviteTime.txtCaviteTime.style.backgroundImage="url(http://www.otsscorp.com/Images/day2.jpg)";
	document.frmCaviteTime.txtCaviteTime.style.color="black";}
    else		
	{document.frmCaviteTime.txtCaviteTime.style.backgroundImage="url(http://www.otsscorp.com/Images/night2.jpg)";
	document.frmCaviteTime.txtCaviteTime.style.color="fuchsia";}
//rgb(255,255,255)

}
//////////////////////////////////////////////////////////////////////////
// Routine for clocks
// function to calculate local time
// in a different city
// given the city's UTC offset
function calcTime(offset, location) {	
    // make array with days of week
    var weekday=new Array(7);
    weekday[0]="SUN";
    weekday[1]="MON";
    weekday[2]="TUE";
    weekday[3]="WED";
    weekday[4]="THUR";
    weekday[5]="FRI";
    weekday[6]="SAT";
	
    // create array with months
    var month=new Array(12);
    month[0]="JAN";
    month[1]="FEB";
    month[2]="MAR";
    month[3]="APR";
    month[4]="MAY";
    month[5]="JUN";
    month[6]="JUL";
    month[7]="AUG";
    month[8]="SEP";
    month[9]="OCT";
    month[10]="NOV";
    month[11]="DEC";

    // create Date object for current location
    d = new Date();
   
    // convert to msec
    // add local time zone offset
    // get UTC time in msec
    utc = d.getTime() + (d.getTimezoneOffset() * 60000);
   
    // create new Date object for different city
    // using supplied offset
    nd = new Date(utc + (3600000*offset));

    var hrs = nd.getHours();
    var min = nd.getMinutes();
    var sec = nd.getSeconds();		
    if (hrs>6 && hrs<18)
       {clockcolor = 'day';}
    else		
       {clockcolor = 'night';}
    // build the time for 24hr clock
    hrs = checkTime(hrs);	
    min = checkTime(min);
    sec = checkTime(sec);	
    var tm=hrs+":"+min+":"+sec;
    // build date
    var dt = weekday[nd.getDay()];
    dt = dt+" "+month[nd.getMonth()];
    dt = dt+" "+nd.getDate();
    // concat date and time
    var dttm = dt+"\r"+tm;
    return dttm;

}

//////////////////////////////////////////////////////////////////////////
// This function places a zero in front of numbers below 10
// used by CalcTime

function checkTime(i)
{
if (i<10)
  {
  i="0" + i;
  }
return i;
}


//////////////////////////////////////////////////////////////////////////
// Routine for ballcounter - Not used jr 4/10/08
function ballcount() {
var BallsPerMs = 0;
var strMs ="";
var i = 2;
var txtMs ="";
BallsPerMs = 4;
time=new Date();
ms = time.getTime();
ms = ms - 757382400000;      // Number of ms since 1994
ms = ms * BallsPerMs;
var strMs = ms.toString();
for (i=strMs.length; i>=3; i= i-3)
{
 if (i == strMs.length)
  {txtMs = strMs.substring(i-3,i) + txtMs;}
 else
  {txtMs = strMs.substring(i-3,i) + "," + txtMs;}
} 
document.frmBallCnt.txtBallCnt.value=txtMs;
}



//////////////////////////////////////////////////////////////////////////
// Routine to place the logo, and selected banner at the top of the page.
//
// arg name used for image selection file name, and anchor definition
// arg restricted is boolean, indicating whether the target for the
//   anchor is in the restricted subdirectory.
//
// jr 10/2/07 changed otsslogo.jpg to otsslogo.gif
// jr 11/10/07 Not being used, but we'll save it to use later
function Banner(name, showlogo)
{
  var LogoFile = ImagePath + 'OTSSLogo.gif';
  var BannerFile = BannerImagePath + 'bnr' +  name + '.gif';
  var BannerBar = BannerImagePath + 'bnrBar.gif';
  var BannerRem = BannerImagePath + 'bnrGlobLeft.gif';

  var BannerLogo = BannerImagePath + 'bnrBarLogo.gif';

  // Load the BIG logo image
  if (showlogo != undefined)
  {
    document.write('<p>');
    document.write('<img src="' + LogoFile + '" alt="[OnTarget Logo Image]" border="0" >');
    document.write('</p>');
  }
  // To make the banner variable width, it is built in a table with a fixed number of pixels
  //  for the globe part, and expanding 'bar' to fill the display.
  //  These will be the full width of the users display
  document.write('<table border="0" cellpadding="0" cellspacing="0" width="100%">');
  document.write('<tr>');

  // First column is the label
  // Load the banner image based on arguemnt
  document.write('<td width="140">');
  document.write('<img src="' + BannerFile + '" height="110" border="0" alt="OnTarget ' + name + ' Banner">');
  document.write('</td>');

  // Next column is the remainder of the globe image
  document.write('<td width="352">');
  document.write('<img src="' + BannerRem + '" height="110" border="0" alt="OnTarget ' + name + ' Banner">');
  document.write('</td>');

  
  // Populate the rest of the width by stretching the 'bar'
  document.write('<td>');
  document.write('<img src="' + BannerBar + '" height="110" width="36px" border="0" alt="OnTarget ' + name + ' Banner">');
  document.write('</td>');

  //add empty column to fill width of page	
  document.write('<td style="width: 100%;"></td>'); 

  // Load the logo image on the bar if not the big logo
  if (showlogo == undefined)
  {
    // Attempt at the logo'ed bar
    document.write('<td width="200">');
    document.write('<img src="' + BannerLogo + '" width: 323px; height: 100px border="0" alt="OnTarget ' + name + ' Banner">');
    document.write('</td>');
  }

  // End the table
  document.write('</tr></table>');

  // Horizontal rule
  document.write("<hr>");
}


//////////////////////////////////////////////////////////////////////////
// Write out the footer that is commmon to all pages
function Footer()
{

  document.write('<table border="0" cellpadding="0" cellspacing="0" width="100%">');
  document.write('  <tr>');
  document.write('    <td>');
//<!-- Navigation buttons -->
  document.write('      <p>');
  document.write('        [<a href="Home.htm">Home</a>]');
  document.write('        [<a href="Products.htm">Products</a>]');
  document.write('        [<a href="Services.htm">Services</a>]');
  document.write('        [<a href="Downloads.htm">Downloads</a>]');

  // rem jr 10/2/07 document.write('<img src="Images/OTSSLogo2.gif" alt="Logo" style="width: 200px; height: 56px;" align="right">');

  document.write('      </p>');
//<!-- Footer -->
  document.write('      <h6>Send mail to');
  document.write('        <a href="mailto:webmaster@otsscorp.com">');
  document.write('           webmaster@otsscorp.com');
  document.write('        </a> with questions or comments about this website.<br>');
  document.write('        Copyright © 2005, 2006, 2007, 2008 OnTarget Systems &amp; Services Inc.<br>');
  document.write('        Last modified: 07/12/2008 </h6>');
  document.write('    </td>');
  document.write('  </tr>');
  document.write('</table>');
}

/////////////////////////////////////////////////////////////////////////
//
//  NONE OF THIS NAVLIST STUFF IS USED IN THE NEWER VERSION OF THIS WEB SITE
//  USE menu_var.js and menu_com.js   jr 4/12/08
//////////////////////////////////////////////////////////////////////////
// Build the HTML to put the navigation list on
//  the left of the screen.
//
// arg name used for image selection file name, and anchor definition
// arg restricted is boolean, indicating whether the target for the

// This is what I want to end up with
//   anchor is in the restricted subdirectory.
//      <li><a href="Home.htm">
//        <img src="Images/ButtonHome.gif" alt="Home" style="border:0px; solid"
//        onMouseOver="src='Images/ButtonHomeOver.gif'"
//        onMouseOut="src='Images/ButtonHome.gif'"
//        ></a></li>

// name is for finding the button
// selected is whether selected image is used
// source is for next nav
function NavListLeft(name, selected, source)
{
  // Set-up for file names for buttons and link
  var strLink;
  if (name == "Home")
    strLink = "index.phtml";
  else
    strLink = name + '.htm';
  var strFileOut = ButtonImagePath + 'btn' + name + '.gif';
  var strFileOver = ButtonImagePath + 'btn' + name + 'Over.gif';
  var strFileSel = ButtonImagePath + 'btn' + name + 'Sel.gif';

  // Build strings for buttons navigation assignment
  var HTMLsrc;          // Button src image name
  var HTMLalt;          // Button alt text command
  var HTMLsty;          // Button style command
  var HTMLmov;          // Button mouse over command

  if (selected)         // This button selected
    HTMLsrc = ' src="' + strFileSel + '"';
  else
    HTMLsrc = ' src="' + strFileOut + '"';

  HTMLalt = ' alt="' + name + '"';
  HTMLsty = ' style="border:0px;solid"';
  HTMLmov = ' onMouseOver="src=' + "'" + strFileOver + "'" + '"';

  if (selected)
    HTMLmou = ' onMouseOut="src=' + "'" + strFileSel + "'" + '"';
  else
    HTMLmou = ' onMouseOut="src=' + "'" + strFileOut + "'" + '"';

  // For shared pages, add the source to the link
  if (source!=undefined)
    strLink = source
  var HTML = '<li><a href="' + strLink + '"><img "' + HTMLsrc + HTMLsty + HTMLalt + HTMLmov + HTMLmou + '></a></li>';

// TODO Pre-load the 'over' images
//  img1 = new Image();
//  img1.src = strFileOver;
//  img1.src = strFileSel;

  document.write(HTML);
}


//////////////////////////////////////////////////////////////////////////
// Build the Products->OTS6300 submenu
//  selected changes highlight for selected item
function NavList6300(selected)
{
   NavListLeft('Benefits',       selected == 'Benefits',      'OTS6300Benefits.htm');
   NavListLeft('Features',       selected == 'Features',      'OTS6300Features.htm');
   NavListLeft('Options',        selected == 'Options',       'OTS6300Options.htm');
   NavListLeft('Specifications', selected == 'Specifications','OTS6300Specifications.htm');
   NavListLeft('Packages',       selected == 'Packages',      'OTS6300Packages.htm');
   NavListLeft('Handlers',       selected == 'Handlers',      'OTS6300Handlers.htm');
   NavListLeft('Inspection',     selected == 'Inspection',    'OTS6300Inspection.htm');
   NavListLeft('Download',       selected == 'Download',      'Downloads6300.htm');
}

//////////////////////////////////////////////////////////////////////////
// Build the Products->OTS5020 submenu
//  selected changes highlight for selected item
function NavList5020(selected)
{
   NavListLeft('Benefits',       selected == 'Benefits',      'OTS5020Benefits.htm');
   NavListLeft('Features',       selected == 'Features',      'OTS5020Features.htm');
   NavListLeft('Options',        selected == 'Options',       'OTS5020Options.htm');
   NavListLeft('Specifications', selected == 'Specifications','OTS5020Specifications.htm');
   NavListLeft('Packages',       selected == 'Packages',      'OTS5020Packages.htm');
   NavListLeft('Download',       selected == 'Download',      'Downloads5020.htm');
}

//////////////////////////////////////////////////////////////////////////
// The nav list for the downloads section built here
function NavListDownloads(selected)
{
//   NavListLeft('OTS150',         selected == 'OTS150',         'Downloads150.htm');
//   if (selected == 'OTS150') NavListDownloadsKeys();

//   NavListLeft('OTS180',         selected == 'OTS180',         'Downloads180.htm');
//   if (selected == 'OTS180') NavListDownloadsKeys();

//   NavListLeft('OTS300',         selected == 'OTS300',         'Downloads300.htm');
//   if (selected == 'OTS300') NavListDownloadsKeys();

   NavListLeft('OTS5020',        selected == 'OTS5020',        'Downloads5020.htm');
   if (selected == 'OTS5020') NavListDownloadsKeys();

   NavListLeft('OTS5100',        selected == 'OTS5100',        'Downloads5100.htm');
   if (selected == 'OTS5100') NavListDownloadsKeys();

   NavListLeft('OTS5200',        selected == 'OTS5200',        'Downloads5200.htm');
   if (selected == 'OTS5200') NavListDownloadsKeys();

   NavListLeft('OTS5300',        selected == 'OTS5300',        'Downloads5300.htm');
   if (selected == 'OTS5300') NavListDownloadsKeys();

   NavListLeft('OTS5500',        selected == 'OTS5500',        'Downloads5500.htm');
   if (selected == 'OTS5500') NavListDownloadsKeys();

   NavListLeft('OTS6300',        selected == 'OTS6300',        'Downloads6300.htm');
   if (selected == 'OTS6300') NavListDownloadsKeys();

   NavListLeft('Vision',         selected == 'Vision',         'DownloadsVision.htm');
   if (selected == 'Vision') NavListDownloadsKeysVision();

   NavListLeft('General',        selected == 'General',        'DownloadsGeneral.htm');
//   if (selected == 'General') NavListDownloadsKeys();

}


function NavListDownloadsKeys()
{
   document.write('<ul class="navbar3">');
     NavListLeft('Manuals',    false, '#Manuals' );
     NavListLeft('Schematics', false, '#Schematics' );
     NavListLeft('Software',   false, '#Software' );
     NavListLeft('Updates',    false, '#Updates' );
     NavListLeft('Training',   false, '#Training' );
     NavListLeft('Other',      false, '#Other' );
   document.write('</ul>');
}

function NavListDownloadsKeysVision()
{
   document.write('<ul class="navbar3">');
     NavListLeft('Manuals',    false, '#Manuals' );
//     NavListLeft('Schematics', false, '#Schematics' );
     NavListLeft('Software',   false, '#Software' );
     NavListLeft('Updates',    false, '#Updates' );
     NavListLeft('Training',   false, '#Training' );
     NavListLeft('Other',      false, '#Other' );
   document.write('</ul>');
}
//////////////////////////////////////////////////////////////////////////
// Put this stuff in here so that a common presentation of the
//  downloads format is preserved
// Download category heading, also assigns tag for nav link
function DownloadEntry(relpath, description)
{
  var HTMLSource;       // Source file spec
  var HTMLLink;
  var HTMLStr;
  var fname;

  var strImage;

  HTMLSource = RestrictedPath + relpath;

  // strip path to just filename
  fname = relpath.substring(relpath.lastIndexOf("/")+1);

  if (relpath.substring(relpath.lastIndexOf(".")) == ".pdf")
  {
    HTMLLink = "[PDF]";
    strImage = ImagePath + 'AdobePDF.gif';
  }
  else if (relpath.substring(relpath.lastIndexOf(".")) == ".zip")
  {
    HTMLLink = "[ZIP]";
    strImage = ImagePath + 'Zip.gif';
  }
  else
  {
    HTMLLink = "VIEW";
  }


//  HTMLStr = '<li><a href="' + HTMLSource + '">' + fname + '</a> - ' + description + '</li>';

//HTMLStr = '<li>' + description + " " +'<a href="' + HTMLSource + '">' + HTMLLink  + '</a></li>';


// Testing for logo's
  HTMLStr = '<li class="dwnld1">' + description + ' ' +'<img src="' + strImage + '"><a href="' + HTMLSource + '">' + HTMLLink  + '</a></li>';



  document.write(HTMLStr);
}


//////////////////////////////////////////////////////////////////////////
//
function DownloadHeading(label, description)
{
  var HTMLStr;       // Source file spec

  HTMLStr = '<ul class="dwnld1"><a name=' + label + '><h3>' + description + '</h3></a>';

  document.write(HTMLStr);
}

//////////////////////////////////////////////////////////////////////////
//
function DownloadHeadingEnd()
{
  var HTMLStr;       // Source file spec

  HTMLStr = '</ul>';
  document.write(HTMLStr);
}


