function c_vote(id, mark)
{	if (id != '')	$.get('/req/c_vote.php?id='+id+'&mark='+mark,
	function(data)
	{		$('#c_vote'+id).html(data);
	});
}
function sh(id)
{
        obj = document.getElementById(id);
        if (obj.style.display == 'none')
        {
                obj.style.display = '';
        }
        else
        {
                obj.style.display = 'none';
        }
}

function turnedit(id, what)
{
         sh(what+'form'+id);
         sh(what+'display'+id);
         rc = document.getElementById(what+'field'+id);
         rv = document.getElementById(what+'display'+id);
         if(document.all)
         {
                 rc.value = rv.innerText;
         }
         else
         {
                 rc.value = rv.textContent;
         }

}

function check_review(btn, cntnt, scnt)
{
        content = document.getElementById(cntnt);
        btn = document.getElementById(btn);
        cnt = document.getElementById(scnt);
        cnt.innerHTML = content.value.length;
        if (content.value.length <1000)
        {
                btn.disabled = 1;
        }
        else
        {
                btn.disabled = 0;
        }
}


function review_min_max(id)
{
        obj = document.getElementById('reviewdisplay'+id);
        b = document.getElementById('r_min_max'+id);
        if (obj.style.height == '')
        {
                if (obj.clientHeight > 400)
                {
                        b.style.display = 'block';
                        b.innerHTML = 'Показать все';
                        obj.style.height = '20em';
                }
        }
        else
        {
                if (b.style.display != 'none')
                {
                        b.innerHTML = 'Свернуть';
                }
                obj.style.height = '';
        }
}
function review_prepare(id, userid)
{
        if (getcookie('c_access')<=2 || getcookie('c_userid')==userid)
        {
                document.getElementById('changereview'+id).style.display='';
        }
}
function check_com(btn, field)
{
        content = document.getElementById(field);
        btn = document.getElementById(btn);
        if (content.value.length <50)
        {
                btn.disabled = 1;
        }
        else
        {
                btn.disabled = 0;
        }
}

function check_mis(btn, field)
{
        content = document.getElementById(field);
        btn = document.getElementById(btn);
        if (content.value.length <5)
        {
                btn.disabled = 1;
        }
        else
        {
                btn.disabled = 0;
        }
}

function resetsearch()
{
        document.getElementById('search').value = '';
        document.getElementById('search_type').selectedIndex = 0;
        document.getElementById('genre').selectedIndex = 0;
        document.getElementById('country').selectedIndex = 0;
        document.getElementById('average').selectedIndex = 0;
        document.getElementById('month').selectedIndex = 0;
        document.getElementById('year').value = '';
}

function set_params(param, value)
{
        if (window.XMLHttpRequest)
        {
                req = new XMLHttpRequest();
                //req.onreadystatechange = checkstate;
                req.open("GET", 'inc/setparams.php?param='+param+'&value='+value, true);
                req.send(null);
        }
        else if (window.ActiveXObject)
        {
                req = new ActiveXObject("Microsoft.XMLHTTP");
                if (req)
                {
                        //req.onreadystatechange = checkstate;
                        req.open("GET", 'inc/setparams.php?param='+param+'&value='+value, true);
                        req.send();
                }
        }
}

function setcookie(name, value)
{
        var d = new Date();
        d.setYear('2010');
        var curCookie = name+"="+escape(value)+"; expires=" + d.toGMTString()+"; path=/;";
        document.cookie = curCookie;
}

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 showhide_search_login()
{
        sf = document.getElementById('search_form');
        obj = document.getElementById('plus_minus');
        if (sf.className == 'invis')
        {
                vis = 'vis';
                obj.innerHTML = '-';
        }
        else
        {
                vis = 'invis';
                obj.innerHTML = '+';
        }
        sf.className = vis;
        if (lf = document.getElementById('login_form'))
        {
                lf.className = vis;
        }
        setcookie('params[search_login]', vis);
}

function imgchange(img)
{
        if (img.name != 'image'+imgcount) return;

        imgcount++;
        obj = document.getElementById('imagecontent');

        newinput = document.createElement('input');
        newinput.type = 'file';
        newinput.name = 'image'+imgcount;
        newinput.size = 70;
        newinput.id = 'image'+imgcount;
        newinput.onchange = new Function("imgchange(this)");

        btn = document.createElement('input');
        btn.type = 'button';
        btn.value = 'Очистить';
        btn.className = 'btn';
        btn.onclick = new Function("clearinp('image"+imgcount+"')");

        obj.appendChild(newinput);
        obj.appendChild(btn);
        obj.appendChild(document.createElement('br'));
}

function clearinp(inp)
{
        originalInput = document.getElementById(inp);

        newinput = document.createElement('input');
        newinput.type = 'file';
        newinput.name = originalInput.name;
        newinput.size = originalInput.size;
        newinput.id = originalInput.id;
        newinput.onchange = new Function("imgchange(this)");

        originalInput.parentNode.insertBefore(newinput, originalInput);
        originalInput.parentNode.removeChild(originalInput);
}
var imgcount = 1;

function quick_search(p, i, o, s)
{
        var path;
        var sym;
        var req;
        var inp_o;
        var out_o;
        var cur_p;
        var strcount;
        var last_st;
        var ms;
        var sub;

        path = p;
        sym = s;
        inp_o = document.getElementById(i);
        out_o = document.getElementById(o);
        cur_p = -1;
        ms = 0;
        csub = 1;

        inp_o.onkeyup = ac_keyup;
        inp_o.onkeydown = ac_keydown;
        inp_o.onblur = ac_blur;
        inp_o.onfocus = ac_focus;
        out_o.style.display = 'none';
        //out_o.style.position = 'absolute';

        function clear_div()
        {
                out_o.style.display = 'none';
                //out_o.style.position = 'absolute';
                out_o.innerHTML = '';
                cur_p = -1;
                strcount = 0;
        }
        function ac_blur()
        {
                if (ms == 1) return false;
                inp_o.value = 'Быстрый поиск по фильмам и персонам';
                clear_div();
        }
        function ac_focus()
        {
                inp_o.value = '';
        }
        function ac_keydown(event)
        {
                if (window.event) k = window.event.keyCode;
                else k = event.keyCode;

                if (k == 38 && strcount>0)
                {
                        if (cur_p != -1) document.getElementById('ac_str'+cur_p).className = last_st;
                        cur_p--;
                        if (cur_p < 0)
                        {
                                cur_p = strcount-1;
                        }
                        last_st = document.getElementById('ac_str'+cur_p).className;
                        document.getElementById('ac_str'+cur_p).className = 'ac_sel'
                        return false;
                }
                else if (k == 40 && strcount>0)
                {
                        if (cur_p != -1) document.getElementById('ac_str'+cur_p).className = last_st;
                        cur_p++;
                        if (cur_p == strcount)
                        {
                                cur_p = 0;
                        }
                        last_st = document.getElementById('ac_str'+cur_p).className;
                        document.getElementById('ac_str'+cur_p).className = 'ac_sel'
                        return false;
                }
                else if ((k == 27 || k == 13) && (cur_p != -1))
                {
                        return false;
                }
        }
        function ac_keyup(event)
        {
                if (window.event) k = window.event.keyCode;
                else k = event.keyCode;

                if (k == 27)
                {
                        clear_div();
                        return false;
                }
                else if (k == 13)
                {
                        if (cur_p != -1)
                        {
                                window.location = document.getElementById('ac_value'+cur_p).value;
                        }
                        clear_div();
                        return false;
                }
                else if(k != 38 && k != 40)
                {
                        if (inp_o.value.length >= sym) XRequest();
                        else clear_div();
                }
                else
                {
                        return false;
                }
        }
        function XRequest()
        {
                if (window.XMLHttpRequest)
                {
                        req = new XMLHttpRequest();
                        req.onreadystatechange = XCheckstate;
                        req.open("GET", path+'?'+inp_o.name+'='+encodeURI(encodeURI(inp_o.value)), true);
                        req.send(null);
                }
                else if (window.ActiveXObject)
                {
                        req = new ActiveXObject("Microsoft.XMLHTTP");
                        if (req)
                        {
                                req.onreadystatechange = XCheckstate;
                                req.open("GET", path+'?'+inp_o.name+'='+encodeURI(encodeURI(inp_o.value)), true);
                                req.send();
                        }
                }
        }
        function XCheckstate()
        {
                if (req.readyState == 4)
                {
                        if (req.status == 200)
                        {
                                out_o.innerHTML = req.responseText;
                                if (req.responseText == '')
                                {
                                        clear_div();
                                        strcount = 0;
                                }
                                else
                                {
                                        out_o.style.display = '';
                                        strcount = document.getElementById('ac_count').value;
                                        for (i=0; i<strcount; i++)
                                        {
                                                obj = document.getElementById('ac_str'+i);
                                                obj.mp = i;
                                                obj.onmouseover = mover;
                                                obj.onmouseout = mout;
                                                obj.onclick = mclick;
                                        }
                                }
                                cur_p = -1;
                        }
                }
        }
        function mout()
        {
                ms = 0;
        }
        function mover()
        {
                ms = 1;
                if (cur_p != -1)
                {
                        document.getElementById('ac_str'+cur_p).className = last_st;
                }
                cur_p = this.mp;
                last_st = this.className;
                this.className = 'ac_sel';
        }
        function mclick()
        {
                if (cur_p != -1)
                {
                        window.location = document.getElementById('ac_value'+cur_p).value;
                }
                clear_div();
        }
}

function copy_select(cont, el, c)
{
        obj2 = document.getElementById(cont);
        obj = document.getElementById(el);

        eval('cnt = '+c+';');

        if (cnt == 10) return;

        newe = obj.cloneNode(true);
        newe.name += '['+cnt+']';
        newe.style.display = '';
        newe.id += cnt;

        obj2.appendChild(newe);
        obj2.appendChild(document.createElement('br'));

        cnt++;
        eval(c+'=cnt;');
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function http_request(path, func)
{
        path = encodeURI(encodeURI(path));
        if (window.XMLHttpRequest)
        {
                req = new XMLHttpRequest();
                req.onreadystatechange = func;
                req.open("GET", path, true);
                req.send(null);
        }
        else if (window.ActiveXObject)
        {
                req = new ActiveXObject("Microsoft.XMLHTTP");
                if (req)
                {
                        req.onreadystatechange = func;
                        req.open("GET", path, true);
                        req.send();
                }
        }
}
function http_result()
{
        if (req.readyState == 4)
        {
                if (req.status == 200)
                {
                        return req.responseText;
                }
                else return false;
        }
        else return false;
}

////////////////////////////////////////////////////////////////////////////////
var genrecount = 0;
var countrycount = 0;

function get_genre_list()
{
        str = http_result();
        if (str != false)
        {
                obj = document.getElementById('genre_content');
                obj.innerHTML += str;
                genrecount++;
        }
}

function get_country_list()
{
        str = http_result();
        if (str != false)
        {
                obj = document.getElementById('country_content');
                obj.innerHTML += str;
                countrycount++;
        }
}

function min_max(id, height)
{
        obj = document.getElementById(id);
        b = document.getElementById(id+'_min_max');
        if (obj.style.height == '')
        {
                if (obj.clientHeight >  height)
                {
                        b.style.display = 'block';
                        b.innerHTML = 'Показать все';
                        obj.style.height =  height+'px';
                }
        }
        else
        {
                if (b.style.display != 'none')
                {
                        b.innerHTML = 'Свернуть';
                }
                obj.style.height = '';
        }
}