﻿function ahah(url, target,pid,lr) {
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (req != undefined) {
		req.onreadystatechange = function() {ahahDone(url, target,pid,lr);};
		req.open("GET", url, true);
		req.send("");
	} else {
		document.getElementById(target).innerHTML = 'error1';
	}
}  

function ahahDone(url, target,pid,lr) {
	if (req.readyState == 4) { // only if req is "loaded"
		if (req.status == 200) { // only if "OK"
			if (pid == 18) {
				initGallery(1);
			} else if (pid == 19) {
				initGallery(4);
			} else if (pid == 20) {
				initGallery(5);
			} else {
				if (lr == 'L') {
					if (document.getElementById('contentTable')) {
						document.getElementById('contentTable').innerHTML = window.normalContent;
					}
				}
			}
			document.getElementById(target).innerHTML = req.responseText;
			if (lr == 'L') {
				slideShow('off');
			}
			
			if (pid == 1) {
				if (lr == 'L') {
					hideName();
					slideShow('on');
					document.getElementById('contentRight').className = 'contentRightHome';
					replaceDivWithFlash('/flash/home-slideshow.swf','slideshow',566,307,'',9,true,'slideshowdiv');
					loadFile = 'files/pagesource/homeright.html?pid='+pid;
					load(loadFile,'contentRight',1,'R');
				} else {
					replaceDivWithFlash('/flash/EnterEmailAddress.swf','emailaddress',272,112,'',9,true,'emailaddressdiv');
				}
			} else if (pid == 8) {
				document.getElementById('contentRight').className = 'contentRightContact';
				setImage(31);
				setName();
				contactBoxHTML = document.getElementById('contactBox').innerHTML;
				document.getElementById('contentRight').innerHTML = document.getElementById('contentRight').innerHTML + '<br><br>' + contactBoxHTML;
			} else {
				if (document.getElementById('contentRight')) {
					document.getElementById('contentRight').className = 'contentRightNormal';
				}
				setImage(0);
				setName();
				if (document.getElementById("nonScrollContent")) {
					thisText = document.getElementById("nonScrollContent").innerHTML;
					document.getElementById("nonScrollContent").innerHTML = "";
					document.getElementById("slideshowdiv").innerHTML = thisText;
					slideShow("nonScroll");
				}
				
				if (pid == 22) {
					slideShow('motivation');
				}
			}
		} else {
			document.getElementById(target).innerHTML = 'Error loading page.  Contact Webmaster.';
		}
	}
}

function load(name, div,pid,lr) {
	ahah(name,div,pid,lr);
	return false;
}