﻿// JScript File
var timerID=0;

//var imgArray = new Array("~/images/eagle-banner1a.swf","~/images/eagle-banner2a.swf","~/images/eagle-banner3a.swf");
var swfExtArray = new Array("swf");
var imgExtArray = new Array("jpg","gif");
var BrowserIsIE;
var divControlName;
var boxWidth;
var boxHeight;
var PlayImmediately;
var BackGroundColor;
var Loop;
var Quality;
var FlashMenu;

function setupAdbanner(isIE, seconds, divName, width, height, play, bgColor, loop, quality, menu) {
	FlashMenu = menu;
	Loop = loop;
	Quality = quality;
	BackGroundColor = bgColor;
	boxHeight = height;
	boxWidth = width;
	PlayImmediately = play;
	milliseconds = seconds * 1000;
	BrowserIsIE = isIE;
	divControlName = divName;

	rotate();	
	timerID = setInterval("rotate()", milliseconds); //uncomment to rotate swf files
}

function cleanupPage() {
	if (timerID)
		clearInterval(timerID);
}

function ValidateDiv(divName)
{
	var divFlash = findObj(divName);
	if (divFlash == null)
	{
		alert("Error locating a div named: " + divName + ".  Check case of name.");
		return null;
	}
	if (divFlash.tagName != "DIV")
	{
		alert("Error: " + divName + " does not appear to be a DIV.");
		return null;
	}
	return divFlash;
}

function rotate() {
	imgIndex = Math.ceil(Math.random() * imgArray.length) - 1;
	var filename = imgArray[imgIndex];
	var ext = filename.substring(filename.length-3);
	
	for (var i=0; i < swfExtArray.length; i++)
	{
		if (swfExtArray[i] == ext)
		{
			//alert("flash file located: " + filename);
			if (BrowserIsIE)
				CreateIEFlash(divControlName, filename, boxWidth,boxHeight,BackGroundColor, PlayImmediately, Loop, Quality, FlashMenu);
			else
				CreateAltFlash(divControlName, filename, boxWidth, boxHeight, Loop, PlayImmediately, Quality, FlashMenu);
			return;
		}
	}
	for (var i=0; i < imgExtArray.length; i++)
	{
		if (imgExtArray[i] == ext)
		{
			var adbanner = ValidateDiv(divControlName);
			//alert("image file located: " + filename);
			adbanner.innerHTML = "<img src='" + filename + "' width=" + boxWidth + " height=" + boxHeight + " border='0' />";
			return;
		}
	}
	alert("Unsupported file " + filename);        
}

function CreateAltFlash(divName, Movie, Width, Height, Loop, Play, Qual, UseMenu)
{
	var adbanner = ValidateDiv(divName);
	//var div = findObj(DivName);
    var code = ("<object type='application/x-shockwave-flash' loop='" + Loop + "' ");
    code += ("data='" + Movie + "' width='" + Width + "' height='" + Height + "' ");
    code += ("play='" + Play + "' quality='" + Qual + "' menu='" + UseMenu + "' />");
    adbanner.innerHTML = code;
}

//since Microsoft lost the flash war this file must be external.  I had originally
//embedded the code in the DiggsAdRotator but the flash activation error occurrs.
function CreateIEFlash(divName, Movie, Width, Height, BGC, Play, Loop, Qual, UseMenu)
{
	var adbanner = ValidateDiv(divName);
	var ID="ShortTimerFlash";
	var clsid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
	var codebase="http://download.macromedia.com/pub/";
	codebase+="shockwave/cabs/flash/swflash.cab";
	codebase+="#version=6,0,40,0";
	
	var code = ('<object classid="' + clsid + '" ');
	code += ('codebase="'+ codebase + '" ');
	
	if (Width>0)
		code += ('width="'+ Width + '" '); 
	if (Height>0)
		code += ('height="' + Height + '" ');
	code += ('id="' + ID + '">');
	code += ('<param name="movie" value="'+ Movie + '"');
	if (Qual.length>0)
		code += ('<param name="quality" value="'+Qual+'">');
	if (BGC.length>0) 
		('<param name="bgcolor" value="'+ BGC +'>');
	code += ('<param name="loop" value="' + Loop + '">');
	code += ('<param name="play" value="'+ Play +'">');
	code += ('<param name="menu" value="'+ UseMenu +'">');
	code += ('</object>');
	adbanner.innerHTML = code;
}

<!-- browser independant way to locate an object -->
function 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=findObj(n,d.layers[i].document);
	
	if(!x && d.getElementById) x=d.getElementById(n); 
  
	return x;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
function addUnLoadEvent(func) {
  var oldonload = window.onunload;
  if (typeof window.onload != 'function') {
    window.onunload = func;
  } else {
    window.onunload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}