function window_contents(rss) {
	return '		<div style="border: 1px solid #000000; background-color: #FFFFE1; padding: 10px 2px 2px 2px;">		<form onsubmit="SubscribeAudioListener(\''+rss+'\'); return false" id="subscribe_form">		<span id="change">To receive a link to a new chapter each day, enter your email address: <input type="text" name="email" id="email" />		<input type="submit" value="Subscribe"/>	</span> <input type="submit" value="Close" onclick="popped.close(); return false;"/>	</form><p style="border-top: thin black solid; padding-top:10px;">LibriVox will not keep any record of your email address; it will be sent to publicliterature.org, who will only use it to send you the emails you have requested.</p> <p><a href="http://publicliterature.org/privacy.php" target="_blank">publicliterature privacy policy</a></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('Chapter-a-day Subscription', 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', '/wp-content/plugins/emailperday/subscribe.rb', 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 SubscribeAudioListener(rss){
	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['rss'] = rss;
 	params['email'] = email;
 	do_ajax_magic(params);
 }//end else

}//end SubscribeAudioListener

function working() { document.getElementById("change").innerHTML = "Contacting publicliterature.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 for daily emails has been received. Enjoy!"; }