function window_contents(idx) {
	return '		<div style="align: center; border: 1px solid #000000; background-color: #FFFFE1; padding: 10px 2px 2px 2px;">		<form onsubmit="notify_me('+idx+'); return false" id="notify_form"><span id="change">To be notified when this book is completed, enter your email address: <input type="text" name="email" id="email" />		<input type="submit" value="Notify Me"/> </span><input type="submit" value="Close" onclick="popped.close(); return false;"/></form><p style="border-top: thin black solid; padding-top:10px;">LibriVox will only use your email address to send you the email you have requested; it will then be deleted from our system</p></div>';
}

var popped;
function disp(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
	popped = createWindow('Notify me', 300, '#D6E1F5', 1, 1, posx, posy);
}


function do_ajax_magic(params) {
    var xmlHttpReq = false;
    // Mozilla/Safari/Opera
    if (window.XMLHttpRequest) {
        xmlHttpReq = new XMLHttpRequest();
        if (xmlHttpReq.overrideMimeType)
        { // Opera doesn't support this, but also doesn't need it
            xmlHttpReq.overrideMimeType('text/xml');
        }
    }
    // IE
    else if (window.ActiveXObject) {
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    xmlHttpReq.open('POST', 'http://librivox.org/newcatalog/notify/notify.php', true);
    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttpReq.onreadystatechange = function() {
        if (xmlHttpReq.readyState == 4) {
					if (xmlHttpReq.status == 200) { success(); }
					else { fail(xmlHttpReq.status); }
        }
    }  
    var qs = "";
    for (var param in params) {
    	if (qs!="") { qs = qs + "&"; }
    	qs = qs + param + "=" + escape(params[param]);
    }
    working();
    try {
    	xmlHttpReq.send(qs);
    } catch(err) {
    	fail(-1);
    }
} 


function notify_me(idx){
	var email = document.getElementById("email").value;
 if ((email==null) || (email.length==0)){
  alert("Please enter your email address.");
 }//end if email not entered


 else{
 	params = {};
 	params['idx'] = idx;
 	params['email'] = email;
 	do_ajax_magic(params);
 }//end else

}

function working() { document.getElementById("change").innerHTML = "Contacting librivox.org..."; }
function fail(s) { document.getElementById("change").innerHTML = "Sorry, there was a problem processing your request. ("+s+")"; }
function success() { document.getElementById("change").innerHTML = "Your request to be notified when this book is complete has been received. Thank you!"; }
