//This function preloads the global navigation elements
var navRoll = false;

//Set this variable to false so no global rollovers will work until all preloading is done.
function pl()
{
	plImages();
	navRoll = true;
}

function plImages()
{
    var linkArray = document.getElementsByTagName("img");
    for (var loop=0; loop<linkArray.length; loop++)
    {
        if (linkArray[loop].className == "pl")
        {
			var fullIpath = linkArray[loop].src; //Gets full imagepath including http://, domain name and image name
            var fullPathLngth = fullIpath.lastIndexOf('/'); //Finds last '/' used to strip away image name.
            if (fullIpath.indexOf('https://') != -1)
            {
				var httpStrip = 8;
			}
			else
			{
				var httpStrip = 7;
			}
			var iPathDom = fullIpath.substring(httpStrip,fullPathLngth); //Gets path without http:// and image name.
			var iPathDomLngth = iPathDom.indexOf('/'); //Finds first '/' used to strip away domain name.
            var imgPath = iPathDom.substring(iPathDomLngth,iPathDom.length); //Gets path without http:// and image name.
            var imgId = linkArray[loop].id; //Gets the id of the image
            uPreload(imgId,imgPath);
        }
    }
}

//This function preloads rollover images with a,i and o suffixes for active, inactive and on states.
//The function can preload any number of images.
//Usage: uPreload('list of images separated by commas','path where the images live','OPTIONAL: pass in any variable to load active and on states','OPTIONAL: pass in a different file extension other than gif');

function uPreload(imgList, uPath, iSufx)
{
  var imgNew = '';
  var imgSrc = '';
  var imgExt = 'gif';
  if(iSufx != null)
   {
      var imgSuffix = new Array('i', 'a', 'o');
   }
   else 
   {
      var imgSuffix = new Array('i', 'a');
   }
   if(document.images)
   {
      var imgArgArray = imgList.split(',');
      for(var z = 0; z < imgArgArray.length; z++)
      {
         var imgArg = imgArgArray[z];
         var imgSufLen = imgSuffix.length;
         for(j = 0; j < imgSufLen; j++)
         {
            var imgSuf = imgSuffix[j];
            var imgNew = imgArg + imgSuf + ' = new Image();';
            eval(imgNew);
            var imgSrc = imgArg + imgSuf + '.src = \'' + uPath + '/' + imgArg + imgSuf + '.' + imgExt + '\';';
            eval(imgSrc);
         }
      }
   }
}

//This function is for navigation rollover images; uName is name of graphic, uState is on, off or over state
function nr(uName, uState)
{
   if(navRoll)
   {
      document.images[uName].src = self[uName + uState].src;
   }
}

function checkIt(string) 
{
var detect = navigator.userAgent.toLowerCase();
return detect.indexOf(string) + 1;
}

function MM_showHideLayers()
{
var i,p,v,obj,args=MM_showHideLayers.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')?'visible':(v=='hide')?'hidden':v; }
if (checkIt('mac')&&v=='visible') obj.pixelTop = obj.pixelTop ;
obj.visibility=v; }
}

function MM_findObj(n, d) 
{
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 wPop(url, winName, wWidth, wHeight, scrll)
{
   var scrollB;
   if(!scrll)
   {
      scrollB = 'no';
      var pWidth = wWidth;
   }
   else 
   {
      scrollB = scrll;
      wWidth = parseInt(wWidth) + 20;
   }
   var iMyWidth;
   var iMyHeight;
   wHeight = wHeight;
   //Added twelve pixels to ALL popup heights to compensate for newer/larger popup header logo. 
   iMyWidth =(window.screen.width / 2) - (wWidth / 2 + 10);
   //half the screen width minus half the new window width (plus 5 pixel borders).
   iMyHeight =(window.screen.height /2) - (wHeight / 2 + 15);
   //half the screen height minus half the new window height (plus title and status bars).
   var zWin = window.open(url, winName, "status=no,width=" + wWidth + ",height=" + wHeight + ",resizable=no,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=" + scrollB);
   zWin.focus();
}

// generic flash checker/embedder -- usage: embdFlsh(width,height,"path to flash including swf name","path to 508 including file name")
// to NOT display alert box omit "path to 508" (in case you are displaying more than one flash movie on a page)
function embdFlsh(flashWidth, flashHeight, flashSwf, altJpg, VisitChecker)
{
	var swfVisited = '';
	detectFlash(7);
	if(VisitChecker != null){
		cookiesOfforOn();
		if(cookiesOn)
		{
			var vis_ansWer = getCookie('flashVisited');
		}
		if(cookiesOn && (vis_ansWer != null))
		{
			swfVisited = '&visited=' + vis_ansWer;
		}
		else
		{
			swfVisited = '&visited=no';
		}
	}
   if (flashSwf.indexOf("?") != -1 ) //Check to see if we're pointing to XML files/appending the URL
   {
   		var fullUrl = flashSwf.split("?") //Split flashSwf at the "?" so we can get the path and swf name without xml data on the next line.
   		var flUrl = fullUrl[0];
   		var flashUrl = flUrl.substring(flUrl.lastIndexOf("/"),flUrl.length); //Gets specific name of SWF without path. We find this so we can get only the path on the next line.
   		var flashPath = flUrl.substring(0,flUrl.length - flashUrl.length); //Gets full path without SWF name to use for object base parameter.
   }
   else
   {
   	var flashUrl = flashSwf.substring(flashSwf.lastIndexOf("/"),flashSwf.length); //Gets specific name of SWF without path. We find this so we can get only the path on the next line.
   	var flashPath = flashSwf.substring(0,flashSwf.length - flashUrl.length); //Gets full path without SWF name to use for object base parameter.
   }
   var mPc = '';
   if(haveFlash && haveFlashVer)
   {
		mPc = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"" + flashWidth + "\" height=\"" + flashHeight + "\" align=\"middle\">";
		mPc += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
		mPc += "<param name=\"base\" value=\"" + flashPath + "\" />";
		mPc += "<param name=\"movie\" value=\"" + flashSwf + swfVisited + "\" />";
		mPc += "<param name=\"quality\" value=\"high\" />";
		mPc += "<embed src=\"" + flashSwf + swfVisited + "\" quality=\"high\" width=\"" + flashWidth + "\" height=\"" + flashHeight + "\" align=\"middle\" base=\"" + flashPath + "\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\">";
		mPc += "</object>";
	}
   else if(!haveFlash || !haveFlashVer && altJpg == null)
   {
		mPc += '<div style="text-align: center; padding: 50px;">';
		mPc += '<p><strong>It appears you don\'t have Macromedia Flash!</strong></p>';
		mPc += '<p>You need Macromedia Flashpayer 7 to view the content on apollodatatech.com.</p>';
		mPc += '<p><a href="http://www.macromedia.com/go/getflashplayer" target="_blank">Click here to download the Macromedia Flashplayer.</a></p>';
		mPc += '</div>';
	}
	else if(!haveFlash || !haveFlashVer && altJpg != null)
   {
		mPc += '<img src="' + flashPath + '/' + altJpg + '" width="' + flashWidth + '" height="' + flashHeight + '" />';
	}
   //alert(mPc);
   document.write(mPc);
}

function hDr(pathRoot)
{
	embdFlsh('782', '96', pathRoot + 'swf/header.swf', 'header.jpg');

}

function swfQuote(pathRoot)
{
	var myUrl = getUrl();
	if (myUrl == 'text_mining')
	{
		pathRoot = './text_mining_quotes/';
	}

	embdFlsh('173', '240', pathRoot + 'swf/squotes.swf');
}

var cookiesOn = false;

function cookiesOfforOn(){
	if ((document.cookie != '') || (document.cookie != null) || (document.cookie != 'null')){
		cTemp = '';
		SetCookie('cookies_on','yes',null,'/');
		cTemp = getCookie('cookies_on');
		if(cTemp == 'yes'){
			cookiesOn = true;
			//alert('Cookies: ' + cookiesOn);
		}else if(cTemp != 'yes'){
			cookiesOn = false;
			//alert('Cookies: ' + cookiesOn);
		}
	}else{
		cookiesOn = false;
		//alert('Cookies: ' + cookiesOn);
	}
}

function SetCookie(name,value,expires,path,domain,secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

var detectableWithVB = false;
var pluginFound = false;
var haveFlash = false;			// boolean. does the user have the flash at all?
var haveFlashVer = false;		// boolean. does the user have the correct version of flash? This isn't always required.
var flash2Installed = false;    // boolean. true if flash 2 is installed
var flash3Installed = false;    // boolean. true if flash 3 is installed
var flash4Installed = false;    // boolean. true if flash 4 is installed
var flash5Installed = false;    // boolean. true if flash 5 is installed
var flash6Installed = false;    // boolean. true if flash 6 is installed
var flash7Installed = false;    // boolean. true if flash 7 is installed
var flash8Installed = false;    // boolean. true if flash 8 is installed
var flash9Installed = false;    // boolean. true if flash 9 is installed
var flash10Installed = false;    // boolean. true if flash 10 is installed
var maxVersion = 10;             // highest version we can actually detect
var actualVersion = 0;          // version the user really has
var requiredVersion = 7;		// base version flash that we're requiring
var pName = '';

function detectPlugin(plugName) {
    pName = plugName;
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    numFound++;
		}   
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
	    }
	}
    }
    return pluginFound;
}

// Write vbscript detection on ie win. IE on Windows doesn't support regular
// JavaScript plugins array detection.
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;    // true if we're on ie
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false; // true if we're on windows
var VBcode = '';
if(isIE && isWin){
  VBcode += '<SCR' + 'IPT LANGUAGE=VBScript\> \n';
  VBcode += '\'do a one-time test for a version of VBScript that can handle this code\n';
  VBcode += 'on error resume next\n';
  VBcode += 'detectableWithVB = True\n';
  VBcode += '\'and the following function handles QuickTime\n';
  VBcode += 'Function detectQuickTimeActiveXControl()\n';
  VBcode += '  on error resume next\n';
  VBcode += '  pName = "QuickTime"\n';
  VBcode += '  detectQuickTimeActiveXControl = False\n';
  VBcode += '  If detectableWithVB Then\n';
  VBcode += '    detectQuickTimeActiveXControl = False\n';
  VBcode += '    hasQuickTimeChecker = false\n';
  VBcode += '    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")\n';
  VBcode += '    If IsObject(hasQuickTimeChecker) Then\n';
  VBcode += '      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then \n';
  VBcode += '        detectQuickTimeActiveXControl = True\n';
  VBcode += '      End If\n';
  VBcode += '    End If\n';
  VBcode += '  End If\n';
  VBcode += 'End Function\n';
  VBcode += '\'this next function will detect most plugins\n';
  VBcode += 'Function detectActiveXControl(activeXControlName)\n';
  VBcode += '  on error resume next\n';
  VBcode += '  pName = activeXControlName\n';
  VBcode += '  detectActiveXControl = False\n';
  VBcode += '  If detectableWithVB Then\n';
  VBcode += '     detectActiveXControl = IsObject(CreateObject(activeXControlName))\n';
  VBcode += '  End If\n';
  VBcode += 'End Function\n';
  VBcode += '\'this next function will detect Flash\n';
  VBcode += 'Function detectFlashActiveXControl() \n';
  VBcode += '  on error resume next\n';
  VBcode += '	flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n';
  VBcode += '	if (flash2Installed) then flashVersion=2 \n';
  VBcode += '	flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n';
  VBcode += '	if (flash3Installed) then flashVersion=3 \n';
  VBcode += '	flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n';
  VBcode += '	if (flash4Installed) then flashVersion=4 \n';
  VBcode += '	flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n';  
  VBcode += '	if (flash5Installed) then flashVersion=5 \n';
  VBcode += '	flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n'; 
  VBcode += '	if (flash6Installed) then flashVersion=6 \n';
  VBcode += '	flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n';
  VBcode += '	if (flash7Installed) then flashVersion=7 \n';
  VBcode += '	flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n';
  VBcode += '	if (flash8Installed) then flashVersion=8 \n';
  VBcode += '	flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n';
  VBcode += '	if (flash9Installed) then flashVersion=9 \n';
  VBcode += 'End Function\n'; 
  VBcode += '</SCR' + 'IPT\> \n';
  document.writeln(VBcode);
}

function detectFlash(fVer) {
 if (fVer != null){
 	var requiredVersion = fVer;// Version the user needs to view site (max 7, min 2)
 }else{
 	var requiredVersion = 4;
 }
  // If navigator.plugins exists...
  if (navigator.plugins) {
    if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
    	haveFlash = true;
      	var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      	var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
     	//alert("Flash plugin description: " + flashDescription);
		var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
		flash10Installed = flashVersion == 0;
		flash2Installed = flashVersion == 2;
		flash3Installed = flashVersion == 3;
		flash4Installed = flashVersion == 4;
		flash5Installed = flashVersion == 5;
		flash6Installed = flashVersion == 6;
		flash7Installed = flashVersion == 7;
		flash8Installed = flashVersion == 8;
		flash9Installed = flashVersion >= 9;
		
	}else if (detectableWithVB) {
  		//flash2Installed = false;
  		detectFlashActiveXControl();
  		if (flash7Installed) haveFlash = true;
  	}
 }

	// loop through all versions we're checking, and set actualVersion to highest detected version
	for (var i = 2; i <= maxVersion; i++) {	
		if (eval("flash" + i + "Installed") == true)
			actualVersion = i;
	}
	// if we're on webtv, the version supported is 2 (pre-summer2000, or 3, post-summer2000)
	// note that we don't bother sniffing varieties of webtv. you could if you were sadistic...
	if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 2;	
	// uncomment next line to display flash version during testing
	//alert("version detected: " + actualVersion);
	//alert("Required Version: " + requiredVersion);
	// we're finished getting the version. time to take the appropriate action
	if (actualVersion >= requiredVersion) {
		haveFlashVer = true;
	}else{
		haveFlashVer = false;
		}
}

function leftNav(section,mNav,mSnav)
{
	var useJsRedir = false;
	var dw='<div class="ln_hdr"></div>';
	if (section == 'News')
	{
		var navItems = new Array(new Array("News Releases|releases"),new Array("Research|research"))
	}
	if (section == 'Company')
	{
		var navItems = new Array(new Array("Leadership|who"),new Array("What We Do|what","Our Approach|approach"),new Array("Our Partners|partners","Project REAL|projreal"),new Array("What They Say|they_say"),new Array("Careers|careers"),new Array("Offices|offices"))
	}
	if (section == 'Solutions')
	{
		useJsRedir = true;
		var navItems = new Array(new Array("Industries|industries"),new Array("Methodology|methodology|parent"),new Array("Technology|technology","data mining|data_mining|parent","data warehousing|data_warehousing|parent","OLAP|olap","text mining|text_mining","research|research"))
	}
	for (var i = 0; i < navItems.length; i++)
	{
		var nav = navItems[i][0].split("|");
		if (nav[0] != mNav || mSnav != 'null')
		{
			if (!nav[2] && !useJsRedir)
			{
				dw += '<div class="ln"><a href="' + nav[1] + '.html" target="if">' + nav[0] +'</a></div>';
			}
			else if (!nav[2] && useJsRedir)
			{
				dw += '<div class="ln"><a href="shell.html?' + nav[1] + '" target="_parent">' + nav[0] +'</a></div>';
			}
			else if (nav[2] && useJsRedir)
			{
				dw += '<div class="ln"><a href="' + nav[1] + '.html" target="_parent">' + nav[0] +'</a></div>';
			}
		}
		else
		{
			dw += '<div class="lno">' + nav[0] +'</div>';
		}
		if (nav[0] == mNav)
		for (var j = 1; j < navItems[i].length; j++)
		{
			var snav = navItems[i][j].split("|");
			if (snav[0] != mSnav)
			{
				if (!snav[2] && !useJsRedir)
				{
					dw += '<div class="lsn"><a href="' + snav[1] + '.html" target="if">' + snav[0] +'</a></div>';
				}
				else if (!snav[2] && useJsRedir)
				{
					dw += '<div class="lsn"><a href="shell.html?' + snav[1] + '" target="_parent">' + snav[0] +'</a></div>';
				}
				else if (snav[2] && useJsRedir)
				{
					dw += '<div class="lsn"><a href="' + snav[1] + '.html" target="_parent">' + snav[0] +'</a></div>';
				}
				//dw += '<div class="lsn"><a href="' + snav[1] + '.html" target="if">' + snav[0] +'</a></div>';
			}
			else
			{
				dw += '<div class="lsno">' + snav[0] +'</a></div>';
			}
		}
	}
	changeContent('ln_wrap',dw);
}

function getIframe()
{
	var xUrl = document.location;
	var xUrl = xUrl.toString();
	if(xUrl.indexOf("?") != -1 || xUrl.indexOf("shell") != -1)
	{
		var fullUrl = xUrl.split("?");
		var ifUrl = fullUrl[1] + '.html';
		document.getElementById('if').setAttribute('src',ifUrl);
	}
}

function getUrl()
{
	var xUrl = document.location;
	var xUrl = xUrl.toString();
	var fullUrl = xUrl.split("?");
	var ifUrl = fullUrl[1];
	return ifUrl;
}

function changeContent(id,shtml) {
	var el = parent.document.getElementById? parent.document.getElementById(id): parent.document.all[id];
    if (el && typeof el.innerHTML != "undefined") el.innerHTML = shtml;
}

function copyToPrintDiv() { //copies content frame contents to hidden div used for printing
    //"if" = Inline Frame, to be consistent with CSS identity
    var ifPrintDiv = parent.document.getElementById("if_print"); 
    if (ifPrintDiv) ifPrintDiv.innerHTML = self.document.body.innerHTML; 
}
