// main javascript functions for AAM web site



/* ***********************************************************
Example 4-5 (DHTMLapi.js)
"Dynamic HTML:The Definitive Reference"
by Danny Goodman
Published by O'Reilly & Associates  ISBN 1-56592-494-0
http://www.oreilly.com
Copyright 1998 Danny Goodman.  All Rights Reserved.
************************************************************ */
// DHTMLapi.js custom API for cross-platform
// object positioning by Danny Goodman (http://www.dannyg.com)

// Global variables
var isNav, isIE
var coll = ""
var styleObj = ""
if (parseInt(navigator.appVersion) >= 4) {
  if (navigator.appName == "Netscape") {
    isNav = true
  } else {
    isIE = true
    coll = "all."
    styleObj = ".style"
  }
}

// Convert object name string or object reference
// into a valid object reference
function getObject(obj) {
  var theObj
  if (typeof obj == "string") {
    theObj = eval("document." + coll + obj + styleObj)
  } else {
    theObj = obj
  }
  return theObj
}

// Positioning an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
  var theObj = getObject(obj)
  if (isNav) {
    theObj.moveTo(x,y)
  } else {
    theObj.pixelLeft = x
    theObj.pixelTop = y
  }
}

// Moving an object by x and/or y pixels
function shiftBy(obj, deltaX, deltaY) {
  var theObj = getObject(obj)
  if (isNav) {
    theObj.moveBy(deltaX, deltaY)
  } else {
    theObj.pixelLeft += deltaX
    theObj.pixelTop += deltaY
  }
}

// Setting the z-order of an object
function setZIndex(obj, zOrder) {
  var theObj = getObject(obj)
  theObj.zIndex = zOrder
}

// Setting the background color of an object
function setBGColor(obj, color) {
  var theObj = getObject(obj)
  if (isNav) {
    theObj.bgColor = color
  } else {
    theObj.backgroundColor = color
  }
}

// Setting the visibility of an object to visible
function show(obj) {
  var theObj = getObject(obj)
  theObj.visibility = "visible"
}

// Setting the visibility of an object to hidden
function hide(obj) {
  var theObj = getObject(obj)
  theObj.visibility = "hidden"
}

// Retrieving the x coordinate of a positionable object
function getObjectLeft(obj)  {
  var theObj = getObject(obj)
  if (isNav) {
    return theObj.left
  } else {
    return theObj.pixelLeft
  }
}

// Retrieving the y coordinate of a positionable object
function getObjectTop(obj)  {
  var theObj = getObject(obj)
  if (isNav) {
    return theObj.top
  } else {
    return theObj.pixelTop
  }
}

// Utility function returns the available content width space in browser window
function getInsideWindowWidth(){
  if (isNav) {
    return window.innerWidth
  } else {
    return document.body.clientWidth
  }
}
// Utility function returns the available content height space in browser window
function getInsideWindowHeight() {
  if (isNav) {
    return window.innerHeight
  } else {
    return document.body.clientHeight
  }
}


/* *********************************************************** */

// mta stuff


// function to insert space
// syntax: spacer(<x space> <y space> <distance from top level>)

// arguments are in pixels
// NB if either argument is 0, then this function makes it 1
// as a zero height/width gif doesn't make sense
//
// This uses top.location to determine the url of the /pics directory
// and can therefore be run from anywhere.


function spacer(x,y){
  var basehref= top.location.protocol + "//" + top.location.hostname + top.location.pathname;
  var newlength;

  //basehref will be http:www.aam.co.uk online and file:/C:\aam\NEW\INDEX.HTM (or similar) //
  // when offline                                                                          //

  if(basehref.indexOf("aam.co.uk")>0){ // online
    }
  else{  // offline

    if(
      (basehref.indexOf("index.htm")<0)&&
      (basehref.indexOf("Index.htm")<0)&&
      (basehref.indexOf("INDEX.HTM")<0)
      ){
      // alert("spacer called when top.location is not pointing to index.htm");
      }
    else{
      newlength=basehref.length-"index.htm".length;

      basehref=basehref.substring(0,newlength);
    }
  }

  if((x>0) & (y>0)){
    document.write("<img src='" + basehref + "pics/5x5.gif' width=" + x + " height= " + y + ">");
  }
  if(arguments.length==3){document.write(arguments[2]);}
}



// function to check to see if we are in the right frame
// and open the contents of the current page there
// (if we are in inherited frames or the wrong frame)

function checkname(name,url){
  if(self.name!=name){
    location.replace(url);
  }
}


// procs fo allow pages wrongly called outside of frames to reposition themselves

function BreakOutOfFrames(){
  if (window != top) top.location.href = location.href;
}

// top.replacearr and top.newarr are declared in index.htm

// proc to set things up at the top level

function PrepareTopLevel(){

  // first remove the "?"

  var searchstr=new String();
  var tmparr=new Array();

  if(location.search.indexOf("?")>-1){
    searchstr=location.search.substr(1);
    searchstr=unescape(searchstr);
    tmparr=searchstr.split("&");
    var i;
    var j;  // a write index, this need not equal i, as js arrays are sparse

    j=0;
    for(i=0;i<tmparr.length;i++){
      ptr=tmparr[i].indexOf(">");
      if(ptr>-1){
        replacearr[j]=tmparr[i].slice(0,ptr);
        newarr[j]=tmparr[i].slice(ptr+1);
        j++;
      }
    }

    }
  else{
    searchstr="";
  }
}


// proc to force frames, and to reload frames as needed
// this relies on replacearr and newarr being declared
// and PrepareTopLevel() being run at the top level of
// the frameset.

// This works by testing to see if the frame name
// fails to match the name supplied in the "name"
// argument.

// If the path argument is empty then the top level frameset is loaded

// If path is not empty, then it is assumed to be a string
// of the form <framename="fileto replace with">, and when
// the frameset is loaded, that frame gets replaced.

// topurl is the url of the top level frameset relative to this file

function PutInFrames(name, path, topurl){
  if(name.length<1)error("PutInFrames called with no first argument");
  if(topurl.length<1)error("PutInFrames called with no first argument");
  var i;
  var namefound=0;

  var names_arr=new Array();

  names_arr=name.split("OR");

  for(i=0;i<names_arr.length;i++){
    if(self.name==names_arr[i])namefound=1;

  }


  if(namefound!=1){
    if(path.indexOf(".htm")>0){
      top.location.replace(topurl + "?" + path);
      }
    else{
      top.location.replace(topurl);
    }
    }
  else{
    // now do any re-loading that might be passed through top.replacearr
    var i;
    var indfound=-1;
    for(i=0;i<top.replacearr.length;i++){
      if(self.name==top.replacearr[i])indfound=i;
    }

    if(indfound!=-1){
      var newurl=top.newarr[indfound];

      // here I want to use splice() but it's not in IE 5, so we do it by hand (grr)

      for(i=indfound+1;i<top.replacearr.length;i++){
        top.replacearr[i-1]=top.replacearr[i];
        top.newarr[i-1]=top.newarr[i];
      }
      top.replacearr.length=top.replacearr.length-1;
      top.newarr.length=top.newarr.length-1;

      location.replace(newurl);
    }
  }
}


function onLoadProc(){
  //Preloadpics();
}

function onUnloadProc(){
  //DeleteLastImage();
}



// function to force very soft reloading of pages when browser resizes

function onResizeProc(){history.go(0);}


// function to hide email addresses from robots


var mto="m" + "a" + "i" + "l" + "t" + "o:";
var uid1="ma";
var uid2="il";
var atstr ="@";
var d0="sil";
var d1="ver";
var d2="fen.c";
var d3="om";

function blat(){
  document.write("<a href='" + mto + uid1 + uid2 + atstr + d0 + d1 + d2 + d3 + "'>");
  document.write(uid1 + uid2 + atstr + d0 + d1 + d2 + d3 + "</a>");

}



