var Across = {

    FormType       : 'store',

    back : function ()
    {
        history.go(-1);
    },

    reload : function ()
    {
        window.location = window.location.href;
    },
	
    reloadWin : function (to)
    {
        if (to == false)
        {
            window.location = window.location.href;
        }
        else
        {
            window.location = to;
        }
    },

    clearField : function (item)
    {
        $(item).attr('value', '');
    },
	
	sendRegistration : function (thisFom)
    {
        Across.actualForm = thisFom;

		$.post("/", 
			'Func=users.sendRegistration&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					var string = '<ul>';

					jQuery.each(data.items, function(i, val) {
						string += '<li><label for="'+i+'">'+val+'</label></li>';
				    });

					$('#reg-errors').html(string + '</ul>');
				}
				else
				{
					$('.main-right').html( data.message );
				}
			},
			"json"
		);
    },

    sendActivation : function (thisFom)
    {
        Across.actualForm = thisFom;

		$.post("/", 
			'Func=users.sendActivation&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					var string = '<ul>';

					jQuery.each(data.items, function(i, val) {
						string += '<li><label for="'+i+'">'+val+'</label></li>';
				    });

					$('#reg-errors').html(string + '</ul>');
				}
				else
				{
					$('#content-right').html( data.message );
				}
			},
			"json"
		);
    },


    sendM : function (thisFom)
    {
        Across.actualForm = thisFom;

        $.post("/",
            'Func=contacts.sendMessage&'+$(thisFom).serialize(),
            function(data) {

                if (data.error)
                {
                    jQuery.each(data.items, function(i, val) {
                        $('#'+i).val(val);
                    });
                }
                else
                {

                    Across.actualForm.reset();
                    alert(data.message);
                }
            },
            "json"
            );
    },
    
    getGuestform : function ()
	{
		$.post("/", 
			'Func=guestbook.getGuestform', 
			function(data) {
				$('#guest-add').html(data);
			},
			"text"
		);
	},

	addGuest : function (thisFom)
    {
        Across.actualForm = thisFom;

		$.post("/", 
			'Func=guestbook.addGuest&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					if ( data.message )
					{
						$('#guest-errors').html('<p><strong>'+data.message+'</strong></p>');
					}
					else
					{
						var string = '<ul>';

						jQuery.each(data.items, function(i, val) {
							string += '<li><label for="'+i+'">'+val+'</label></li>';
						});


						$('#guest-errors').html(string + '</ul>');
					}
				}
				else
				{
				    console.log(data.message);
					$('#form-content').html( data.message );
				}
			},
			"json"
		);
	},



    registrationType: function()
    {

            if($('#type2').attr('checked') === true)
            {
                $('.user_documents').show();
            }
            else
            {
                $('.user_documents').hide();
            }

    },

    initTab: function ()
    {
        var tabContainers = $('div.tabcontent > div');
        var tabs = $('div.tabs > a');

		if ( $('div.tabcontent > div.active').size() > 0 )
		{
			$('div.tabcontent > div').hide().filter('.active').show();

			tabs.each(function (i) {
				if ( $(this).attr('rel') == $('div.tabcontent > div.active').attr('id') ) {
					tabs.removeClass('active');
					$(this).addClass('active');
				}
			});
		}
		else
		{
	        tabContainers.hide().filter(':first').show();
		}

        $('.tabs a').click( function(){

			tabContainers.hide();
            tabs.removeClass('active');
            $(this).addClass('active');

            $('#' + $(this).attr('rel')).show();
        });
    },

    copyFields : function (items)
    {
        jQuery.each(items, function(i, val) {
            $('#'+val).val( $('#'+i).val() );
        });
    },

	pushBasket : function (thisFom, id)
    {
        Across.actualForm = thisFom;

        $.post("/",
            'Func=products.basket.pushBasket&id='+id+'&'+$(thisFom).serialize(),
            function(data) {
				$('#right-basket').html(data.data);


            },
            "json"
		);
	}
};

$(document).ready(function(){
	//Across.initTab();
    //Across.registrationType();
});