function ahah1(url,target) {
    document.getElementById(target).innerHTML = 'loading data...';
    if (window.XMLHttpRequest) {
       	req1 = new XMLHttpRequest();
        req1.onreadystatechange = function() {ahahDone1(target);};
        req1.open("GET", url, true);
        req1.send(null);
    } else if (window.ActiveXObject) {
        req1 = new ActiveXObject("Microsoft.XMLHTTP");
        if (req1) {
            req1.onreadystatechange = function() {ahahDone1(target);};
            req1.open("GET", url, true);
            req1.send();
        }
    }
} 

function ahahDone1(target) {
   // only if req is "loaded"
   if (req1.readyState == 4) {
       // only if "OK"
       if (req1.status == 200 || req1.status == 304) {
           results = req1.responseText;
           document.getElementById(target).innerHTML = results;
       } else {
           document.getElementById(target).innerHTML="ahah error:\n" +
               req1.statusText;
       }
   }
}

function ahah2(url,target) {
    document.getElementById(target).innerHTML = 'loading data...';
    if (window.XMLHttpRequest) {
       	req2 = new XMLHttpRequest();
        req2.onreadystatechange = function() {ahahDone2(target);};
        req2.open("GET", url, true);
        req2.send(null);
    } else if (window.ActiveXObject) {
        req2 = new ActiveXObject("Microsoft.XMLHTTP");
        if (req2) {
            req2.onreadystatechange = function() {ahahDone2(target);};
            req2.open("GET", url, true);
            req2.send();
        }
    }
} 

function ahahDone2(target) {
   // only if req is "loaded"
   if (req2.readyState == 4) {
       // only if "OK"
       if (req2.status == 200 || req2.status == 304) {
           results = req2.responseText;
           document.getElementById(target).innerHTML = results;
       } else {
           document.getElementById(target).innerHTML="ahah error:\n" +
               req2.statusText;
       }
   }
}


function loadPages(leftpage, rightpage, musicfile, nomusic) {
	if (leftpage != '') {
		ahah1(leftpage, 'leftpage');
	}
	if (rightpage != '') {
		ahah2(rightpage, 'rightpage');
	}
	if (musicfile != '') {
		loadMusicPlayer(musicfile);
	}
	if (nomusic == true) {
		unloadMusicPlayer();
	}
}

function loadMusicPlayer(filename) {
	document.getElementById('mp3player').innerHTML = '<embed ' +
			'src="media/mp3player.swf" ' +
			'width="290" height="20" allowfullscreen="true" ' +
			'allowscriptaccess="always" ' +
			'flashvars="&file=' + 
			filename + 
			'&height=20&width=290&backcolor=0xffcc66&showdigits=false"/>';
}

function unloadMusicPlayer() {
	document.getElementById('mp3player').innerHTML = '';
}

