var req; 
function getXmlHttp()
{
  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 sendAjax(url,func)
{
  req = getXmlHttp();
  if (req)
  {
      req.onreadystatechange = func;      
      req.open("GET", url, true);  
      req.send(null);
  }
}

function send_vacans()
{        //  alert("s");    
  var errors="<span class='x' name='x' "; 
  errors+="onmouseover='this.style.cursor=\"pointer\";return false;' ";
  errors+="onclick='close_win(\"popup_error_vacans\");return false;' title='Закрыть' >x</span><br/> ";
  errors+="<span id='error_mes_vacans' class='error_mes'><ul>";
  var fl=0;                                                     
  var birthday=document.getElementById("birthday_vacans").value;
  var fio=document.getElementById("fio_vacans").value; 
  var address=document.getElementById("address_vacans").value; 
  var phone=document.getElementById("phone_vacans").value; 
  var spec=document.getElementById("spec_vacans").value; 
  var work=document.getElementById("work_vacans").value; 
  var dop_info=document.getElementById("dop_info_vacans").value; 
  var zp=document.getElementById("zp_vacans").value;
  var m_status=document.getElementById("m_status_vacans").value;
  var child=document.getElementById("child_vacans").value;
  var education=document.getElementById("education_vacans").value;
  var comp=document.getElementById("comp_vacans").value;
  
  if(birthday=="" || birthday==null){errors+="<li>Не указана дата рождения</li>";fl=1;}
  if(fio=="" || fio==null){errors+="<li>Не указано ФИО</li>";fl=1;}
  if(address=="" || address==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;}
  if(spec=="" || spec==null){errors+="<li>Не указана специальность</li>";fl=1;}   
  if(work=="" || work==null){errors+="<li>Не указана текущая работа</li>";fl=1;}   
  if(zp=="" || zp==null){errors+="<li>Не указана желаемая з/п</li>";fl=1;}   
  if(m_status=="" || m_status==null){errors+="<li>Не указано семейное положение</li>";fl=1;}   
  if(child=="" || child==null){errors+="<li>Не указано количество детей</li>";fl=1;}   
  if(education=="" || education==null){errors+="<li>Не указано образование</li>";fl=1;}   
  if(comp=="" || comp==null){errors+="<li>Не указан уровень компьютерных навыков</li>";fl=1;}   
  errors+="</ul></span>";
 
  if(fl!=0)
  {
    var pos = getElementPosition("btn_send_vacans"); 
    var left = pos.left; 
    var top = pos.top;     
    
    document.getElementById("popup_error_vacans").style.width="300px";
     document.getElementById("popup_error_vacans").style.left=left-200+"px"; 
        document.getElementById("popup_error_vacans").style.top=top-10+"px"; 
    document.getElementById("popup_error_vacans").innerHTML=errors;
    opacity('popup_error_vacans',0,100,300);
    return;
  }
  var url="http://www.prilesnoe.com/modules/mod_vacans_action.php?flag_action=add_vacans&birthday="+birthday+"&fio="+encodeURIComponent(fio)+"&address="+encodeURIComponent(address)
      +"&phone="+phone+"&spec="+encodeURIComponent(spec)+"&work="+encodeURIComponent(work)+"&zp="
      +encodeURIComponent(zp)+"&m_status="+encodeURIComponent(m_status)
      +"&child="+child+"&education="+encodeURIComponent(education)+"&comp="+encodeURIComponent(comp)+"&dop_info="+encodeURIComponent(dop_info);
    sendAjax(url,function(){updateOnSendZakaz(req);});
}
function updateOnSendZakaz()
{
  if (req.readyState == 4)
  {
    if (req.status == 200)
    {
      var response = req.responseText;
      if(response=="ok")
      {
        var pos = getElementPosition("btn_send_vacans"); 
        var left = pos.left; 
        var top = pos.top;
        document.getElementById("popup_error_vacans").style.width="200px";
        document.getElementById("popup_error_vacans").style.height="100px";
        document.getElementById("popup_error_vacans").style.left=left-200+"px"; 
        document.getElementById("popup_error_vacans").style.top=top-200+"px"; 
        document.getElementById("popup_error_vacans").innerHTML="<span id='error_mes_vacans' class='error_mes1'>Ваша заявка отправлена</span>"; 
        opacity('popup_error_vacans',0,100,300); 
        setTimeout("opacity('popup_error_vacans'," + 100+","+0+","+300 + ")",1500); 
        clearForm();
      }
      else
      {
        var pos = getElementPosition("btn_send_vacans"); 
        var left = pos.left; 
        var top = pos.top;
        document.getElementById("popup_error_vacans").style.width="200px";
        document.getElementById("popup_error_vacans").style.height="100px";
         document.getElementById("popup_error_vacans").style.left=left-200+"px"; 
        document.getElementById("popup_error_vacans").style.top=top-200+"px";  
        document.getElementById("popup_error_vacans").innerHTML="<span id='error_mes_vacans' class='error_mes1'>"+response+"</span>";
        document.getElementById("popup_error_vacans").style.width=document.getElementById("div_vacans").style.width;
        opacity('popup_error_vacans',0,100,300); 
        setTimeout("opacity('popup_error_vacans'," + 100+","+0+","+300 +  ")",1500);
      }
    }
  }
}

function clearForm()
{
  document.getElementById("birthday_vacans").value="";
  document.getElementById("fio_vacans").value="";
  document.getElementById("address_vacans").value="";
  document.getElementById("phone_vacans").value="";
  document.getElementById("spec_vacans").value="";
  document.getElementById("work_vacans").value="";
  document.getElementById("dop_info_vacans").value="";
  document.getElementById("zp_vacans").value="";
}