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();
}
MM_reloadPage(true);

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

///////////////////////// NON DREAMWEAVER SCRIPTS ///////////////////////////////////////////////////

function addLoadEvent(func) {	// Simon Willison - simonwillison.net
  	var oldonload = window.onload;
  	if (typeof window.onload != 'function') {
		window.onload = func;
  	} 
	else {
		window.onload = function() {
	      		if (oldonload) {
		  		oldonload();
	  		}
	      		func();
	    	}
  	}
}

function popup(mylink, windowname)	{
if (!window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=500,height=200,scrollbars=yes,resizable=yes');
return false;
}
////////////////////////////// MY FUNCTIONS BELOW ///////////////////////////////////////////////////

function loadEvents()	{	// mine load events for each page
	addLoadEvent(externalLinks());
	addLoadEvent(preLoadImages('/images/print_win_over.gif'));
	addLoadEvent(new ShowInfoWindow('infoWindowContainer').init());
}

function encode(string) {
    if (encodeURIComponent) {
        return encodeURIComponent(string);
    }
    if (escape) {
        return escape(string);
    }
}

function decode(string)	{
	if (decodeURIComponent)	{
		return decodeURIComponent(string);
	}
	if (unescape)	{
		return unescape(string);
	}
}

function addFav() {
	if (!document.createElement || !document.getElementById) {return false;}
	var fav = document.createElement('a');
	var holder = document.getElementById('add_fav');
	var text = document.createTextNode('Add to your favorites');
	fav.setAttribute('href' , 'javascript:void(0)');
	fav.setAttribute('title', 'Add this page to your favorites');
	fav.setAttribute('class', 'text_white');
	if (fav.addEventListener) { // Moz
		fav.addEventListener('click', function (e) {
			var title = document.title;
			var url = window.location;
			if	(window.sidebar)	{ // moz
				window.sidebar.addPanel(title, url, "");
			}
			else if (window.external)	{ // IE
				window.external.AddFavorite(url, title);
			}
			else if (window.opera && window.print)	{//opera
				var opr = document.createElement('a');
				opr.setAttribute('rel','sidebar');
				opr.setAttribute('href',url);
				opr.setAttribute('title',title);
				opr.click();
			}
		}, false);
	}
	else { // IE
		fav.attachEvent('onclick', function (e) {
			var title = document.title;
			var url = window.location;
			if (window.external)	{ // IE
				window.external.AddFavorite(url, title);
			}
			else if (window.opera && window.print)	{//opera
				var opr = document.createElement('a');
				opr.setAttribute('rel','sidebar');
				opr.setAttribute('href',url);
				opr.setAttribute('title',title);
				opr.click();
			}
		});
	}
	fav.appendChild(text);
	holder.appendChild(fav);
	
}

function externalLinks() { // adaption by me
 	if (!document.getElementsByTagName) return; 
 	var a = document.getElementsByTagName("a");
	var len = a.length;
	for (var i=0; i<len; i++) { 
		var aLength = a[i];
		var rel = aLength.getAttribute("rel");
		switch (rel)	{
			case 'external':
				aLength.target = '_blank';
//				aLength.title = (aLength.title != "") ? aLength.title+" (link opens in a new window)" : "link opens in a new window";
				aLength.className = (aLength.className != "") ? aLength.className+"_external" : "external";
				break;
			default:
				return;
				break;
		}
	}
}

function printWin()	{
	if (!document.createElement || !document.getElementById) {return false;}
	var img = document.createElement('img');
	var holder = document.getElementById('print');
	img.setAttribute('src', '/images/print_win.gif');
	img.setAttribute('alt', 'Print this window');
	img.setAttribute('height', '19');
	img.setAttribute('width', '113');
	img.setAttribute('id', 'printImg');
	if (img.addEventListener) {
		img.addEventListener('click', function (e) {window.print()}, false);
		img.addEventListener('mouseover', 
			function (e) {
				var overImg = '/images/print_win_over.gif';
				var start = document.getElementById('printImg');
				start.src = overImg;
			}, 
		false);
		img.addEventListener('mouseout', 
			function (e) {
				var start = document.getElementById('printImg');
				var restoreImg = '/images/print_win.gif';
				start.src = restoreImg;
			}, 
		false);
	}
	else {
		img.attachEvent('onclick', function (e) {window.print()});
		img.attachEvent('onmouseover', 
			function (e) {
				var overImg = '/images/print_win_over.gif';
				var start = document.getElementById('printImg');
				start.src = overImg;
			}	
		);
		img.attachEvent('onmouseout', 
			function (e) {
				var start = document.getElementById('printImg');
				var restoreImg = '/images/print_win.gif';
				start.src = restoreImg;
			}
		);
	}
	holder.appendChild(img);
}

function preLoadImages()	{
	if (!document.images)	{return false;}
	var arg = preLoadImages.arguments;
	var argLen = arg.length;
	imgObj = new Image();
	images = new Array();
	for (var i=0; i<argLen; i++)	{
		images[i] = arg[i];
		imgObj.src = images[i];
	}
}

function goBack(id)	{
	if (!document.createElement || !document.getElementById) {return false;}
	var myLink = document.createElement('a');
	var holder = document.getElementById(id);
	var text = document.createTextNode('Go back to the previous page');
	myLink.setAttribute('href' , 'javascript: void(0)');
	if (myLink.addEventListener) { // Moz
		myLink.addEventListener('click', function (e) {
			document.history.go(-1)
		}, false);
	}
	else { // IE
		myLink.attachEvent('onclick', function (e) {
			document.history.go(-1)
		});
	}
	myLink.appendChild(text);
	holder.appendChild(myLink);
}


/////////////////////////////////////////////////////////////////  Cookie functions  ///////////////////////////////////////////////////////////////////////// 

function bakeCookie(name, value, expireDays)	{
	var expire = new Date();
	expire.setDate(expire.getDate()+expireDays);
	var day = (expireDays == null) ? '' : ';expires='+expire.toGMTString();
	document.cookie = name + '=' +encode(value) + day;
}

function eatCookie(name)	{
	document.cookie = name + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

function findCookie(name)	{
	if (document.cookie.length > 0)	{
		var look = document.cookie.indexOf(name + '=');
		if (look != -1)	{
			start = look + name.length+1;
			var end = document.cookie.indexOf(';');
			if (end == -1)	{	// only 1 cookie present
				end = document.cookie.length;
			}
			return decode(document.cookie.substring(start, end));
		}
		return false;
	}
}

function noCookieAlert()	{
	bakeCookie('cookie_test', 'TEST', 1);
	var f = findCookie('test');
	if (f === false)	{
		return 0;
		alert('You need to be able to accept cookies to use this area.');
	}
	else	{
		return 1;
	}
}

function ShowInfoWindow(eId) {
	this.eId = eId;
	this.infoArray = [];
	this.infoPopupId = 'infoPopup';
	this.infoWindowId = '_infoWindow_';
}
// ShowInfoWindow.prototypes

ShowInfoWindow.prototype.show = function(e) {
	if (!e) {var e = window.event;}

	// Location of event
	var posX = 0;
	var posY = 0;
	var targ = null;

	targ = e.target ? e.target : e.srcElement;

	if (e.pageX || e.pageY) {
		posX = e.pageX;
		posY = e.pageY;
	}
	else if (e.clientX || e.clientY) {
		posX = e.clinetX;
		posY = e.clientY;
		posX += document.body.scrollLeft + document.documentElement.scrollLeft;
		posY += document.body.scrollTop +  document.documentElement.scrollTop;
	}

	// text for infoPopup
	var targId = targ.getAttribute('id');
	var re = new RegExp('^' + this.infoWindowId + '(\\d+)$');
	// window.alert('re string: ' + re.toString());

	targId = re.test(targId);
	targId = RegExp.$1;
	text = this.infoArray[targId];

	this.createPopup(posX, posY, text);
}

ShowInfoWindow.prototype.hide = function() {
	var popup = document.getElementById(this.infoPopupId);
	if (!popup) {return;}
	popup.parentNode.removeChild(popup);
}


ShowInfoWindow.prototype.createPopup = function(posX, posY, text) {
	var popup = document.getElementById(this.infoPopupId);
	if (!popup) {
		popup = document.createElement('div');
		popup.setAttribute('id', this.infoPopupId);
		popup.style.position = 'absolute';
		popup.style.top = posY + 5 + 'px';
		popup.style.left = posX + 5 + 'px';
		popup.style.width = '40%';
		popup.style.padding = '3px';
		popup.style.zIndex = 999;
		popup.style.border = '3px solid #000';
		popup.style.backgroundColor = '#fff';
		popup.style.backgroundImage = 'url(/images/bg.gif)';
//		popup.setAttribute('class', 'infoPopup');
		var popText = document.createTextNode(text);
		popup.appendChild(popText);

		document.body.appendChild(popup);
	}
}

ShowInfoWindow.prototype.add = function(c) {
	var thisObj = this;
	var children = c.childNodes;
	var liI = 0;

	for (var i=0, il=children.length; i<il; i++) { // list of all infoWindowContainer children includes \n and \n\n
		if (children[i].nodeName.toUpperCase()=='LI') {
			var grandKids = children[i].childNodes;
//			window.alert('Li number: ' + liI + '\nchildren length: ' + il + '\ngrandKids length: ' + grandKids.length);
			for (var j=0; j<3; j++) {
				if (grandKids[j].nodeName.toUpperCase()=='A') {
					// get text into infoArray
					var text = grandKids[j].parentNode.lastChild.nodeValue;
					this.infoArray[liI] = text;
//					window.alert('LiI: ' + liI + '\ntext: ' + text + '\n\ninfoArray text: ' + this.infoArray[liI]); // working
					grandKids[j].parentNode.removeChild(grandKids[j].parentNode.lastChild); // this is working.

					var gkClass = grandKids[j].className;
					gkClass=='' ? grandKids[j].setAttribute('class', 'infoWindow') : grandKids[j].setAttribute('class', gkClass + ' infoWindow');
					grandKids[j].setAttribute('id', this.infoWindowId + liI);
					// event handling
					if (grandKids[j].addEventListener) {
						grandKids[j].addEventListener('mouseover', function(e) {thisObj.show(e).call(thisObj)}, false);
						grandKids[j].addEventListener('mouseout', function(e) {thisObj.hide().call(thisObj)}, false);
					}
					else if (grandKids[j].attachEvent) {
						grandKids[j].attachEvent('onmouseover', function() {thisObj.show().call(thisObj)});
						grandKids[j].attachEvent('onmouseout', function() {thisObj.hide().call(thisObj)});
					}
					else {
						grandKids[j].onmouseover = thisObj.show().call(thisObj);
						grandKids[j].onmouseout = thisObj.hide().call(thisObj);
					}
				}
				else {
					continue;
				}
			}
		liI++; 
		}
		else {
			continue;
		}	
	}
}

ShowInfoWindow.prototype.init = function() {
	if (!(document.getElementById && document.createElement && document.createTextNode && document.getElementsByTagName && (document.addEventListener || document.attachEvent))) {return;}
	var container = document.getElementById(this.eId);
	if (!container) {return;}
	this.add(container);
}

function xmlHttpObject()	{
	var HTTPrequest = false;
    if (window.XMLHttpRequest) { // Mozilla
    	HTTPrequest = new XMLHttpRequest();
      	if (HTTPrequest.overrideMimeType) {
        	HTTPrequest.overrideMimeType('text/xml');
        }
    } 
	else if (window.ActiveXObject) { // IE
        try {
            HTTPrequest = new ActiveXObject("Msxml2.XMLHTTP");
        } 
		catch (e) {
            try {
				HTTPrequest = new ActiveXObject("Microsoft.XMLHTTP");
            }
			catch (e) { // doesnt work
			}
        }
    }
	if (!HTTPrequest)	{
		alert('Giving up. Cannot create an XMLHTTP Instance');
		return false;
	}
	return HTTPrequest;
}

function getAjaxResponse(type, url)	{		// type = text || XML
	var ajax = xmlHttpObject();
	ajax.onreadystatechange = function()	{
		try {
			if(ajax.readyState == 4) {
				switch (ajax.status)	{
				case 200:
					if (type == 'XML')	{
						var resp = ajax.responseXML;
					}
					else if (type == 'text')	{
						var resp = ajax.responseText;
					}
					else	{
						alert('Ajax method not supported');
					}
					//alert('Response: ' + resp);
					//return resp;
					break;
				case 404:
					alert('URL not found');
					break;
				case 403:
					alert('Access denied');
					break;
				default:
					alert('Error: status code is ' + ajax.status);
					break;
				}
			}
		}
		catch (e)	{
			alert('Caught Exception: ' + e.description);
		}
	}
	ajax.open('GET', url, true);
	ajax.send(null);
}























function ajaxRequest(url)	{
	var HTTPrequest = false;
    if (window.XMLHttpRequest) { // Mozilla
    	HTTPrequest = new XMLHttpRequest();
      	if (HTTPrequest.overrideMimeType) {
        	HTTPrequest.overrideMimeType('text/xml');
        }
    } 
	else if (window.ActiveXObject) { // IE
        try {
            HTTPrequest = new ActiveXObject("Msxml2.XMLHTTP");
        } 
		catch (e) {
            try {
				HTTPrequest = new ActiveXObject("Microsoft.XMLHTTP");
            }
			catch (e) { // doesnt work
			}
        }
    }
	if (!HTTPrequest)	{
		alert('Giving up. Cannot create an XMLHTTP Instance');
		return false;
	}
	HTTPrequest.onreadystatechange = function()	{
		result(HTTPrequest);
	}
	HTTPrequest.open('GET', url, true);
    HTTPrequest.send(null);
}

function result(req)	{
	try {
		if(req.readyState == 4) {
			switch (req.status)	{
			case 200:
				var response = req.responseText;
				alert('Response: ' + response);
				break;
			case 404:
				alert('URL not found');
				break;
			case 403:
				alert('Access denied');
				break;
			default:
				alert('Error: status code is ' + req.status);
				break;
			}
		}
	}
	catch (e)	{
		alert('Caught Exception: ' + e.description);
	}
}

