function clearText(el)
{
    if ($(el).attr('prev')==$(el).val())
    {
        $(el).val('');
    }
}

function retText(el)
{
    var el_val=$(el).val();
    el_val=el_val.replace(/^\s+/, '');
    el_val=el_val.replace(/\s+$/, '');
    if (el_val=='')
    {
        $(el).val($(el).attr('prev'));
    }
}

function send(form_id)
{
    var options= {  
                target: "#update_"+form_id,
                url: "functions/feedback.php"
                  }
    $('#'+form_id).ajaxSubmit(options);
}

function checkEmail(el)
{
    if (el.value!='')
    {
        if(!/[a-z0-9_]+@[a-z0-9_]+.[a-z]{2,4}/.test(el.value))
        {
            alert('Вы ввели не правильный e-mail');
        }
    }
}

var begin_time=new Date(1993, 3, 21);
function lifetime()
{
    var curr_time=new Date();
    var life=new Date(curr_time-begin_time);
    $('span[class=second]').append('<br/>'+life.getUTCSeconds());
    var second_top=$('span[class=second]').css("top"); 
    second_top=parseInt(second_top)-13;
    second_top=second_top+'px';
    $('span[class=second]').animate({"top": second_top});
    if (life.getUTCSeconds()==0)
    {
        $('span[class=minute]').append('<br/>'+life.getUTCMinutes());
        var minute_top=$('span[class=minute]').css("top"); 
        minute_top=parseInt(minute_top)-13;
        minute_top=minute_top+'px';
        $('span[class=minute]').animate({"top": minute_top});
        if (in_array(life.getUTCMinutes(),[1,21,31,41,51])) { $('#minute_text').html('минута'); } else if (in_array(life.getUTCMinutes(),[2,3,4,22,23,24,32,33,34,42,43,44,52,53,54])) { $('#minute_text').html('минуты'); } else { $('#minute_text').html('минут'); }
    }
    $('#lifetime_hour').html(life.getUTCHours());
}

function in_array(needle, haystack, strict) 
{
    var found=false, key, strict=!!strict;
    for (key in haystack) 
    {
        if ((strict && haystack[key]===needle) || (!strict && haystack[key]==needle)) 
        {
            found=true;
            break;
        }
    }
    return found;
}
setInterval('lifetime()',1000);

function view_town_weather(th)
{
    if (parseInt($('#weather-block').css('height'))=='105')
    {
        $('#weather-block').animate({height: "350px"},500);
        $(th).html('закрыть');    
    }
    else
    {
        $('#multi_town').animate({top: "0px"},100);
        $('#weather-block').animate({height: "105px"},500);
        $(th).html('все города <img src="/userfile/frontend/blok-top/strela.png"/>');
    }
}

var freeze=false;

function weather_down()
{
    if (freeze==true) { return false; }
    var top=$('#multi_town').css("top");
    top=parseInt(top)-122;
    var limit=0;
    if (parseInt($('#weather-block').css('height'))!='105')
    {
        limit=300;
    }
    if ((parseInt($('#multi_town').css("height"))+top)>limit) 
    { 
        top=top+'px';
        freeze=true;
        $('#multi_town').animate({top: top},500,function(){
            freeze=false;
        }); 
    }
}

function weather_up()
{
    if (freeze==true) { return false; }
    var top=$('#multi_town').css("top");
    top=parseInt(top)+122;
    if (top<=0) 
    { 
        top=top+'px';
        freeze=true;
        $('#multi_town').animate({top: top},500,function(){
            freeze=false;
        }); 
    }
}

function getAbsolutePos(el)
{
    var r={ x: el.offsetLeft, y: el.offsetTop};
    if (el.offsetParent)
    {
       var tmp=getAbsolutePos(el.offsetParent);
        r.x+=tmp.x;
        r.y+=tmp.y;
    }
    return r;
}