function findValue(li, node) {
   if( li == null ) return alert("Совпадений не найдено");
   if( !!li.extra ) var sValue = li.extra[0];
   
   if(li.extra[0] == "0"){
	   document.getElementById(node).value = '';
	   document.getElementById(str_replace('f_', 'tmp_', node)).value = '';
   }

   document.getElementById(node).value = li.extra[0];
}

function selectItem(li, node) { findValue(li, node); }

function formatItem(row) { return row[0]; }

function wopen(pageURL, pageName, width, height) {
	if(width == '100%') width = $(window).width();
	if(height == '100%') height = $(window).height();
	window.open(pageURL, pageName, 'width='+width+',height='+height+',top=0,left=0,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');
}

function str_replace ( search, replace, subject ) {
 
    if(!(replace instanceof Array)){
        replace=new Array(replace);
        if(search instanceof Array){
            while(search.length>replace.length){
                replace[replace.length]=replace[0];
            }
        }
    }
 
    if(!(search instanceof Array))search=new Array(search);
    while(search.length>replace.length){
        replace[replace.length]='';
    }
 
    if(subject instanceof Array){
        for(k in subject){
            subject[k]=str_replace(search,replace,subject[k]);
        }
        return subject;
    }
 
    for(var k=0; k<search.length; k++){
        var i = subject.indexOf(search[k]);
        while(i>-1){
            subject = subject.replace(search[k], replace[k]);
            i = subject.indexOf(search[k],i);
        }
    }
 
    return subject;
 
}
