/*jQuery(document).ready(function() {
jQuery("a#login").click(function(){login();return false;});
jQuery("#login_div span#close").click(function(){login_bezar()});
}); 
function login(){
	
	jQuery('#login_bg').show().one("click",function(){login_bezar()}); 
	jQuery().one("keyup",function(event){
			if(event.which == 27)
				login_bezar();  
			});
	jQuery('#login_div').slideDown();
	
}
function login_bezar(){
	

	jQuery('#login_bg').hide();
	jQuery('#login_div').slideUp("slow");
	
}*/

$(document).ready(function(){
		
	 $("a.fancybox").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false,
				'titlePosition' :   'over'
	});
	
	$("a.iframe").fancybox({
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'width' : '75%',
		'height' : '75%',
		'overlayShow'	:	true,
		'autoScale' : true,
		'type' : 'iframe',
				'titlePosition' :   'over'
	});
		
		$('.hs .gomb').click(function() {
				if( $(this).parent('.hs').hasClass('aktiv') ){
						$(this).parent('.hs').addClass('perm');
						$(this).parent('.hs').children('.submenus').slideUp('slow',function(){
							 $('.perm').removeClass('aktiv').removeClass('perm');
						});
				}else{
						$('.hs.aktiv').addClass('perm');
						$('.hs.aktiv').children('.submenus').slideUp('slow',function(){
							 $('.perm').removeClass('aktiv').removeClass('perm');
						});
						$(this).parent('.hs').addClass('aktiv');
						$(this).parent('.hs').children(".submenus").slideDown();
				}
						
		});
		
	$('div.klink').click(function() {
		//var aname= this.name;
		$aname= $(this).attr('name');
		$todiv = '#'+$aname;
		//$.scrollTo( '#'+$aname, 800, {easing:'elasout'} );
		$.scrollTo( $todiv, 400); 
		//alert('#'+$aname);
	});
	
	$('#simple_search_form').submit(function() {
		//alert('Handler for .submit() called.');
		//return false;
	});
	
	
	
	
	$( "#dialog:ui-dialog" ).dialog( "destroy" );
		
		var yourname 						= $( "#yourname" ),
				youremail 					= $( "#youremail" ),
				yourtelephone 			= $( "#yourtelephone" ),
				yourfax 						= $( "#yourfax" ),
				yourbillname 				= $( "#yourbillname" ),
				yourcity 						= $( "#yourcity" ),
				yourpostalcode 			= $( "#yourpostalcode" ),
				yourstreet 					= $( "#yourstreet" ),
				delivery 						= $( "#delivery_megrendeles" ),
				deliverycity 				= $( "#deliverycity" ),
				deliverypostalcode 	= $( "#deliverypostalcode" ),
				deliverystreet 			= $( "#deliverystreet" ),
				deliverycomment 		= $( "#deliverycomment" ),
				deliveryschool 			= $( "#deliveryschool" ),
				payment 						= $( "#payment" ),
				allFields = $( [] ).add( yourname )
													 .add( youremail )
													 .add( yourtelephone )
													 .add( yourfax )
													 .add( yourbillname )
													 .add( yourcity )
													 .add( yourpostalcode )
													 .add( yourstreet )
													 .add( deliveryschool )
													 .add( delivery )
													 .add( deliverycity )
													 .add( deliverypostalcode )
													 .add( deliverystreet )
													 .add( deliverycomment )
													 .add( payment ),
				tips 			= $( ".validateTips" );

		function updateTips( t ) {
			tips
				.text( t )
				.addClass( "ui-state-highlight" );
			setTimeout(function() {
				tips.removeClass( "ui-state-highlight", 1500 );
			}, 500 );
		}

		function checkLength( o, n, min, max ) {
			if ( o.val().length > max || o.val().length < min ) {
				o.addClass( "ui-state-error" );
				updateTips( "A(z) '" + n + "' hossza minimum " +
					min + ", maximum " + max + " karakter." );
				return false;
			} else {
				return true;
			}
		}

		function checkRegexp( o, regexp, n ) {
			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass( "ui-state-error" );
				updateTips( n );
				return false;
			} else {
				return true;
			}
		}
		
		$( "#megrendeles-form" ).dialog({
			autoOpen: false,
			height: 570,
			width: 500,
			modal: true,
			buttons: {
				"Megrendelés": function() {
					var bValid = true;
					allFields.removeClass( "ui-state-error" );

					bValid = bValid && checkLength( yourname, "Ön neve", 3, 50 );
					bValid = bValid && checkLength( youremail, "Email cím", 6, 80 );
					bValid = bValid && checkLength( yourbillname, "Telefonszám", 5, 50 );
					bValid = bValid && checkLength( yourcity, "Város", 2, 50 );
					bValid = bValid && checkLength( yourpostalcode, "Irányítószám", 4, 16 );
					bValid = bValid && checkLength( yourstreet, "Utca, házszám", 3, 50 );
					bValid = bValid && checkLength( deliverycity, "Szállítás városa", 3, 50 );
					bValid = bValid && checkLength( deliverypostalcode, "Szállítás irányítószáma", 4, 50 );
					bValid = bValid && checkLength( deliverystreet, "Szállítás utca, házszám", 3, 50 );
					if(delivery.val() == '1'){
						bValid = bValid && checkLength( deliveryschool, "Iskola neve", 3, 50 );
					}else{
					
					}

					// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
					bValid = bValid && checkRegexp( youremail, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "eg. ui@jquery.com" );

					if ( bValid ) {
						$.ajax({
							url: '/inc/ajax/popup_megrendeles.php',
							type: "POST",
							async: false,
							ataType : 'json',
							data: {
																											yourname:yourname.val(),
																											youremail:youremail.val(),
																											yourtelephone:yourtelephone.val(),
																											yourfax:yourfax.val(),
																											yourbillname:yourbillname.val(),
																											yourcity:yourcity.val(),
																											yourpostalcode:yourpostalcode.val(),
																											yourstreet:yourstreet.val(),
																											delivery:delivery.val(),
																											deliveryschool:deliveryschool.val(),
																											deliverycity:deliverycity.val(),
																											deliverypostalcode:deliverypostalcode.val(),
																											deliverystreet:deliverystreet.val(),
																											deliverycomment:deliverycomment.val(),
																											payment:payment.val()
																											
																										},
							contentType: "application/x-www-form-urlencoded;charset=UTF-8",
							success: function(data){
								/*if(data != '111'){
									alert('Hiba történt a rendelés küldéekor! Kérjük rendeljen újra!');
								}*/
							},
							error:function (xhr, ajaxOptions, thrownError){
                alert('Hiba történt a rendelés küldéekor! Kérjük rendeljen újra!');
              }  
																											
																										
						});
						
						$( this ).dialog( "close" );
					}
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});

		$( "#megrendeles" )
			.button()
			.click(function() {
				$( "#megrendeles-form" ).dialog( "open" );
		});
		
		$( "#megrendeles2" )
			.button()
			.click(function() {
				$( "#megrendeles-form" ).dialog( "open" );
		});
	
	
	
	
		
});


