/**
 * JavaScrits
 */

$(document).ready(function()
{
    showErrorMessage('');
    //---------------------------------------------------------------
    
    $('#text table').each(function(){
        thead = $(this).find('thead, th');
        
        if (!thead.length)
        {
            $(this).find('tr:first-child').addClass('thead');
        }
    });	
	
	if($('#services_list li span').length)
    {
        var tabHeight = Math.max($('#services_list li a').height(), $('#services_list li a').innerHeight());
        
        $('#services_list li span').each(function(){
            var elementHeight = $(this).height();
            
            if(tabHeight > elementHeight)
            {
                var paddingTop = Math.round((tabHeight - elementHeight) / 2);
                $(this).css({'top':paddingTop+'px'});
            }
        });
    }
    //---------------------------------------------------------------
});
//---------------------------------------------------------------

/*
	Strips spaces from start and end of string
	Param:
		str string (text)
*/
function trimString (str)
{
	while (str.charAt(0) == ' ')
		str = str.substring(1);
	while (str.charAt(str.length - 1) == ' ')
		str = str.substring(0, str.length - 1);

	return str;
}
//---------------------------------------------------------------

function toggleBlocks(obj, idA, idB, togge_active) {
	$('#' + idA).hide('fast');
	$('#' + idB).show('fast');
	if (togge_active)
	{
		var jObj = $(obj);
		jObj.parent().parent().find('a').removeClass('active');
		jObj.addClass('active');
		jObj.blur();
	}
}
//----------------------------------------------------------

function showErrorMessage(text)
{
    if (text)
    {
        $('#error-message').html(text);
        $('#error-message-container a').trigger('click');
    }
    else
    {
        var html = '';
        
        var errMsgContainer = $('.page-messages-container');
        if (errMsgContainer.length)
        {
            if (errMsgContainer.length > 1)
            {
                errMsgContainer.each(function(){
                    html += $.trim($(this).html());
                });
            }
            else
            {
                html = $.trim(errMsgContainer.html());
            }
        }
        
        if(html)
        {
            $('#error-message').html(html);
            $('#error-message-container a').trigger('click');
        }
    }
}
//----------------------------------------------------------

