// Library Javascript

// we love macromedia and use it 3 times a day
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

//
//Dealing with Flash
//
var movieName = "theFlash";

function thisMovie(movieName) {
  // IE and Netscape refer to the movie object differently.
  // This function returns the appropriate syntax depending on the browser.
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[movieName]
  }	else {
    return document[movieName]
  }
}

// Checks if movie is completely loaded.
// Returns true if yes, false if no.
function movieIsLoaded (theMovie) {
  if (typeof(theMovie) != "undefined") {
    return theMovie.PercentLoaded() == 100;
  } else {
    return false;
  }
}


function playmovie() {
  if (movieIsLoaded(thisMovie(movieName))) {
    thisMovie(movieName).Play();
  }
}

function stopmovie() {
  if (movieIsLoaded(thisMovie(movieName))) {
    thisMovie(movieName).StopPlay();
  }
}

//
// Tab Functions
// 
function autoTabs() {
 var g,b,k,f,args=autoTabs.arguments;a=parseInt(args[0]);if(isNaN(a))a=0;
 if(!document.p7setc){p7c=new Array();document.p7setc=true;for(var u=0;u<10;u++){
 p7c[u]=new Array();}}for(k=0;k<p7c[a].length;k++){if((g=MM_findObj(p7c[a][k]))!=null){
 b=(document.layers)?g:g.style;b.zIndex="30000";}}for(k=1;k<args.length;k++){
 if((g=MM_findObj(args[k]))!=null){b=(document.layers)?g:g.style;b.zIndex="40000";f=false;
 for(var j=0;j<p7c[a].length;j++){if(args[k]==p7c[a][j]) {f=true;}}
 if(!f){p7c[a][p7c[a].length++]=args[k];}}}
  stopmovie();
}

function toggleTabPanel() {
  var i,p,v,obj,args=toggleTabPanel.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'40000':(v=='hide')?'30000':v; }
    obj.zIndex=v; }
	playmovie();
}

// for onmouseover events etc not affected by child elements

function xContains (container, containee) {
  var isParent = false;
  do {
    if ((isParent = container == containee))
      break;
    if(containee)
	    containee = containee.parentNode;

  }
  while (containee != null);
  return isParent;
}

function triggerMouseArea(e,el)
{
	var rel = (window.event) ? e.toElement : e.relatedTarget;
	
	return !(xContains(el,rel));
}


// form field focus stuff
// add-hide default input text and emulate :focus pseudo-class for IE

function prepInput( id,text ) {
	//check that getElementById is supported and element exists
	if (!document.getElementById(id)) { return false; }	
		var elem = document.getElementById(id);
		// assign holder text to input
		elem.setAttribute('value', text);
		// store class name
		var origClass = elem.className;
		// add 'onfocus' behaviour
		elem.onfocus = function() {
			// append 'focus' to class, emulates :focus pseudo-class for IE 
			this.className += " focus";
			// auto selection of text
			this.select();
		}
		// return class name to origClass after element loses focus
		elem.onblur = function() {
			this.className = origClass;	
		}
}

function addEvent(elm, evType, fn, useCapture) {
  // cross-browser event handling for IE5+, NS6 and Mozilla 
  // By Scott Andrew 
  if (elm.addEventListener) { 
    elm.addEventListener(evType, fn, useCapture); 
    return true; 
  } else if (elm.attachEvent) { 
    var r = elm.attachEvent('on' + evType, fn); 
    return r; 
  } else {
    elm['on' + evType] = fn;
  }
}

