var xmlhttp, form, type=1;

function sendCode(form_nr)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }

form = document.forms[form_nr];
var url="send_active_code.php?FIRSTNAME=" + form.elements['FIRSTNAME'].value;
url += "&POSTCODE=" + form.elements['POSTCODE'].value + "&EMAIL=" + form.elements['EMAIL'].value + "&sid="+Math.random() + "&TYPE=" + type;
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
	if (xmlhttp.readyState==4)
		{
		xmlDoc=xmlhttp.responseXML;
		switch(xmlDoc.getElementsByTagName('STATUS')[0].childNodes[0].nodeValue)
			{
			case 'alert': alert(xmlDoc.getElementsByTagName('reply')[0].childNodes[0].nodeValue); break;
			case 'location': window.location=xmlDoc.getElementsByTagName('reply')[0].childNodes[0].nodeValue; break;
			case 'message': document.getElementById("txtHint").innerHTML=xmlDoc.getElementsByTagName('reply')[0].childNodes[0].nodeValue; break;
			}
		form.elements['FIRSTNAME'].value=xmlDoc.getElementsByTagName('FIRSTNAME')[0].childNodes[0].nodeValue;
		form.elements['POSTCODE'].value=xmlDoc.getElementsByTagName('POSTCODE')[0].childNodes[0].nodeValue;
		form.elements['EMAIL'].value=xmlDoc.getElementsByTagName('EMAIL')[0].childNodes[0].nodeValue;
		}
}

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;
}

function DF(name)
{
	window.open('download.php?sid='+Math.random()+'&id='+name);
}

function sendForm(form_nr)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
form = document.forms[form_nr];
var url="sendform.php?f1=" + form.elements['f1'].value;
for(q=2;q<=20;q++) { url+='&f'+q+'=' + form.elements['f'+q].value; }
url += "&sid="+Math.random();
xmlhttp.onreadystatechange=stateChangedSendForm;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChangedSendForm()
{
	if (xmlhttp.readyState==4)
		{
		out_text=xmlhttp.responseText;
		if(out_text != 'Location'){	alert(out_text); }
		else { window.location='page23.html'; }
		}
}

function setType(nr){ type=nr; }
