


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('supp_')>=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 absPosition(obj)
{ 
 var x = y = 0; 

    while(obj)
    { 
     x += obj.offsetLeft; 
     y += obj.offsetTop; 
     obj = obj.offsetParent; 
    }

 return {x:x, y:y};
}








function addOption(list, value, text, isDefaultSelected, isDefaultSelected, isSelected)
{
 var _option = document.createElement("option");
 _option.appendChild(document.createTextNode(text));
 _option.setAttribute("value", value);

 if(isDefaultSelected)
 _option.defaultSelected = true;

 else if(isSelected)
 _option.selected = true;

 list.appendChild(_option);
}








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 str_replace(subject, search, replace)
{
 return subject.split(search).join(replace);
}











function reset_del()
{
  if(!confirm('Удалить ?'))
  {
   event.returnValue=false;
   event.cancelBubble=true;
  }
}











function isNotMax(e)
{
 e = e || window.event;

 var target = e.target || e.srcElement;

 var code=e.keyCode?e.keyCode:(e.which?e.which:e.charCode)

    switch (code)
    {
     case 13:

     case 8:

     case 9:

     case 46:

     case 37:

     case 38:

     case 39:

     case 40:

     return true;
    }

 return target.value.length <= target.getAttribute('maxlength');
}










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('phone is entered incorrectly');
   return false;
  }

 return true;
}







function check_email(str)
{
 if( !/^[a-zA-Z\d\-_\.]+@[a-zA-Z\d\-_\.]+\.[a-zA-Z]+$/.test(str) )
 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 vote_win;

function open_vote_win(name, id)
{
 if(vote_win)
 vote_win.close();

 if(name)
 name = '<br><span style="color:#d5a33d;">"'+name+'"</span><br>';

 vote_win=window.open('', 'vote_win', 'width=400,height=200,resizable=0');
 vote_win.document.open();
 vote_win.document.writeln('<HTML><HEAD><TITLE>оцените фильм по пятибальной шкале</TITLE></HEAD><BODY leftmargin=0 topmargin=0 bgcolor=#211b18 ><center><br>');
 vote_win.document.writeln('<p style="color: #EEEEEE; font: 600 10pt Tahoma;">Оцените фильм '+name+' по пятибальной шкале</p><br>'); 

 for(i=1; i<6; i++)
 vote_win.document.writeln('<a href=/details.php?id='+id+'&hidden=1&vote='+i+'><img src=/img/star_big_on.png width=31 height=31 border=0></a>');

 vote_win.document.writeln('</center></BODY></HTML>');
 vote_win.document.close();
 vote_win.focus();
}









var SepWin;

function OpenSepWin(url, width, height)
{
if (SepWin) SepWin.close();
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 req, ab;

function request(url, id, cash, callback, data)
{
    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();
                }
            }
        }

     if(data)
     req.open('POST', url, true);
     else
     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);

        if(data)
        {
         req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
         req.send(data);
        }
        else
        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;
}






