var Across = {
	
	clearField: function(item)
    {
        $(item).attr('value', '');
    },
	sendM: function(thisFom)
    {
        Across.actualForm = thisFom;
        
        $.post("/", 'Func=contacts.sendMessage&' + $(thisFom).serialize(), function(data)
        {
		
            if (data.error) 
            {
				
				$('.text200').removeClass('error');
				
                jQuery.each(data.items, function(i, val)
                {
                    $('#' + i).val(val);
					$('#' + i).addClass('error');
                });
            }
            else 
            {
            	/*
                Across.actualForm.reset();
				$('.contact-content').html(data.message);
				*/
				window.location.href = data.url;
				
            }
        }, "json");
    },
	searchButtonHover : function()
	{
		$('.search-container').addClass('search-container-h');
	},
	searchButtonOut : function()
	{
		$('.search-container').removeClass('search-container-h');
	},addComment : function (post_id, thisFom)
    {
        Across.actualForm = thisFom;

		$.post("/", 
			'Func=blog.addComment&post_id='+post_id+'&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					if ( data.message )
					{
						
						$('#guest-errors').show();
						
						Across.actualForm.reset();
						$('#guest-errors').html('<p><strong>'+data.message+'</strong></p>');
					}
					else
					{
						
						$('#guest-errors').show();
						
						var string = '<ul>';

						jQuery.each(data.items, function(i, val) {
							string += '<li><label for="'+i+'">'+val+'</label></li>';
						});


						$('#guest-errors').html(string + '</ul>');
					}
				}
				else
				{
					
					//$('#guest-errors').show();
					
					Across.actualForm.reset();
					window.location.reload();
					//$('#guest-errors').html('<p><strong>'+data.message+'</strong></p>');
				}
			},
			"json"
		);
	},
	addBasketKnowledge : function(id,reset,discount)
	{
		
		$.post("/", 'Func=knowledge.order.addBasketKnowledge&knowledge_id=' + id+'&reset='+reset+'&discount='+discount, function(data)
        {
		
            if (data.error) 
            {
				alert('Hiba!');
            }
            else 
            {
    			$('.sum').html(data.sum);
				$('.discount').html(data.discount);
				
				jQuery.each(data.selected, function(i, val)
                {
					$('#k_'+val).attr('checked',true);

                });
				
            }
        }, "json");
		
	},
	knowledgeOrder: function(thisFom)
    {
        Across.actualForm = thisFom;
        
        $.post("/", 'Func=knowledge.order.knowledgeOrder&' + $(thisFom).serialize(), function(data)
        {
		
            if (data.error) 
            {
				
				$('.text200').removeClass('error');
				
                jQuery.each(data.items, function(i, val)
                {
					
					$('#' + i).val(val);
					$('#' + i).addClass('error');
                    
                });
				
				if(data.msg != '')
				{
					$('.error-row').show();
					$('#error').html(data.msg);
				}
				
				if(data.msg == '')
				{
					$('.error-row').hide();
				}
				
            }
            else 
            {
				$('.error-row').hide();
            	window.location.href = data.url;
                
				
            }
        }, "json");
    },
	freemailOrder: function(thisFom)
    {
        Across.actualForm = thisFom;
		
		
        $.post("/", 'Func=freemail.order.knowledgeOrder&' + $(thisFom).serialize(), function(data)
        {
		
            if (data.error) 
            {
				
				$('.text200').removeClass('error');
				
                jQuery.each(data.items, function(i, val)
                {
                    $('#' + i).val(val);
					$('#' + i).addClass('error');
                });
				
				if(data.msg)
				{
					$('.error-row').show();
					$('.error').html(data.msg);
				}
				
            }
            else 
            {
							
            	window.location.href = data.url;
                
				
            }
        }, "json");
    },
    facefreemailOrder: function(thisFom)
    {
        Across.actualForm = thisFom;
		
        $.post("/", 'Func=freemail.order.knowledgeOrder&' + $(thisFom).serialize(), function(data)
        {
            if (data.error) 
            {
                jQuery.each(data.items, function(i, val)
                {
                    $('#' + i).val(val);
					$('#' + i).addClass('error');
                });	
            }
            else 
            {							
            	Across.actualForm.reset();
				$('.subscribe').html('Köszönjük, hogy feliratkoztál tanfolyamunkra!<br />Jól döntöttél, hogy feliratkoztál tanfolyamunkra!<br />Feliratkozásod megerősítéséhez most menj, és ellenőrizd az e-mail postafiókod. Köszönjük!');
            }
        }, "json");
    },
    
    
	addBasketFreemail : function(id)
	{
		
		$.post("/", 'Func=freemail.order.addBasketKnowledge&knowledge_id=' + id, function(data)
        {
		
            if (data.error) 
            {
				alert('Hiba!');
            }
            else 
            {
				
				jQuery.each(data.selected, function(i, val)
                {
					$('#k_'+val).attr('checked',true);

                });
				
            }
        }, "json");
		
	},
	registerBulletin : function(thisFom)
	{
		
		Across.actualForm = thisFom;
		
		$.post("/", 'Func=blog.default.registerBulletin&' + $(thisFom).serialize(), function(data)
        {
		
            if (data.error) 
            {
				$('.bulletin-message').hide();
				$('.bulletin-text').hide();
				$('.bulletin-error').show();
				$('.bulletin-error').html(data.msg);
            }
            else 
            {
				$('.bulletin-text').hide();
				$('.bulletin-error').hide();
				$('.bulletin-message').show();
				$('.bulletin-message').html(data.msg);
				
				Across.actualForm.reset();
				
            }
        }, "json");
		
	},
	orderStudy : function(thisFom)
	{
		
		Across.actualForm = thisFom;
		
		$.post("/", 'Func=freestudy.default.orderStudy&' + $(thisFom).serialize(), function(data)
        {
		
            if (data.error) 
            {
				jQuery.each(data.items, function(i, val)
                {
                    $('#' + i).val(val);
					$('#' + i).addClass('error');
                });
            }
            else 
            {
				window.location.href = data.url;
				
            }
        }, "json");
		
	},
    sendProgramInfo : function (thisFom)
    {
        Across.actualForm = thisFom;
		
		$.post("/", 'Func=programs.sendProgramInfo&' + $(thisFom).serialize(), function(data)
        {
		
            if (data.error) 
            {
            	if(data.message != '')
            	{
            		$('.trainingerror').show();
            		$('.trainingerror').html(data.message);
            	}
            	
            	if(data.message == '')
            	{
            		$('.trainingerror').hide();
            	}
            	
				jQuery.each(data.items, function(i, val)
                {
                    $('#' + i).val(val);
					$('#' + i).addClass('error');
                });
            }
            else 
            {
            	$('.trainingerror').hide();
				window.location.href = data.url;
				
            }
        }, "json");
    }
	
}

$(document).ready(function() {

	$('.home-item-lead').cycle({
				fx: 'fade' 
	});

	
	$('input:checkbox:checked').each(function(){
		Across.addBasketKnowledge($(this).val(),1,$('#discount').val());
	});
	
	//Across.addBasketKnowledge(0);
	
});


