var Across = {

    FormType: 'update',
	expressInstall : '/layout/swf/express_install.swf',
	flashVersion : '9.0.0',

    setType: function(to)
    {
        Across.FormType = to;
    },

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

	transportMode : function()
	{
		
		var option = $('input[name=transport]:checked').val();
		
		if(option == 'home')
		{
			$('#payment_cash').attr('checked',false);
			$('#payment_cash').attr('disabled','disabled');
			
			//$('#payment_after').removeAttr('disabled');
			//$('#payment_after').attr('checked',false);
			
		}
		
		if(option == 'personal')
		{
			$('#payment_after').attr('checked',false);
			$('#payment_after').attr('disabled','disabled');
			
			//$('#payment_cash').removeAttr('disabled');
			//$('#payment_cash').attr('checked',false);
		}
		
	},

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

    registrationType: function()
    {
		
		//maganszemely
		if($('#type1').attr('checked') === true)
		{
			
			$('.firm-data').hide();
			$('.user_documents').hide();
			
			$('.reg-billing').show();
			
			$('.contactperson').hide();
						
			$('.reg-contact-contactcopy').hide();
			
			$('.reg-contact').show();
			
			$('#company-fiscal').hide();
			
			$('#reg-contact-name').hide();
			$('#reg-contact-post').hide();
			$('#reg-contact-email').hide();
			
			$('.personaldata').show();
			
			
		}
		//viszontelado
        if ($('#type2').attr('checked') === true)
        {
			
			$('#company-fiscal').show();
			
			$('.reg-contact').show();
			$('.firm-data').show();
            $('.user_documents').show();
			$('.reg-billing').show();
			
			$('.reg-contact-contactcopy').show();
			
        }
        
		//ceg
		if($('#type3').attr('checked') === true)
		{
			
			$('#company-fiscal').show();
			
			$('.reg-contact').show();
			$('.reg-billing').show();
			$('.firm-data').show();
			$('.user_documents').hide();
			
			$('.reg-contact-contactcopy').show();
			
			
		}
		
    },

    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.removeClass('active');
            tabs.each(function(i)
            {
                if ($(this).attr('rel') == $('div.tabcontent > div.active').attr('id'))
                {
                    $(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();
        });
    },

    showImages: function()
    {
        $('div.tabcontent > div').hide();
        $('#images').show();
        $(document).scrollTo($('#images'), 800);

        $('div.tabs > a').each(function(i)
        {

            if ($(this).attr('rel') == 'images')
            {
                $('div.tabs > a').removeClass('active');
                $(this).addClass('active');
            }
        });
    },

    initLeftTabs: function()
    {
        var tabContainers = $('div.left-data > div.boxbody-np');
        var tabs = $('div.left-data > div.tabs-image > a');

        if ($('div.tabs-image > a').size() > 0)
        {
            $('div.left-data > div.boxbody-np').hide().filter('.active').show();

            tabs.removeClass('active');

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

        $('div.tabs-image > a').click(function()
        {

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

            tabContainers.each(function(i, val)
            {
                if ($(this).attr('rel') == $(val).attr('id'))
                {
                    $(this).addClass('active');
                }
            });

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

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

	addOne : function(id)
	{
		$.post("/", 'Func=products.basket.addOne&id=' + id, function(data)
        {
			
			if (data.error) {
				alert(data.message);
			}
			else 
			{
				$('#right-basket').html(data.data);
				alert('Az Ön kosarának tartalma frissült!');
			}
			
        }, "json");			
	},
	
    pushBasket: function(thisFom, id)
    {
		val = $('.mini-input-bordered').val();

		if (val == 0)
		{
            alert('Kérjük adja meg az igényelt mennyiséget!');
			return false;
		}

        Across.actualForm = thisFom;

        $.post("/", 'Func=products.basket.pushBasket&id=' + id + '&' + $(thisFom).serialize(), function(data)
        {
			
			if (data.error) {
				alert(data.message);
			}
			else 
			{
				$('#right-basket').html(data.data);
				alert('Az Ön kosarának tartalma frissült!');
			}
			
        }, "json");
    },

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

        $.post("/", 'Func=products.basket.updateBasket&' + $(thisFom).serialize(), function(data)
        {
        	
            //return;
            if (Across.FormType == 'update')
            {
                Across.reloadWin(false);
            }
            else
            {
                Across.reloadWin(data);
            }
            
        }, "text");
    },

    voteComment : function (vote, item)
    {
        $('#vote').val(vote);
        $('.votes > a').removeClass('active');
        $(item).addClass('active');
    },

    storeComment : function (thisFom)
    {
        if ( $('#vote').val() == 0)
        {
            alert('Kérem adja meg az értékelését, 1-től 5-ig!');
            return;
        }
        Across.actualForm = thisFom;

        $.post("/", 'Func=products.productinfo.storeComments&' + $(thisFom).serialize(), function(data)
        {
            if (data.error)
            {
                jQuery.each(data.items, function(i, val)
                {
                    $('#' + i).val(val);
                });
            }
            else
            {
                $('#comments').html(data.message);
            }
        }, "json");
    },

	installAnim : function ()
	{
		var flashvars = {
			xml : '/hu/getxml',
            delayMs : 4500
		};

		var params = {
			scale: "noBorder",
			allowFullscreen:"true",
			allowScriptAccess:"always",
			wmode : 'window'
		};
		var attributes = {
			id : 'player',
			name : 'player'
		};

		swfobject.embedSWF(
			'/layout/swf/3b_header.swf',
			'header-anim-container',
			"980", "203",
			Across.flashVersion,
			Across.expressInstall,
			flashvars,
			params,
			attributes
		);
	},
	
	toggleBox : function(toggleclass)
	{
		$('.toggle_'+toggleclass).toggle();
	},
	
	userSubscribe: function(thisFom)
    {
        Across.actualForm = thisFom;

        $.post("/", 'Func=newsletters.usersubscribe.subscribe&' + $(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");
    }
	
};

$(document).ready(function()
{
    Across.initTab();
    Across.initLeftTabs();
    Across.registrationType();
	Across.transportMode();
	$("#search-string").autocomplete("/hu/gyorskereses/", { minChars:2, width: 220});
	
	//mask input
	jQuery(function($){
	   $("#company_bank").mask("99999999-99999999-99999999");
	   $.mask.definitions['s']='[1-2]';
	   $("#company_fiscal").mask("99999999-s-99");
	   $("#company_regnumber").mask("99-99-999999")
	});

});

