var ie4 = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true : false;

function hidelayers() {
	try {
		if(!ns4){
			var arrLayer = Array('subnav-about-us','subnav-solutions','subnav-careers','subnav-contact','subnav-community','nav-hide-button');
			var arrButton = Array('nav-about-us-button','nav-solutions-button','nav-community-button','nav-careers-button','nav-contact-button');
			
			for(var whichLayer = 0; whichLayer < arrLayer.length; whichLayer++){
				if (ie4) {document.all[arrLayer[whichLayer]].style.visibility = "hidden";}
				if (ns6) {document.getElementById([arrLayer[whichLayer]]).style.visibility = "hidden";}
			}
			
			for(var whichButton = 0; whichButton < arrButton.length; whichButton++){
				if (ie4) {document.all[arrButton[whichButton]].className = "";}
				if (ns6) {document.getElementById([arrButton[whichButton]]).className = "";}
			}
					
		}
	} catch(e) {
		//suppress errors
	}

}

function showlayer(whichLayer, parentLayer, whichClass) {
	try {
		if(whichLayer!=""){
			if (ie4) {document.all[whichLayer].style.visibility = "visible";}
			if (ns6) {document.getElementById([whichLayer]).style.visibility = "visible";}
		}
		
		if (ie4) {document.all[parentLayer].className = whichClass;}
		if (ns6) {document.getElementById([parentLayer]).className = whichClass;}	
		
		if (ie4) {document.all['nav-hide-button'].style.visibility = "visible";}
		if (ns6) {document.getElementById(['nav-hide-button']).style.visibility = "visible";}	
	} catch(e) {
		//suppress errors
	}

}

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;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


/*******************************************************
FLASH DETECT 2.5
All code by Ryan Parman and mjac, unless otherwise noted.
(c) 1997-2004 Ryan Parman and mjac
http://www.skyzyx.com
*******************************************************/

// This script will test up to the following version.
flash_versions = 20;

// Initialize variables and arrays
var flash = new Object();
flash.installed=false;
flash.version='0.0';

// Dig through Netscape-compatible plug-ins first.
if (navigator.plugins && navigator.plugins.length) {
	for (x=0; x < navigator.plugins.length; x++) {
		if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1) {
			flash.version = navigator.plugins[x].description.split('Shockwave Flash ')[1];
			flash.installed = true;
			break;
		}
	}
}

// Then, dig through ActiveX-style plug-ins afterwords
else if (window.ActiveXObject) {
	for (x = 2; x <= flash_versions; x++) {
		try {
			oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
			if(oFlash) {
				flash.installed = true;
				flash.version = x + '.0';
			}
		}
		catch(e) {}
	}
}

// Create sniffing variables in the following style: flash.ver[x]
// Modified by mjac
flash.ver = Array();
for(i = 4; i <= flash_versions; i++) {
	eval("flash.ver[" + i + "] = (flash.installed && parseInt(flash.version) >= " + i + ") ? true : false;");
}



function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) {
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
    highlightEndTag = "</font>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  
  return newText;
}


/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(){
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
	var doSearch = false;
	var referrer = document.referrer;
	var current = location.href;
	var start_position;
	var tmp
	var str = "";
	var searchText = "";
	var highlightStartTag = "<span class=\"search-phrase\">";
	var highlightEndTag = "</span>";
	var warnOnFailure = false;
	var treatAsPhrase = false;
	
	//check the referrer
	if(referrer.indexOf("/search")>0 || current.indexOf("/search")>0){
		
		if(current.indexOf("/search")>0){
			referrer = location.href;
		}
		
		//remove portion up to querystrings
		for (var i=0; i < referrer.length; i++) {
			tmp = referrer.charAt(i);
			if(tmp=="?"){
					start_position = i + 1;
					break;
			}
		}
		str = referrer.substring(start_position, referrer.length);
		
		//split the keeypairs
		arrQuery = str.split("&");
		
		for(i=0;i<arrQuery.length;i++){
			arrPair = arrQuery[i].split("=");
			if(arrPair[0]=="query"){
				searchText = arrPair[1];
				doSearch = true;
				break;
			}
		}
	}
	
	
	if(doSearch && searchText!=""){
		if (treatAsPhrase) {
			searchArray = [searchText];
		} else {
			searchArray = searchText.split(" ");
		}
		
		if (!document.body || typeof(document.body.innerHTML) == "undefined") {
			if (warnOnFailure) {
				alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
			}
			return false;
		}
		
		var bodyText = document.body.innerHTML;
		for (var i = 0; i < searchArray.length; i++) {
			bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
		}
		
		document.body.innerHTML = bodyText;
		return true;
	}else{
		return true;
	}
}