var Across = {

	showTab : function (id)
	{
		$('.tabs-content').hide();
		$('#'+id).show();
		//$(document).scrollTo($('.tabs'), 800);
	},

	showImage : function (id)
	{
		$('.home-image').css('display', 'none');
		$('#'+id).css('display', 'block');
	},

    clearField: function(item)
    {
        $(item).attr('value', '');
		$(item).removeClass('text250');
		$(item).removeClass('error');
		$(item).addClass('text250active');
    },
    
	blurField: function(item)
	{
		$(item).removeClass('text250active');
		$(item).addClass('text250');
	},
	
	checkTherms : function ()
	{
		if ( $('#therms').attr('checked'))
		{
			return true;
		}

		return false;
	},

    sendM: function(thisFom)
    {
		if (!Across.checkTherms())
		{
			alert( rights_text );
			return false;
		}

        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");
    },
    
	sendSubscription : function (thisFom)
    {
		if (!Across.checkTherms())
		{
			alert(rights_text);
			return false;
		}

        Across.actualForm = thisFom;

		$.post("/", 
			'Func=contacts.sendSubscription&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					jQuery.each(data.items, function(i, val) {
						$('#newsletter_' + i).val(val);
						$('#newsletter_' + i).addClass('error');
				    });
				}
				else
				{
					$('#dialog-content').html(data.message);
				}
			},
			"json"
		);
    },
	
	sendComment : function (thisForm,newsid)
	{
		if (!Across.checkTherms())
		{
			alert(rights_text);
			return false;
		}

		Across.actualForm = thisForm;
		
		$.post("/",'Func=news.saveMessage&'+$(thisForm).serialize()+'&newsid='+newsid,
		function(data)
		{
			if(data.error)
			{
				jQuery.each(data.items, function(i, val) {
					$('#comment_' + i).val(val);
				});
			}
			else
			{	
				location.reload();
			}
		},
		"json"
		);
	},
	
	toggleBox : function(boxid)
	{
		if($('#'+boxid).is('.right-box-main-selected'))
		{
			$('#'+boxid).removeClass('right-box-main-selected');	
		}
		else{
			$('#'+boxid).addClass('right-box-main-selected');
		}
		
		$("#toggle_"+boxid).toggle("slow");
	},
	
	showList: function (tableid)
	{
		$(document).scrollTo($('#'+tableid), 800);
	},

    alert : function (text)
    {
        dialogHandler.alert({
            Title: 'Figyelem',
            Body : text
        });            
    },

    popup : function ()
    {
        dialogHandler.popup({
            Title: 'Figyelem',
            Body : 'aaaa',
			Func : function ()  {
				alert('hehe');
			}
        });            
    },
    
    subscriptionForm : function (title)
	{
		$.post("/",'Func=contacts.subscriptionform',
		function(data)
		{
			dialogHandler.popup({
				Title: title,
				Body : data
			});
		},
		"text"
		);
	},
    
	cartmenForm : function (title)
	{
		$.post("/",'Func=contacts.cartmenform',
		function(data)
		{
			$('#dialog-content').addClass('dialog-content-cartmen');
			dialogHandler.popup({
				Title: title,
				Body : data
			});
		},
		"text"
		);
	},
	
	infoForm : function (title)
	{
		$.post("/",'Func=contacts.infoform',
		function(data)
		{
			dialogHandler.popup({
				Title: title,
				Body : data
			});
		},
		"text"
		);
	},
	
	proposalForm : function (title, item)
	{
		$.post("/",'Func=contacts.proposalform&item='+item,
		function(data)
		{
			dialogHandler.popup({
				Title: title,
				Body : data
			});
		},
		"text"
		);
	},

	sendInvitation : function (title, lid)
	{
		$.post("/",'Func=contacts.invitationForm',
		function(data)
		{
			dialogHandler.popup({
				Title: title,
				Body : data
			});
		},
		"text"
		);
	},

	campaignRegistration : function (title, id)
	{
		$.post("/",'Func=contacts.campaignRegistrationForm&item='+id,
		function(data)
		{
			dialogHandler.popup({
				Title: title,
				Body : data
			});
		},
		"text"
		);
	},

	sendCampaign : function (thisForm)
	{
		if (!Across.checkTherms())
		{
			alert(rights_text);
			return false;
		}

		Across.actualForm = thisForm;
		
		$.post("/",'Func=contacts.sendCampaign&'+$(thisForm).serialize(),
		function(data)
		{
			if(data.error)
			{
				jQuery.each(data.items, function(i, val) {
					$('#campaign_' + i).val(val);
					$('#campaign_' + i).addClass('error');
				});
			}
			else
			{
				$('#dialog-content').html(data.message);
			}			
		},
		"json"
		);
	},

	doInvitation : function (thisForm)
	{
		if (!Across.checkTherms())
		{
			alert(rights_text);
			return false;
		}

		Across.actualForm = thisForm;
		
		$.post("/",'Func=contacts.doInvitation&'+$(thisForm).serialize(),
		function(data)
		{
			if(data.error)
			{
				jQuery.each(data.items, function(i, val) {
					$('#invitation_' + i).val(val);
					$('#invitation_' + i).addClass('error');
				});
			}
			else
			{
				$('#dialog-content').html(data.message);
			}			
		},
		"json"
		);
	},

	sendCartmen : function (thisForm)
	{
		if (!Across.checkTherms())
		{
			alert(rights_text);
			return false;
		}

		Across.actualForm = thisForm;
		
		$.post("/",'Func=contacts.savecartmen&'+$(thisForm).serialize(),
		function(data)
		{
			if(data.error)
			{
				jQuery.each(data.items, function(i, val) {
					$('#cartmen_' + i).val(val);
					$('#cartmen_' + i).addClass('error');
				});
			}
			else
			{
				$('#dialog-content').html(data.message);
			}			
		},
		"json"
		);
	},

	popwin : function (url,width,height)
	{
		if ( !width ) width = '760';
		if ( !height ) height = '540';

	    var popupWin = window.open(url,'popupWin','width='+width+'px,height='+height+'px,left=100,top=100,menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=no,screenX=100,screenY=100,directories=no,location=no');

		popupWin.focus();
        return false;
	},

    printView : function ()
    {
        Across.popwin('?print');
    },

	setDates : function ()
	{
		var settings = {
			hu : {
				dateFormat      : 'yy-mm-dd',
				dayNamesMin     : ['Va', 'Hé', 'Ke', 'Sze', 'Cs', 'Pé', 'Szo'],
				monthNames      : ['Január', 'Február', 'Március', 'Április', 'Május', 'Június', 'Július', 'Augusztus', 'Szeptember', 'Október', 'November', 'December']
			},
			en : {
				dateFormat      : 'yy-mm-dd',
				dayNamesMin     : ['Vaaaa', 'Hé', 'Ke', 'Sze', 'Cs', 'Pé', 'Szo'],
				monthNames      : ['Január', 'Február', 'Március', 'Április', 'Május', 'Június', 'Július', 'Augusztus', 'Szeptember', 'Október', 'November', 'December']
			},
			de : {
				dateFormat      : 'yy-mm-dd',
				dayNamesMin     : ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
				monthNames      : ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember']
			},
			cz : {
				dateFormat      : 'yy-mm-dd',
				dayNamesMin     : ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
				monthNames      : ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember']
			},
			sk : {
				dateFormat      : 'yy-mm-dd',
				dayNamesMin     : ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
				monthNames      : ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember']
			}
		};

		var d = new Date();

		$('.date').datepicker({ 
			dateFormat      : settings[page_language].dateFormat,
			showOn          : 'focus',
			dayNamesMin     : settings[page_language].dayNamesMin,
			monthNames      : settings[page_language].monthNames,
			firstDay        : 1,
			minDate         : new Date(d.getFullYear(), d.getMonth(), d.getDate()+1)
		});
	},

	getGetAddress : function (country)
	{
		$.post("/",'Func=reserve.getGetAddress&country='+country,
		function(data)
		{
			$('.get_address').html(data);
		},
		"text"
		);
	},
    
	storeReservation1 : function (thisForm, nextUrl)
	{
		Across.actualForm = thisForm;
		
		$.post("/",'Func=reserve.storeReservation1&'+$(thisForm).serialize(),
		function(data)
		{
			if(data.error)
			{
				$('.errors').html('');
				var errors = '<div>';
				
				jQuery.each(data.items, function(i, val) {
					errors += val + '<br />';
				});

				errors += '</div>';

				$('.errors').html(errors);
			}
			else
			{

				window.location = nextUrl;
			}			
		},
		"json"
		);
	},
    
	storeReservation2 : function (car)
	{
		
		$.post("/",'Func=reserve.choosecar.storeReservation2&car='+car,
		function(data)
		{
			if(data.error)
			{
				$('#errors1').html('');
				
				var errors = '<div>';
				
				jQuery.each(data.error, function(i, val) {
					errors += val + '<br />';
				});

				errors += '</div>';

				$('#errors1').html(errors);
			}
			else
			{
				window.location = data;
			}
		},
		"json"
		);
	},
    
	storeReservation3 : function (thisForm, nextUrl)
	{
		Across.actualForm = thisForm;
		$('.errors').html('');
		
		$.post("/",'Func=reserve.pay.storeReservation3&nexturl='+nextUrl+'&'+$(thisForm).serialize(),
		function(data)
		{
			if(data.redirect)
			{
				window.location = data.redirect;
			}
			
			if(data.error1)
			{
				var errors1 = '<div>';
				
				jQuery.each(data.items1, function(i, val) {
					errors1 += val + '<br />';
				});

				errors1 += '</div>';

				$('#errors1').html(errors1);
				$(document).scrollTo($('#errors1'), 100);

            }
            
            if(data.error2)
            {
				var errors2 = '<div>';
				
				jQuery.each(data.items2, function(i, val) {
					errors2 += val + '<br />';
				});

				errors2 += '</div>';

				$('#errors2').html(errors2);                
			}
			
            if(!data.error1 && !data.error2)
			{
				window.location = data.link;
			}			
		},
		"json"
		);
	},
	
	
	storeInquery : function (thisForm, nextUrl)
	{
		Across.actualForm = thisForm;
		$('.errors').html('');
		
		$.post("/",'Func=reserve.pay.storeInquery&nexturl='+nextUrl+'&'+$(thisForm).serialize(),
		function(data)
		{
			if(data.redirect)
			{
				window.location = data.redirect;
			}
			
			if(data.error1)
			{
				var errors1 = '<div>';
				
				jQuery.each(data.items1, function(i, val) {
					errors1 += val + '<br />';
				});

				errors1 += '</div>';

				$('#errors1').html(errors1);
				$(document).scrollTo($('#errors1'), 100);

            }
            
            if(data.error2)
            {
				var errors2 = '<div>';
				
				jQuery.each(data.items2, function(i, val) {
					errors2 += val + '<br />';
				});

				errors2 += '</div>';

				$('#errors2').html(errors2);                
			}
			
            if(!data.error1 && !data.error2)
			{
				window.location = data.link;
			}			
		},
		"json"
		);
	},
    
    showTerms : function(item)
    {
        $('.tooltip').show();

		var pos = $(item).offset();
        $('.tooltip').css('top', (pos.top-60)+'px');

    },
    
    hideTerms : function()
    {
        $('.tooltip').hide();
    },

    storeExtras : function (thisForm)
	{
		Across.actualForm = thisForm;
        
        $.post("/",'Func=reserve.pay.storeExtras&'+$(thisForm).serialize(),
        function(data)
        {
            $('.rent-yourcar').html(data.extras);
            $('#prePay').html(data.prepay);
        },
        "json"
        );
	},
    
    prePay : function (payType)
	{
        
        $.post("/",'Func=reserve.pay.prePay&prepay='+payType,
        function(data)
        {
            $('#prePay').html(data.prepay);
        },
        "json"
        );
	},
    
    checkEmail : function (title, email)
	{
        
        $.post("/",'Func=users.checkEmail&email='+email,
        function(data)
        {
            if(data)
            {
            	dialogHandler.popup({
			
				Title : title,
				Body : data
		
				});
				
				$('#user_password').focus();
            }
        },
        "json"
        );
	},
    
	doLogin : function(thisform)
	{
		
		$.post("/", 'Func=users.gologin&'+$(thisform).serialize(), function(data)
        	{
				
				
				if(data.message)
				{
					$('#popup-message').html(data.message);
				}
				
				if (data.errors)
				{
					jQuery.each(data.items, function(i, val) {
						$('#' + i).val(val);
						$('#' + i).addClass('error');
				    });
				}
				else
				{
					window.location.reload();
				}
        	}, "json");
		
	},

	sendLostPassword : function(thisform)
	{
		
		$.post("/", 'Func=users.lostpass.sendPassword&'+$(thisform).serialize(), function(data)
        	{
				
				if(data.message)
				{
					$('#popup-message').html(data.message);
				}
				
				if (data.errors)
				{
					jQuery.each(data.items, function(i, val) {
						$('#' + i).val(val);
						$('#' + i).addClass('error');
				    });
					
				}
        	}, "json");
		
	},
	
	setHeights : function()
	{
		var rental_fees = $('#rental-fees .reserve-block-white').height();
		var prepay_fees = $('#prepay-fees .reserve-block-white').height();
		if(rental_fees > prepay_fees)
		{
			$('#prepay-fees .reserve-block-white').height(rental_fees)
		}
		else
		{
			$('#rental-fees .reserve-block-white').height(prepay_fees)
		}
		
	
		var payer_datas = $('#payer-datas .reserve-block-white').height();
		var driver_datas = $('#driver-datas .reserve-block-white').height();
		if(payer_datas > driver_datas)
		{
			$('#driver-datas .reserve-block-white').height(payer_datas)
		}
		else
		{
			$('#payer-datas .reserve-block-white').height(driver_datas)
		}
	}
    
};

$(window).ready(function () {
	Across.setDates();
	Across.setHeights();
});
