function get(id){
    return document.getElementById(id);
}

function openWindow(id,w,h){ //v2.0
  var scw=w;
  var sch=h;
  var x=(screen.Width-scw)/2;
  var y=(screen.Height-sch)/2;
  wnd=window.open("preview.php?id="+id, "Object","toolbar=no,location=no,directory=no,status=no,scrollbars=yes,resizable=no,left="+x+",top="+y+",width="+scw+" ,height="+sch);
}

function showbloq(id){
    if(get(id).style.display=='none'){
      get(id).style.display='';
    }else{
     get(id).style.display='none';
    };
 }

      function createXMLHttp() {
        if(typeof XMLHttpRequest != "undefined") { // для браузеров аля Mozilla

          return new XMLHttpRequest();
        } else if(window.ActiveXObject) { // для Internet Explorer (all versions)
          var aVersions = ["MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0",
                   "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp",
                   "Microsoft.XMLHttp"
                   ];
          for (var i = 0; i < aVersions.length; i++) {
            try { //
              var oXmlHttp = new ActiveXObject(aVersions[i]);

              return oXmlHttp;
            } catch (oError) {

            }
          }
          throw new Error("Невозможно создать объект XMLHttp.");
        }
      }


      function getRequestBody(oForm) {
        var aParams = new Array();
        for(var i = 0; i < oForm.elements.length; i++) {
          var sParam = encodeURIComponent(oForm.elements[i].name);
          sParam += "=";
          sParam += encodeURIComponent(oForm.elements[i].value);
          aParams.push(sParam);
        }
        return aParams.join("&");
      }

      function sendRequestPOST(id, id_content, action) {
        var oForm = document.getElementById(id);//document.forms[0];
        var sBody = getRequestBody(oForm);
        var oXmlHttp = createXMLHttp();
        oXmlHttp.open("POST", action, true);
        oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        document.getElementById(id_content).innerHTML="<img src='img/i1.gif' border='0'>";
        oXmlHttp.onreadystatechange = function() {
          if(oXmlHttp.readyState == 4) {
            if(oXmlHttp.status == 200) {
              //alert(oXmlHttp.responseText);
              saveResult(oXmlHttp.responseText, id_content);
              //saveResult("", 'pagebartop');
              //saveResult("", 'pagebarbottom');
            } else {
              saveResult("Ошибка: " + oXmlHttp.statusText, id_content);
            }
          }
        };
        oXmlHttp.send(sBody);
      }

      function sendRequestPOST_LISTING(id, action) {
        var oForm = document.getElementById(id);
        var sBody = getRequestBody(oForm);
        var oXmlHttp = createXMLHttp();
              saveResult("Обработка данных", 'pagebartop');
              saveResult("Обработка данных", 'pagebarbottom');
        oXmlHttp.open("POST", action, true);
        oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

        oXmlHttp.onreadystatechange = function() {
          if(oXmlHttp.readyState == 4) {
            if(oXmlHttp.status == 200) {
              saveResult(oXmlHttp.responseText, 'pagebartop');
              saveResult(oXmlHttp.responseText, 'pagebarbottom');
            } else {
              saveResult("Ошибка: " + oXmlHttp.statusText, id_content);
            }
          }
        };
        oXmlHttp.send(sBody);
      }


      function sendRequestGET(id) {
      if(id!=0){
	        var url = "ajax_script/select_distrib.php?id_country="+id;
	        var oXmlHttp = createXMLHttp();

	        oXmlHttp.open("GET", url, true);
            document.getElementById("distrib_select").innerHTML = "<img src='img/i1.gif'>"
	        oXmlHttp.onreadystatechange = function() {
	          if(oXmlHttp.readyState == 4) {
	            if(oXmlHttp.status == 200) {
	              document.getElementById("distrib_select").innerHTML = oXmlHttp.responseText;
	            } else {
	              document.getElementById("distrib_select").innerHTML = oXmlHttp.responseText;
	            }
	          }
	        };
          oXmlHttp.send(null);
        }else{
            document.getElementById("distrib_select").innerHTML = "";
        }

      }

      function saveResult(sText, id) {
        document.getElementById(id).innerHTML=sText;
      }
//==============================================================================

      function  set_mail(fio, user_mail, mess){
         document.getElementById('send_user').value = document.getElementById(fio).value;
         document.getElementById('ans_mail').value = document.getElementById(user_mail).value;
         document.getElementById('send_feed').value = document.getElementById(mess).value;
         sendRequestPOST("ajax_data_form", "send_mail_res", "ajax_script/send.php");
      }

      function  set_id(id, value, action, mod, form_id, div_id_content){
         document.getElementById(id).value = value;
         document.getElementById("mod").value = mod;
              saveResult("", 'pagebartop');
              saveResult("", 'pagebarbottom');
         sendRequestPOST(form_id, div_id_content, action);
      }

      function  set_news_list(page, list_page){
         document.getElementById("page").value = page;
         document.getElementById("list_page").value = list_page;
         sendRequestPOST('ajax_data_form', 'content', 'ajax_script/get_news.php');
      }

      function  set_distrib_list(page, list_page){
         document.getElementById("page").value = page;
         document.getElementById("list_page").value = list_page;
         sendRequestPOST('ajax_data_form', 'content', 'ajax_script/get_distrib.php');
      }

      function  set_prod_list(page, list_page){
         document.getElementById("page").value = page;
         document.getElementById("list_page").value = list_page;
         sendRequestPOST('ajax_data_form', 'content', 'ajax_script/get_prod.php');
      }

      function  set_news_list_page(page, list_page){
         document.getElementById("page").value = page;
         document.getElementById("list_page").value = list_page;
         sendRequestPOST('ajax_data_form', 'content', 'ajax_script/get_news.php');
         sendRequestPOST_LISTING('ajax_data_form', 'ajax_script/list.php');
      }

      function  set_distrib_list_page(page, list_page){
         document.getElementById("page").value = page;
         document.getElementById("list_page").value = list_page;
         sendRequestPOST('ajax_data_form', 'content', 'ajax_script/get_distrib.php');
         sendRequestPOST_LISTING('ajax_data_form', 'ajax_script/list.php');
      }

      function  set_prod_list_page(page, list_page){
         document.getElementById("page").value = page;
         document.getElementById("list_page").value = list_page;
         sendRequestPOST('ajax_data_form', 'content', 'ajax_script/get_prod.php');
         sendRequestPOST_LISTING('ajax_data_form', 'ajax_script/list.php');
      }

      function  news(action, form_id, mod){
        if(mod==document.getElementById("mod").value){
          reload_listing = 1;
        }else{
          reload_listing = 0;
        };
         document.getElementById("mod").value = mod;
         sendRequestPOST('ajax_data_form', 'content', 'ajax_script/get_news.php');
         if(reload_listing == 0){
           set_news_list(1, 1);
         }
         sendRequestPOST_LISTING('ajax_data_form', 'ajax_script/list.php');
      }

      function  distrib(action, form_id, mod){
        if(mod==document.getElementById("mod").value){
          reload_listing = 1;
        }else{
          reload_listing = 0;
        };
         document.getElementById("mod").value = mod;
         //sendRequestPOST('ajax_data_form', 'content', 'ajax_script/get_distrib.php');
         if(reload_listing == 0){
           set_distrib_list(1, 1);
         }
         sendRequestPOST_LISTING('ajax_data_form', 'ajax_script/list.php');
         if(document.getElementById("m2").innerHTML == ""){
            distrib_menu_open();
         }else{
            distrib_menu_close();
         }
      }

      function  prod(id, action, form_id, mod){
        if(mod==document.getElementById("mod").value){
          reload_listing = 1;
        }else{
          reload_listing = 0;
        };
         document.getElementById("id_distrib").value = id;
         document.getElementById("mod").value = mod;
         sendRequestPOST('ajax_data_form', 'content', action);
         if(reload_listing == 0){
           set_prod_list(1, 1);
         }
         sendRequestPOST_LISTING('ajax_data_form', 'ajax_script/list.php');
      }//==============================================================================

     function distrib_menu_open(){
	        var url = "ajax_script/get_distrib_menu.php";
	        var oXmlHttp = createXMLHttp();
	        oXmlHttp.open("GET", url, true);
            document.getElementById("m2").innerHTML = "<img src='img/i1.gif' border='0'>"
	        oXmlHttp.onreadystatechange = function() {
	          if(oXmlHttp.readyState == 4) {
	            if(oXmlHttp.status == 200) {
	              document.getElementById("m2").innerHTML = oXmlHttp.responseText;
	            } else {
	              document.getElementById("m2").innerHTML = oXmlHttp.responseText;
	            }
	          }
	        };
          oXmlHttp.send(null);
     }

     function distrib_menu_close(){
	      document.getElementById("m2").innerHTML = "";
     }

function  srch(sss1, sss2, sss3){
rc = true;
if (sss1 =='') {
alert("Пожалуйста заполните все поля");
rc = false;
return rc;
}
if (sss2 =='') {
alert("Пожалуйста заполните все поля");
rc = false;
return rc;
}
if (sss3 =='') {
alert("Пожалуйста заполните все поля");
rc = false;
return rc;
}
}

function  clear_pole(){
  document.getElementById("fio").value = "";
  document.getElementById("user_mail").value = "";
  document.getElementById("mess").value = "";
}

