var httpxml="";
var xmlhttp="";
function findAjax()
{
	try
    {
	 httpxml=new XMLHttpRequest();
    }
	catch (e)
    {
		try
		{
			httpxml=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			httpxml=new ActiveXObject("Microsoft.XMLHTTP");
		}
    }
  return httpxml;

}
function addnewsletter()
{
	xmlhttp=findAjax();
	var div=document.getElementById("newsletter");
	var email=div.value;
	if(email=="email@address.com")
	{
		alert('Please use proper e-mail');
		return;
	}
	var patrn=/.+@.+\.[a-zA-Z]{2,4}$/;
	if(!patrn.exec(email))
	{
		return;
	}
	var url="http://www.chinatouristmaps.com/forms/newsletter.php?email="+email+"&&"+Math.random();
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=myback;
	xmlhttp.send(null);
}
function myback() 
{ 
  if (xmlhttp.readyState==4)
  { 
	if(xmlhttp.responseText=="1")
	 {
		alert('Thank you for subscribing to our newsletter. The chinatouristmaps Team');
	 }
	 else if(xmlhttp.responseText=="2")
	  {
		alert('You are already registered to our newsletter. We hope you have enjoyed our previous publications.');
	 }
	 else 
	  {
		alert('The system is busy, please try again later.');
	 }
  }
}
