function getXMLHttp()
{
  var xmlHttp

  try
  {
    //Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    //Internet Explorer
    try
    {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
      try
      {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e)
      {
        alert("Your browser does not support AJAX!")
        return false;
      }
    }
  }
  return xmlHttp;
}

function changeKidsNum(number)
{
	if(number > 0){
		var xmlHttp = getXMLHttp();
  
		xmlHttp.onreadystatechange = function(){
			if(xmlHttp.readyState == 4){
				changeKidsNumResponse(xmlHttp.responseText);
			}
		}

		xmlHttp.open("GET", "form/changeKidsNum.php?number=" + number, true); 
		xmlHttp.send(null);
	}
}

function changeKidsNumResponse(response)
{
  document.getElementById('children_age').innerHTML = response;
}

function changeExtras(name)
{
	
	var xmlHttp = getXMLHttp();
  
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4){
			changeExtrasResponse(xmlHttp.responseText, name);
		}
	}

	xmlHttp.open("GET", "form/changeApartment.php?extras=" + name, true); 	
	xmlHttp.send(null);
	
}

function changeExtrasResponse(response, name)
{
	document.getElementById('div_extras').innerHTML = response;
}


function changeKids(name)
{
	
	var xmlHttp = getXMLHttp();
  
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4){
			changeKidsResponse(xmlHttp.responseText, name);
		}
	}

	xmlHttp.open("GET", "form/changeApartment.php?children=" + name, true); 	
	xmlHttp.send(null);
	
}

function changeKidsResponse(response, name)
{
	document.getElementById('div_children_num').innerHTML = response;
	changeExtras(name);
}

function changeApartment(name)
{
	
	var xmlHttp = getXMLHttp();
  
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4){
			changeApartmentResponse(xmlHttp.responseText, name);
		}
	}

	xmlHttp.open("GET", "form/changeApartment.php?adult=" + name, true); 	
	xmlHttp.send(null);
	
}

function changeApartmentResponse(response, name)
{
	document.getElementById('div_adult_num').innerHTML = response;
	changeKids(name);
}


