// set default url (home page) 
var mnuFyl = "menu.html"
// declare menu arrays
var lnks = new Array()
var lbls = new Array()
var ttls = new Array()
//Global variables
var i = 1
var winW = 0, winH = 0;
// set pW and pH for iframe padding to allow for menu column or footer + header
var pW = 160
var pH = 184
function findIdx(item, arr) {
	// find index position of {item}
	// in Array {arr} - return -1, if 
	// item not found 
	var idx;
	var last = arr.length;
	var lookin ="";
	for (var i = 0; i < last; i++) {
		lookin = " "+arr[i];
		if (lookin.indexOf(item)>0) { 
			idx = i;
			// quit on first "found"
			break;
		}
	}
	return idx;
}

// populate menu
function mnuPop(mnuLnk,mnuLbl,mnuTtl) {
	 lnks[i]= mnuLnk;
	 lbls[i] = mnuLbl;
	 ttls[i] = mnuTtl;
	 i++;
}
// write menu
function drawMnu(v) {
	var count = 1;
	if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion)<=4) ){
  		document.write("<h3 align='center'>Sorry, navigating this site requires Internet Explorer 5+ for Windows, ");
		document.writeln("Mozilla 5+ or Firefox for any system, or Mac Safari.</h3>");
 	}
	else {
		while (count<= lnks.length) {
			if (lnks[count]==null) {
				count++;
				}
			else {
				document.write("<input type='button' id='mBtn' value='");
				document.write(lbls[count]);
				document.write("' title='");
				document.write(ttls[count]);
				document.write("' onClick=clientSideInclude('");
				document.write(lnks[count]);
				document.writeln("') onMouseOver=\"id='mBtnOver'\" onMouseOut=\"id='mBtn'\">")
				if (v) {document.writeln("<br>")}
				count++;
			}
		}
	}
}

function findWinSize() {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		winW = window.innerWidth;
		winH = window.innerHeight;
	} else if( document.documentElement &&
		( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		winW = document.documentElement.clientWidth;
		winH = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		winW = document.body.clientWidth;
		winH = document.body.clientHeight;
	}
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
}

function clientSideInclude(cURL) {
  // check for querystring item f
  var f = getQueryVariable("f")
  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
 var element = document.getElementById('contnt');
 var fItem = lnks[1]; 
  if (req) {
    // Synchronous request, wait till we have it all
	if (cURL) {
	 	var cURL_array = cURL.split(",");
 		var gURL = cURL_array[0];
 		var frameIt = cURL_array[1];
		if (gURL == fItem) {
			window.location.replace(mnuFyl);
			// set switch to skip element.innerHTML assignment since we dont get req.responseText
			var skipReq = true;
		}
		else {
			req.open('GET', gURL, false);
	    	req.send(null);
		}
	}
	// if no selection was passed
	else { 
		// test for/get file url passed in querystring
		if (f) { 
			// find index of f in 
			var fndx = findIdx(f, lnks);
			fItem = lnks[fndx]; 
			// dropped in for test
			cURL = fItem
		 	var cURL_array = cURL.split(",");
	 		var gURL = cURL_array[0];
	 		var frameIt = cURL_array[1];
			req.open('GET', gURL, false);
			req.send(null);
			////
			//req.open('GET', f,false);
			//req.send(null);
		 }
		// otherwise get first menu element
		else { 
			cURL = fItem
		 	var cURL_array = cURL.split(",");
	 		var gURL = cURL_array[0];
	 		var frameIt = cURL_array[1];
			req.open('GET', gURL, false);
			req.send(null);
		}
	}
	if (! skipReq) {
		// if iFrame switch passed, set up iframe
		if (frameIt) {
			if (cURL_array[1]!=1) {
				window.open(gURL);
			}
			else {
				findWinSize();
			    element.innerHTML = 
					"<iframe id='conFrame' src='" + gURL + "' width='" + (winW-pW) + "' height='"  + 
					(winH-pH) + "' scrolling='auto'><h3 align='center'>" + 
					"Sorry, your browser does not support iFrame content.</h3></iframe>";
			}
		} else {
		    element.innerHTML = req.responseText;
		}
	}
  }else {
    element.innerHTML =
   		"<h3 align='center'>Sorry, your browser does not support XMLHTTPRequest objects. This page requires Internet Explorer 5 " +
   		"or better for Windows, or Firefox for any system, or Safari. Other compatible browsers may also exist.</h3>";
  }
}
//fix menu
var IE = document.all?true:false;
document.writeln("<style type='text/css'>");
if (IE) { 
	document.writeln("html, body { height: 100%; overflow: auto; }");
	document.write(".fixed { position:absolute; }");
} else {
	document.writeln(".fixed { position:fixed; }");
}
document.writeln("</style>");

function PopNote(popit) {
	var popupURL = popit;
	var popupName = "popNote";
	var popup = window.open(popupURL,popupName,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=400,height=400,');
	popup.location = popupURL;
}

function maskedMail(r, d, e, s) {
    // use like maskedMail(recipient,domain name,domain ext,subject)
    var mailerURL = "mailto:" + r + "@" + d + "." + e;
    if (s) { mailerURL = mailerURL + "&subject=" + s }
    var mailer = window.location.replace(mailerURL);
}

