// set default url (home page) 
var mnuFyl = "index.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 = 200
var pH = 10
// populate menu
function mnuPop(mnuLnk,mnuLbl,mnuTtl) {
	 lnks[i]= mnuLnk;
	 lbls[i] = mnuLbl;
	 ttls[i] = mnuTtl;
	 i++;
}
// write menu
function drawMnu() {
	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'\">")
				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 alertWinSize() {
	findWinSize();
	alert("Window dimensions in pixels:\n\t Width: " + winW + "\n\t Height: " + winH);
}

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) { 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>";
  }
}
