$(document).ready(function() {
	
	// $('.kosarsav img').load(function() {
		// alert($('.kosarsav img').attr('clientWidth'));
	// });
	
	$(".menu td").hover(function(){
		$(this).find(".submenu").show();
	},function(){
		$(this).find(".submenu").hide();
	});

	$(".numbermask").attr('alt','integer');
	$.mask.masks.integer = {mask:'999999999999999'}
	$('.numbermask').setMask();
	
	$('.emailmask').change(function(){
		var hasError = false;
		var emailaddressVal = $(this).val();
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		if(!emailReg.test(emailaddressVal)) {
			alert("Kérjük, hogy helyes e-mail címet adjon meg!");
			$(this).val('');
			hasError = true;
	    }
		if(hasError == true) { return false; }
	});

	$('.partner .p').hover(function(){
		$(this).find('img').css('marginLeft',-95);
	},function(){
		$(this).find('img').css('marginLeft',0);
	});
	
	$('form').submit(function(){
		var submitfake=false;
		$(this).find('.textalt').each(function(){
			if ($(this).val()==$(this).attr('alt')) { submitfake=true; }
		});
		if (submitfake) { return false; }
	});
	
	$('.textalt').each(function(){
		var alt=$(this).attr('alt');
		$(this).val(alt);
		$(this).css('font-style','italic');
	});

	$('.textalt').focus(function(){
		var alt=$(this).attr('alt');
		if ($(this).val()==alt){
			$(this).val('');
			$(this).css('font-style','normal');
		}
	});
	
	$('.textalt').blur(function(){
		var alt=$(this).attr('alt');
		if ($(this).val()==''){
			$(this).val(alt);
			$(this).css('font-style','italic');
		}
	});
	
	$('.megegyezik').click(function(){
		$('input[name=szallit_nev]').val($('input[name=szamla_nev]').val());
		$('input[name=szallit_irsz]').val($('input[name=szamla_irsz]').val());
		$('input[name=szallit_varos]').val($('input[name=szamla_varos]').val());
		$('input[name=szallit_utca]').val($('input[name=szamla_utca]').val());
		var tel=($('input[name=szamla_telefon]').val()!='')?$('input[name=szamla_telefon]').val():'';
		$('input[name=szallit_telefon]').val(tel);
	});
	
	$('.szallitadat').keyup(function(){
		$('.megegyezik').attr('checked',false);
	});
	
	$("a.fanbox").fancybox({
		'overlayShow'	: true,
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.5,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		//'titlePosition'	: 'inside'
	});
	
});

function number_format(a, b, c, d) {
 a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
 e = a + '';
 f = e.split('.');
 if (!f[0]) {
  f[0] = '0';
 }
 if (!f[1]) {
  f[1] = '';
 }
 if (f[1].length < b) {
  g = f[1];
  for (i=f[1].length + 1; i <= b; i++) {
   g += '0';
  }
  f[1] = g;
 }
 if(d != '' && f[0].length > 3) {
  h = f[0];
  f[0] = '';
  for(j = 3; j < h.length; j+=3) {
   i = h.slice(h.length - j, h.length - j + 3);
   f[0] = d + i +  f[0] + '';
  }
  j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
  f[0] = j + f[0];
 }
 c = (b <= 0) ? '' : c;
 return f[0] + c + f[1];
}
