var Irishcat = {
	
	newsletterSubscribe : function (thisFom)
    {
		if (!Irishcat.checkNewsletterTherms())
		{
			alert(rights_text);
			return false;
		}

        Irishcat.actualForm = thisFom;

		$.post("/", 
			'Func=newsletters.subscribe&lang='+sitelang+'&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					jQuery.each(data.items, function(i, val) {
						$('#newsletter_' + i).val(val);
						$('#newsletter_' + i).addClass('error');
				    });
				}
				else
				{
					$('#subscribeform').html(data.message);
				}
			},
			"json"
		);
    },

	clearField : function(obj)
	{
		
		$(obj).val('');
		
	},

	checkNewsletterTherms : function ()
	{
		if ( $('#newslettertherms').attr('checked'))
		{
			return true;
		}

		return false;
	},

	checkTherms : function ()
	{

		if ( $('#therms').attr('checked'))
		{
			return true;
		}

		return false;
	},

	checkNewTherms : function ()
	{
		
		if ( $('#ntherms').attr('checked'))
		{
			return true;
		}

		return false;
	},
	
    checkSignup : function ()
	{
		Irishcat.signup_text = 'Kérjük pipálja be a jelentkezést!';
		
		console.log( $('#signup') );
		
		if ( $('#signup').attr('checked'))
		{
			return true;
		}

		return false;
	},
	
	sendM: function(thisFom)
    {
		if (!Irishcat.checkTherms())
		{
			alert( rights_text );
			return false;
		}

        Irishcat.actualForm = thisFom;
        
        $.post("/", 'Func=contacts.sendMessage&lang='+sitelang+'&' + $(thisFom).serialize(), function(data)
        {
        
            if (data.error) 
            {
                jQuery.each(data.items, function(i, val)
                {
                    $('#' + i).val(val);
                });
            }
            else 
            {
            
                Irishcat.actualForm.reset();
                alert(data.message);
            }
        }, "json");
    },
    
	sendSubscription : function (thisFom)
    {
		if (!Irishcat.checkTherms())
		{
			alert(rights_text);
			return false;
		}

        Irishcat.actualForm = thisFom;

		$.post("/", 
			'Func=contacts.sendSubscription&lang='+sitelang+'&'+$(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"
		);
    },
	
	sendInnerSubscription : function (thisFom)
    {
		if (!Irishcat.checkTherms())
		{
			alert(rights_text);
			return false;
		}

        Irishcat.actualForm = thisFom;

		$.post("/", 
			'Func=contacts.sendSubscription&lang='+sitelang+'&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					jQuery.each(data.items, function(i, val) {
						$('#newsletter_' + i).val(val);
						$('#newsletter_' + i).addClass('error');
				    });
				}
				else
				{
					$('#message-content-inner').html(data.message);
				}
			},
			"json"
		);
    },
	
	
    subscriptionForm : function (title)
	{
		$.post("/",'Func=contacts.subscriptionform&lang='+sitelang,
		function(data)
		{
			dialogHandler.popup({
				Title: title,
				Body : data
			});
		},
		"text"
		);
	},
    
	cartmenForm : function (title)
	{
		$.post("/",'Func=contacts.cartmenform&lang='+sitelang,
		function(data)
		{
			$('#dialog-content').addClass('dialog-content-cartmen');
			dialogHandler.popup({
				Title: title,
				Body : data
			});
		},
		"text"
		);
	},
	
	infoForm : function (title)
	{
		$.post("/",'Func=contacts.infoform&lang='+sitelang,
		function(data)
		{
			dialogHandler.popup({
				Title: title,
				Body : data
			});
		},
		"text"
		);
	},
	
	proposalForm : function (title, item)
	{
		$.post("/",'Func=contacts.proposalform&lang='+sitelang+'&item='+item,
		function(data)
		{
			dialogHandler.popup({
				Title: title,
				Body : data
			});
		},
		"text"
		);
	},

	sendInvitation : function (title, lid)
	{
		$.post("/",'Func=contacts.invitationForm&lang='+sitelang,
		function(data)
		{
			dialogHandler.popup({
				Title: title,
				Body : data
			});
		},
		"text"
		);
	},
	
	
	doInvitation : function (thisForm)
	{
		if (!Irishcat.checkTherms())
		{
			alert(rights_text);
			return false;
		}

		Irishcat.actualForm = thisForm;
		
		$.post("/",'Func=contacts.doInvitation&lang='+sitelang+'&'+$(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"
		);
	},
	
	testDriveForm : function (title, lid)
	{
		$.post("/",'Func=contacts.testdriveform&lang='+sitelang,
		function(data)
		{
			dialogHandler.popup({
				Title: title,
				Body : data
			});
		},
		"text"
		);
	},
	
	saveTestdrive : function (thisFom)
    {
		if (!Irishcat.checkNewTherms())
		{
			alert(rights_text);
			return false;
		}
		
		if (!Irishcat.checkSignup())
		{
			alert(Irishcat.signup_text);
			return false;
		}
		
        Irishcat.actualForm = thisFom;

		$.post("/", 
			'Func=contacts.saveTestdrive&lang='+sitelang+'&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					jQuery.each(data.items, function(i, val) {
						$('#testdrive_' + i).val(val);
						$('#testdrive_' + i).addClass('error');
				    });
				}
				else
				{
					$('#dialog-content').html(data.message);
				}
			},
			"json"
		);
    },
	
	offerForm : function (title, lid)
	{
		$.post("/",'Func=contacts.offerform&lang='+sitelang,
		function(data)
		{
			dialogHandler.popup({
				Title: title,
				Body : data
			});
		},
		"text"
		);
	},
	
	saveOffer : function (thisFom)
    {
		if (!Irishcat.checkTherms())
		{
			alert(rights_text);
			return false;
		}
		
        Irishcat.actualForm = thisFom;

		$.post("/", 
			'Func=contacts.saveOffer&lang='+sitelang+'&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					jQuery.each(data.items, function(i, val) {
						$('#offer_' + i).val(val);
						$('#offer_' + i).addClass('error');
				    });
				}
				else
				{
					$('#dialog-content').html(data.message);
				}
			},
			"json"
		);
    },

	sendCartmen : function (thisForm)
	{
		if (!Irishcat.checkNewTherms())
		{
			alert(rights_text);
			return false;
		}

		Irishcat.actualForm = thisForm;
		
		$.post("/",'Func=contacts.savecartmen&lang='+sitelang+'&'+$(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;
	},
	
	cartmenForm : function (title)
	{
		$.post("/",'Func=contacts.cartmenform&lang='+sitelang,
		function(data)
		{
			$('#dialog-content').addClass('dialog-content-cartmen');
			dialogHandler.popup({
				Title: title,
				Body : data
			});
		},
		"text"
		);
	},   

    printView : function ()
    {
        Irishcat.popwin('?print');
    },
    
    getType : function(obj)
    {
    	
    	//alert($(obj).val());
    	
    	var brand_id = $(obj).val();
    	
    	$.post("/",'Func=usedcar.getTypes&lang='+sitelang+'&brand_id='+brand_id,
		function(data)
		{
			if(data.error)
			{
				
			}
			else
			{
				$('#types').html(data.msg);
			}			
		},
		"json"
		);
    },
	
	getSalePromo : function(car_id)
    {	
    	$.post("/",'Func=newcar.car.getSalePromo&lang='+sitelang+'&car_id='+car_id,
		function(data)
		{
			if(data.error)
			{
				
			}
			else
			{
				$('#feeling').data('nivoslider').stop();
				$('#feeling').hide();

				if ($('#saleimg').html() == "")
				{
					$('#saleimg').html(data.img);
					$('#saleimg').slideDown();
				}
				else
				{
					$('#saleimg').fadeOut('fast', function() {
						$('#saleimg').html(data.img);
						$('#saleimg').fadeIn();
					});

				}

				
				$(document).scrollTo($('.pagemenu'), 800);
			}			
		},
		"json"
		);
    },
	
	getModelSalePromo : function(model_id)
    {	
    	$.post("/",'Func=newcar.models.getSalePromo&lang='+sitelang+'&model_id='+model_id,
		function(data)
		{
			if(data.error)
			{
				
			}
			else
			{
				$('#feeling').data('nivoslider').stop();
				$('#feeling').hide();

				if ($('#saleimg').html() == "")
				{
					$('#saleimg').html(data.img);
					$('#saleimg').slideDown();
				}
				else
				{
					$('#saleimg').fadeOut('fast', function() {
						$('#saleimg').html(data.img);
						$('#saleimg').fadeIn();
					});

				}

				
				$(document).scrollTo($('.pagemenu'), 800);
			}			
		},
		"json"
		);
    }
    
};

$(window).ready(function () {
	 
});
