
// Initialize variables:

var qq = '\"';						// Escaped double quote character
var d=document;

var popWin;
var popWin2;
var browserWin;

// ============================================================================================================

// if (self.location == top.location) {			// Prevent this frame from loading outside the frameset
//	top.location.href = 'index.html';
// }

// ============================================================================================================


function preloadGIF() {					// Load button highlights into the browser's memory cache

	if (d.images){ 
		if(!d.allImages) d.allImages=new Array();
		var i,j=d.allImages.length, imgList=preloadGIF.arguments;

		for(i=0; i<imgList.length; i++)
			if (imgList[i].indexOf("#")!=0){ 
					d.allImages[j]=new Image; 
					d.allImages[j++].src='images/' + imgList[i] + '.gif';
			}
		}
}


function preloadGIFsub() {				// Load button highlights from a subdirectory

	if (d.images){ 
		if(!d.allImages) d.allImages=new Array();
		var i,j=d.allImages.length, imgList=preloadGIFsub.arguments;

		for(i=0; i<imgList.length; i++)
			if (imgList[i].indexOf("#")!=0){ 
					d.allImages[j]=new Image; 
					d.allImages[j++].src='../images/' + imgList[i] + '.gif';
			}
		}
}


function validateEmailField() {				// Checks to see if the field named 'email' has @ and . chars
							// Returns +1 if true
	emailFieldObj = getObjectByID('email');
	var email = emailFieldObj.value;

	var emailRegEx = /^[^@]+@[^@]+.[a-z]{2,}$/i;

	if(email.search(emailRegEx) == -1){
		validEmail = 0;
	} else {
		validEmail = 1;
	}

	return validEmail;
}


function getObjectByID(name) {				// Get an object's ID tag for easy referencing

	if (document.getElementById) {				// Firefox and Safari
		return document.getElementById(name);
	} else if (document.all) {				// IE
		return document.all[name]; 
	} else if (document.layers) {
		return document.layers[name];
	} else {
		return document.getElementById(name);		// Default for unknown browsers
	}
}


function getFrameObj(whichFrame){				// Returns an iFrame object reference when called from
								//   the parent document. Use to call iFrame functions
								//   from the parent.
	var frameObj = getObjectByID(whichFrame);
	return frameObj.contentWindow;
}


function embedFlash(thisFile, w, h) {	// Shows the activeX control without an annoying 'activate' prompt

	var embedCode = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' " 
		+ "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='" + w + "' height='" + h + "'> " 
		+ "<param name='movie' value='" + thisFile + "' /> " 
		+ "<param name='quality' value='high' /> " 
		+ "<param name='wmode' value='transparent' /> " 
		+ "<embed src='" + thisFile + "' width='" + w + "' height='" + h + "' quality='high' " 
		+ "pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' wmode='transparent'> " 
		+ "</embed></object>";

	document.write(embedCode);
}


function buttonState(buttonID, state) {			// Change button state by replacing .gif files:
							// Valid states are '', '_h', and '_s'
	var buttonName = buttonID + 'Btn';
	var newImgFile = 'images/mmBtn_' + buttonID + state + '.gif';

	buttonObj = getObjectByID(buttonName);

	buttonObj.src = newImgFile;
}


function toggleMenu(menuID) {				// If table is visible, hide it and vice versa

	var menuName = menuID + "Menu";
	menuObj = getObjectByID(menuName);

	if (menuObj.style.display == "none") {
		menuObj.style.display = "";
	} else {
		menuObj.style.display = "none";
	}
}

function toggleObject(ID) {				// If table is visible, hide it and vice versa

	thisObj = getObjectByID(ID);

	if (thisObj.style.display == "none") {
		thisObj.style.display = "";
	} else {
		thisObj.style.display = "none";
	}
}

function showObject() {				// Show a dynamic form field or menu
							// Iterates through argument list if an array is input
	var lastObj = showObject.arguments.length;
	for(n=0; n<lastObj; n++) {
		thisObj = getObjectByID(showObject.arguments[n]);
		thisObj.style.display = "";
	}
}



function hideObject() {					// Show a dynamic form field or menu
							// Iterates through argument list if an array is input
	var lastObj = hideObject.arguments.length;
	for(n=0; n<lastObj; n++) {
		thisObj = getObjectByID(hideObject.arguments[n]);
		thisObj.style.display = "none";
	}
}


function expandMenu(menuID) {				// Show menu and highlight associated button

	buttonState(menuID, '_h');
	showObject(menuID + 'Menu');
}


function collapseMenu(menuID) {				// Hide menu and de-highlight associated button

	buttonState(menuID, '');
	hideObject(menuID + 'Menu');
}


function getScreenSpecs(defaultW, defaultH) {		// Accepts default width and height as input and returns 
													// either actual screen width and height or the defaults
	screenH = defaultH
	screenW = defaultW;

	if (parseInt(navigator.appVersion)>3) {
		 screenH = screen.height;
		 screenW = screen.width;
	}
	else if (navigator.appName == "Netscape" 
	    && parseInt(navigator.appVersion)==3
	    && navigator.javaEnabled()
	) 
	{
	 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
	 var jScreenSize = jToolkit.getScreenSize();
	 screenH = jScreenSize.height;
	 screenW = jScreenSize.width;
	}

	return [screenW, screenH];
}


function getAvailHeight() {

    var screenH = screen.height;
    if(document.all){
        availH = document.body.clientHeight;	// For IE
    }else{
        availH = innerHeight - 15;		// Offset for Firefox
    }
    return availH;
}


function getAvailWidth() {

    var screenW = screen.width;
    if(document.all){
        availW = document.body.clientWidth;
    }else{
        availW = innerWidth;
    }
    return availW;
}



function toggleOnSelect(id, showValue, v) {		// Shows an object if the selected value = a specified value;
							//	otherwise hides it
	var thisObj = getObjectByID(id);

	if (v == showValue) {					// user selected the show value: show it

		thisObj.style.display = '';
	} else {						// user selected something else; hide it
		thisObj.style.display = 'none';
	}
}


function openWin(whichURL, winW, winH) {			// Open document in a new window with no toolbars or resizing

	var screenWH = getScreenSpecs(1024, 768);
	screenW = screenWH[0];
	screenH = screenWH[1];

	popWin=window.open(whichURL,"pWin2","toolbar=no,scrollbars=yes,resizable=no,width="+winW+",height="+winH+ ",left=" + Math.round((screenW/2)-(winW/2))+ ",top=" + Math.round((screenH/3)-(winH/2)) );
}

function closePopup() {								// Closes popWin
	setTimeout('popWin.close();', 2000);
}

function openVideo(streamURL, winW, winH) {			// Open a video stream in a new window with no toolbars or resizing

	var screenWH = getScreenSpecs(1024, 768);
	screenW = screenWH[0];
	screenH = screenWH[1];

	var playerURL = "videoPlayer.php?file=" + streamURL + "&w="+winW + "&h="+winH;
	
		// Enlarge the video window slightly to fit the video and controls
	
	winW = parseInt( winW * 1.95 );
	winH = parseInt( winH * 1.95 );

	popWin2=window.open(playerURL,"pWin2","toolbar=no,scrollbars=yes,resizable=no,width="+winW+",height="+winH+ ",left=" + Math.round((screenW/2)-(winW/2))+ ",top=" + Math.round((screenH/3)-(winH/2)) );
}


function browserWin(whichURL,winW,winH) {		// Open document in a new window with full browser controls

	var screenWH = getScreenSpecs(1024, 768);
	screenW = screenWH[0];
	screenH = screenWH[1];

	browserWin=window.open(whichURL,"bWin","menubar=yes,toolbar=yes,location=yes,scrollbars=yes,resizable=yes,width="+winW+",height="+winH+ ",left=" + Math.round((screenW/2)-(winW/2))+ ",top=" + Math.round((screenH/3)-(winH/2)) );
}


function statusAlert(msg) {				// Send a stylized prompt to the statusDiv

	setText('statusDiv', "<span class='alertPrompt indent4'><img src='images/icon-exclaim.gif'>" + msg + "</h2>");
	
}


function focusOn(targetID) {		// Gives focus to the named field or form object

	var targetObj = getObjectByID(targetID);
	targetObj.focus();
}


function focusWhenVisible(targetID, hiddenID) {		// Gives focus to targetID when hiddenID is visible

	var hiddenObj = getObjectByID(hiddenID);
	var hideStatus = hiddenObj.style.display;
// alert(hideStatus);
	if(hideStatus == '') {		
		setTimeout("focusOn('"+targetID+"');", 300);				// hiddenObj is visible: set focus
	} else {
		setTimeout("focusWhenVisible('"+targetID+"', '"+hiddenID+"');", 800);	// hiddenObj is invisible: delay another 800 ms
	}
}

function setActionAndSubmit (formName, state) {			// Specify the current action and post form data

	formObj = getObjectByID(formName);
	formObj.action.value = state;
	formObj.submit();
}


function setText (ID, text) {					// Sets the innerHTML of a <span> field to desired text.

	var textSpanObj = getObjectByID(ID);
	textSpanObj.innerHTML = text;
}

function getText (ID) {						// Returns the innerHTML of a specified <span> field

	var textSpanObj = getObjectByID(ID);
	var text = textSpanObj.innerHTML;

	return(text);
}

String.prototype.replaceAll = function( 			// Replaces all instances of a given substring

	strTarget, 		// The substring you want to replace
	strSubString 		// The string you want to replace in
){
	var strText = this;
	var intIndexOfMatch = strText.indexOf( strTarget );
 

	// Keep looping until all instances of the target string get replaced:
	
	while (intIndexOfMatch != -1){

		strText = strText.replace( strTarget, strSubString )	// Replace this instance
		intIndexOfMatch = strText.indexOf( strTarget );		// Any more?
	}
 
	return( strText );
}

function setValue () {				// Sets the value property of specified field(s)

	var lastObj = (setValue.arguments.length);
	for(n=0; n<lastObj; n++) {
		thisID = setValue.arguments[n]
		thisObj = getObjectByID(thisID);
		thisVal = setValue.arguments[++n];

		thisObj.value = thisVal;
	}
}

function getValue (id) {			// Returns the value property of the specified object

	var obj = getObjectByID(id);
	return obj.value;
}

function setCheckbox(id, state) {				// Sets checkbox values off or on

	var obj = getObjectByID(id);
	if(obj) {
		obj.checked = state;
	}
}

function showPrompt (msg) {					// Displays the (!) icon and a message in a Div whose id='prompt'
	
	var icon = "<img src='images/icon-exclaim.gif'>";
	var br = "<br><img src='images/spacer.gif' width='26' height='10'>";		// line break followed by a spacer
	
	msg.replaceAll('<br>', br);							// replace <br> with the special line break
	setText('prompt', '<p>' + msg + '</p>');
}

function submitURLdata(url, id) {				// Sends the value of listed objects to the URL via GET method

	var thisObj = getObjectByID(id);
	var thisURL = url + "?" + id + "=" + thisObj.value;

	window.location = thisURL;
}

function submitURLformData(url, form, id1, id2) {		// Sends the value of <form> objects to the URL via GET method

	if (form) {
		objRef = form + '.' + id1;
	} else {
		objRef = id1;
	}

	var thisObj = eval(objRef);
	var thisURL = url + "?" + id1 + "=" + thisObj.value;

	if (id2) {
		objRef = form + '.' + id2;
		thisObj = eval(objRef);
		thisURL += '&' + id2 + '=' + thisObj.value;
	}
	window.location = thisURL;
}

function forwardURLdata(gotoURL) {				// Reads the GET data string from the current bodyFrame URL, appends it to gotoURL,
								//	and branches to that page

	var parameterList = parent.bodyFrame.location.href.split("?");		// GET Parameters

	gotoURL += "?" + parameterList[1];
	window.location = gotoURL;
}


function parseURLdata(frameRef, param) {	// Reads a frame's URL and splits it into its components
						// scope: parent.bodyFrame, top, etc.

	var paramResult = null;

	var parameterList = frameRef.location.href.split("?");	// GET Parameters
	var result = 0;

	if (parameterList.length == 1) {			// No parameters; set defaults for home page:

		result = 0;

	} else {						// Split list into name.value pairs

		var parameterPairs = parameterList[1].split("&");
		var nameAndValue = new Array();
		var paramValue = new Array();
		var paramKey = new Array();

		for (p=0; p < parameterPairs.length; p++) {	// Cycle through name/value pairs & store values

			nameAndValue = parameterPairs[p].split("=");
			paramKey[p] = nameAndValue[0];
			paramValue[p] = nameAndValue[1];

			if (paramKey[p] == param) {		// Is this the target key?
				paramResult = paramValue[p];
			}
		}
	}

	// Remove anchors from selected:

	if (paramValue) {

		var last = (paramValue.length) - 1;

		if (paramValue[last].search('#') > 0) {

			var segment = selected.split("#");
			paramValue[last] = segment[0];
		}
	}

	if (param) {
		return paramResult;
	} else {						// No target param specified; return a list of values
		return paramValue;
	}
}

function disableIfEqual(targetControl, srcControl, thisValue) {		// Disables targetControl if srcControl has thisValue

	srcObj = getObjectByID(srcControl);
	targetObj = getObjectByID(targetControl);

	if (srcObj.value == thisValue) {

		targetObj.disabled = true;
	} else {
		targetObj.disabled = false;
	}
}

function disableIfNotEqual(targetControl, srcControl, thisValue) {	// Disables targetControl if srcControl DOESN'T have thisValue

	srcObj = getObjectByID(srcControl);
	targetObj = getObjectByID(targetControl);

	if (srcObj.value !== thisValue) {

		targetObj.disabled = true;
	} else {
		targetObj.disabled = false;
	}
}


