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

    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"
            );
    },
    
    sendO : function (thisFom)
    {
        Across.actualForm = thisFom;

        $.post("/",
            'Func=contacts.orders.sendOrder&'+$(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"
            );
    },



    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();
});
