var loc1opened=0;
var loc2opened=0;


function changeColor(id){
id.className="active";
}

function changeBack(id){
id.className="orangebg";
}


function cColor(id){
id.className="t_active";
}

function cBack(id){
id.className="t_norm";
}

function getAuto(str,id){
if (str.length>2){
var req = getXmlHttp();

req.onreadystatechange = function() {  
// onreadystatechange активируется при получении ответа сервера
if (req.readyState == 4) { 
// если запрос закончил выполняться
//statusElem.innerHTML = req.statusText // показать статус (Not Found, ОК..)
if(req.status == 200) { 
// если статус 200 (ОК) - выдать ответ пользователю
document.getElementById("loc"+id).innerHTML=req.responseText;
if (req.responseText.length>0){
document.getElementById("loc"+id).className="loc";
if (id==1){loc1opened=1;}
if (id==2){loc2opened=1;}
setTimeout("locOpenState("+id+")",5);
}
else{
document.getElementById("loc"+id).className="shownone";
}
}
// тут можно добавить else с обработкой ошибок запроса
}
}
// (3) задать адрес подключения
req.open('GET', '/getAuto.php?str='+encodeURI(str)+"&id="+id, true);  

// объект запроса подготовлен: указан адрес и создана функция onreadystatechange
// для обработки ответа сервера
// (4)
req.send(null);  // отослать запрос
}
else{
document.getElementById("loc"+id).className="shownone";
}
}


function switchCities(){
var req = getXmlHttp();
req.onreadystatechange = function() {  
if (req.readyState == 4) { 
if(req.status == 200) { 
var oHouseList = document.forms["rushotels"].elements["h_city"];
var oHouseListOptionsCnt = oHouseList.options.length;
oHouseList.length = 0;
var response=req.responseText;
var massiv = response.split("#");
var cityNames = massiv[0].split(",");
var cityValues = massiv[1].split(",");
for (i = 0; i < cityValues.length; i++){
if (document.createElement){
var newHouseListOption = document.createElement("OPTION");
newHouseListOption.text = cityNames[i];
newHouseListOption.value = cityValues[i];
(oHouseList.options.add) ? oHouseList.options.add(newHouseListOption) : oHouseList.add(newHouseListOption, null);
}
}
}
}
}
req.open('GET', '/switchCities.php?str='+encodeURI(document.getElementById("h_country").value), true);  
req.send(null);  // отослать запрос
}



function getXmlHttp(){
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}

function doSub(city,id){
if(id==1){document.getElementById("B_LOCATION_1").value=city;}
if(id==2){document.getElementById("E_LOCATION_1").value=city;}
document.getElementById("loc"+id).className="shownone";
}


function closeFunction(){
if (loc1opened==2){document.getElementById("loc1").className = "shownone"; loc1opened=0;}
if (loc2opened==2){document.getElementById("loc2").className = "shownone"; loc2opened=0;}
}

function locOpenState(id){
if(id==1){loc1opened=2;}
if(id==2){loc2opened=2;}
}

function showAmadeus(){
document.amadeuSend.submit();
document.getElementById("thisframe").height=700;
}

function moscow(){
if (document.getElementById("passport1").className!="ntoptext_a"){
document.getElementById("passport1").className = "ntoptext_";
}
}

function moscowin(){
document.getElementById("passport1").className = "ntoptext_a";
document.getElementById("passpic1").src="/img/red.gif";
document.getElementById("passport2").className = "ntoptext";
document.getElementById("passpic2").src="/img/blue.gif";
document.getElementById("moscowinfo").className="showall";
document.getElementById("samarainfo").className="shownone";
}


function moscowout(){
if (document.getElementById("passport1").className!="ntoptext_a"){
document.getElementById("passport1").className = "ntoptext";
}
}

function samara(){
if (document.getElementById("passport2").className!="ntoptext_a"){
document.getElementById("passport2").className = "ntoptext_";
}
}

function samaraout(){
if (document.getElementById("passport2").className!="ntoptext_a"){
document.getElementById("passport2").className = "ntoptext";
}
}

function samarain(){
document.getElementById("passport2").className = "ntoptext_a";
document.getElementById("passpic2").src="/img/red.gif";
document.getElementById("passport1").className = "ntoptext";
document.getElementById("passpic1").src="/img/blue.gif";
document.getElementById("moscowinfo").className="shownone";
document.getElementById("samarainfo").className="showall";
}


function makeBooking(hotel,room){
document.getElementById("h_id").value=hotel;
document.getElementById("h_room").value=room;
document.getElementById("h_action").value="book";
document.rushotels.submit();
}

function hotelInfo(hotel){
document.getElementById("h_id").value=hotel;
document.getElementById("h_action").value="hotelInfo";
document.rushotels.submit();
}



function changeRus(){
document.getElementById("rusdop").className='showall';
document.getElementById("rusbottom").innerHTML='<table width=100% cellspacing=0 cellpadding=0 border=0><tr><td valign=top align=center bgcolor=#FAFCFF style="padding-top:15px;"><input type=image src=/img/hotelsearch.gif border=0></td></tr><tr><td valign=top class=bottform><table width=100% cellspacing=0 cellpadding=0 border=0><td valign=top class=formright><a style="cursor:hand;cursor:pointer;" onclick=changeRusBack();><img src=/img/dextend.gif border=0 width=180 height=17></a></td></table></td></tr></table>';
}

function changeRusBack(){
document.getElementById("rusdop").className='shownone';
document.getElementById("rusbottom").innerHTML='<table width=100% cellspacing=0 cellpadding=0 border=0><tr><td valign=top align=center bgcolor=#FAFCFF class=dots style="padding-top:15px;"><input type=image src=/img/hotelsearch.gif border=0></td></tr><tr><td valign=top class=bottform><table width=100% cellspacing=0 cellpadding=0 border=0><td valign=top align=right class=formleft><a style="cursor:hand;cursor:pointer;" onclick=changeRus();><img src=/img/extended.gif border=0 width=132 height=17></a></td></table></td></tr></table>';
}

function checkFields(h_kol,h_type){
var oksend=1;
for (ii=1;ii<=h_kol;ii++){
for (jj=1;jj<=h_type;jj++){
if (document.getElementById("fio["+ii+"]["+jj+"]").value.length==0){
document.getElementById("fio["+ii+"]["+jj+"]").value='необходимо заполнить данное поле';
document.getElementById("fio["+ii+"]["+jj+"]").className="inp3z";
oksend=0;
}
if (document.getElementById("fioname["+ii+"]["+jj+"]").value.length==0){
document.getElementById("fioname["+ii+"]["+jj+"]").value='необходимо заполнить данное поле';
document.getElementById("fioname["+ii+"]["+jj+"]").className="inp3z";
oksend=0;
}
if (document.getElementById("birth["+ii+"]["+jj+"]").value.length==0){
document.getElementById("birth["+ii+"]["+jj+"]").value='необходимо заполнить данное поле';
document.getElementById("birth["+ii+"]["+jj+"]").className="inp3z";
oksend=0;
}
}
}

if (document.getElementById("orgname").value.length==0){
document.getElementById("orgname").value='необходимо заполнить данное поле';
document.getElementById("orgname").className="inp3z";
oksend=0;
}

if (document.getElementById("orgmail").value.length==0){
document.getElementById("orgmail").value='необходимо заполнить данное поле';
document.getElementById("orgmail").className="inp3z";
oksend=0;
}

if (document.getElementById("orgphone1").value.length==0 && document.getElementById("orgphone2").value.length==0 && document.getElementById("orgphone3").value.length==0){
document.getElementById("orgphone1").value='необходимо заполнить данное поле';
document.getElementById("orgphone1").className="inp3z";
oksend=0;
}

if (oksend==0){document.getElementById("necc").className="showall";}
else{document.sendhotels.submit();}
}

function checkNo(field){
if (field.value=='необходимо заполнить данное поле'){
field.value='';
field.className="inp3";
}
}

function checkMail(id){
if (id==1){
if (document.getElementById("subscribe").value=='Укажите Ваш e-mail'){document.getElementById("subscribe").value='';}
}
if (id==2){
if (document.getElementById("subscribe").value==''){document.getElementById("subscribe").value='Укажите Ваш e-mail';}
}
}

function newSubscriber(){
var req = getXmlHttp();
req.onreadystatechange = function() {  
if (req.readyState == 4) { 
if(req.status == 200) {
document.getElementById("mysubscribe").innerHTML=req.responseText;
}
}
}
req.open('GET', '/subscribe.php?mailer='+encodeURI(document.getElementById("subscribe").value), true);  
req.send(null);  // отослать запрос
}


function getXmlHttp(){
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}

