function sendmail() {
	update_status("Sending...");

	var email    = $('email').value;
	var mobifile = $('mobifile').value;
	var epubfile = $('epubfile').value;
	var q_orig   = $('q_orig').value;
        var chk="off";
        if(document.getElementById("checkkindle").checked==true){
            chk="on"
        }
       

	var url = 'sendmail.php';
	var parms = "email="+email+"&mobifile="+mobifile+"&epubfile="+epubfile+"&q_orig="+q_orig+"&checkkindle="+chk;
	new Ajax.Request(
		url,
		{asynchronous:true,
		 evalScripts:true,
		 method:'post',
		 parameters: parms,
		 onSuccess:function(transport) {

			if(transport.responseText.indexOf("Message Sent") > 0){
				update_status("Email Sent.");
			}else{
				error_msg = transport.responseText.replace(/^.*Error: /,"");
				update_status("Sorry, the email would not send.  "+ error_msg);
			}
			$('bookform').style.display='block';
		 }
		});
	return false;

}

function buildbook() {
	var url = document.location.href;
	url = 'build2.php' + url.substring(url.indexOf("?"),url.length);
	var http_handle;
	var i;
	var params = "";
	for (i=0;i < document.form.urls.length; i++) {
	  if (document.form.urls[i].checked) {
	    params = params + "url" + i + "=" + document.form.urls[i].value + "&";
	  }
	}
	params = params + "q=" + document.form.q.value;
	if (window.XMLHttpRequest){
		http_handle = new XMLHttpRequest();
		if (http_handle.overrideMimeType){
			http_handle.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject){
		try {
			http_handle = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_handle = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_handle){
		alert("We are sorry but you are using an outdated browser.  To view this site you must update your browser.");
		return false;
	}

    http_handle.open("POST",url,true);
	http_handle.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http_handle.setRequestHeader("Content-length", params.length);
    http_handle.setRequestHeader("Connection", "close");
    http_handle.onreadystatechange= function() {
	  if (http_handle.readyState == 4){
	    if (http_handle.status == 200) {
   		  alert(http_handle.responseText);
	      document.getElementById('buildstatus').innerHTML = "Your Book is Done";
		  return true;
		}
      }
    }
    http_handle.send(params);	
	document.getElementById('buildstatus').innerHTML = "Your Book is Building";
	return true;
}

function update_status(s){
	$('status').innerHTML = s;
}