

function get_GET(key)
{
 get = new String(window.location);
 x = get.indexOf('?');
 if(x == -1) return "";

 l = get.length;
 get = get.substr(x+1, l-x);
 l = get.split('&');

    for(i=0; i<l.length; i++)
    {
     get = l[i].split('=');
     if(get[0] == key)
     return get[1];
    }

 return "";
}







function get_query()
{
 var query="";

 get = new String(window.location);
 x = get.indexOf('?');
 if( x == -1 )
 return "";

 l = get.length;
 if( (x+1) >= l )
 return "";

 get = get.substr(x+1, l-x);
 l = get.split('&');

    for(i=0; i<l.length; i++)
    {
     get = l[i].split('=');

     if( get[0].indexOf('PageNr')>=0 || get[0].indexOf('id')>=0 || get[0].indexOf('owner')>=0 || get[0].indexOf('seller_')>=0 || get[0].indexOf('level')>=0 )
     query = query + get[0] + '=' + get[1] + '&';
    }

 return query;
}








function get_self()
{
 get = new String(window.location);
 x = get.indexOf('//');
 if(x == -1) return "";

 l = get.length;
 get = get.substr(x+2, l-x);
 x = get.indexOf('/');
 if(x == -1) return "";

 l = get.length;
 get = get.substr(x+1, l-x);
 y = get.indexOf('.');
 if(y == -1) return "";

 get = get.substr(0, y);

 return get;
}









function getrandom(max_random)
{
 var min_random = 0;

 max_random++;

 var range = max_random - min_random;
 var n=Math.floor(Math.random()*range) + min_random;

 return n;
}






function set_cookie(name, value, expires)
{
 matches = /^http:\/\/(?:www.)?([^\/\?\&]+)/.exec(location.href);

 path = '/';
 domain = '.'+matches[1];
 secure = '';

 var todaydate=new Date();
 var expdate=new Date(todaydate.getTime()+expires*1000);

 if(expires)
 expires = expdate.toGMTString();

 document.cookie = name + "=" + escape(value) +
 ((expires) ? "; expires=" + expires : "") +
 ((path) ? "; path=" + path : "") +
 ((domain) ? "; domain=" + domain : "") +
 ((secure) ? "; secure" : "");
}






function get_cookie(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));
        }
     }


 if(!setStr)
 setStr = '';

 return(setStr);
}








function reset_del()
{
  if(!confirm('Удалить ?'))
  {
   event.returnValue=false;
   event.cancelBubble=true;
  }
}








function reset_confirm()
{
  if(!confirm('Подтверждение операции'))
  {
   event.returnValue=false;
   event.cancelBubble=true;
  }
}








function getElementNum(form, obj)
{
 var i = 0;

  while(form.elements[i])
  {
   if (form.elements[i] == obj ) return i;
   i++;
  }

 return 0;
}








function check_phone(str)
{
  if( !/^\d-\d{3}-\d{3}-\d{2}-\d{2}$/.test(str) )
  {
   alert('телефон следует вводить в формате: x-xxx-xxx-xx-xx\nи только один номер');
   return false;
  }
}







function check_email(str)
{
  if( !/^[a-zA-Z\d\-_\.]+@[a-zA-Z\d\-_\.]+\.[a-zA-Z]+$/.test(str) )
  {
   alert('email введен неверно');
   return false;
  }

 return true;
}







function keyFilter(e, strPattern)
{
 var isIE = (document.all) ? 1 : 0;

 var chr = (isIE) ? e.keyCode : e.which;
 var ch = String.fromCharCode(chr);

   if(chr != 13 && chr != 8 && chr != 0)
   {
    var re = new RegExp(strPattern);

      if(ch.search(re) == -1)
      {
       if(isIE)
       e.returnValue = false;

       else
       e.preventDefault();
      }
   }
}









var SepWin;

function OpenSepWin(url, width, height)
{

 if(SepWin)
 SepWin.close();

 if(!width)
 width = 1280;

 if(!height)
 height = 800;


 SepWin=window.open (url, 'SepWin', 'width='+width+',height='+height+',resizable=0');
 SepWin.document.open();
 SepWin.document.writeln('<HTML><HEAD><TITLE>Изображение</TITLE></HEAD><BODY leftmargin=0 topmargin=0><img src='+url+' border=0></BODY></HTML>');
 SepWin.document.close();
 SepWin.focus();
}











var Detail_Hwnd;

function Open_Detail_Hwnd(url, width, height)
{
 if(Detail_Hwnd) Detail_Hwnd.close();

 SepWin=window.open (url, 'Detail_Hwnd', 'width='+width+',height='+height+',resizable=1');

 SepWin.focus();
}









function is_new_year()
{
 date = new Date();

 month = date.getMonth();

 day = date.getDate();

 if( ( month == 11 && day >= 20 ) || ( month == 0 && day <= 10 ) )
 return 1;

 else
 return 0;
}











function video(id)
{
 SepWin = window.showModalDialog('/video.php?id='+id, 'video', 'dialogWidth:700px;dialogHeight:450px;center:1;scroll:0;help:0;status:0');

   if(event)
   {
    event.returnValue=false;
    event.cancelBubble=true;
   }
}










var req, ab;

function request(url, id, cash, callback)
{
    try
    {
     req = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
         req = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(E)
        {
         req = false;
        }
    }

    if(!req && typeof XMLHttpRequest!='undefined')
    req = new XMLHttpRequest();


    if(req)
    {
        req.onreadystatechange = function ()
        {
         clearTimeout(ab);

            if(req.readyState == 4)
            {
                if(req.status == 200)
                {
                 if(req.getResponseHeader("Set-Cookie"))
                 document.cookie = req.getResponseHeader("Set-Cookie");

                 if(id)
                 id.innerHTML = req.responseText;

                 if(callback)
                 callback();
                }
            }
        }

     req.open('GET', url, true);
     req.setRequestHeader("Accept","*/*");
     req.setRequestHeader("Referer", location.href);
     if(!cash)
     req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
     if(document.cookie)
     req.setRequestHeader("Cookie", document.cookie);
     req.send(null);

     ab = window.setTimeout("req.abort();", 10000);
    }
}














function urlencode( str )
{
 var histogram = {}, tmp_arr = [];
 var ret = str.toString();
    
    var replacer = function(search, replace, str)
    {
     var tmp_arr = [];
     tmp_arr = str.split(search);
     return tmp_arr.join(replace);
    };

 histogram["'"]   = '%27';
 histogram['(']   = '%28';
 histogram[')']   = '%29';
 histogram['*']   = '%2A';
 histogram['~']   = '%7E';
 histogram['!']   = '%21';
 histogram['%20'] = '+';


 ret = encodeURIComponent(ret);
   
    for (search in histogram)
    {
     replace = histogram[search];
     ret = replacer(search, replace, ret);
    }
    
 return ret.replace( /(\%([a-z0-9]{2}))/g, function(full, m1, m2) { return "%"+m2.toUpperCase(); } );

 return ret;
}













function add_favorite(a)
{   
 title=document.title;   
 url=document.location;   

    try
    {   
     // Internet Explorer   
     window.external.AddFavorite(url, title);   
    }   

    catch(e)
    {
       try
       {   
        // Mozilla   
        window.sidebar.addPanel(title, url, "");   
       }   

       catch(e)
       {
        // Opera   

          if (typeof(opera)=="object")
          {
           a.rel="sidebar";   
           a.title=title;   
           a.url=url;   

           return true;   
          }   

          else
          {
           // Unknown   
           alert('Press Ctrl-D to add in Favorites.');   
          }   
       }   
    }   

 return false;   
}

