
function sendEmail(params)
{
	
if (!validate('email_form', 'to_email') || !validate('email_form', 'from_email'))
	return false;


if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  




xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {

  getByID('email_this_page').innerHTML=xmlhttp.responseText;
 
    }
  }

xmlhttp.open("GET","/book/inc/book_email.php?" +params,true);

xmlhttp.send();
return false;

}

function getByID(ID){
    if (document.getElementById){
		
        return document.getElementById(ID);
    }
    else if ((document.all) && (eval ('document.all.' + ID))){
        return eval ('document.all.' + ID);
    }
}


function validate(form_id,email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.forms[form_id].elements[email].value;
   var addresses = address.split(",");
   for ( var i in addresses )
   {
	   addresses[i] = addresses[i].replace(/^\s+|\s+$/g, '') ;//trim
	   if(reg.test(addresses[i]) == false) {
		  alert('Invalid Email Address, please re-enter');
		  return false;
   		}
   }
	
   return true;
}
function buildParams()
{
	
	var params = "";
	params += '&isbn=' + getByID('email_form_isbn').value
			+'&to_email=' + getByID('to_email').value
			+'&from_email=' + getByID('from_email').value
			+'&copy_to_sender=' + getByID('copy_to_sender').value
			+'&message=' + getByID('email_message').value;
	
	
	return params;
}

