 //GLOBAL VARIABLES AND ROUTINES FOR GENERAL PURPOSE AND MAIN INTERFACE

  var layerRef, styleSwitch, layerOpen, layerClose;
  var browserType = "old";

//Initialize variables that can be used to make functions cross browser.

	if (document.getElementById && !document.all) {
        layerRef="document.getElementById";
        styleSwitch=".style";
		layerOpen = "(";
		layerClose = ")";
		browserType = "NN5";
  
	} else if (parseInt(navigator.appVersion) >= 4) {
		if (navigator.appName == "Netscape") {
	        layerRef="document.layers";
	        styleSwitch="";
			layerOpen = "[";
			layerClose = "]";
	        browserType = "NN4";
	        document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP | Event.KEYPRESS);
		}else{
			appVer = navigator.appVersion.toLowerCase();
			is_minor = parseFloat(appVer);
			iePos  = appVer.indexOf('msie');
			if (iePos !=-1) {
       			is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
			}
			is_ie6up = (is_minor >= 6);

			if (is_ie6up) {
				layerRef="document.getElementById";
		        styleSwitch=".style";
				layerOpen = "(";
				layerClose = ")";
				browserType = "IE6";
			} else {
		        layerRef="document.all";
		        styleSwitch=".style";
				layerOpen = "[";
				layerClose = "]";
		        browserType = "IE4";
			}
		}
	}
	
function WM_preloadImages() {


   // LOAD IMAGES INTO BROWSER'S CACHE FOR LATER USE

  // Usage: WM_preloadImages('imagelocation','image 1 URL','image 2 URL','image  URL',...);
  // where imagelocation is the path to the images
    

   // Don't bother if there's no document.images
	if (document.images) {
		if (typeof document.WM == 'undefined') {
			document.WM = new Object();
		}

		document.WM.loadedImages = new Array();

		// Loop through all the passed arguments and create a new image
		// for each

		var argLength = WM_preloadImages.arguments.length;
		
		var imageloc = WM_preloadImages.arguments[0];

		for (arg=1; arg<argLength; arg++) {
			document.WM.loadedImages[arg] = new Image();
			document.WM.loadedImages[arg].src = imageloc + "/" + WM_preloadImages.arguments[arg];
		}
	}
}



//GENERAL FUNCTIONS FOR SHOWING AND HIDING LAYERS

   //Accepts the layer name and shows it by setting its visibility property
   //to 'visible'

   function showLayer(layerName){
		eval(layerRef+layerOpen+'"'+layerName+'"'+layerClose+styleSwitch+'.visibility="visible"');
   }

   //Accepts the layer name and hides it by setting its visibility property
   //to 'hidden'

   function hideLayer(layerName){
		eval(layerRef+layerOpen+'"'+layerName+'"'+layerClose+styleSwitch+'.visibility="hidden"');
   }

   // Accepts the document ref (for cross=frame control)
   // AND layer name and shows it by setting its visibility property
   // to visible'

   function showXframeLayer(docRef, layerName){
		eval(docRef+layerRef+layerOpen+'"'+layerName+'"'+layerClose+styleSwitch+'.visibility="visible"');
   }

   // Accepts the document ref (for cross=frame control)
   // AND layer name and hides it by setting its visibility property
   // to 'hidden'

   function hideXframeLayer(docRef, layerName){
		eval(docRef+layerRef+layerOpen+'"'+layerName+'"'+layerClose+styleSwitch+'.visibility="hidden"');
   }


 // LOAD NEW IMAGE
 // This function receives
 //     the name of the layer where the image resides,
 //     the name of the image, and
 //     the url of the new image to be displayed
 // and replaces the current image with the new one.

 function loadImage(docRef,layerName,imageName,imgUrl) {
    //eval(docRef + layerRef+'[layerName].document.images[imageName].src=imgUrl');
	//alert(docRef + layerRef+layerOpen+"layerName"+layerClose+".document.images[imageName].src=imgUrl");
	if (browserType == "NN5" || browserType == "IE6") {
		document.images[imageName].src=imgUrl;
	} else {
		eval(docRef + layerRef+'[layerName].document.images[imageName].src=imgUrl');
	}
 }

 
// Dynamic DIV text content swapping

function swapHTML(docref,text,divName){

	if (browserType == "NN4") {
		eval(docref + "document.layers[divName].document.write(text)");
		eval(docref + "document.layers[divName].document.close()");
	} else if (browserType == "NN5") {
		rng = eval(docref + "document.createRange()");
		el = eval(docref + "document.getElementById(divName)");
		rng.setStartBefore(el);
		htmlFrag = rng.createContextualFragment(text);
		
		while (el.hasChildNodes()) {
			el.removeChild(el.lastChild);
		}
		el.appendChild(htmlFrag);

	} else {
		eval(docref + "document.all[divName].innerHTML=text");
	}
}

function getDivContents(docref,divName){
	text = "I don't know";
	if (browserType == "NN4") {
		eval("text = " + docref + "document.layers[divName].value");
	} else if (browserType == "NN5") {
		el = eval(docref + "document.getElementById(divName)");
		text = el.innerHTML;
	} else {
		eval("text = " + docref + "document.all[divName].innerHTML");
	}
	return text;
}


