jsHover = function() {
	var hEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0, len=hEls.length; i<len; i++) {
		hEls[i].onmouseover=function() { this.className+=" jshover"; }
		hEls[i].onmouseout=function() { this.className=this.className.replace(" jshover", ""); }
	}
}

if (window.attachEvent && navigator.userAgent.indexOf("Opera")==-1) window.attachEvent("onload", jsHover);


function check_comment(form){
  if(isEmpty(form.message.value)) { alert("Укажите текст комментария."); focus(form.message);       return false; }
  if(isEmpty(form.captcha_code.value) && isEmpty(form.password.value)) { alert("Укажите число на картинке."); focus(form.captcha_code); return false; }
  return true;
  }

function check_opinion(form){
  if(isEmpty(form.plus.value)) { alert("Укажите достоинства."); focus(form.message);       return false; }
  if(isEmpty(form.minus.value)) { alert("Укажите недостатки."); focus(form.message);       return false; }
  if(isEmpty(form.captcha_code.value) && isEmpty(form.password.value)) { alert("Укажите число на картинке."); focus(form.captcha_code); return false; }
  return true;
  }




function change_shapka(){
    if (document.getElementById('shapka_regions').style.display=='none'){
        document.getElementById('shapka_regions').style.display='';
    } else {
        document.getElementById('shapka_regions').style.display='none';
    }

    if (document.getElementById('shapka_common').style.display=='none'){
        document.getElementById('shapka_common').style.display='';
    } else {
        document.getElementById('shapka_common').style.display='none';
    }

    if (document.getElementById('region_tab').className=='sel'){
        document.getElementById('region_tab').className='';
    } else {
        document.getElementById('region_tab').className='sel';
    }

    if (document.getElementById('select_region_tab').className=='sel'){
        document.getElementById('select_region_tab').className='';
    } else {
        document.getElementById('select_region_tab').className='sel';
    }
}    
    
function open_tread(var_item){ document.getElementById(var_item).style.display="";}
function close_tread(var_item){ document.getElementById(var_item).style.display="none";}
function select_form(what){
  if (what == "cat"){
    document.getElementById("cat_search").style.display="";
    document.getElementById("site_search").style.display="none";
    document.getElementById("tab_scat").className="s_sel";
    document.getElementById("tab_ssite").className="s_unsel";
    }
  else if (what == "site"){
    document.getElementById("cat_search").style.display="none";
    document.getElementById("site_search").style.display="";
    document.getElementById("tab_ssite").className="s_sel";
    document.getElementById("tab_scat").className="s_unsel";
    }
}


function comment_vote(comment_id,vote) {
    JsHttpRequest.query(
        'upd.php',
        {'act': 'vote', 'comment_id': comment_id, 'vote': vote},  
        function(result, errors) {
        if (result) {document.getElementById("comment_id_"+comment_id).innerHTML = "<img src='/i/voted.png' alt='Голос учтен' title='Голос учтен'>";}
        },
        false
    );
}

function newscomment_vote(comment_id,vote) {
    JsHttpRequest.query(
        'upd.php',
        {'act': 'vote', 'newscomment_id': comment_id, 'vote': vote},  
        function(result, errors) {
        if (result) {document.getElementById("comment_id_"+comment_id).innerHTML = "<img src='/i/voted.png' alt='Голос учтен' title='Голос учтен'>";}
        },
        false
    );
}

function opinion_vote(opinion_id,vote) {
    JsHttpRequest.query(
        'upd.php',
        {'act': 'vote', 'opinion_id': opinion_id, 'vote': vote},  
        function(result, errors) {
        if (result) {document.getElementById("opinion_id_"+opinion_id).innerHTML = "<img src='/i/voted.png' alt='Голос учтен' title='Голос учтен'>";}
        },
        false
    );
}


function getRadioGroupValue(radioGroupObj)
{
for (var i=0; i < radioGroupObj.length; i++){
    if (radioGroupObj[i].checked){
      return radioGroupObj[i].value;
      }
    }
return null;
}
        
function qsearch_update(){
  var q=document.getElementById('q').value;
  var st;
  var s=document.getElementById('search_popup');
  
  if (document.cat_search_form.st != undefined ){
    st = getRadioGroupValue(document.cat_search_form.st);
    } else {
    st = null;
    }
  if (q.length>=3){
    quick_search(q,st);
    } else {
    s.style.display='none';
    }
}

function quick_search(q,st) { 
  JsHttpRequest.query('upd.php', {'q': q, 'st': st},  
    function(result, errors) { 
      if (result) {
        document.getElementById("search_popup").innerHTML = result; 
        document.getElementById("search_popup").style.display='block'; 
        } else {
        document.getElementById("search_popup").style.display='none'; 
        }
      },
    false
    );
}

function select_post(what){
  if (what == "comment"){
    document.getElementById("block_comment").style.display="block";
    document.getElementById("block_opinion").style.display="none";
    document.getElementById("tab_comment").className="h_sel";
    document.getElementById("tab_opinion").className="h_unsel";
    }
  else if (what == "opinion"){
    document.getElementById("block_comment").style.display="none";
    document.getElementById("block_opinion").style.display="block";
    document.getElementById("tab_comment").className="h_unsel";
    document.getElementById("tab_opinion").className="h_sel";
    }
  else {
    document.getElementById("block_comment").style.display="none";
    document.getElementById("block_opinion").style.display="none";
    document.getElementById("tab_comment").className="h_unsel";
    document.getElementById("tab_opinion").className="h_unsel";
  }
}

function comment_reply(form,pid){
  form.comment_pid.value=pid; select_post("comment"); document.location.href = "#block"; 
  }

function select_newspost(what){
  if (what == "comment"){
    document.getElementById("block_comment").style.display="block";
    document.getElementById("tab_comment").className="h_sel";
    }
  else {
    document.getElementById("block_comment").style.display="none";
    document.getElementById("tab_comment").className="h_unsel";
  }
}

function newscomment_reply(form,pid){
  form.comment_pid.value=pid; select_newspost("comment"); document.location.href = "#block"; 
  }


function shop_description(shop_id) {
    JsHttpRequest.query(
        'upd.php',
        {'shop_id': shop_id},  
        function(result, errors) {
        if (result) {document.getElementById("shop_description").innerHTML = result;}
        },
        true
    );
}

