var c=0;var t;var timer_is_on=0;var last_sea='';
var c2=0;var t;var timer_is_on2=0;

function timedCount()
{
if (c==2)
{
stopCount();
return;
}
c=c+1;
t=setTimeout("timedCount()",500);
}

function doTimer(){
$("#resu_w8").show();
$("#resu").show();
if (!timer_is_on)
{
timer_is_on=1;
timedCount();
}
}


function stopCount()
{
clearTimeout(t);
timer_is_on=0;
sear(get('sea').value);
}

function sear(m)
{
if (last_sea == trim(m))
{
last_sea = trim(m);
$("#resu_w8").hide();
return;
}
if (m=="")
{
$("#resu_w8").hide();
return;
}
$.post(virpath+'index.php?hp=1&m=search', {'m':m},
function(response) {
var response = response.split("|");
if ( response )
{

if ( response[0] == 'ok' && response[1] )
{
setTimeout(function()
{
get('channelsList').innerHTML=response[1];$("#resu_w8").hide();
last_sea = trim(m);
}, 10);
return true;
} else{
get('channelsList').innerHTML=response[1];$("#resu_w8").hide();
last_sea = trim(m);
}
}
}
);
}








function doTimer2(){
if(get('field_to').value.length<3)
return

if (!timer_is_on2)
{
timer_is_on2=1;
timedCount2();
}
}


function timedCount2()
{
if (c2==2)
{
stopCount2();
return;
}
c2=c2+1;
t2=setTimeout("timedCount2()",500);
}


function stopCount2()
{
clearTimeout(t2);
timer_is_on2=0;
lookup(get('field_to').value);
}
function lookup(ins) {
if(ins.length == 0) {
$('#suggestions').hide();
} else if(ins.length > 2) {
$.post(virpath+"index.php?hp=1&m=search&v=get_usns", {m:""+ins+""}, function(data){
if(data.length >0) {
$('#suggestions').show();
$('#autoSuggestionsList').html(data);
}
});
}
}

function fill(TV, img) {
$('#field_to').val(TV);
get('avator_img').src=img;
setTimeout("$('#suggestions').hide();", 200);
}



function trim(m)
{
return m.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}
