//
// Javascript Utilities
// by Morgan Davis, DTL Networx (http://www.dtl.net)
// Copyright (C) 2004 - All Rights Reserved
//



// Browser gestalt

Browser = {
 id : function() {return navigator.userAgent;},
 isMac : function() {return this.id().indexOf("Mac") > 0;},
 isMac_IE5 : function() {return this.isIE5() && this.isMac();},
 isOpera : function() {return this.id().indexOf("Opera") > 0;},
 isSafari : function() {return this.id().indexOf("Safari") > 0;},
 isKonq : function() {return this.id().indexOf("Konqueror") > 0;},
 isGecko : function() {return !this.isOpera() && this.id().indexOf("Gecko") > 0;},
 isMoz : function() {return this.isGecko() && this.id().indexOf("Netscape") == -1;},
 isIE3 : function() {return this.id().indexOf("MSIE 3") > 0;},
 isIE4 : function() {return this.id().indexOf("MSIE 4") > 0;},
 isIE5 : function() {return !this.isOpera() && this.id().indexOf("MSIE 5") > 0;},
 isIE5_0 : function() {return !this.isOpera() && this.id().indexOf("MSIE 5.0") > 0;},
 isIE6 : function() {return !this.isOpera() && this.id().indexOf("MSIE 6") > 0;},
 hasLayers : function() {return Boolean(document.layers);},
 hasAll : function() {return Boolean(document.all);},
 hasImages : function() {return Boolean(document.images);},
 hasForms : function() {return Boolean(document.forms);},
 hasRegExp : function() {return Boolean(window.RegExp);},
 hasGEBI : function() {return Boolean(document.getElementById);},
 hasGEBTN : function() {return Boolean(document.getElementsByTagName);},
 hasActiveX : function() {return Boolean(window.ActiveXObject);},
 hasCreateDoc : function() {return Boolean(document.implementation && document.implementation.createDocument);},
 hasNoXML : function() {return this.isKonq() || this.isIE4();}
};


// Ugly but functional Macromedia standards

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;
}

// Get a style object for item by id

function getStyleObj(id) {
 var obj = MM_findObj(id);
 if (obj) {
  if ((Browser.hasGEBI() || Browser.hasAll()))
   return obj.style;
  else if (Browser.hasLayers())
   return obj;
 }
 alert("JavaScript error: could not find style object for '" + id + "'");
 return null;
}


// Gets and returns the visibility state for the item by id.
// Visibility does not reallocate space used by object.
// If optional visibility state is passed, it sets a new state.
// States:
//		hidden
//		visible

function getSetVisibility(id, state) {
 var styleObj = getStyleObj(id);
 var old = styleObj.visibility;

//alert("getSetVisibility called for id " + id + " with state " + state + " (obj = " + styleObj + ") old = " + old);

 if (state != null)
  styleObj.visibility = state;

 // Fix NS4 glitch
 if (old == 'hide')
  old = 'hidden';
 else if (old == 'show')
  old = 'visible';
 return old;
}


// Sets the visibility state of an item by id.
// If state argument is omitted, it toggles the current state.

function setVisibility(id, state) {
 if (state == null)
  state = getSetVisibility(id) == "display" ? "hidden" : "display";
 else if (state == false)
  state = 'hidden';
 else if (state == true)
  state = 'visible';
 getSetVisibility(id, state);
// return (state);
}


// Set opacity (%) on an object by id

function setOpacity(id, pct) {
 var obj = MM_findObj(id);
 if (obj.filters) {
  obj.filters("alpha").opacity = pct;
 } else if (obj.style)
  obj.style.MozOpacity = obj.style.khtmlOpacity = obj.style.opacity = pct/100;
}
