/**
 * JavaScrits
 */

$(document).ready(function()
{
    $('a.fancybox').fancybox({
        titlePosition:'over'
    });
    
    $('a#orderNewslettersLink').each(function(){
        var href = $(this).attr('href');
        href = href + 'ajax.1';
        
        $(this).attr('href', href);
        $(this).fancybox({
            padding:0,
            titleShow:false,
            autoDimensions:false,
            width:370,
            height:240
        });
    });
    
    showErrorMessage('');
});
//---------------------------------------------------------------

/*
	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 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');
        }
    }

}
//----------------------------------------------------------

function validateSearchForm()
{
    var jField = $('#qSearchField');
    var value = $.trim(jField.val());
    var defaultValue = $.trim(jField.attr('title'));
    
    if ((defaultValue) && (value == defaultValue))
    {
        value = '';
    }
    $('#qSearchButton').blur();
    
    return (value) ? true : false;
}
//----------------------------------------------------------

function validateNewslettersWidgetForm()
{
    var jField = $('#recipient_email');
    var value = $.trim(jField.val());
    var defaultValue = $.trim(jField.attr('title'));
    
    if ((defaultValue) && (value == defaultValue))
    {
        value = '';
    }
    $('#recipient_email').blur();
    
    return (value) ? true : false;
}
//----------------------------------------------------------

