function plotis2(){
    var plotis2 = 0;
    $('top_meniu').childElements().each(function(el){
        plotis2 += el.getWidth();
    });
    $('top_meniu').setStyle({
       width: plotis2 + 30 + 'px'
    });
}

function prisijungimo_forma(){
    if (document.search.query.value == "") {
        document.search.query.value = document.search.query.defaultValue;
    }
}

function plotis(){
    var plotis = 340 - $('rezultatai').getWidth();
    var max = 0;
    $('rezai').childElements().each(function(el){
        var kiek = el.getWidth()
        if (kiek > max) {
            max = kiek;
        }
    });
    $('jo').setStyle({
        width: plotis + 'px'
    });

}

function rodyti(kas){
    if (document.getElementById(kas).style.display == 'none') {
        document.getElementById(kas).style.display = 'block';
        document.getElementById('pl').className = 'minus';
    }
    else {
        document.getElementById(kas).style.display = 'none';
        document.getElementById('pl').className = 'pl';
    } 
    return false;
}

// tikrinam forma
function check_finansai(){
    if ($F('name').blank()) {
        alert('Prašome įvesti vardą');
        return false;
    }
    else
        if ($F('email').blank() || check_email($F('email')) == false) {
            alert('Netinkamas el. paštas!');
            return false;
        }
        else
            if ($F('tel').blank() || $F('tel').length < 8) {
                alert('Prašome įvesti telefono numerį');
                return false;
            }
            else
                if ($F('info').blank()) {
                    alert('Prašome įvesti užklausos tekstą');
                    return false;
                }
    return true;
}

// tikrinam el pasta
function check_email(str){
    var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    (filter.test(str)) ? testresults = true : testresults = false;
    return (testresults)
}

function go_page(page,dir,lang) {   
    update = $('go');
    backPage(page-1);
    new Ajax.Updater(update.id, '/pus', {parameters: { page: page,dir:dir,lang2:lang } });
}
//back cookie katalogui
function createCookie(name,value,days) {
    document.cookie = name+"="+value+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
function backMenu(lang) {   
    var value='visi_0_'+lang;
    createCookie('jml_back',value,'1'); 
}
function backLang(lang) {
    var cookie=readCookie('jml_back');
    var exploded = cookie.split('_');
    var value=exploded[0]+'_'+exploded[1]+'_'+lang;
    createCookie('jml_back',value); 
}
function backAction(action) {
    var cookie=readCookie('jml_back');
    var exploded = cookie.split('_');
    var value=action+'_0_'+exploded[2];
    createCookie('jml_back',value); 
}
function backPage(page) {
    var cookie=readCookie('jml_back');
    var exploded = cookie.split('_');
    var value=exploded[0]+'_'+page+'_'+exploded[2];
    createCookie('jml_back',value); 
}



function hidetrail(){
    document.onmousemove = ""
    document.getElementById('ttimg').src = '/img/s.gif'
    gettrailobj().visibility = "hidden"
    gettrailobj().left = -1000
    gettrailobj().top = 0
}

function showtrail(width, height, file){
    if (navigator.userAgent.toLowerCase().indexOf('opera') == -1) {
        w = width
        h = height
        
        // followmouse()
        
        document.getElementById('ttimg').src = file
        document.onmousemove = followmouse
        gettrailobj().visibility = "visible"
        gettrailobj().width = w + "px"
        gettrailobj().height = h + "px"
        
        
    }
}
