var arrowWidth  = 25;
var arrowMargin = 5;

var IE4 = false;
var NS4 = false;
var DOM = false;
var IE5 = false;
var NS6 = false;
// Detect browser version
IE4 = (document.all           ) ? true : false;
NS4 = (document.layers        ) ? true : false;
DOM = (document.getElementById) ? true : false;
if ( DOM )
{ NS6 = ( navigator.appName == 'Netscape' );
  if ( ( navigator.userAgent.indexOf('MSIE 5') > -1 )
    || ( navigator.userAgent.indexOf('MSIE 6') > -1 )
     ) { IE4 = false; IE5 = true; }
}

// Get Object ID
function getObjectID(name)
{
  var objectID = null;
  if ( NS4 ) objectID = eval('document.name');
  if ( IE4 ) objectID = eval('document.all(name)');
  if ( DOM ) objectID = eval('document.getElementById(name)');
  return objectID;
}

// Set Visibility
function setVisibility(div,visibility)
{
  if ( NS4 )
  {
    div.visibility = visibility;
  }
  else
  {
    div.style.visibility = visibility;
  }
}

// Set Position
function setPosition(div,xPos,yPos)
{
  if ( NS4 )
  {
    div.left = xPos;
    div.top  = yPos;
  }
  else
  {
    div.style.left = xPos+'px';
    div.style.top  = yPos+'px';
  }
}

// Return browser type
function browserType()
{
  if ( IE4 || DOM ) return 'E'; else return 'N';
}

// Return browser style
function browserStyle()
{
  if ( IE4 || IE5 ) return 'IE'; else return 'N6';
}

// Strip the page name from the URL
function pageName(url)
{
  if ( !url ) url = parent.location.href;
  position = url.indexOf('/');
  while ( position >= 0 )
  {
    url = url.substring(position+1);
    position = url.indexOf('/');
  }
  return url.substring(0,url.indexOf('.'));
}

// Strip the requested page number from the URL
function pageNumber()
{
  var page = 1;
  if ( location.search )
  {
    if ( parseInt(location.search.substring(1)) > 1 )
    { 
      page = location.search.substring(1);
    }
  }
  return page;
}

// Build an URL from the page name and number
function buildURL(main,page)
{
  var url = './'+main+'.html';
  if ( page ) url = url+'?'+page;
  return url;
}

// Open a new window in full screen mode
function openWindow(main,page)
{
  var url = buildURL(main,page);
  if ( IE4 || IE5 )
  {
    window.open(url,main,'fullscreen');
  }
  if ( NS4 || NS6 )
  {
    var width  = screen.availWidth  - 10;
    var height = screen.availHeight - 30;
    var stats  = 'screenX=0,screenY=0,width='+width+',height='+height;
    window.open(url,main,stats);
  }
}

// Force navigation pages to load in their frame page
function forceFrames()
{
  if ( parent.location.href == self.location.href )
  {
    var main = pageName();
    window.location.href = buildURL(main.substring(0,main.length-1));
  }
}

// Load main page
function loadMainPage(main,page)
{
  parent.location.href = buildURL(main,page);
}

// Load first page
function loadFirstPage(page)
{
  if ( parent.location.href != self.location.href )
  {
    if ( pageName(parent.mainpage.location.href) == 'dummy' )
    {
      loadPage(page,'mainpage');
    }
  }
}

// Load page
function loadPage(page,target)
{
  if ( parent.location.href != self.location.href )
  {
    eval('parent.'+target+'.location.href="'+buildURL(page)+'"');
  }
}

// Create a new image object
function newImage(source)
{
  if ( document.images )
  {
    var result = new Image();
    result.src = './images/'+source;
    return result;
  }
}

// Load a new image
function loadImage(image,source)
{
  if ( source != null && document.images )
  {
    var url = './images/'+source;
    if ( document[image].src != url )
    {
      document[image].src = url;
    }
  }
}

// Writes a single navigation arrow
function writeArrow(type,page,direction,alt)
{
  if ( page == null )
  {
    document.write(getLine(arrowWidth,arrowWidth));
  }
  else
  {
    var iOut  = type+'1'+direction+'.gif'; arrow = newImage(iOut );
    var iOver = type+'2'+direction+'.gif'; arrow = newImage(iOver);
    var pName = pageName();
    var text = ' name="'+direction+'"'
             + ' alt="'+alt+'"'
             + ' onmouseover="loadImage(\''+direction+'\',\''+iOver+'\');"'
             + ' onmouseout="loadImage(\''+direction+'\',\''+iOut+'\');"';
    document.write(openData());
    document.write('<a href="javascript:loadPage(\''+pName+page+'\',\''+pName+'\');">');
    document.write(getImage(iOut,arrowWidth,arrowWidth,text));
    document.write('</a>');
    document.write(closeData());
  }
}

// Write the navigation arrows
function writeArrows(type,width,left,right,text)
{
  if ( !left  ) left  = null;
  if ( !right ) right = null;
  var textWidth = width - ( arrowWidth * 2 );
  document.write(openTable(width,arrowMargin+arrowWidth));
  document.write(openRow());
  document.write(getLine(arrowWidth,arrowMargin));
  document.write(getLine(textWidth ,arrowMargin));
  document.write(getLine(arrowWidth,arrowMargin));
  document.write(nextRow());
  writeArrow(type,left ,'left' ,'Previous Page');
  document.write(nextData(text,textWidth,arrowWidth,'page'));
  writeArrow(type,right,'right','Next Page'    );
  document.write(closeRow());
  document.write(closeTable());
}

function menuOut(e)
{
  null;
}
