function Insert_Email()
{
  var email = document.getElementById('subscribe_email').value;
  //Check Data
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
  if (filter.test(email))
  {
	  var adress_name = email.split('@');
		adress_name = adress_name[0];
		AJAXRequestURL("/mailing_list/insertquery.php?name="+adress_name+"&email="+email,SubscribeServerResponse);
  }
  else
  {
    Set_Message("Onjuist emailadres",'/img/bg/nb-btn-error.jpg');
  }
}
function SubscribeServerResponse()
{
  switch (xmlHttpResponseText)
	{
	  case "succes":
		  Set_Message("Bedankt voor u interesse",'/img/bg/nb-btn-succes.jpg');
			//document.getElementById("subscribe_button").style.display='none';
		break;
	  case "already exists":
		  Set_Message("U Emailadres bestaat al",'/img/bg/nb-btn-error.jpg');
		break;
		case "":
		  Set_Message("Geen reactie van server",'/img/bg/nb-btn-error.jpg');
		break;
		default:
		  Set_Message("Error: "+xmlHttpResponseText,'/img/bg/nb-btn-error.jpg');
		break;
	}
}
function Set_Message(message,img)
{
  document.getElementById("subscribe_message").innerHTML=message;
	document.getElementById("subscribe_form").style.display="none";
	document.getElementById("subscribe_message").style.display="";
	document.getElementById("subscribe_button").style.background="url("+img+")";
	document.getElementById("subscribe_button").onclick=Reset_Message;
}
function Reset_Message()
{
	document.getElementById("subscribe_message").style.display="none";
	document.getElementById("subscribe_form").style.display="";
	document.getElementById("subscribe_button").onclick=Insert_Email;
	document.getElementById("subscribe_button").style.background="url(/img/bg/nb-btn.gif)";
}

