// Javascript Base General file

  // Сообщение о неправильно заполненной форме
  var errorMsg = "Внимание: поля отмеченные красным цветом заполнены неправильно!\n\nAttention: Fields marked in red are filled incorrectly!\n\nHinweis: Felder rot markiert sind falsch ausgefüllt!";
  // Цвет фона для неправильно заполненных полей
  //var errorColor = "#FFC6C6";
  var errorColor = "#FF9B9B"; // более красноватый
  // Список ID поставщиков - "Доставка"
  var listPostIDs  = new Array("3","20","53");
  // Паттерн для проверки e-mail адреса
  var emailPattern = /^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/;

  // Функция проврки заполненности полей при поиске гостиницы
  function SearchHotels()
    {
      colorReseter("level,from,to")//,type,pricemin,pricemax");
      var level = $F("level");
      var from = $F("from");
      var to = $F("to");
      //var placing = $F("type");
      //var pricemin = $F("pricemin");
      //var pricemax = $F("pricemax");
      if(level=="" || from=="" || to=="")// || placing=="" || pricemin=="" || pricemax=="")
        {
          if(level=="") $("level").style.backgroundColor = errorColor;
          if(from=="") $("from").style.backgroundColor = errorColor;
          if(to=="") $("to").style.backgroundColor = errorColor;
          //if(placing=="") $("type").style.backgroundColor = errorColor;
          //if(pricemin=="") $("pricemin").style.backgroundColor = errorColor;
          //if(pricemax=="") $("pricemax").style.backgroundColor = errorColor;
          $("errorsBlock").show();
          return false;
        }
      else
        {
          $("loading").show();
          //var params = "action=SearchHotels&class="+class+"&from="+from+"&to="+to+"&placing="+placing+"&pricemin="+pricemin+"&pricemax="+pricemax;
          var params = "action=SearchHotels&level="+level+"&from="+from+"&to="+to;
          var ajax = new Ajax.Updater({success: 'SearchResult'}, '/getter.php', {method: 'post', asynchronous: false, parameters: params, onFailure: null});
          $("loading").hide();
          return true;
        }
    }

  // Функция построения строки запроса
  function constructorQS(list)
    {
      var qs = "";
      var list = list.split(",");
      for(var i=0; i<list.length; i++)
        {
          qs = qs+""+list[i]+"="+$F(list[i])+"&";
        }
      return qs;
    }

  function checkFormPartnership()
    {
      $("loading").show();
      var list = "firstname,lastname,country,postcode,city,street,house,office,organization,phone,email,password,captcha";
      colorReseter(list);
      var params = "action=regNewPartner&"+constructorQS(list);
      var ajax = new Ajax.Request('/getter.php', {method: 'post', asynchronous: false, parameters: params, onSuccess: function(transport){ res = transport.responseText;}});
      var pat = /^\[N\]/
      if(pat.test(res))
        {
          res = res.substr(3);
          colorSeter(res);
          $("errorsBlock").show();
        }
      else
        {
          $("formArea").innerHTML = res;
        }
      $("loading").hide();
    }

  function errorWindow(action)
    {
      if(action=="show") $("errorWindow").show();
      if(action=="hide") $("errorWindow").hide();
    }

  function termsWindow(action)
    {
      if(action=="show") $("TermsBlock").show();
      if(action=="hide") $("TermsBlock").hide();
    }

  function UpdatePartnerInfo()
    {
      var list = "firstname,lastname,postcode,country,city,street,house,office,organization,phone,email";
      colorReseter(list);
      var errors = 0;
      if($F("firstname")=="") { errors = 1; $("firstname").style.backgroundColor = errorColor; }
      if($F("lastname")=="") { errors = 1; $("lastname").style.backgroundColor = errorColor; }
      if($F("postcode")=="") { errors = 1; $("postcode").style.backgroundColor = errorColor; }
      if($F("country")=="") { errors = 1; $("country").style.backgroundColor = errorColor; }
      if($F("city")=="") { errors = 1; $("city").style.backgroundColor = errorColor; }
      if($F("street")=="") { errors = 1; $("street").style.backgroundColor = errorColor; }
      if($F("house")=="") { errors = 1; $("house").style.backgroundColor = errorColor; }
      if($F("office")=="") { errors = 1; $("office").style.backgroundColor = errorColor; }
      if($F("organization")=="") { errors = 1; $("organization").style.backgroundColor = errorColor; }
      if($F("phone")=="") { errors = 1; $("phone").style.backgroundColor = errorColor; }
      if(errors==0)
        {
          var params = "action=UpdatePartnerInfo&firstname="+$F("firstname")+"&lastname="+$F("lastname")+"&postcode="+$F("postcode")+"&country="+$F("country")+"&city="+$F("city")+"&street="+$F("street")+"&house="+$F("house")+"&office="+$F("office")+"&organization="+$F("organization")+"&phone="+$F("phone")+"&password="+$F("password");
          var ajax = new Ajax.Request('/getter.php', {method: 'post', asynchronous: false, parameters: params, onSuccess: function(){$("updateGood").show()}, onFailure: null});
          return true;
        }
      else
        {
         $("errorsBlock").show();
         return false;
        }
    }

  // Функция проверки группы radio переключателей на предмет выделенности хотя бы одного
  // list - должна принять ссылку на объект!
  // если ничего не выделено - возвращает false, иначе - значение объекта
  function checkList(list)
    {
      //alert(list.length);
      var test = 0;
      if(list)
        {
          for(var i=0; i<list.length; i++)
            {
              if(list[i].checked == true)
                {
                  test = list[i].value;
                  break;
                }
            }
        }
      if(test==0) return false;
      else return test;
    }

  // Функция удаления фонового цвета с полей перечисленных в списке list
  function colorReseter(list)
    {
      var list = list.split(",");
      for(var j=0; j<list.length; j++)
        {
          if($(list[j]))
            {
              $(list[j]).style.backgroundColor = null;
            }
        }
    }

  // Функция установки фона для неправильно заполненных полей
  function colorSeter(list)
    {
      var list = list.split(",");
      for(var i=0; i<list.length; i++)
        {
          if($(list[i]))
            {
              $(list[i]).style.backgroundColor = errorColor;
            }
        }
    }

  function CheckSiteForm(alias, type)
    {
      var errors = 0;
      switch(alias)
        {
          case "cnt": // Contacts - отправка письма менеджеру
          var fList = "manager,username,useremail,usermessage";
          colorReseter(fList);
          if($F("manager")=="") { errors = 1; $("manager").style.backgroundColor = errorColor; }
          if($F("username")=="") { errors = 1; $("username").style.backgroundColor = errorColor; }
          if($F("useremail")=="") { errors = 1; $("useremail").style.backgroundColor = errorColor; }
          if($F("usermessage")=="") { errors = 1; $("usermessage").style.backgroundColor = errorColor; }
          break;

          case "tv":
          var fList = "citizenship,ServicesList,firstname,lastname,bdd,bdm,bdy,passportnumber,visaissues,visaexpires,sex,city1,TargetHotel1,cfirstname,clastname,cemail,supplier2,da_country,da_zip,da_city,da_address,da_phone,deliveryfax,PayMethods,area_terms,choise1,choise2,choise3,choise4,choise5";
          colorReseter(fList);
          if($F("citizenship")==""){ errors = 1; $("citizenship").style.backgroundColor = errorColor; }
          if($("orderform").visaentries && checkList($("orderform").visaentries) == false) { errors = 1; $("ServicesList").style.backgroundColor = errorColor; }
          if($F("sex")=="") { errors = 1; $("sex").style.backgroundColor = errorColor; }
          if($F("firstname")=="") { errors = 1; $("firstname").style.backgroundColor = errorColor; }
          if($F("lastname")=="") { errors = 1; $("lastname").style.backgroundColor = errorColor; }
          if($F("bdd")=="") { errors = 1; $("bdd").style.backgroundColor = errorColor; }
          if($F("bdm")=="") { errors = 1; $("bdm").style.backgroundColor = errorColor; }
          if($F("bdy")=="") { errors = 1; $("bdy").style.backgroundColor = errorColor; }
          if($F("passportnumber")=="") { errors = 1; $("passportnumber").style.backgroundColor = errorColor; }
          if($F("visaissues")=="") { errors = 1; $("visaissues").style.backgroundColor = errorColor; }
          if($F("visaexpires")=="") { errors = 1; $("visaexpires").style.backgroundColor = errorColor; }
          if($F("city1")=="") { errors = 1; $("city1").style.backgroundColor = errorColor; }
          if($F("TargetHotel1")=="") { errors = 1; $("TargetHotel1").style.backgroundColor = errorColor; }
          if($F("TargetHotel1")=="choise1" && $F("choise1")=="") { errors = 1; $("choise1").style.backgroundColor = errorColor; }
          if($F("TargetHotel2")=="choise2" && $F("choise2")=="") { errors = 1; $("choise2").style.backgroundColor = errorColor; }
          if($F("TargetHotel3")=="choise3" && $F("choise3")=="") { errors = 1; $("choise3").style.backgroundColor = errorColor; }
          if($F("TargetHotel4")=="choise4" && $F("choise4")=="") { errors = 1; $("choise4").style.backgroundColor = errorColor; }
          if($F("TargetHotel5")=="choise5" && $F("choise5")=="") { errors = 1; $("choise5").style.backgroundColor = errorColor; }
          switch($F("supplier2"))
            {
              case "3":
              case "20":
              case "53":
              if($F("da_country")=="") { errors = 1; $("da_country").style.backgroundColor = errorColor; }
              if($F("da_zip")=="") { errors = 1; $("da_zip").style.backgroundColor = errorColor; }
              if($F("da_city")=="") { errors = 1; $("da_city").style.backgroundColor = errorColor; }
              if($F("da_address")=="") { errors = 1; $("da_address").style.backgroundColor = errorColor; }
              if($F("da_phone")=="") { errors = 1; $("da_phone").style.backgroundColor = errorColor; }
              break;
              case "38":
              if($F("supplier2")==38 && $F("deliveryfax")=="") { errors = 1; $("deliveryfax").style.backgroundColor = errorColor; }
            }
          if(type=="guest")
            {
              if($("orderform").paymethod && checkList($("orderform").paymethod) == false) { errors = 1; $("PayMethods").style.backgroundColor = errorColor; }
              if($F("cfirstname")=="") { errors = 1; $("cfirstname").style.backgroundColor = errorColor; }
              if($F("clastname")=="") { errors = 1; $("clastname").style.backgroundColor = errorColor; }
              if(!emailPattern.test($F("cemail"))) { errors = 1; $("cemail").style.backgroundColor = errorColor; }
              if($("terms").checked==false) { errors = 1; $("area_terms").style.backgroundColor = errorColor; }
            }
          break;
          
          case "bv":
          var fList = "deliveryfax,area_ServicesList,citizenship,ordertype,supplier2,firstname,lastname,sex,bdd,bdm,bdy,visaissues,visaexpires,visacountry,visacity,livingcountry,livingcity,birthcountry,birthcity,copypassport,city1,companyname,companyposition,companyaddress,companyphone,PayMethods,cfirstname,clastname,cemail,area_terms,da_country,da_zip,da_address,da_phone,da_city";
          colorReseter(fList);
          if($F("citizenship")==""){ errors = 1; $("citizenship").style.backgroundColor = errorColor; }
          if($F("citizenship")!=="" && checkList($("orderform").ordertype) == false) { errors = 1; $("area_ServicesList").style.backgroundColor = errorColor; }
          if($F("sex")=="") { errors = 1; $("sex").style.backgroundColor = errorColor; }
          if($F("firstname")=="") { errors = 1; $("firstname").style.backgroundColor = errorColor; }
          if($F("lastname")=="") { errors = 1; $("lastname").style.backgroundColor = errorColor; }
          if($F("bdd")=="") { errors = 1; $("bdd").style.backgroundColor = errorColor; }
          if($F("bdm")=="") { errors = 1; $("bdm").style.backgroundColor = errorColor; }
          if($F("bdy")=="") { errors = 1; $("bdy").style.backgroundColor = errorColor; }
          if($F("visaissues")=="") { errors = 1; $("visaissues").style.backgroundColor = errorColor; }
          if($F("visaexpires")=="") { errors = 1; $("visaexpires").style.backgroundColor = errorColor; }
          if($F("city1")=="") { errors = 1; $("city1").style.backgroundColor = errorColor; }
          if($F("visacountry")=="") { errors = 1; $("visacountry").style.backgroundColor = errorColor; }
          if($F("visacity")=="") { errors = 1; $("visacity").style.backgroundColor = errorColor; }
          if($F("livingcountry")=="") { errors = 1; $("livingcountry").style.backgroundColor = errorColor; }
          if($F("livingcity")=="") { errors = 1; $("livingcity").style.backgroundColor = errorColor; }
          if($F("birthcountry")=="") { errors = 1; $("birthcountry").style.backgroundColor = errorColor; }
          if($F("birthcity")=="") { errors = 1; $("birthcity").style.backgroundColor = errorColor; }
          //if($F("copypassport")=="") { errors = 1; $("copypassport").style.backgroundColor = errorColor; }
          if($F("companyname")=="") { errors = 1; $("companyname").style.backgroundColor = errorColor; }
          if($F("companyposition")=="") { errors = 1; $("companyposition").style.backgroundColor = errorColor; }
          if($F("companyaddress")=="") { errors = 1; $("companyaddress").style.backgroundColor = errorColor; }
          if($F("companyphone")=="") { errors = 1; $("companyphone").style.backgroundColor = errorColor; }
          if($F("supplier2")=="") { errors = 1; $("supplier2").style.backgroundColor = errorColor; }
          else
            {
              switch($F("supplier2"))
                {
                  case "3":
                  case "20":
                  case "53":
                  if($F("da_country")=="") { errors = 1; $("da_country").style.backgroundColor = errorColor; }
                  if($F("da_zip")=="") { errors = 1; $("da_zip").style.backgroundColor = errorColor; }
                  if($F("da_city")=="") { errors = 1; $("da_city").style.backgroundColor = errorColor; }
                  if($F("da_address")=="") { errors = 1; $("da_address").style.backgroundColor = errorColor; }
                  if($F("da_phone")=="") { errors = 1; $("da_phone").style.backgroundColor = errorColor; }
                  break;
                  case "38":
                  //if($F("supplier2")==38 && $F("deliveryfax")=="") { errors = 1; $("deliveryfax").style.backgroundColor = errorColor; }
                  if($F("deliveryfax")=="") { errors = 1; $("deliveryfax").style.backgroundColor = errorColor; }
                }
            }
          if(type=="guest")
            {
              //if($("orderform").paymethod && checkList($("orderform").paymethod) == false) { errors = 1; $("PayMethods").style.backgroundColor = errorColor; }
              if(!checkList($("orderform").paymethod)) { errors = 1; $("PayMethods").style.backgroundColor = errorColor; }
              if($F("cfirstname")=="") { errors = 1; $("cfirstname").style.backgroundColor = errorColor; }
              if($F("clastname")=="") { errors = 1; $("clastname").style.backgroundColor = errorColor; }
              if(!emailPattern.test($F("cemail"))) { errors = 1; $("cemail").style.backgroundColor = errorColor; }
              if($("terms").checked==false) { errors = 1; $("area_terms").style.backgroundColor = errorColor; }
            }
          break;

          case "bb":
          var fList = "citizenship,area_ServicesList,supplier2,firstname,lastname,visaissues,visaexpires,visacountry,visacity,copypassport,copyvisa,city1,companyname,companyposition,companyaddress,companyphone,PayMethods,cfirstname,clastname,cemail,area_terms,da_country,da_zip,da_address,da_phone,da_city";
          colorReseter(fList);
          if($F("citizenship")==""){ errors = 1; $("citizenship").style.backgroundColor = errorColor; }
          if(checkList($("orderform").ordertype) == false) { errors = 1; $("area_ServicesList").style.backgroundColor = errorColor; }
          if($F("firstname")=="") { errors = 1; $("firstname").style.backgroundColor = errorColor; }
          if($F("lastname")=="") { errors = 1; $("lastname").style.backgroundColor = errorColor; }
          if($F("visaissues")=="") { errors = 1; $("visaissues").style.backgroundColor = errorColor; }
          if($F("visaexpires")=="") { errors = 1; $("visaexpires").style.backgroundColor = errorColor; }
          if($F("visacountry")=="") { errors = 1; $("visacountry").style.backgroundColor = errorColor; }
          if($F("visacity")=="") { errors = 1; $("visacity").style.backgroundColor = errorColor; }
          if($F("livingcountry")=="") { errors = 1; $("livingcountry").style.backgroundColor = errorColor; }
          if($F("livingcity")=="") { errors = 1; $("livingcity").style.backgroundColor = errorColor; }
          if($F("birthcountry")=="") { errors = 1; $("birthcountry").style.backgroundColor = errorColor; }
          if($F("birthcity")=="") { errors = 1; $("birthcity").style.backgroundColor = errorColor; }
          if($F("companyname")=="") { errors = 1; $("companyname").style.backgroundColor = errorColor; }
          if($F("companyposition")=="") { errors = 1; $("companyposition").style.backgroundColor = errorColor; }
          if($F("companyaddress")=="") { errors = 1; $("companyaddress").style.backgroundColor = errorColor; }
          if($F("companyphone")=="") { errors = 1; $("companyphone").style.backgroundColor = errorColor; }
          //if($F("copypassport")=="") { errors = 1; $("copypassport").style.backgroundColor = errorColor; }
          //if($F("copyvisa")=="") { errors = 1; $("copyvisa").style.backgroundColor = errorColor; }
          if($F("city1")=="") { errors = 1; $("city1").style.backgroundColor = errorColor; }
          if($F("supplier2")=="") { errors = 1; $("supplier2").style.backgroundColor = errorColor; }
          else
            {
              switch($F("supplier2"))
                {
                  case "3":
                  case "20":
                  case "53":
                  if($F("da_country")=="") { errors = 1; $("da_country").style.backgroundColor = errorColor; }
                  if($F("da_zip")=="") { errors = 1; $("da_zip").style.backgroundColor = errorColor; }
                  if($F("da_city")=="") { errors = 1; $("da_city").style.backgroundColor = errorColor; }
                  if($F("da_address")=="") { errors = 1; $("da_address").style.backgroundColor = errorColor; }
                  if($F("da_phone")=="") { errors = 1; $("da_phone").style.backgroundColor = errorColor; }
                  break;
                  case "38":
                  if($F("supplier2")==38 && $F("deliveryfax")=="") { errors = 1; $("deliveryfax").style.backgroundColor = errorColor; }
                }
            }

          if(type=="guest")
            {
              if(checkList($("orderform").paymethod) == false) { errors = 1; $("PayMethods").style.backgroundColor = errorColor; }
              if($F("cfirstname")=="") { errors = 1; $("cfirstname").style.backgroundColor = errorColor; }
              if($F("clastname")=="") { errors = 1; $("clastname").style.backgroundColor = errorColor; }
              if(!emailPattern.test($F("cemail"))) { errors = 1; $("cemail").style.backgroundColor = errorColor; }
              if($("terms").checked==false) { errors = 1; $("area_terms").style.backgroundColor = errorColor; }
            }
          break;

          case "rv":
          var fList = "firstname,lastname,datefrom,dateto,livingplace,copypassport,copyvisa,copymigrationcard,cfirstname,clastname,cemail,area_terms,PayMethods,area_ServicesList";
          colorReseter(fList);
          if(checkList($("orderform").type) == false) { errors = 1; $("area_ServicesList").style.backgroundColor = errorColor; }
          if($F("firstname")=="") { errors = 1; $("firstname").style.backgroundColor = errorColor; }
          if($F("lastname")=="") { errors = 1; $("lastname").style.backgroundColor = errorColor; }
          if($F("datefrom")=="") { errors = 1; $("datefrom").style.backgroundColor = errorColor; }
          if($F("dateto")=="") { errors = 1; $("dateto").style.backgroundColor = errorColor; }
          if($F("livingplace")=="") { errors = 1; $("livingplace").style.backgroundColor = errorColor; }
          //if($F("copypassport")=="") { errors = 1; $("copypassport").style.backgroundColor = errorColor; }
          //if($F("copymigrationcard")=="") { errors = 1; $("copymigrationcard").style.backgroundColor = errorColor; }
          //if($F("copyvisa")=="") { errors = 1; $("copyvisa").style.backgroundColor = errorColor; }
          if(type=="guest")
            {
              if(checkList($("orderform").paymethod) == false) { errors = 1; $("PayMethods").style.backgroundColor = errorColor; }
              if($F("cfirstname")=="") { errors = 1; $("cfirstname").style.backgroundColor = errorColor; }
              if($F("clastname")=="") { errors = 1; $("clastname").style.backgroundColor = errorColor; }
              if(!emailPattern.test($F("cemail"))) { errors = 1; $("cemail").style.backgroundColor = errorColor; }
              if($("terms").checked==false) { errors = 1; $("area_terms").style.backgroundColor = errorColor; }
            }
          break;

          case "ap":
          var fList = "firstname,lastname,cfirstname,clastname,cemail,area_terms,PayMethods";
          colorReseter(fList);
          if($F("firstname")=="") { errors = 1; $("firstname").style.backgroundColor = errorColor; }
          if($F("lastname")=="") { errors = 1; $("lastname").style.backgroundColor = errorColor; }
          if(type=="guest")
            {
              if(checkList($("orderform").paymethod) == false) { errors = 1; $("PayMethods").style.backgroundColor = errorColor; }
              if($F("cfirstname")=="") { errors = 1; $("cfirstname").style.backgroundColor = errorColor; }
              if($F("clastname")=="") { errors = 1; $("clastname").style.backgroundColor = errorColor; }
              if(!emailPattern.test($F("cemail"))) { errors = 1; $("cemail").style.backgroundColor = errorColor; }
              if($("terms").checked==false) { errors = 1; $("area_terms").style.backgroundColor = errorColor; }
            }
          break;

          case "ex":
          var fList = "adate,travellers,duration,firstname,lastname,excursionlanguage,place,cfirstname,clastname,cemail,area_terms,PayMethods";
          colorReseter(fList);
          if($F("adate")=="") { errors = 1; $("adate").style.backgroundColor = errorColor; }
          if($F("travellers")=="") { errors = 1; $("travellers").style.backgroundColor = errorColor; }
          if($F("duration")=="") { errors = 1; $("duration").style.backgroundColor = errorColor; }
          if($F("firstname")=="") { errors = 1; $("firstname").style.backgroundColor = errorColor; }
          if($F("lastname")=="") { errors = 1; $("lastname").style.backgroundColor = errorColor; }
          if($F("excursionlanguage")=="") { errors = 1; $("excursionlanguage").style.backgroundColor = errorColor; }
          if($F("place")=="") { errors = 1; $("place").style.backgroundColor = errorColor; }
          if(type=="guest")
            {
              if(checkList($("orderform").paymethod) == false) { errors = 1; $("PayMethods").style.backgroundColor = errorColor; }
              if($F("cfirstname")=="") { errors = 1; $("cfirstname").style.backgroundColor = errorColor; }
              if($F("clastname")=="") { errors = 1; $("clastname").style.backgroundColor = errorColor; }
              if(!emailPattern.test($F("cemail"))) { errors = 1; $("cemail").style.backgroundColor = errorColor; }
              if($("terms").checked==false) { errors = 1; $("area_terms").style.backgroundColor = errorColor; }
            }
          break;

          case "tr":
          var fList = "adate,hour,minute,quantity,from,fromplace,to,toplace,firstname,lastname,cfirstname,clastname,cemail,area_terms,PayMethods";
          colorReseter(fList);
          if($F("adate")=="") { errors = 1; $("adate").style.backgroundColor = errorColor;}
          if($F("hour")=="") { errors = 1; $("hour").style.backgroundColor = errorColor;}
          if($F("minute")=="") { errors = 1; $("minute").style.backgroundColor = errorColor;}
          if($F("quantity")=="") { errors = 1; $("quantity").style.backgroundColor = errorColor;}
          if($F("from")=="") { errors = 1; $("from").style.backgroundColor = errorColor;}
          if($F("to")=="") { errors = 1; $("to").style.backgroundColor = errorColor;}
          if($F("to")=="7|city" && $F("toplace")=="") { errors = 1; $("toplace").style.backgroundColor = errorColor;}
          if($F("firstname")=="") { errors = 1; $("firstname").style.backgroundColor = errorColor;}
          if($F("lastname")=="") { errors = 1; $("lastname").style.backgroundColor = errorColor;}
          if(type=="guest")
            {
              if(checkList($("orderform").paymethod) == false) { errors = 1; $("PayMethods").style.backgroundColor = errorColor; }
              if($F("cfirstname")=="") { errors = 1; $("cfirstname").style.backgroundColor = errorColor; }
              if($F("clastname")=="") { errors = 1; $("clastname").style.backgroundColor = errorColor; }
              if(!emailPattern.test($F("cemail"))) { errors = 1; $("cemail").style.backgroundColor = errorColor; }
              if($("terms").checked==false) { errors = 1; $("area_terms").style.backgroundColor = errorColor; }
            }
          break;

          case "rc":
          var fList = "deparea,hours,quantity,depdate,depth,deptm,firstname,lastname,cfirstname,clastname,cemail,area_terms,PayMethods";
          colorReseter(fList);
          if($F("deparea")=="") { errors = 1; $("deparea").style.backgroundColor = errorColor; }
          if($F("hours")=="") { errors = 1; $("hours").style.backgroundColor = errorColor; }
          if($F("quantity")=="") { errors = 1; $("quantity").style.backgroundColor = errorColor; }
          if($F("depdate")=="") { errors = 1; $("depdate").style.backgroundColor = errorColor; }
          if($F("depth")=="") { errors = 1; $("depth").style.backgroundColor = errorColor; }
          if($F("deptm")=="") { errors = 1; $("deptm").style.backgroundColor = errorColor; }
          if($F("firstname")=="") { errors = 1; $("firstname").style.backgroundColor = errorColor; }
          if($F("lastname")=="") { errors = 1; $("lastname").style.backgroundColor = errorColor; }
          if(type=="guest")
            {
              if(checkList($("orderform").paymethod) == false) { errors = 1; $("PayMethods").style.backgroundColor = errorColor; }
              if($F("cfirstname")=="") { errors = 1; $("cfirstname").style.backgroundColor = errorColor; }
              if($F("clastname")=="") { errors = 1; $("clastname").style.backgroundColor = errorColor; }
              if(!emailPattern.test($F("cemail"))) { errors = 1; $("cemail").style.backgroundColor = errorColor; }
              if($("terms").checked==false) { errors = 1; $("area_terms").style.backgroundColor = errorColor; }
            }
          break;
          
          case "paydetails":
          switch(type)
            {
              case "3":
              if($F("paydetails0")=="") { errors = 1; $("paydetails0").style.backgroundColor = errorColor; }
              if($F("paydetails1")=="") { errors = 1; $("paydetails1").style.backgroundColor = errorColor; }
              if($F("paydetails2")=="") { errors = 1; $("paydetails2").style.backgroundColor = errorColor; }
              if($F("paydetails3")=="") { errors = 1; $("paydetails3").style.backgroundColor = errorColor; }
              if($F("paydetails4")=="") { errors = 1; $("paydetails4").style.backgroundColor = errorColor; }
              break;
              
              case "5":
              if($F("paydetails0")=="") { errors = 1; $("paydetails0").style.backgroundColor = errorColor; }
              break;
            }
          break;
        }
      if(errors==0)
        {
          //$("orderbutton").disabled = true;
          return true;
        }
      else
        {
          $("errorsBlock").show();
          return false;
        }
    }


  // Функция добавления наценок к общей стоимости квартиры (+ стоимость кровати + стоимость за въезд\выезд)
  function ChargeAP(id, place)
    {
      $("viewprice_addbed_"+id).hide();
      $("viewprice_ea_"+id).hide();
      $("viewprice_ldb_"+id).hide();
      $("viewprice_lda_"+id).hide();
      
      var ftotal = parseFloat($("ftotal_"+id).innerHTML);

      if($("checkinEA") && $("checkinEA").checked == true)  { ftotal += parseFloat($("charge_ea").innerHTML); $("viewprice_ea_"+id).show();}
      if($("checkinLDB") && $("checkinLDB").checked == true) { ftotal += parseFloat($("charge_ldb").innerHTML); $("viewprice_ldb_"+id).show();}
      if($("checkinLDA") && $("checkinLDA").checked == true) { ftotal += parseFloat($("charge_lda").innerHTML); $("viewprice_lda_"+id).show();}
      if($("addplace") && $("addplace").checked == true) { ftotal += parseFloat($("preprice_addplace_"+id).innerHTML); $("viewprice_addbed_"+id).show();}


      $("price_total_"+id).innerHTML = ftotal.toFixed(2);
    }


  // Функция надбавки процентов к стоимости первой\последней ночи за поздние\ранний выезды
  function AddCheckinAP(check, id)
    {
      var ftotal = parseFloat($("ftotal_"+id).innerHTML);
      var addplace = 0;
      if($("addplace")) addplace = parseFloat($F("addplace"));
      if(check=="std")
        {
          $("price_total_"+id).innerHTML = ftotal+addplace;
          $("charge").value = 0;
        }
      else
        {
          var charge = parseFloat($("charge_"+check).innerHTML);
          $("charge").value = charge;
          $("price_total_"+id).innerHTML = ftotal+charge+addplace;
        }
    }

  // Функция прибавления\вычитания к общей стоимости, стоимости квартиры
  function AddBedAP(id)
    {
      var ftotal = parseFloat($("ftotal_"+id).innerHTML);
      if($("addplace").checked == true)
        {
          $("viewprice_addbed_"+id).show();
          $("price_addplace_"+id).innerHTML = $("preprice_addplace_"+id).innerHTML;
          var sum = parseFloat($("price_total_"+id).innerHTML)+parseFloat($("preprice_addplace_"+id).innerHTML);
          $("price_total_"+id).innerHTML = sum.toFixed(2);
        }
      else
        {
          $("viewprice_addbed_"+id).hide();
          var sum = parseFloat($("price_total_"+id).innerHTML)-parseFloat($("preprice_addplace_"+id).innerHTML);
          $("price_total_"+id).innerHTML = sum.toFixed(2);
          $("price_addplace_"+id).innerHTML = 0;
        }
    }

  function apDetails(id)
    {
      var listIDs = $("listIDs").innerHTML;
      listIDs = listIDs.split("|");
      for(var i=0; i<listIDs.length; i++)
        {
          var el = listIDs[i];
          if(el==id)
            {
              $("apblock_"+el).style.backgroundColor = "#EFEFEF";
              var params = "action=GetFormAP&id="+el;
              var target = "ApartmentDetails_"+el;
              var ajax = new Ajax.Updater({success: target}, '/getter.php', {method: 'post', asynchronous: false, parameters: params, onFailure: null});
            }
          else
            {
              $("apblock_"+el).style.backgroundColor = "";
              $("ApartmentDetails_"+el).innerHTML = "";
            }
        }
    }

  function SearchApartments()
    {
      $("rooms").style.backgroundColor = null;
      $("from").style.backgroundColor = null;
      $("to").style.backgroundColor = null;
      
      var rooms = $F("rooms");
      var from = $F("from");
      var to = $F("to");
      if(rooms=="" || from=="" || to=="" || from==to)
        {
          if(from==to) { $("from").style.backgroundColor = errorColor; $("to").style.backgroundColor = errorColor; }
          if(rooms=="") $("rooms").style.backgroundColor = errorColor;
          if(from=="") $("from").style.backgroundColor = errorColor;
          if(to=="") $("to").style.backgroundColor = errorColor;
          $("errorsBlock").show();
          return false;
        }
      else
        {
          $("loading").show();
          var params = "action=SearchApartments&rooms="+rooms+"&from="+from+"&to="+to;
          var ajax = new Ajax.Updater({success: 'SearchResult'}, '/getter.php', {method: 'post', asynchronous: false, parameters: params, onFailure: null, evalScripts: true});
          $("loading").hide();
          return true;
        }
    }
  
  // Функция добавления ко всем полям формы id="xxx", где xxx - имя формы
  //   было: <input type='' name='field_name' value=''/>
  // станет: <input type='' name='field_name' id='field_name' value=''/>
  function addIDtoName(target)
    {
      var myForm = document[target];
      for (var i=0; i<myForm.length; i++ )
        {
          myForm.elements[i].setAttribute("id", myForm.elements[i].name);
        }
    }

  function Get2Post(getString)
    {
      var parms = getString.split('?');
      var newF = document.createElement("form");
      newF.action = parms[0];
      newF.method = 'post';
      var parms = parms[1].split('&');
      for (var i=0; i<parms.length; i++)
        {
          var pos = parms[i].indexOf('=');
          if (pos > 0)
            {
              var key = parms[i].substring(0,pos);
              var val = parms[i].substring(pos+1);
              var newH = document.createElement("input");
              newH.name = key;
              newH.type = 'hidden';
              newH.value = val;
              newF.appendChild(newH);
            }
        }
      document.getElementsByTagName('body')[0].appendChild(newF);
      newF.submit();
    }

  function PasswordGenerator(length, field)
    {
      var str = '';
      for( ; str.length<length; str += Math.random().toString(36).substr(2));
      $(field).value = str.substr(0, length);
    }

  function SendLostPassword()
    {
      var email = $F("email");
      var ajax = new Ajax.Updater({success: 'TargetLostPassword'}, 'usergate.php', {method: 'post', parameters: "action=lost&email="+email, onFailure: null});
    }

  // Функция добавления поля выбора своей гостиницы
  function AddFieldMyHotel(obj, field)
    {
      $(field).hide();
      if(obj.options[obj.selectedIndex].value == field)
        {
          $(field).show();
        }
    }

  // Функция получения списка гостиниц по ID номеру города
  function GetHotels(CityID, TargetHotel, number)
    {
      if(CityID=="")
        {
          var delhotel = "choise"+TargetHotel.substr(-1);
          $(delhotel).hide();
        }
      var params = 'action=GetHotelsList&id='+CityID+"&number="+number;
      var ajax = new Ajax.Updater({success: TargetHotel}, '/getter.php', {method: 'post', asynchronous: false, parameters: params, onFailure: null});
    }

  // Функция расчета стоимости Делового приглашения на бланке организации
  function GetPriceBB()
    {
      var supplier2 = $F("supplier2");
      var da_country = $F("da_country");
      var ordertype = checkList($("orderform").ordertype);
      switch(supplier2)
        {
          case "3":
          case "20":
          case "53":
          $("DeliveryFax").hide();
          $("DeliveryForm").show();
          break;
          
          case "38":
          $("DeliveryFax").show();
          $("DeliveryForm").hide();
          break;
          
          default:
          $("DeliveryFax").hide();
          $("DeliveryForm").hide();
        }
      var params = "action=GetPriceVisaBB&ordertype="+ordertype+"&supplier2="+supplier2+"&da_country="+da_country;
      var ajax = new Ajax.Updater({success: 'Price'}, '/getter.php', {method: 'post', asynchronous: false, parameters: params, onFailure: null});
    }

  // Функция расчета стоимости визы
  function GetPriceTV()
    {
      var citizenship = $F("citizenship");
      var visaentries = checkList($("orderform").visaentries);
      var supplier2 = $F("supplier2");
      var da_country = $F("da_country");
      switch(supplier2)
        {
          case "3":
          case "20":
          case "53":
          $("DeliveryForm").show();
          $("DeliveryFax").hide();
          break;
          
          case "38":
          $("DeliveryForm").hide();
          $("DeliveryFax").show();
          break;
          
          default:
          $("DeliveryForm").hide();
          $("DeliveryFax").hide();
          break;
        }
      if(visaentries==1 || visaentries==2 || da_country!=="")
        {
          var params = "action=GetPriceVisaT&supplier2="+supplier2+"&da_country="+da_country+"&visaentries="+visaentries+"&citizenship="+citizenship;
          var ajax   = new Ajax.Updater({success: 'Price'}, '/getter.php', {method: 'post', asynchronous: false, parameters: params, onFailure: null});
        }
    }

  // Функция расчета целевой даты в зависимости от исходной
  // diff - количество прибавляемых дней
  // target_field - ID целевого поля
  // source_field - ID исходного поля
  // addFunction - имя функции JS, которая должна запуститься после выбора второй даты
  function GetTargetDate(diff, target_field, source_field)
    {
      $(target_field).value = "";
      var params = "action=GetTargetDate&sourcedate="+$F(source_field)+"&diff="+diff+"&target_field="+target_field;
      var ajax   = new Ajax.Updater({success: 'TargetDate'}, '/getter.php', {method: 'post', asynchronous: false, parameters: params, onFailure: null, evalScripts: true});
    }


  function GetServicesListTV()
    {
      var citizenship = $F("citizenship");
      if(citizenship) $("ServicesList").show();
      else $("ServicesList").hide();
      var GetS = new Ajax.Updater({success: 'ServicesList'}, '/getter.php', {method: 'post', asynchronous: false, parameters: "action=GetServicesListTV&citizenship="+citizenship, onFailure: null});
      var GetPM = new Ajax.Updater({success: 'PayMethods'}, '/getter.php', {method: 'post', asynchronous: false, parameters: "action=GetPayMethods&citizenship="+citizenship, onFailure: null});
    }

  function GetServicesListBV()
    {
      //var citizenship = $("citizenship").value;
      $('supplier2').innerHTML = null;
      var GetS = new Ajax.Updater({success: 'ServicesList'}, '/getter.php', {method: 'post', asynchronous: false, parameters: "action=GetServicesListBV&citizenship="+$F("citizenship"), onFailure: null});
      var GetPM = new Ajax.Updater({success: 'PayMethods'}, '/getter.php', {method: 'post', asynchronous: false, parameters: "action=GetPayMethods&citizenship="+$F("citizenship"), onFailure: null});
    }

  function GetDeliveryForm()
    {
      var supplier2 = $F("supplier2");
      if(supplier2==3 || supplier2==20 || supplier2==53)
        {
          $("DeliveryForm").show();
        }
      else
        {
          $F("da_country") = "";
          $("DeliveryForm").hide();
        }
      var SendDM = new Ajax.Updater({success: null}, '/getter.php', {method: 'post', asynchronous: false, parameters: "action=SetDeliveryMethod&deliverymethod="+deliverymethod, onFailure: null});
    }

  function GetPriceBV()
    {
      var supplier2 = $("supplier2").value;
      switch(supplier2)
        {
          case "3":
          case "20":
          case "53":
          $("DeliveryFax").hide();
          $("DeliveryForm").show();
          break;
          
          case "38":
          $("DeliveryFax").show();
          $("DeliveryForm").hide();
          break;
          
          default:
          $("DeliveryFax").hide();
          $("DeliveryForm").hide();
          break;
        }

      var ordertype = checkList($("orderform").ordertype);
      var params = "action=GetPriceBusinessVisa&ordertype="+ordertype;
      pattern = /^bt/;
      // ТЕЛЕКС
      if(pattern.test(ordertype))
        {
          $("orderform").da_country.value = "";
          if(supplier2==1 || supplier2==2 || supplier2==3 || supplier2==4)
            {
              $('supplier2').innerHTML = null;
            }
          $("DeliveryForm").hide();
          if(supplier2==3 || supplier2==20 || supplier2==53 || supplier2=="" || supplier2==38 || supplier2==40 || supplier2==41)
            {
              var GetDM = new Ajax.Updater({success: 'supplier2'}, '/getter.php', {method: 'post', asynchronous: false, parameters: "action=GetDeliveryMethod&ordertype="+ordertype, onFailure: null});
            }
        }
      // ОРИГИНАЛ
      else
        {
          if(supplier2=="" || supplier2==42)
          {
              $("supplier2").innerHTML = null;
              var GetDM = new Ajax.Updater({success: 'supplier2'}, '/getter.php', {method: 'post', asynchronous: false, parameters: "action=GetDeliveryMethod&ordertype="+ordertype, onFailure: null});
          }
          if(supplier2==3 || supplier2==20 || supplier2==53)
                {
                  $("DeliveryForm").show();
                }
              else
                {
                  $("orderform").da_country.value = "";
                  $("DeliveryForm").hide();
                }
        }

      params = params+"&supplier2="+supplier2;
      da_country = $("orderform").da_country.value;
      if(da_country !== "")
        {
          params = params+"&da_country="+da_country;
        }
      var GetPrice = new Ajax.Updater({success: 'Price'}, '/getter.php', {method: 'post', asynchronous: false, parameters: params, onFailure: null});
    }

  function GetPriceVR()
    {
      var type = checkList($("orderform").type);
      if(type)
        {
          var params = "action=GetPriceVisaRegistration&type="+type;
          var ajax = new Ajax.Updater({success: 'Price'}, '/getter.php', {method: 'post', asynchronous: false, parameters: params, onFailure: null});
        }
    }

  function GetPriceRC()
    {
      var params = 'action=GetPriceRentacar&hours='+$F("hours")+'&quantity='+$F("quantity")+'&time='+$F("depth");
      var ajax   = new Ajax.Updater({success: 'Price'}, '/getter.php', {method: 'post', asynchronous: false, parameters: params, onFailure: null});
    }

  function GetPriceEX(id)
    {
      if($("toplace").checked == true) { var toplace = "ON"; }
      if($("fromplace").checked == true) { var fromplace = "ON"; }
      var params = 'action=GetPriceExcursion&id='+id+'&travellers='+$F("travellers")+'&toplace='+toplace+'&fromplace='+fromplace;
      if($("duration")!== null) { params = params+"&duration="+$F("duration"); }
      var ajax   = new Ajax.Updater({success: 'Price'}, '/getter.php', {method: 'post', asynchronous: false, parameters: params, onFailure: null});
    }

  function GetPriceTR()
    {
      var qnt = $F("quantity");
      var from = $F("from");
      var to = $F("to");
      var hour = $F("hour");
      var params = 'action=GetTransferPrice&qnt='+qnt+'&from='+from+'&to='+to+'&hour='+hour;
      typeCITY = /city/;
      if(typeCITY.test(to)) $("toplaceBlock").show();
        else $("toplaceBlock").hide();
      var ajax   = new Ajax.Updater({success: 'Price'}, '/getter.php', {method: 'post', asynchronous: false, parameters: params, onFailure: null});
    }

  function GetTransferList()
    {
      var from = $F("from");
      typeCITY = /city/;
      typeAIR = /airport/;
      typeRWS = /railways/;

      $("cityblock").hide();
      $("airportblock").hide();
      $("rwsblock").hide();


      if(typeAIR.test(from)) { $("airportblock").show(); $("defaultblock").hide(); }
      if(typeRWS.test(from)) { $("rwsblock").show(); $("defaultblock").hide(); }
      if(typeCITY.test(from)) { $("cityblock").show(); $("defaultblock").hide(); }
      
      var params = 'action=GetTransferList&from='+from;
      var ajax   = new Ajax.Updater({success: 'to'}, '/getter.php', {method: 'post', asynchronous: false, parameters: params, onFailure: null});
    }

  function CheckFieldsPartnerShip()
    {
      var errors = "";
      var form = document.partnership;
      var pat = /^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/;
      if(form.firstname.value=="") errors = errors+"- First name\n";
      if(form.lastname.value=="") errors = errors+"- Last name\n";
      if(form.country.value=="") errors = errors+"- Country\n";
      if(form.postcode.value=="") errors = errors+"- Postal\ZIP code\n";
      if(form.city.value=="") errors = errors+"- City/town\n";
      if(form.street.value=="") errors = errors+"- Street\n";
      if(form.house.value=="") errors = errors+"- House\n";
      if(form.office.value=="") errors = errors+"- Office number\n";
      if(form.organization.value=="") errors = errors+"- Name of organisation\n";
      if(form.phone.value=="") errors = errors+"- Phone\n";
      if(!pat.test(form.email.value)) errors = errors+"- E-mail\n";
      if(form.password.value=="") errors = errors+"- Password\n";
      if(errors=="")
        {
          return true;
        }
      else
        {
          errors = "Follow errors will be found:\n\n"+errors;
          alert(errors);
          return false;
        }
    }
    
  function OrderDetails(id, uid)
    {
      var link = "printorderform.php?id="+id+"&uid="+uid;
      window.open(link,'','top=, left=, menubar=0, toolbar=0, location=0, directories=0, status=0, scrollbars=1, resizable=0, width=800, height=600');
    }
    
  // Функция установки языка интерфейса по-умолчанию для конкретного партнера. Вызывается из кабинета.
  function SetDefaultLanguage()
    {
      var params = "action=SetDefaultLanguage&language="+$F("deflanguage");
      var ajax = new Ajax.Updater({success: 'changelanguageresult'}, '/getter.php', {method: 'post', asynchronous: false, parameters: params, onFailure: null});
    }
    
  // Функция установки валюты интерфейса по-умолчанию для конкретного партнера. Вызывается из кабинета.
  function SetDefaultCurrency()
    {
      var params = "action=SetDefaultCurrency&currency="+$F("defcurrency");
      var ajax   = new Ajax.Updater({success: 'changecurrencyresult'}, '/getter.php', {method: 'post', asynchronous: false, parameters: params, onFailure: null});
    }

  function ManagerPhoto()
    {
      var params = "action=GetManagerPhoto&mid="+$F("manager");
      var ajax = new Ajax.Updater({success: 'TargetPhoto'}, 'getter.php', {method: 'post', parameters: params, onFailure: null});
    }
  function CheckFieldsContacts()
    {
      var errors = "";
      if($F("manager")=="") errors = errors+"\n- Employee";
      if($F("username")=="") errors = errors+"\n- Your name";
      if(!emailPattern.test($F("useremail"))) errors = errors+"\n- Your e-mail";
      if($F("usermessage")=="") errors = errors+"\n- Your message";
      if(errors!=="")
        {
          errors = "Next errors will be found:\n"+errors;
          alert(errors);
          return false;
        }
      else
        {
          return true;
        }
    }
  // Подсчет вводимых символов в поле
  function SymbolsLimiter(source, limit)
    {
      var length = limit-$F(source).length;
      if(length<0) $(source).value = $F(source).substr(0,limit+1);
    }
