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';
}


function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
        var cookie = " " + document.cookie;
        var search = " " + name + "=";
        var setStr = null;
        var offset = 0;
        var end = 0;
        if (cookie.length > 0) {
                offset = cookie.indexOf(search);
                if (offset != -1) {
                        offset += search.length;
                        end = cookie.indexOf(";", offset)
                        if (end == -1) {
                                end = cookie.length;
                        }
                        setStr = unescape(cookie.substring(offset, end));
                }
        }
        return(setStr);
}


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.innerHTML="<iframe style='z-index:1;position: absolute; left: 354; top: 199;display: none; width:565px; height:434px' id='popup' name='popup' border='0' frameborder='0' scrolling='no'></iframe>";
  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').src=url;
 document.getElementById('popup').style.display='block';
 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";
 }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;
  }
}
