function show_cat(el)
{
  try{
    el1=document.getElementById('li-'+el);
    if (el1.className=='menu_td_catalog_1')el1.className='menu_select_td_catalog1';else
    el1.className='menu_td_catalog_1';
  }catch (err){}

  try{
    el2=document.getElementById('ul-'+el);
    if (el2.style.display=='none')el2.style.display='';else
    el2.style.display='none';
  }catch (err){}
}



function changbg(obg,show)
{
 if (show)obg.className='menu_select_td_1';
 if (!show)obg.className='menu_td_1';
}


// возвращает cookie если есть или undefined
function getCookie(name) {
    var matches = document.cookie.match(new RegExp(
      "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
    ))
    return matches ? decodeURIComponent(matches[1]) : undefined
}

// уcтанавливает cookie
function setCookie(name, value, props) {
    props = props || {}
    var exp = props.expires
    if (typeof exp == "number" && exp) {
        var d = new Date()
        d.setTime(d.getTime() + exp*1000)
        exp = props.expires = d
    }
    if(exp && exp.toUTCString) { props.expires = exp.toUTCString() }

    value = encodeURIComponent(value)
    var updatedCookie = name + "=" + value
    for(var propName in props){
        updatedCookie += "; " + propName
        var propValue = props[propName]
        if(propValue !== true){ updatedCookie += "=" + propValue }
    }
    document.cookie = updatedCookie

}

// удаляет cookie
function deleteCookie(name) {
    setCookie(name, null, { expires: -1 })
}


function img_popup(img)//отображает картинку в попапе
{
 width=600;
 height=550;

 s_width = screen.width;
 s_height = screen.height;

 win_width=s_width/2-width/2;
 win_height=s_height/2-height/2;
 window.open('img_popup.php?patch='+img,null,'width='+width+',height='+height+',Top='+win_height+',Left='+win_width+',scrollbars=yes,resizable=yes');
}

window.onresize=popupmove;
window.onscroll=popupmove;

function create_window()
{
  popup_div=document.createElement('DIV');
  popup_div.id='popup';
  popup_div.style.position='absolute';
  popup_div.style.display='none';
  popup_div.style.backgroundColor='#ffffff';
  popup_div.style.width='800px';
  popup_div.style.height='600px';
  popup_div.style.zIndex='100';
  popup_div.id='popup';
  popup_div.id='popup';

   var div=document.createElement('span');
   div.innerHTML="<a href='javascript:popup_close()'><img hspace='5' border='0' align='middle' vspace='5' src='/images/close.gif'></a>";
   div.style.cssFloat='right';
   div.style.width='25px';
   div.style.height='20px';
   popup_div.appendChild(div);

   var div=document.createElement('DIV');
   div.innerHTML="<iframe style='width:100%;height:100%;' id='popup_frame' name='popup' border='0' frameborder='0'></iframe>";
   div.style.backgroundColor='white';
   popup_div.appendChild(div);
  document.body.appendChild(popup_div);
}

function popupmove()//отображаем попап во фрейме
{
 if (document.getElementById('popup'))
 {
 ShadowDIV=document.getElementById('shadowdiv');
 if (!ShadowDIV)
 {
   var ShadowDIV=document.createElement('DIV');
   ShadowDIV.id='shadowdiv';
   document.body.appendChild(ShadowDIV);
   if(window.addEventListener){ // Mozilla, Netscape, Firefox
    ShadowDIV.addEventListener('click', popup_close, false);
    } else { // IE
      ShadowDIV.attachEvent('onclick', popup_close);
    }

 }else ShadowDIV=document.getElementById('shadowdiv');
 try{document.getElementById('shadowdiv').style.top=document.body.scrollTop;}catch (err){}

 if (document.getElementById('popup').style.display!='none')
 ShadowDIV.style.display='';
 if (!document.getElementById('popup'))create_window();
 width=document.getElementById('popup').style.width;
 height=document.getElementById('popup').style.height;

 if (width=='')width=document.getElementById('popup').width;
 if (height=='')height=document.getElementById('popup').height;

 width=parseInt(width);
 height=parseInt(height);

 s_width = parseInt(document.body.clientWidth);
 s_height = parseInt(document.body.clientHeight);

 win_width=parseInt(s_width/2-width/2);
 win_height=parseInt(s_height/2-height/2+30);

 if (win_width<30)win_width=30;
 if (win_height<30)win_height=30;
 document.getElementById('popup').style.left=win_width;
 document.getElementById('popup').style.top=win_height+document.body.scrollTop;
 }
}


 function popup(url)//открывает попап окно с заданый URL
{
 if (!document.getElementById('popup'))create_window();
 document.getElementById('popup_frame').src=url;
 document.getElementById('popup').style.width='800px';
 document.getElementById('popup').style.height='600px';
 document.getElementById('popup').style.display='';
 try{document.getElementById('shadowdiv').style.top=document.body.scrollTop;}catch (err){}
 popupmove();
}

function popup_close()//закрываем фрейм
{
 try{
 document.getElementById('popup').style.display="none";
 document.getElementById('shadowdiv').style.display="none";
 document.getElementById('popup_frame').src='';
 }catch (err){window.close()}
}

function resize(width_value,height_value,max_width_value,max_height_value)//делаем ресайз фрейма
{
  if (width_value>max_width_value||height_value>max_height_value)
  {
    document.getElementById('popup').style.width=width_value;
    document.getElementById('popup').style.height=height_value;
  }else
  {
    document.getElementById('popup').style.width=max_width_value;
    document.getElementById('popup').style.height=max_height_value;
  }
}


 function admin_show(event){

    event = (event) ? event : window.event; // IE
    if (event.ctrlKey && event.shiftKey && (event.keyCode==65 || event.keyCode==83))
    {
      var admin_div=document.createElement("div");
      var width=200;
      var height=160;
      var s_width = screen.width;
      var s_height = screen.height;
      //логин
      admin_div.style.width=width+'px';
      admin_div.style.height=height+'px';
      admin_div.style.position='absolute';
      admin_div.style.left=s_width/2-width/2+'px';
      admin_div.style.top=s_height/2-((height/2)*2)+'px';
      admin_div.style.backgroundColor='blue';
      admin_div.style.filter='alpha(opacity=85)';
      admin_div.style.opacity='0.85';
      admin_div.style.padding='5 5 5 5';
      document.body.appendChild(admin_div);
      //форма
      form= document.createElement('form');
      form.setAttribute('action', '');
      form.method='post';
      admin_div.appendChild(form);

      inp = document.createElement('p');
      inp.innerHTML='Вход пользователя';
      inp.style.fontWeight="bolder";
      inp.style.color="red";
      inp.style.margin='0 0 5 0';
      inp.style.textAlign='center';
      form.appendChild(inp);

      //имя пользователя
      inp = document.createElement('p');
      inp.style.fontSize='10';
      inp.style.margin='5 0 0 0';
      inp.style.color='white';
      inp.innerHTML='Имя пользователя:';
      form.appendChild(inp);

      inp = document.createElement('input');
      inp.name='login';
      inp.style.textAlign='center';
      inp.style.width='190px';
      inp.style.margin='5 5 0 5';
      form.appendChild(inp);


      //пароль
      inp = document.createElement('p');
      inp.style.fontSize='10';
      inp.style.margin='5 0 0 0';
      inp.style.color='white';
      inp.innerHTML='Пароль:';
      form.appendChild(inp);

      inp = document.createElement('input');
      inp.setAttribute('type', 'password');
      inp.name='password';
      inp.style.width='190px';
      inp.style.margin='5 5 0 5';
      inp.style.textAlign='center';
      form.appendChild(inp);

      inp = document.createElement('p');
      inp.style.fontSize='10';
      inp.style.margin='5 0 0 5';
      inp.style.color='white';
      inp.innerHTML='<input type=checkbox name=remember style="margin: 0 0 0 0"> Запомнить';
      form.appendChild(inp);


      //войти
      inp = document.createElement('p');
      inp.align='center';
      inp.style.margin='5 0 0 0';
      form.appendChild(inp);

      inp_submit = document.createElement('input');
      inp_submit.setAttribute('type', 'submit');
      inp_submit.value='Войти';
      inp_submit.style.fontSize='12';
      inp_submit.style.fontFamily='Arial';
      inp_submit.style.fontWeight="bolder";
      inp_submit.style.width='80px';
      inp_submit.style.height='20px';
      inp_submit.style.margin='0 0 0 5';
      inp.appendChild(inp_submit);

      inp_submit = document.createElement('input');
      inp_submit.setAttribute('type', 'submit');
      inp_submit.onclick=function (e){el=this.parentNode.parentNode.parentNode;el.parentNode.removeChild(el);}
      inp_submit.value='Отмена';
      inp_submit.style.fontSize='12';
      inp_submit.style.fontFamily='Arial';
      inp_submit.style.fontWeight="bolder";
      inp_submit.style.width='80px';
      inp_submit.style.height='20px';
      inp_submit.style.margin='0 0 0 5';
      inp.appendChild(inp_submit);

    }
 }
 document.onkeydown=admin_show;
