/////ajax request object
var request = null;
try {
  request = new XMLHttpRequest();
} catch (trymicrosoft) {
  try {
    request = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (othermicrosoft) {
    try {
      request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (failed) {
      request = null;
    }
  }
}

if (request == null)
  alert("Error creating request object!");
  /////ajax request object
  
function loadForm(formname, params)
{
  //url = "http://localhost:4000/amtuk/NIEUW/includes/views/form/" + formname;
  
  //url="http://amtuk.railmedia.ro/v2/includes/views/form/" + formname;
  url="http://www.amtuk.com/includes/views/form/" + formname;
  
  request.open("POST", url, true);
  
  request.onreadystatechange = getReadyStateHandler(request, updateForm);
      request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      request.setRequestHeader("Content-length", params.length);
      request.setRequestHeader("Connection", "close");

  request.send(params);
 }
 
function updateForm()
{
if (request.readyState == 4) {
    if (request.status == 200) {
		 var result = request.responseText;
		 document.getElementById("ajaxform").innerHTML=result;

		}
   }
}

function sendform2()
{
	result = validateFormOnSubmitInquiry2(document.getElementById('form2')); 
	
	if (result) 
	{
	  fullname = encodeURIComponent(document.getElementById('fullname').value);
	  telephone = encodeURIComponent(document.getElementById('telephone').value);
	  email = encodeURIComponent(document.getElementById('email').value);
	  address1 = encodeURIComponent(document.getElementById('address1').value);
	  address2 = encodeURIComponent(document.getElementById('address2').value);
	  town = encodeURIComponent(document.getElementById('town').value);
	  county = encodeURIComponent(document.getElementById('county').value);
	  postcode = encodeURIComponent(document.getElementById('postcode').value);
	  
	  jobtype = encodeURIComponent(document.getElementById('jobtype').value);
	  jobdesc = encodeURIComponent(document.getElementById('jobdesc').value);

	  loadForm("page3.php", "jobtype="+jobtype+"&jobdesc="+jobdesc+"&fullname="+fullname+"&telephone="+telephone+"&email="+email+"&address1="+address1+"&address2="+address2+"&town="+town+"&county="+county+"&postcode="+postcode);
	}
}

function sendform3()
{
	result = validateFormOnSubmitInquiry3(document.getElementById('form3')); 
	
	if (result) 
	{
	  index = document.getElementById('startdate').selectedIndex;
	  startdate = encodeURIComponent(document.getElementById('startdate').options[index].value);
	  promocode = encodeURIComponent(document.getElementById('promocode').value);
	  agentcode = encodeURIComponent(document.getElementById('agentcode').value);
		
	  fullname = encodeURIComponent(document.getElementById('fullname').value);
	  telephone = encodeURIComponent(document.getElementById('telephone').value);
	  email = encodeURIComponent(document.getElementById('email').value);
	  address1 = encodeURIComponent(document.getElementById('address1').value);
	  address2 = encodeURIComponent(document.getElementById('address2').value);
	  town = encodeURIComponent(document.getElementById('town').value);
	  county = encodeURIComponent(document.getElementById('county').value);
	  postcode = encodeURIComponent(document.getElementById('postcode').value);
	  
	  jobtype = encodeURIComponent(document.getElementById('jobtype').value);
	  jobdesc = encodeURIComponent(document.getElementById('jobdesc').value);

	  loadForm("page4.php", "jobtype="+jobtype+"&jobdesc="+jobdesc+"&fullname="+fullname+"&telephone="+telephone+"&email="+email+"&address1="+address1+"&address2="+address2+"&town="+town+"&county="+county+"&postcode="+postcode+"&startdate="+startdate+"&promocode="+promocode+"&agentcode="+agentcode);
	}
}
