var xmlhttp;

function entercompetition(cpemail,cpname,cppostcode)
{


if (cpemail.length == 0 || cpname.length == 0 || cppostcode == 0)
  {
  document.getElementById("competition_result").innerHTML="You have not included a name, email or postcode.";
  document.getElementById("competition_result").style.border="0px";
  document.getElementById("competition_result").style.backgroundColor="transparent";
  document.getElementById("competition_result").style.color="red";
  return;
  }

else if (!/^([\w+_-]+(?:\.[\w+_-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i.test(document.getElementById("competitionemail").value))

 {
  var isemail = "no";
  document.getElementById("competition_result").innerHTML="Your email is incorrect.";
  document.getElementById("competition_result").style.border="0px";
  document.getElementById("competition_result").style.backgroundColor="transparent";
  document.getElementById("competition_result").style.color="red";
  return;
 }


if (cpemail.length > 0 && cpname.length > 0 && cppostcode.length > 0 && isemail != "no")

{

xmlhttp=GetXmlHttpObject()
if (xmlhttp==null)
  {
  alert ("Your browser does not support XML HTTP Request");
  return;
  }
var url="http://www.bluelizardreptiles.co.uk/competition.php";
url=url+"?c="+cpemail;
url=url+"&p="+cpname;
url=url+"&a="+cppostcode;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged19;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);

}

}

function stateChanged19()
{
if (xmlhttp.readyState==4)
  {
    if(xmlhttp.responseText == "Your details have been entered into this months competition.")

    {

    document.getElementById("competition_result").innerHTML=xmlhttp.responseText;
    document.getElementById("competition_result").style.backgroundColor="#FFFFFF";
    document.getElementById("competition_result").style.color="black";

    }

    if(xmlhttp.responseText == "Only 1 entry allowed per day.")

    {

    document.getElementById("competition_result").innerHTML=xmlhttp.responseText;
    document.getElementById("competition_result").style.backgroundColor="#FFFFFF";
    document.getElementById("competition_result").style.color="red";

    }

  }
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

