var xmlHttp = createXmlHttpRequestObject();
var showErrors = true;
var cache = new Array();
var debugMode = 1;

function createXmlHttpRequestObject()
{
  var xmlHttp;
  try
  {
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
    {
      try
      {
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      }
      catch (e) {}
    }
  }
  if (!xmlHttp)
  {
    alert("Error creating the XMLHttpRequest object.");
  }
  else
  {
    return xmlHttp;
  }
}

function displayError(message)
{
  alert("Error accessing the server! ->    "+(debugMode ? "" + message : "<br/>"));
}

//***************************************************
function reloadGallery()
{
	opener.location.reload(true);
	window.close();
}



function onSelectionHotel()
{	var hotel = document.getElementById("hotelSelection").value;

	window.location.href = hotel;}

// функция переходит на страницу страны, пр нажатие на картинки, на главной странице
function toPassPage(url)
{checkOrderStatus}

function viewDoorForm()
{
	document.getElementById("viewDoorForm").style.display = "block";
}

// функция переходит на страницу по ссылке
function reloadPage(url)
{
	window.location.href = url;
}

function searchOrder(url, type)
{
	if(type=='searchMain')
	{
		var idOrder = document.getElementById("searchOrder").value;
	}
	else
	{		var idOrder = document.getElementById("checkOrderStatus").value;	}

	if(isNaN(parseInt(idOrder))){}
	else {window.location.href = url+"&idOrder="+idOrder;}
}

function searchTour(url)
{
	var country = document.getElementById("countrySearch").value;
	var city = document.getElementById("citySearch").value;
	var hotel = document.getElementById("hotelSearch").value;
//	alert(country+' - '+city+' - '+hotel);
	if(country != '0' || city != '0' || hotel != '0' )
	{
		reloadPage(url+"&idCountry="+country+"&idCity="+city+"&idHotel="+hotel);
	}

}


function handleKeyStatusOrderTop(e)
{
  e = (!e) ? window.event : e;
  code = (e.charCode) ? e.charCode :
         ((e.keyCode) ? e.keyCode :
         ((e.which) ? e.which : 0));
  if (e.type == "keydown")
  {
    if(code == 13)
    {
      searchOrder('index.php?idOpr=1', 'searchMain');
    }
  }
}

function handleKeyStatusOrder(e)
{
  e = (!e) ? window.event : e;
  code = (e.charCode) ? e.charCode :
         ((e.keyCode) ? e.keyCode :
         ((e.which) ? e.which : 0));
  if (e.type == "keydown")
  {
    if(code == 13)
    {
      searchOrder('index.php?idOpr=1', 'searchOrder');
    }
  }
}

function handleKeyTopDoor(e)
{
  e = (!e) ? window.event : e;
  code = (e.charCode) ? e.charCode :
         ((e.keyCode) ? e.keyCode :
         ((e.which) ? e.which : 0));
  if (e.type == "keydown")
  {
    if(code == 13)
    {
      door("top");
    }
  }
}

function handleKeyDoorReg(e)
{
  e = (!e) ? window.event : e;
  code = (e.charCode) ? e.charCode :
         ((e.keyCode) ? e.keyCode :
         ((e.which) ? e.which : 0));
  if (e.type == "keydown")
  {
    if(code == 13)
    {
      door("door");
    }
  }
}

//**************************************
function selectHotelOnStars(star, city)
{
	par = "star="+star+"&city="+city+"&type=typehotelonstars";
// alert(par);
    if (xmlHttp)
     {
       try
        {
         if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
          {
           var cacheEntry = cache.shift();
           xmlHttp.open("POST", 'php/type_hotel.php', true);
           xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
           xmlHttp.onreadystatechange = processHotelOnStars;
           xmlHttp.send(par);
          }
        }
       catch (e)
        {
         displayError(e.toString()+" ChangeHotel");
        }
     }
}


function processHotelOnStars()
{
  if (xmlHttp.readyState == 4)
  {
    if (xmlHttp.status == 200)
    {
      try
      {
	        resultHotelOnStars();
      }
      catch(e)
      {
        displayError(e.toString()+ " - processChangeHotel");
      }
    }
    else
    {
      displayError(xmlHttp.statusText+ " - processChangeHotel1");
    }
  }
}
// Processes server's response
function resultHotelOnStars()
{
  // read the response
  var response = xmlHttp.responseText;
  // server error?

  if (response.indexOf("ERRNO") >= 0 || response.indexOf("error") >= 0) alert(response);
	htmlMessage = '';
	htmlMessage = response;
	document.getElementById("notSelTypeHotelOnStars").style.display = "none";
	document.getElementById("selTypeHotelOnStars").innerHTML = htmlMessage;
	document.getElementById("selTypeHotelOnStars").style.display = "block";


}


