var req;

function getXmlHttp1()
{
  var req1 = null;    
  if (window.XMLHttpRequest)
  {
    try{req1 = new XMLHttpRequest(); if (req1.overrideMimeType) { req1.overrideMimeType('text/xml');}} catch (e){}
  }
  else if (window.ActiveXObject)
  {
    try {req1 = new ActiveXObject('Msxml2.XMLHTTP');}
    catch (e) {try {req1 = new ActiveXObject('Microsoft.XMLHTTP');} catch (e){}}
  }                                                                             
  return req1;
}

function sendAjax1(url,func)
{
  req = getXmlHttp1();
  if (req)
  {
      req.onreadystatechange = func;

      req.open("GET", url, true);  
      req.send(null);
  }
}

function send_zakaz()
{                           
  var errors="<span class='x' name='x' "; 
  errors+="onmouseover='this.style.cursor=\"pointer\";return false;' ";
  errors+="onclick='close_win(\"mod_online_popup_error\");return false;' title='Закрыть' >x</span><br/> ";
  errors+="<span id='mod_online_error_mes' class='error_mes'><ul>";
  var fl=0;
  var data_start=document.getElementById("mod_online_data_start").value;
  var data_fin=document.getElementById("mod_online_data_fin").value;
  var cat_n=document.getElementById("mod_online_cat_n").value;
  var count_adults=document.getElementById("mod_online_count_adults").value;
  var count_children=document.getElementById("mod_online_count_children").value;
  var count_children2=document.getElementById("mod_online_count_children2").value;
  var name=document.getElementById("mod_online_name").value;
  var sirname=document.getElementById("mod_online_sirname").value;
  var country=document.getElementById("mod_online_country").value;
  var phone=document.getElementById("mod_online_phone").value;
  var arrival_place=document.getElementById("mod_online_arrival_place").value;
  var info=document.getElementById("mod_online_info").value;
  

if(info=="" || info==null)info=" - ";
if(arrival_place=="" || arrival_place==null)arrival_place=" - ";
if(country=="" || country==null)country=" - ";
if(count_children=="" || count_children==null||count_children==0)count_children=" - ";
if(count_children2=="" || count_children2==null||count_children2==0)count_children2=" - ";
  if(data_start=="" || data_start==null){errors+="<li>Не указана начальная дата</li>";fl=1;}
  if(data_fin=="" || data_fin==null){errors+="<li>Не указана конечная дата</li>";fl=1;}
  if(count_adults=="" || count_adults==null||count_adults==0){errors+="<li>Не указано количество людей</li>";fl=1;}
  if(name=="" || name==null){errors+="<li>Не указано имя</li>";fl=1;}
  if(sirname=="" || sirname==null){errors+="<li>Не указана фамилия</li>";fl=1;}
  if(phone=="" || phone==null){errors+="<li>Не указан телефон</li>";fl=1;}
  if ((phone.search(/^([0-9()\s-])*$/)) == -1) {errors+="<li>Неверный формат телефона</li>";fl=1;}
  errors+="</ul></span>";
  if(fl!=0)
  {                                
    var pos = getElementPosition("mod_online_btn_send_zakaz");
    var left = pos.left; 
    var top = pos.top; 
    document.getElementById("mod_online_popup_error").style.width="300px";
    document.getElementById("mod_online_popup_error").style.left=(left+150)+"px";
    document.getElementById("mod_online_popup_error").style.top=(top-100)+"px";
    document.getElementById("mod_online_popup_error").innerHTML=errors;
    opacity('mod_online_popup_error',0,100,300);
    return;
  }

document.getElementById("mod_online_loading_img").style.visibility="visible";
  var url="http://www.prilesnoe.com/modules/mod_online_action.php?flag_action=bronirovanie&data_start="+data_start+"&data_fin="+data_fin+"&cat_n="+cat_n+"&count_adults="+count_adults+"&count_children="+count_children+"&count_children2="+count_children2+"&name="+encodeURIComponent(name)+"&sirname="+encodeURIComponent(sirname)+"&country="+encodeURIComponent(country)+"&phone="+phone+"&arrival_place="+encodeURIComponent(arrival_place)+"&info="+encodeURIComponent(info);
  sendAjax1(url,function(){updateOnSendZakaz1(req);});
}
function updateOnSendZakaz1()
{

  if (req.readyState == 4)
  {
    if (req.status == 200)
    {
      var response = req.responseText;

      if(response=="ok")
      {
document.getElementById("mod_online_loading_img").style.visibility="hidden";

      var pos = getElementPosition("mod_online_btn_send_zakaz");
    var left = pos.left; 
    var top = pos.top;
        document.getElementById("mod_online_popup_error").style.width="200px";
        document.getElementById("mod_online_popup_error").style.height="100px";
        document.getElementById("mod_online_popup_error").style.left=(left+150)+"px";
        document.getElementById("mod_online_popup_error").style.top=(top-100)+"px";
        document.getElementById("mod_online_popup_error").innerHTML="<span id='mod_online_error_mes' class='error_mes1'>Ваш заказ отправлен</span>";
        opacity('mod_online_popup_error',0,100,300);
        setTimeout("opacity('mod_online_popup_error'," + 100+","+0+","+300 + ")",3500);
        clearForm1();
      }
      else
      {
      var pos = getElementPosition("mod_online_btn_send_zakaz");
    var left = pos.left; 
    var top = pos.top;
        document.getElementById("mod_online_popup_error").style.width="200px";
        document.getElementById("mod_online_popup_error").style.height="100px";
        document.getElementById("mod_online_popup_error").style.left=(left+150)+"px";
        document.getElementById("mod_online_popup_error").style.top=(top-100)+"px";
        document.getElementById("mod_online_popup_error").innerHTML="<span id='mod_online_error_mes' class='error_mes1'>Ошибка при отправке заказа.</span>";
        document.getElementById("mod_online_popup_error").style.width=document.getElementById("mod_online_div_zakaz").style.width;
        opacity('mod_online_popup_error',0,100,300);
        setTimeout("opacity('mod_online_popup_error'," + 100+","+0+","+300 +  ")",1500);
      }
    }
  }
}

function clearForm1()
{
  document.getElementById("mod_online_data_start").value="";
  document.getElementById("mod_online_data_fin").value="";
  document.getElementById("mod_online_name").value="";
  document.getElementById("mod_online_sirname").value="";
  document.getElementById("mod_online_phone").value="";
  document.getElementById("mod_online_arrival_place").value="";
  document.getElementById("mod_online_info").value="";
}