function showlist(N)
{
obj_ul=document.getElementById(N);
if (obj_ul.style.display=="block")
obj_ul.style.display="none";
else
obj_ul.style.display="block";
}

function writeob(N)
{
obj_div=document.getElementById(N);
if (obj_div.style.display=="none")
obj_div.style.display="block";
else
obj_div.style.display="none";
}

function addob(N)
{
obj_option=document.getElementById(N);
if (obj_option.style.display=="none")
obj_option.style.display="block";
else
obj_option.style.display="none";
}


var ajaxvote=null;
function getajaxvote(){
if (window.ActiveXObject) // для IE
return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest) 
return new XMLHttpRequest();
else {
alert("Browser does not support ajaxvote.");
return null;
}
}
function voterow(n,z,t,v)
{
obj_div_block=document.getElementById('block'+n);
obj_div_hide=document.getElementById('hide'+n);

  
ajaxvote=getajaxvote();
var param;
if (ajaxvote != null) {
   
ajaxvote.open("POST","modules/voting.php",true);
// если параметров несколько то они разделяются &
param="id="+n+"&usr="+z+"&table="+t+"&vote="+v;
//  добавляем стандартный заголовок http
// посылаемый через ajaxvote
ajaxvote.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajaxvote.setRequestHeader("Content-length", param.length);
ajaxvote.setRequestHeader("Connection", "close");
ajaxvote.onreadystatechange = function(){      
if(ajaxvote.readyState==4 && ajaxvote.status==200);

obj_div_block.style.display="none"// если кнопку нажали Да то скрываем наш tr под номером из массива
obj_div_hide.style.display="block"// если кнопку нажали Да то скрываем наш tr под номером из массива  
}        
}
ajaxvote.send(param);   
}

function voterowblog(n,z,t,v)
{
obj_div_block=document.getElementById('block'+n);
obj_div_hide=document.getElementById('hide'+n);

  
ajaxvote=getajaxvote();
var param;
if (ajaxvote != null) {
   
ajaxvote.open("POST","modules/voting_blog.php",true);
// если параметров несколько то они разделяются &
param="id="+n+"&usr="+z+"&table="+t+"&vote="+v;
//  добавляем стандартный заголовок http
// посылаемый через ajaxvote
ajaxvote.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajaxvote.setRequestHeader("Content-length", param.length);
ajaxvote.setRequestHeader("Connection", "close");
ajaxvote.onreadystatechange = function(){      
if(ajaxvote.readyState==4 && ajaxvote.status==200);

obj_div_block.style.display="none"// если кнопку нажали Да то скрываем наш tr под номером из массива
obj_div_hide.style.display="block"// если кнопку нажали Да то скрываем наш tr под номером из массива  
}        
}
ajaxvote.send(param);   
}

function reprow(n,t,v)
{


ajaxvote=getajaxvote();
var param;
if (ajaxvote != null) {
   
ajaxvote.open("POST","modules/reputation.php",true);
// если параметров несколько то они разделяются &
param="coment="+n+"&user="+t+"&set="+v;
//  добавляем стандартный заголовок http
// посылаемый через ajaxvote
ajaxvote.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajaxvote.setRequestHeader("Content-length", param.length);
ajaxvote.setRequestHeader("Connection", "close");
ajaxvote.onreadystatechange = function(){      
if(ajaxvote.readyState==4 && ajaxvote.status==200);

 
}        
}
ajaxvote.send(param);   
}

   
function click_smile(aid,smile) {
var Open='['+smile+']';
var doc = document.getElementById(aid);
doc.focus();
if (window.attachEvent && navigator.userAgent.indexOf('Opera') === -1) {                                        
var s = doc.sel;
if(s){                                  
var l = s.text.length;
s.text = Open + s.text;
s.moveEnd("character", -Close.length);
s.moveStart("character", -l);                                           
s.select();                
}
}
else {                                              
var ss = doc.scrollTop;
sel1 = doc.value.substr(0, doc.selectionStart);
sel2 = doc.value.substr(doc.selectionEnd);
sel = doc.value.substr(doc.selectionStart, doc.selectionEnd - doc.selectionStart);                                              
doc.value = sel1 + Open + sel + sel2;
doc.selectionStart = sel1.length + Open.length;
doc.selectionEnd = doc.selectionStart + sel.length;
doc.scrollTop = ss;                                             
}
return false;
}
        function savesel(doc)
        {
                if(document.selection) {                
                        doc.sel = document.selection.createRange().duplicate();
                }               
        }
function click_bb(aid,Tag) {
var Open='['+Tag+']';
var Close='[/'+Tag+']';
var doc = document.getElementById(aid);
doc.focus();
if (window.attachEvent && navigator.userAgent.indexOf('Opera') === -1) {                                        
var s = doc.sel;
if(s){                                  
var l = s.text.length;
s.text = Open + s.text + Close;
s.moveEnd("character", -Close.length);
s.moveStart("character", -l);                                           
s.select();                
}
}
else {                                              
var ss = doc.scrollTop;
sel1 = doc.value.substr(0, doc.selectionStart);
sel2 = doc.value.substr(doc.selectionEnd);
sel = doc.value.substr(doc.selectionStart, doc.selectionEnd - doc.selectionStart);                                              
doc.value = sel1 + Open + sel + Close + sel2;
doc.selectionStart = sel1.length + Open.length;
doc.selectionEnd = doc.selectionStart + sel.length;
doc.scrollTop = ss;                                             
}
return false;
}

function showradio(windowName,url){
  if(!window.popups) window.popups=[];
  var wnd=window.popups[windowName];
  if(wnd && !wnd.closed) wnd.focus(); 
  url= "radio.php"
  wnd=window.open(url,windowName, "top=100,left=200,width=435,height=300,location=no,resizable=no");
  wnd.focus();
  window.popups[windowName]=wnd;
}

function dynamicSelect(id1, id2) {
 if (document.getElementById && document.getElementsByTagName) {
  var sel1 = document.getElementById(id1);
  var sel2 = document.getElementById(id2);
  var clone = sel2.cloneNode(true);
  var clonedOptions = clone.getElementsByTagName("option");
  refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
  sel1.onchange = function() {
  refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
  }
 }
}
function refreshDynamicSelectOptions(sel1, sel2, clonedOptions) {
 while (sel2.options.length) {
  sel2.remove(0);
 }
 var pattern1 = /( |^)(select)( |$)/;
 var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + ")( |$)");
 for (var i = 0; i < clonedOptions.length; i++) {
  if (clonedOptions[i].className.match(pattern1) ||
  clonedOptions[i].className.match(pattern2)) {
   sel2.appendChild(clonedOptions[i].cloneNode(true));
  }
 }
}
window.onload = function() {
	dynamicSelect("category", "sub_category");
}
