// Finds an object by name. First looks at the documents attributes,
// then at document.all, and then iterates over all form objects.
function ww_findObj( n, d )
{
  var i,x;
  if ( d==null) {
    d=document;
  }

  // First try the document's attributes
  if ( !(x = d[n] ) && d.getElementById ) {
    // Then try the 'all' array - if its defined.
    x=d.getElementById( n );
  } else if ( !(x = d[n] ) && d.all ) {
    // Then try the 'all' array - if its defined.
    x=d.all[n];
  }
  // If still not found, look through ever form object.
  for ( i=0; !x && i < d.forms.length; i++ ) {
    x=d.forms[i][n];
  }
  return x;
}

// The following viewport functions were described here :
// http://www.quirksmode.org/viewport/compatibility.html
// Not copied verbatum, so any errors are my own.
function ww_innerWidth()
{
  if (self.innerWidth) {
    return self.innerWidth;
  } else if (document.documentElement && document.documentElement.clientWidth) {
    return document.documentElement.clientWidth;
  } else if (document.body) {
    return document.body.clientWidth;
  } else {
    return "ww_innerWidth Failed";
  }
}

function ww_innerHeight()
{
  if (self.innerHeight) {
    return self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) {
    return document.documentElement.clientHeight;
  } else if (document.body) {
    return document.body.clientHeight;
  } else {
    return "ww_innerHeight Failed";
  }
}

function ww_scrollX()
{
  if (self.pageXOffset) {
    return self.pageXOffset;
  } else if (document.documentElement && document.documentElement.scrollLeft) {
    return document.documentElement.scrollLeft;
  } else if (document.body) {
    return document.body.scrollLeft;
  } else {
    return "ww_scrollX failed";
  }
}

function ww_scrollY()
{
  if (self.pageYOffset) {
    return self.pageYOffset;
  } else if (document.documentElement && document.documentElement.scrollTop) {
    return document.documentElement.scrollTop;
  } else if (document.body) {
    return document.body.scrollTop;
  } else {
    return "ww_scrollY failed";
  }
}
// End of viewport functions.


function ww_getEventElement( event )
{
  var ele;
  alert( event );
  alert( event.srcElement );
  if (event.srcElement) {
    return event.srcElement;
  } else {
    return event.target;
  }
}


// Creates a pop-up window - usually called from an a tags on click.
function ww_popup( url, windowName, features, width, height, left, top )
{
  if ( windowName == null) windowName = "popup" + new Date().getMilliseconds();
  if ( features == null ) features = "resizable=yes,menubar=yes,toolbar=yes,scrollbars=yes";

  if ( height != null ) {
    features = features + ",height=" + height;
    if ( top == null ) {
      features = features + ",top=" + ((screen.height - height) / 2);
    } else {
      features = features + ",top=" + top;
    }
  }

  if ( width !=null ) {
    features = features + ",width=" + width;
    if ( left == null ) {
      features = features + ",left=" + ((screen.width - width) / 2);
    } else {
      features = features + ",left=" + left;
    }
  }

  var popupWindow = window.open( url, windowName, features );
  popupWindow.focus();
  return false;
}

// ****  begin IMAGE ROLLOVER functions ****
function ww_changeImage( img, imageUrl )
{
  if ( ! img.oldSrc ) {
    img.ww_oldSrc = img.src;
  }
  img.src = imageUrl;
}
function ww_restoreImage( img )
{
  if ( img.ww_oldSrc ) {
    img.src = img.ww_oldSrc;
  }
}
ww_imageCache = new Array();
function ww_cacheImage( imageUrl )
{
  var image = new Image();
  image.src = imageUrl;
  ww_imageCache[ ww_imageCache.length ] = image;
  // alert( "Cached image : " + imageUrl );
}

// ****  end IMAGE ROLLOVER functions ****


