
// CHECK CLIENT BROWSER & PLATFORM
// original code from http://developer.apple.com/internet/_javascript/
//
// USAGE:	browserNaming();
// NOTES:	call it from within an external JS document
// RESULT:	browserNew = true/false
//			browserName = IE/NS/Opera
//			browserNameLong = IE5/etc
//			Macintosh = true/false
// WORKS:	everything

	var its;
	var browserName;
	var browserNameLong;
	var browserNew;
	var preloadFlag = false;
	var Macintosh = navigator.userAgent.indexOf('Mac')>0;

	function its() {
		var n = navigator;
		var ua = ' ' + n.userAgent.toLowerCase();
		var pl = n.platform.toLowerCase();
		var an = n.appName.toLowerCase();

		// browser version
		this.version = n.appVersion;
		this.nn = ua.indexOf('mozilla') > 0;

		// 'compatible' versions of mozilla aren't navigator
		if(ua.indexOf('compatible') > 0) {
			this.nn = false;
		}
		
		this.opera = ua.indexOf('opera') > 0;
		this.ie = ua.indexOf('msie') > 0;
		this.major = parseInt( this.version );
		this.minor = parseFloat( this.version );

		// platform
		this.mac = ua.indexOf('mac') > 0;
		this.win = ua.indexOf('win') > 0;

		// workaround for IE5 which reports itself as version 4.0
		if(this.ie) {
			if(ua.indexOf("msie 5") > 1) {
			var msieIndex = navigator.appVersion.indexOf("MSIE") + 5;
			this.major = parseFloat(navigator.appVersion.substr(msieIndex,3));
			}
		}

		return this;
	}

	function browserNaming() {
		its = new its();
		
		// is it a DOM-enabled browser?
		if (!document.getElementById) {
			browserNew = false;
		}
		else {
			browserNew = true;
		}

		// need the name, too
		if (its.opera) {
			browserName = "Opera";
		}
		else if (its.ie) {
			browserName = "IE";
		}
		else {
			browserName = "NS";
		}

		// and the number
		browserNameLong = browserName + its.major;
	
	}
	

// CREATING THE MOUSEOVER IMAGES
// USAGE:	createObject('buttonoff','images/specfeature_celluar_off.gif');
// NOTES:	call it from within the preload function
// WORKS:	ie4+, ns4+, opera5

	function createObject(imgName,imgSrc) {
		if (browserNew && (browserName == "NS")) {
		// a DOM-compatible browser
		// which is probably NS6/mozilla (the other code works better in IE/Opera)
			var tempImg = document.createElement("img");
			tempImg.src = imgSrc;
			tempImg.id = imgName;
			tempImg.style.visibility = 'hidden';
			tempImg.style.position = 'absolute';
			tempImg.style.top = 0;
			document.body.appendChild(tempImg);
		}
		else {
		// a non-DOM-compatible browser
		// and IE/Opera
			eval(imgName+' = new Image()');
			eval(imgName+'.src = "'+imgSrc+'"');
		}
	}


// MOUSEOVER SWITCHING
// USAGE:	<a href="#" onmouseover="changeImage(null,'buttonname','buttonnameon');" onmouseout="changeImage(null,'buttonname','buttonnameoff');">
// NOTES:	if the image is in a DIV, substitute 'null' with the DIV name.
// WORKS:	ie4+, ns4+, opera5

	function changeImage(layer,imgName,imgObj) {
		if (preloadFlag) {
			if (browserNew && (browserName == "NS")) {
			// a DOM-compatible browser
			// which is probably NS6/mozilla (the other code works better in IE/Opera)
				thisImage = document.getElementById(imgName);
				newImage = document.getElementById(imgObj);
				newSrc = newImage.getAttribute("src");
				thisImage.setAttribute("src",newSrc);
			}
			else {
			// a non-DOM-compatible browser
			// and IE/Opera
				if ((browserName == "NS") && layer!=null) eval('document.'+layer+'.document.images["'+imgName+'"].src = '+imgObj+'.src')
				else document.images[imgName].src = eval(imgObj+".src")
			}
		}
	}


// REMOVES THE LINK BORDER IN IE5/NS6
// original code by evil@chelu.ro
//
// USAGE:	getLinksToBlur();
// NOTES:	call it from within the preload function
// WORKS:	ie5+, ns6+, opera5+

	function unblur() {
		this.blur();
	}

	function getLinksToBlur() {
		if (!document.getElementById) return
		links = document.getElementsByTagName("a");
		for(i=0; i<links.length; i++) {
			links[i].onfocus = unblur
		}
	}



// POPUP WINDOW (FIXES THE IE4/MAC PROBLEM WHICH MAKES WINDOWS TOO SMALL)
// USAGE:	<a href="#" onclick="spawnWindow('newpage.html','windowname',400,384,'no');">
// NOTES:	substitute 400 with the width, 384 with the height, windowname with the name of the new window, scroll with either 'yes', 'no' or 'auto'
// WORKS:	ie4+, ns4+, opera5

	function spawnWindow(desktopURL,windowName,width,height,scroll) {
 		if (Macintosh) {
 			if (browserNameLong == "IE4") {
				newheight = parseInt(height + 17);
			}
			else if (browserNameLong == "IE4.5") {
				newheight = parseInt(height + 17);
			}
			else {
				newheight = height;
			}
 		}
 		else { newheight = height; }	
 		window.open(desktopURL, windowName, "toolbar=no,location=no,status=yes,menubar=no,scrollbars="+scroll+",width="+width+",height="+newheight+",resizable=no" );
	}

	function spawnWindowToo(desktopURL,windowName,width,height) {
 		window.open(desktopURL, windowName, "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,width="+width+",height="+height+",resizable=no" );
	}


// HIDE AND SHOW LAYERS (ON THE SAME PAGE)
// USAGE:	show('layername'); hide('layername');
// WORKS:	ie4+, ns4+, opera

	function hide(id) {
		if (browserNew) {
			setIdProperty(id,"visibility","hidden");
		}
		else {
			if (browserName == "NS") { document.layers[id].visibility = "hide"; }
			else { document.all[id].style.visibility = "hidden"; }
		}
	}

	function show(id) {
		if (browserNew) {
			setIdProperty(id,"visibility","visible");
		}
		else {
			if (browserName == "NS") { document.layers[id].visibility = "show"; }
			else { document.all[id].style.visibility = "visible"; }
		}
	}

	
// DOM / GET PROPERTY
// original code from http://www.alistapart.com/
//
// NOTES:	given an id and a property (as strings), return the given property of that id.
// WORKS:	ie5+, ns6+, opera5+

	function getIdProperty(id,property) {
		var styleObject = document.getElementById( id );
		if (styleObject != null) {
			styleObject = styleObject.style;
				if (styleObject[property]) {
					return styleObject[ property ];
				}
			}
		return (styleObject != null) ?
		styleObject[property] :
		null;
	}


// DOM / SET PROPERTY
// original code from http://www.alistapart.com/
//
// NOTES:	given an id and a property (as strings), set the given property of that id to the value provided.
// WORKS:	ie5+, ns6+, opera5+

	function setIdProperty(id,property,value) {
		var styleObject = document.getElementById( id );
		if (styleObject != null) {
			styleObject = styleObject.style;
			styleObject[ property ] = value;
		}
	}

// RANDOM NUMBER GENERATOR
// USAGE:	var ranNumber = 0+randNum(40);
// NOTES:	call it from within the main html page
// WORKS:	ie4+, ns4+, opera

	function randNum (num) {
		var now = new Date();
		var rand = Math.round(num * Math.cos(now.getTime()));
		if (rand < 0) rand = - rand; 
		if (rand == 0) rand++;
		return rand;
	}

		function openWin(filename,w,h) {

    var features =
        'width='        + w +
        ',height='      + h +
        ',directories=' + 'no' +
        ',location='    + 'no' +
        ',menubar='     + 'no' +
        ',scrollbars='  + 'no' +
        ',status='      + 'no' +
        ',toolbar='     + 'no' +
        ',copyhistory=' + 'no' +
        ',resizable='   + 'no';


			subWin1=window.open(filename, 'subWin1', features);
		    if (subWin1.opener == null) subWin1.opener = self;
			subWin1.self.focus();
		}
		
		<!-- Begin
closetime = 2; // Close window after __ number of seconds?
// 0 = do not close, anything else = number of seconds

function Start(URL, WIDTH, HEIGHT) {
windowprops = "left=50,top=50,width=" + WIDTH + ",height=" + HEIGHT;
preview = window.open(URL, "preview", windowprops);
if (closetime) setTimeout("preview.close();", closetime*1000);
}

function doPopup() {
url = "http://javascript.internet.com/navigation/delayed-popup-window.html";
width = 267;  // width of window in pixels
height = 103; // height of window in pixels
delay = 2;    // time in seconds before popup opens
timer = setTimeout("Start(url, width, height)", delay*1000);
}
//  End -->

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

		function down(e){
			if((document.layers && e.which!=1) || (document.all && event.button!=1)) return true;
				getMouse(e);
				startY = (mouseY - dragT);
				if(mouseX >= upL && (mouseX <= (upL + upW)) && mouseY >= upT && (mouseY <= (upT + upH))){
					clickUp = true;
					return scrollUp();
				}	
				else if(mouseX >= downL && (mouseX <= (downL + downW)) && mouseY >= downT && (mouseY <= (downT + downH))){
					clickDown = true;
					return scrollDown();
				}
				else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= dragT && (mouseY <= (dragT + dragH))){
					clickDrag = true;
					return false;
				}
				else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= rulerT && (mouseY <= (rulerT + scrollH))){
					if(mouseY < dragT){
						clickAbove = true;
						clickUp = true;
						return scrollUp();
					}
					else{
						clickBelow = true;
						clickDown = true;
						return scrollDown();
					}
				}
			else{
				return true;
			}
		}
		function move(e){
			if(clickDrag && contentH > contentClipH){
				getMouse(e);
				dragT = (mouseY - startY);
		
				if(dragT < (rulerT))
					dragT = rulerT;		
				if(dragT > (rulerT + scrollH - dragH))
					dragT = (rulerT + scrollH - dragH);
		
				contentT = ((dragT - rulerT)*(1/scrollLength));
				contentT = eval('-' + contentT);

				moveTo();
				if(ie4)
					return false;
			}
		}

		function up(){
			clearTimeout(timer);
			// Resetting variables
			clickUp = false;
			clickDown = false;
			clickDrag = false;
			clickAbove = false;
			clickBelow = false;
			return true;
		}

		// Reads content layer top
		function getT(){
			if(ie4)
				contentT = document.all.content.style.pixelTop;
			else if(nn4)
				contentT = document.contentClip.document.content.top;
			else if(dom)
				contentT = parseInt(document.getElementById("content").style.top);
		}

		// Reads mouse X and Y coordinates
		function getMouse(e){
			if(ie4){
				mouseY = event.clientY + document.body.scrollTop;
				mouseX = event.clientX + document.body.scrollLeft;
			}
			else if(nn4 || dom){
				mouseY = e.pageY;
				mouseX = e.pageX;
			}
		}

		// Moves the layer
		function moveTo(){
			if(ie4){
				document.all.content.style.top = contentT;
				document.all.ruler.style.top = dragT;
				document.all.drag.style.top = dragT;
			}
			else if(nn4){
				document.contentClip.document.content.top = contentT;
				document.ruler.top = dragT;
				document.drag.top = dragT;
			}
			else if(dom){
				document.getElementById("content").style.top = contentT + "px";
				document.getElementById("drag").style.top = dragT + "px";
				document.getElementById("ruler").style.top = dragT + "px";
			}
		}

		// Scrolls up
		function scrollUp(){
			getT();
	
			if(clickAbove){
				if(dragT <= (mouseY-(dragH/2)))
					return up();
			}
	
			if(clickUp){
				if(contentT < 0){		
					dragT = dragT - (speed*scrollLength);
			
					if(dragT < (rulerT))
						dragT = rulerT;
				
					contentT = contentT + speed;
					if(contentT > 0)
						contentT = 0;
			
					moveTo();
					timer = setTimeout("scrollUp()",25);
				}
			}
			return false;
		}

		// Scrolls down
		function scrollDown(){
			getT();
	
			if(clickBelow){
				if(dragT >= (mouseY-(dragH/2)))
					return up();
			}

			if(clickDown){
				if(contentT > -(contentH - contentClipH)){			
					dragT = dragT + (speed*scrollLength);
					if(dragT > (rulerT + scrollH - dragH))
						dragT = (rulerT + scrollH - dragH);
			
					contentT = contentT - speed;
					if(contentT < -(contentH - contentClipH))
						contentT = -(contentH - contentClipH);
			
					moveTo();
					timer = setTimeout("scrollDown()",25);
				}
			}
			return false;
		}

		// reloads page to position the layers again
		function reloadPage(){
			location.reload();
		}

		// preloads the scroller stuff
		function eventLoader(){
			if(ie4){
				// Up-arrow X and Y variables
				upL = document.all.up.style.pixelLeft;
				upT = document.all.up.style.pixelTop;		
				// Down-arrow X and Y variables
				downL = document.all.down.style.pixelLeft;
				downT = document.all.down.style.pixelTop;
				// Scrollbar X and Y variables
				dragL = document.all.drag.style.pixelLeft;
				dragT = document.all.drag.style.pixelTop;		
				// Ruler Y variable
				rulerT = document.all.ruler.style.pixelTop;		
				// Height of content layer and clip layer
				contentH = parseInt(document.all.content.scrollHeight);
				contentClipH = parseInt(document.all.contentClip.style.height);
			}
			else if(nn4){
				// Up-arrow X and Y variables
				upL = document.up.left;
				upT = document.up.top;		
				// Down-arrow X and Y variables
				downL = document.down.left;
				downT = document.down.top;		
				// Scrollbar X and Y variables
				dragL = document.drag.left;
				dragT = document.drag.top;		
				// Ruler Y variable
				rulerT = document.ruler.top;
				// Height of content layer and clip layer
				contentH = document.contentClip.document.content.clip.bottom;
				contentClipH = document.contentClip.clip.bottom;
			}
			else if(dom){
				// Up-arrow X and Y variables
				upL = parseInt(document.getElementById("up").style.left);
				upT = parseInt(document.getElementById("up").style.top);
				// Down-arrow X and Y variables
				downL = parseInt(document.getElementById("down").style.left);
				downT = parseInt(document.getElementById("down").style.top);
				// Scrollbar X and Y variables
				dragL = parseInt(document.getElementById("drag").style.left);
				dragT = parseInt(document.getElementById("drag").style.top);
				// Ruler Y variable
				rulerT = parseInt(document.getElementById("ruler").style.top);
				// Height of content layer and clip layer
				contentH = parseInt(document.getElementById("content").offsetHeight);
				contentClipH = parseInt(document.getElementById("contentClip").offsetHeight);
				document.getElementById("content").style.top = 0 + "px";
		
			}
			// Number of pixels scrollbar should move
			scrollLength = ((scrollH-dragH)/(contentH-contentClipH));
			// Initializes event capturing
			if(nn4){
				document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
				window.onresize = reloadPage;
			}
			document.onmousedown = down;
			document.onmousemove = move;
			document.onmouseup = up;
		}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function goURL(daURL) {
    // if the browser can do it, use replace to preserve back button
    if(javascriptVersion1_1) {
	window.location.replace(daURL);
    } else {
	window.location = daURL;
    }
    return;
}

function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
    // check for redirection
    if( redirectURL && ((pluginFound && redirectIfFound) || 
	(!pluginFound && !redirectIfFound)) ) {
	// go away
	goURL(redirectURL);
	return pluginFound;
    } else {
	// stay here and return result of plugin detection
	return pluginFound;
    }	
}

function canDetectPlugins() {
    if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
	return true;
    } else {
	return false;
    }
}

function detectReal(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('RealPlayer');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
		       detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
		       detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
    }	
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectPlugin() {
    // 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;
} // detectPlugin

	function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
	endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
	}
	
	function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
	var j = i + alen;    
	if (document.cookie.substring(i, j) == arg)      
	return getCookieVal (j);    
	i = document.cookie.indexOf(" ", i) + 1;    
	if (i == 0) break;   
	}  
	show('chooseDIV');
	}
	
	function SetCookie (name, value) {  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
	}

	function DeleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
	}

// SWITCH PICTURE IN "MAINPIC"

		function doPic(imgName) {
			if (ns3up || ie4up) {
			imgOn = ("" + imgName);
				if (ns4) {
					document.layers["picDIV"].document.mainpic.src = imgOn;
				}
				else if (ie4) {
					document.images['mainpic'].src = imgOn;
				}
			}
		}

		
// HIDE and SHOW code

function show(id) {
	hideall();
	if (ns4) document.layers[id].visibility = "show"
	else if (ie4) document.all[id].style.visibility = "visible"
}
function hide(id) {
	if (ns4) document.layers[id].visibility = "hide"
	else if (ie4) document.all[id].style.visibility = "hidden"
}


// PLAY AND STOP FUNCTIONS FOR hi AND lo.

function play_lo() {
	if (ns4) {document.layers["loDIV"].document.embeds["lomovie"].DoPlay();}
	else if (ie4) {document.lomovie.DoPlay();}
}
function play_hi() {
	if (ns4) {document.layers["hiDIV"].document.embeds["himovie"].DoPlay();}
	else if (ie4) {document.himovie.DoPlay();}
}
function stop_lo() {
	if (ns4) {document.layers["loDIV"].document.embeds["lomovie"].DoStop();}
	else if (ie4) {document.lomovie.DoStop();}
}
function stop_hi() {
	if (ns4) {document.layers["hiDIV"].document.embeds["himovie"].DoStop();}
	else if (ie4) {document.himovie.DoStop();}
}
function pause_lo() {
	if (ns4) {document.layers["loDIV"].document.embeds["lomovie"].DoPause();}
	else if (ie4) {document.lomovie.DoPause();}
}
function pause_hi() {
	if (ns4) {document.layers["hiDIV"].document.embeds["himovie"].DoPause();}
	else if (ie4) {document.himovie.DoPause();}
}