var lang_rus=new Array();
lang_rus['no_keyword']='Не указано ключевое слово для поиска!';
lang_rus['is_found']='Найдено';
lang_rus['categories_is_selected']=' совпадений. Найденные разделы отмечены голубым цветом.';
lang_rus['categories_not_found']='Подходящих разделов не найдено.';

function trim(value){startpos=0;while((value.charAt(startpos)==" ")&&(startpos<value.length)){startpos++;}if(startpos==value.length){value="";}else{value=value.substring(startpos,value.length);endpos=(value.length)-1;while(value.charAt(endpos)==" "){endpos--;}value=value.substring(0,endpos+1);}return(value);}

function show_flength(fname){
eval('document.addform.' + fname + '_length.value = ' + fname + '_maxlength - document.addform.' + fname + '.value.length');
}

function search_cat(){
var quantity=0;
//замена запятых на пробел
document.addform.srchcats.value = str_replace(document.addform.srchcats.value, ',', ' ', 0);
//удаление 2-х пробелов
var pos=0;
 while(pos!=-1){
 pos=document.addform.srchcats.value.indexOf('  ');
 if(pos!=-1){document.addform.srchcats.value=document.addform.srchcats.value.replace('  ',' ');}
 }
document.addform.srchcats.value=trim(document.addform.srchcats.value.toLowerCase());
if(! document.addform.srchcats.value){alert(lang['no_keyword']);return;}
var allsrchwords=document.addform.srchcats.value.split(' ');
 for(dw=0;dw<allsrchwords.length;dw++){
  for(i=0;i<document.addform.category.length;i++){
  //если первое слово, то очищаем стиль
  if(dw==0){document.addform.category[i].style.backgroundColor='';}
  defcat=document.addform.category[i].text.toLowerCase();
  pos=defcat.indexOf(allsrchwords[dw]);
  if(pos!=-1){document.addform.category[i].style.backgroundColor='#33beec'; quantity++;}
  }
 }
if(quantity){alert(lang['is_found']+' '+quantity+' '+lang['categories_is_selected']);}else{alert(lang['categories_not_found']);}
}

//method: 0-binary, 1-text
//параметр srchstr не должен содержать символа /
function str_replace(str,srchstr,replstr,method){
if(method==1){srchstr=eval('/'+srchstr+'/gi');}else{srchstr=eval('/'+srchstr+'/g');}
return str.replace(srchstr,replstr);
}
