var opera=false;
var gecko=false;
var ie=false;
var safari=false;
var browser=navigator.userAgent.toLowerCase();
var ver=parseFloat(navigator.appVersion);

if(browser.indexOf('msie')!=-1)
{
  ie=true;
  if(browser.indexOf('msie 5.5')!=-1)ver=5.5;
  else if(browser.indexOf('msie 5')!=-1)ver=5;
}

if(browser.indexOf('opera')!=-1)opera=true;
if(browser.indexOf('gecko')!=-1)gecko=true;
if(browser.indexOf('safari')!=-1)safari=true;


function png(element){
if(ie){
var src,method='scale';
var classname=element.className;
if(classname.match('png'))
{
  src=element.getAttribute('src');
  element.setAttribute('src','img/spacer.gif');
}
else if(classname.match('scale')||classname.match('crop'))
{
  src=element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)[1];
  element.style.backgroundImage='none';
  if(classname.match('crop'))method='crop';
}
//alert(src);
element.style.filter="progid:dximagetransform.microsoft.alphaimageloader(src='"+src+"',sizingmethod="+method+")";
}
}


function show_img(img,width,height)
	{
	   var a
	   var b
	   var url
	   vidWindowWidth=width;
	   vidWindowHeight=height;
	   a=(screen.height-vidWindowHeight)/5;
	   b=(screen.width-vidWindowWidth)/2;
	   features="top="+a+",left="+b+",width="+vidWindowWidth+",height="+vidWindowHeight+",toolbar=no,menubar=no,location=no,directories=no,scrollbars=no,resizable=no";
	   url=""+img;
	   window.open(url,'',features,true);
	}
function message (obj, par)
          {
            div = document.getElementById(obj);
            div.style.visibility='visible';
            if (par==1)
             {
                 email = document.getElementById('vost_email');
                 url = '/message.php?id=' + par + '&email=' + email.value;

             }
            else if (par==2)
             {
                 login = document.getElementById('login_form');
                 pass = document.getElementById('pass_form');
                 //alert('we');
                 //saves = document.getElementById('saves');
                 url = '/message.php?id=' + par + '&login_form=' + login.value + '&pass_form=' + pass.value;

             }
                 // Получаем объект XMLHTTPRequest
                 //if(!this.http)
                  {
                   this.http = get_http();
                   this.working = false;
                  }
                 // Запрос
		         if (!this.working && this.http)
		          {
		            var http = this.http;
		            var value;
		            //создаём запрос
		            this.http.open("GET", url, true);
		            //прикрепляем к запросу функцию-обработчик
		            //событий
		            this.http.onreadystatechange = function()
		             {
			            // 4 - данные готовы для обработки
		                if (http.readyState == 4)
		                  {
		                    value = http.responseText;
		                    this.working = false;
			                div.innerHTML = value;
		                  }else
		                  {
		                     // данные в процессе получения,
		                     // можно повеселить пользователя
		                     //сообщениями
		                     // ЖДИТЕ ОТВЕТА
		                  }
		             }
		            this.working = true;
		            this.http.send(null);
		          }
		         if(!this.http)
		          {
		              alert('Ошибка при создании XMLHTTP объекта!')
		          }
          }




function add_kat (par)
          {
            div = document.getElementById('pod_kat');
                 url = '/add_kat.php?id_kat=' + par;
                 // Получаем объект XMLHTTPRequest
                 //if(!this.http)
                  {
                   this.http = get_http();
                   this.working = false;
                  }
                 // Запрос
		         if (!this.working && this.http)
		          {
		            var http = this.http;
		            var value;
		            //создаём запрос
		            this.http.open("GET", url, true);
		            //прикрепляем к запросу функцию-обработчик
		            //событий
		            this.http.onreadystatechange = function()
		             {
			            // 4 - данные готовы для обработки
		                if (http.readyState == 4)
		                  {
		                    value = http.responseText;
		                    this.working = false;
			                div.innerHTML = value;
			                add_type (par);
		                  }else
		                  {
		                     // данные в процессе получения,
		                     // можно повеселить пользователя
		                     //сообщениями
		                     // ЖДИТЕ ОТВЕТА
		                  }
		             }
		            this.working = true;
		            this.http.send(null);
		          }
		         if(!this.http)
		          {
		              alert('Ошибка при создании XMLHTTP объекта!')
		          }
          }
function add_type (par)
          {
            div = document.getElementById('pod_type');
                 url = '/add_type.php?id_kat=' + par;
                 // Получаем объект XMLHTTPRequest
                 //if(!this.http)
                  {
                   this.http = get_http();
                   this.working = false;
                  }
                 // Запрос
		         if (!this.working && this.http)
		          {
		            var http = this.http;
		            var value;
		            //создаём запрос
		            this.http.open("GET", url, true);
		            //прикрепляем к запросу функцию-обработчик
		            //событий
		            this.http.onreadystatechange = function()
		             {
			            // 4 - данные готовы для обработки
		                if (http.readyState == 4)
		                  {
		                    value = http.responseText;
		                    this.working = false;
			                div.innerHTML = value;
		                  }else
		                  {
		                     // данные в процессе получения,
		                     // можно повеселить пользователя
		                     //сообщениями
		                     // ЖДИТЕ ОТВЕТА
		                  }
		             }
		            this.working = true;
		            this.http.send(null);
		          }
		         if(!this.http)
		          {
		              alert('Ошибка при создании XMLHTTP объекта!')
		          }
          }

		 function get_http()
		  {
		    if (window.XMLHttpRequest) {
		        try {
		            return new XMLHttpRequest();
		        } catch (e){}
		    } else if (window.ActiveXObject) {
		        try {
		            return new ActiveXObject('Msxml2.XMLHTTP');
		        } catch (e){}
		        try {
		            return new ActiveXObject('Microsoft.XMLHTTP');
		        } catch (e){}
		    }
		    return null;
		  }
/////////////////////////

 function write_pass ()
  {
    var tr = false;    if (div = document.getElementById('login_form'))
  	 {
  	   var coo = GetCookie('login_form');
  	   if (coo!=null)
  	    {       	div.value = coo;
       	tr = true;
       	}
  	 }
    if (div = document.getElementById('pass_form'))
  	 {
       var coo = GetCookie('pass_form');
  	    if (coo!=null)
  	    {
       	div.value = coo;
       	tr = true;
       	}
  	 }
  	if (tr)
  	 {  	 	if (div = document.getElementById('saves'))
  	     {  	     	div.checked=true;
  	     }
  	 }
  }

 function add_pass ()
  {
  if (div = document.getElementById('saves'))
  	 {
  	 if (div.checked==true)
  	 {	  if (IsCookieEnabled())
	   {
	    SetCookie("pass_form", document.getElementById('pass_form').value, null, null, "/", null);
	    SetCookie("login_form", document.getElementById('login_form').value, null, null, "/", null);
	   }
	   else
	   	alert ("NO Cookie");
	 }
    }
  }


////////////////////////

var cookies;
var cookie;

function SetCookie(strName, oValue , oDateExpires , strDomain , strPath , bSecure)
{
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;

    var oDate = false; // аргумент expires

    if((argc > 2) && (argv[2] != null))
    {
        // задана дата
        // дату допустимо задавать:
        //    объектом Date,
        //    числом (миллисекундное смещение от 00:00:00 01.01.1970)
        //    строкой в формате, приемлемом для Date.parse

        var nStamp = (typeof(argv[2]) != "number")    ?
                Date.parse(argv[2].toString())        :
                argv[2];

        if(!isNaN(nStamp))
            oDate = new Date(nStamp);
            oDate = oDate + 10000;
    }

    document.cookie =   strName + "=" + escape(oValue.toString())                   +
                        (oDate ? "; expires=" + oDate.toGMTString() : "")           +
                        (((argc > 3) && (argv[3])) ? "; domain=" + argv[3] : "")    +
                        (((argc > 4) && (argv[4])) ? "; path=" + argv[4] : "")      +
                        ((argc > 5) ? (argv[5] ? "; secure" : "") : "");

}
function GetCookie(strName)
{
    if((typeof(strName) == "string") && strName.length)
    {
        var i = 0, j;

        var strFind    = strName + "=";
        var strCookie  = document.cookie;

        do
        {
            j = i + strFind.length;

            if(strCookie.substring(i, j) == strFind)
            {
                var nEnd = strCookie.indexOf(";", j);

                if(nEnd < 0)
                    nEnd = strCookie.length;

                return unescape(strCookie.substring(j, nEnd));
            }
        }
        while(i = strCookie.indexOf(" ", j) + 1);
    }

    return null;
}
function DeleteCookie(strName)
{
    document.cookie = strName + "=0; expires=" + (new Date(0)).toGMTString();
}
function DeleteAllCookie()
{
    var arr = new Array();
    var str = document.cookie;

    var i = 0, nBeg = 0, nEnd;

    do
    {
        if((nEnd = str.indexOf("=", nBeg)) > -1)
            arr[i] = str.substring(nBeg, nEnd);
    }
    while(i++, nBeg = str.indexOf(" ", nEnd) + 1);

    for(i = 0; i < arr.length; i++)
        DeleteCookie(arr[i]);
}
function IsCookieEnabled()
{
    if(typeof(navigator.cookieEnabled) != "undefined")
        return navigator.cookieEnabled;
    else
    {
        // свойство navigator.cookieEnabled не поддерживается
        // установим и получим тестовую куку

        var _c = "__V_TEST_COOKIE_NAME_";

        SetCookie(_c, "1");

        if(GetCookie(_c) != null)
        {
            DeleteCookie(_c);
            return true;
        }

        return false;
    }
}

function parseCookie() {
      // Разделение cookie.
      var cookieList = document.cookie.split("; ");
      // Массив для каждого cookie находится в cookieList
      var cookieArray = new Array();
      for (var i = 0; i < cookieList.length; i++) {
         // Разделение пар имя-значение.
         var name = cookieList[i].split("=");
         // Декодирование и добавление в массив cookie.
         cookieArray[unescape(name[0])] = unescape(name[1]);
      }
      return cookieArray;
   }

//################################################################################


var id_type='';
var id_strana='';

 function search (type, par)
  {
  	  if (type=='type')
  	   {          if (par>0)
           {
             div = document.getElementById('hide_texhika');
             div.style.display = 'block';
           }
          else
           {           	 div = document.getElementById('hide_texhika');
             div.style.display = 'none';
           }
          if (par<1) par=100000000;
          div = document.getElementById('search_id_xyd');
          url = '/search.php?type=' + type + '&id_xyd=' + par;
          search_select (div, url);
          div = document.getElementById('search_id_strana');
          url = '/search.php?type=' + type + '&id_strana=' + par;
          search_select (div, url);
          div = document.getElementById('search_id_ganr');
          url = '/search.php?type=' + type + '&id_ganr=' + par;
          search_select (div, url);
          div = document.getElementById('search_id_texnika');
          url = '/search.php?type=' + type + '&id_texnika=' + par;
          search_select (div, url);
          id_type=par;
  	   }
  	  else if (type=='strana')
  	   {
  	      if (par<1) par=100000000;          div = document.getElementById('search_id_xyd');
          url = '/search.php?type=' + type + '&id_type=' + id_type + '&id_xyd=' + par;
          search_select (div, url);
          div = document.getElementById('search_id_ganr');
          url = '/search.php?type=' + type + '&id_type=' + id_type + '&id_ganr=' + par;
          search_select (div, url);
          div = document.getElementById('search_id_texnika');
          url = '/search.php?type=' + type + '&id_type=' + id_type + '&id_texnika=' + par;
          search_select (div, url);
          id_strana=par;
  	   }
  	  else if (type=='xyd')
  	   {
  	      if (par<1) par=100000000;
          div = document.getElementById('search_id_ganr');
          url = '/search.php?type=' + type + '&id_type=' + id_type + '&id_strana=' + id_strana + '&id_ganr=' + par;
          search_select (div, url);
          div = document.getElementById('search_id_texnika');
          url = '/search.php?type=' + type + '&id_type=' + id_type + '&id_strana=' + id_strana + '&id_texnika=' + par;
          search_select (div, url);
  	   }
  }


		function search_select (div, url)
          {
                 // Получаем объект XMLHTTPRequest
                 //if(!this.http)
                  {
                   this.http = get_http();
                   this.working = false;
                  }
                 // Запрос
		         if (!this.working && this.http)
		          {
		            var http = this.http;
		            var value;
		            //создаём запрос
		            this.http.open("GET", url, true);
		            //прикрепляем к запросу функцию-обработчик
		            //событий
		            this.http.onreadystatechange = function()
		             {
			            // 4 - данные готовы для обработки
		                if (http.readyState == 4)
		                  {
		                    value = http.responseText;
		                    this.working = false;
			                div.innerHTML = value;
		                  }else
		                  {
		                     // данные в процессе получения,
		                     // можно повеселить пользователя
		                     //сообщениями
		                     // ЖДИТЕ ОТВЕТА
		                  }
		             }
		            this.working = true;
		            this.http.send(null);
		          }
		         if(!this.http)
		          {
		              alert('Ошибка при создании XMLHTTP объекта!')
		          }
          }

