$(document).ready(function()
{
	$('a[@rel=external]').bind('click', function()
	{
		$(this).attr('target', '_blank');
	});

	$('#newsletter').click(function(){
		if ($(this).val() == 'Įrašykite savo el. pašto adresą')
		{
			$(this).val('');
		}
	});

	$('#newsletter').keypress(function(data){
		if (data['keyCode'] == 13)
			$('#add_email').trigger('click');
	});

	$('#add_email').click(function(){
		$.ajax({
			type: "POST",
			url: '/addEmail.php',
			data: '&email=' + $('#newsletter').val(),
			success: function (data){
				var code = parseInt(data);
				tb_show('', '/confirm.php?height=200&width=500&code=' + code, null);
			}
		});
	});

});

function changeList (select)
{    
	var link = window.location.toString();
	eval("var link = link.replace(/;" + select.name + ":(.[^;]*);/, '')");
    link = link.replace(/;page:(.[^;]*);/, '');
	if (select.name == 'grp')
		window.location = './;' + select.name + ':' + select.options[select.selectedIndex].value + ';';
	else
		window.location = link + ';' + select.name + ':' + select.options[select.selectedIndex].value + ';';
}

function validOrderForm()
{                                    
    var state = false;                 
    state = fieldsCheck('phone', 'email', 'name', 'address', 'company', 'begin', 'budget', 'employees_use', 'employees', 'turnover','type');
    document.location.replace('#error');
    if (document.getElementById(last_fail))
        document.getElementById(last_fail).focus();
    return (state);
}
function validCVForm()
{
	var state = false;                 
    state = fieldsCheck('email', 'phone', 'name', 'file');
    document.location.replace('#error');
    if (document.getElementById(last_fail))
        document.getElementById(last_fail).focus();
    return (state);
}
function validDocumentForm()
{
	var state = false;                 
    state = fieldsCheck('email', 'phone', 'name', 'company');
    document.location.replace('#error');
    if (document.getElementById(last_fail))
        document.getElementById(last_fail).focus();
    return (state);
}
function validGalleryForm()
{
	var state = false;                 
    state = fieldsCheck('email', 'phone', 'name', 'company', 'success');
    document.location.replace('#error');
    if (document.getElementById(last_fail))
        document.getElementById(last_fail).focus();
    return (state);
}
function validSeminaraiForm()
{                                    
    var state = false;                 
    state = fieldsCheck('phone', 'kodas', 'address', 'company', 'name');
    document.location.replace('#error');
    if (document.getElementById(last_fail))
        document.getElementById(last_fail).focus();
    return (state);
}

function validArtejantysSeminaraiForm()
{                                    
    var state = false;                 
    state = fieldsCheck('email', 'name');
    document.location.replace('#error');
    if (document.getElementById(last_fail))
        document.getElementById(last_fail).focus();
    return (state);
}


function validEvaluationForm()
{                                    
    var state = false;                 
    state = fieldsCheck('email', 'company', 'vvs', 'name');
    document.location.replace('#error');
    if (document.getElementById(last_fail))
        document.getElementById(last_fail).focus();
    return (state);
}
function validPostForm()
{   
    var state = false;                 
    state = fieldsCheck('author', 'text');
    document.location.replace('#error');
    if (document.getElementById(last_fail))
        document.getElementById(last_fail).focus();
    return (state);
}
function validThreadForm()
{   
    var state = false;                 
    state = fieldsCheck('author', 'title', 'text');
    document.location.replace('#error');
    if (document.getElementById(last_fail))
        document.getElementById(last_fail).focus();
    return (state);
}

function Citata(post_id)
{                                                                     
    document.getElementById('text').value = document.getElementById('text').value + '[citata]' + document.getElementById('p_'+post_id).innerHTML + '[/citata]';
    document.getElementById('text').focus();
}

function Loadl()
{
    var uls = document.getElementById('topMenu').getElementsByTagName('li');    
    for (var i = 0; i < uls.length ; i++ )
        if (uls[i].className != 'sel')
        {
            uls[i].onmouseover = function () {this.style.background = "url('http://www.vvsgidas.lt/client/images/bg.topMenu_left_h.gif') no-repeat top left #7C1150"};
            uls[i].onmouseout = function () {this.style.background = "url('http://www.vvsgidas.lt/client/images/bg.topMenu_left.gif') no-repeat top left #8E2663"};
            uls[i].getElementsByTagName('a')[0].onmouseover = function () {this.style.background = "url('http://www.vvsgidas.lt/client/images/bg.topMenu_right_h.gif') no-repeat top right"};
            uls[i].getElementsByTagName('a')[0].onmouseout = function () {this.style.background = "url('http://www.vvsgidas.lt/client/images/bg.topMenu_right.gif') no-repeat top right"}; 
        }
    var uls = document.getElementById('mainMenu').getElementsByTagName('li');    
    for (var i = 0; i < uls.length ; i++ )
        if (uls[i].className != 'sel')
        {
            uls[i].onmouseover = function () {this.style.background = "url('http://www.vvsgidas.lt/client/images/bg.mainMenu_left_h.gif') no-repeat top left #426294"};
            uls[i].onmouseout = function () {this.style.background = "url('http://www.vvsgidas.lt/client/images/bg.mainMenu_left.gif') no-repeat top left #6883AC"};
            uls[i].getElementsByTagName('a')[0].onmouseover = function () {this.style.background = "url('http://www.vvsgidas.lt/client/images/bg.mainMenu_right_h.gif') no-repeat top right"};
            uls[i].getElementsByTagName('a')[0].onmouseout = function () {this.style.background = "url('http://www.vvsgidas.lt/client/images/bg.mainMenu_right.gif') no-repeat top right"}; 
        }
}

addLoadEvent(Loadl);
