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) 
            {
				
				$('.text320').removeClass('error');
				
                jQuery.each(data.items, function(i, val)
                {
                    $('#' + i).val(val);
					$('#' + i).addClass('error');
                });
            }
            else 
            {
            
                Across.actualForm.reset();
				alert(data.message);
				
				if ( data.code )
				{
					$('#analytics-code').html( data.code );
				}
            }
        }, "json");
    },
	
	addComment : function (link_pid, thisFom)
    {
        Across.actualForm = thisFom;

		$.post("/", 
			'Func=places.comments.addComment&link_pid='+link_pid+'&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					if ( data.message )
					{
						Across.actualForm.reset();
						$('#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
				{
					Across.actualForm.reset();
					//$('#guest-errors').html('<p><strong>'+data.message+'</strong></p>');
					location.reload();
				}
			},
			"json"
		);
	},
	
	addHotelComment : function (link_pid, thisFom)
    {
        Across.actualForm = thisFom;

		$.post("/", 
			'Func=hotels.comments.addComment&link_pid='+link_pid+'&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					if ( data.message )
					{
						Across.actualForm.reset();
						$('#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
				{
					Across.actualForm.reset();
					//$('#guest-errors').html('<p><strong>'+data.message+'</strong></p>');
					location.reload();
				}
			},
			"json"
		);
	},
	
	calculator1 : function (hotel_id, season_id)
    {
			$.post("?", 
				'Func=hotels.calculator.Calculator&season_id='+season_id+'&hotel_id='+hotel_id,
				function(data) {
					
					if (data.calculator)
					{					
						$('#calculator').html(data.calculator);
					}
				},
				"json"
			);
	},
	
	calculator2 : function (thisFom, hotel_id)
    {
			Across.actualForm = thisFom;
			
			$.post("?", 
				'Func=hotels.calculator.Calculator2&'+$(thisFom).serialize()+'&hotel_id='+hotel_id,
				function(data) {
					
					if (data.total)
					{					
						$('#total').html(data.total);
					}
				},
				"json"
			);
	},
	
	showcalculatorContact :function()
	{
		$('#calculatorContact').show();
	},
	
	calculatorContact : function (thisFom)
    {
        Across.actualForm = thisFom;
        
        $.post("?", 'Func=hotels.calculator.Contact&' + $(thisFom).serialize(), function(data)
        {
		
			if (data.error && data.offerempty)
            {
				alert(data.message);
            }
            else if (data.error) 
            {
				
				$('.text320').removeClass('error');
				
                jQuery.each(data.items, function(i, val)
                {
                    $('#' + i).val(val);
					$('#' + i).addClass('error');
                });
            }
            else 
            {
            
                Across.actualForm.reset();
				alert(data.message);
				$('#description').after(data.data);
				
				
            }
        }, "json");
	},

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

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

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

					$('#subs-errors').html(string);
            }
            else
            {
                $('#subs-errors').html('');
				$('.bg-newsletter').html(data.message);
            }
        }, "json");
    }

}

$(document).ready(function() {
	
	$('.promobox-container').cycle({
				fx: 'fade' 
	});

	
});
