jQuery.noConflict();
jQuery(document).ready(function($){
		
		//alert($("#pp_frame", parent.document.body));
		//parent.document.getElementById('pp_frame').height = document.getElementById('site_end').offsetTop;
		if($("#pp_frame", parent.document.body).length > 0) {
			$("#pp_frame", parent.document.body).attr("height", document.getElementById('site_end').offsetTop);
		}
		
		function kosarLoad(child_call) {
			$.ajax({
							type: "GET",
							url: "kosarAjax.php",
							dataType: "text",
							cache: false,
							success: function(content){
									
									$("#kosarTart").html(content);	
									if(child_call == true) {
										window.opener.document.getElementById("kosarTart").innerHTML = content;
									}	
									//$("#kosarTart").hide();
									//$("#kosarTart").animate({ height: 'show', opacity: 'show' }, 'fast');		
															
									}
			});
		}
		
		if(document.getElementById("kosarTart")) {
			kosarLoad(false);
		}
		
		$("#kosarba_btn").click(
		function() {
				var str = $("#formtest").serialize();
				//alert((str));
				//alert($("input:checked").length);
				if($("input:checked").length == 0) {
					alert("Válassza ki az ár mellett lévő jelölő mezőre történő kattintással, hogy milyen áron vásárolja meg a terméket!")
					return false;
				}
				else if(document.getElementById("formtest").darab.value == 0) {
					alert("Nullánál többet adjon meg!")
					return false;
				}
				else {
						var alapw = $("#loading").width();
						var alaph = $("#loading").height();
					
						var teljesWidth  = alapw + parseInt($("#loading").css("paddingLeft"))
						var teljesHeight  = alaph + parseInt($("#loading").css("paddingLeft"))
						
					
						
						$("#loading").css({
							left: Math.floor(document.body.clientWidth/2-teljesWidth)+"px",
							top: Math.floor((document.body.clientHeight/2-teljesHeight)+(document.body.scrollTop)-100)+"px"
						});
					$("#loading").show();
					
					$.ajax({
						type: "POST",
						url: "shop.php",
						data: str + "&type=ajax",
						dataType: "text",
						cache: false,
						success: function(content){
								
								$("#loading").show();	
									
						
								},
						error: function(textStatus, errorThrown){
								alert('Teststat: '+textStatus +'Hiba: '+errorThrown);	
									
						
								},
						complete: function(textStatus){
								$("#loading").hide();
								kosarLoad();
								alertKosar();
						}
						})
				}
						
		});
		
		function alertKosar() {
			/*Dialog.alert("<b>A kiválasztott termék bekerült a kosárba!</b>", {width:300, height:100, okLabel: "Ok", className: "alphacube",ok:function(win) 				{debug("Hiba!"); return true;}});
			*/
			var timeout; 
			function openInfoDialog() { 
				Dialog.info("<br><br><b>A termék bekerült a kosárba!</b>", {width:250, height:100, showProgress: false,className: "alphacube"}); 
				timeout = 2; 
				setTimeout(infoTimeout, 100) 
			} 
			function infoTimeout() 
			{ 
				timeout--; 
				if (timeout > 0) 
				{ 
					//Dialog.setInfoMessage("<b>A termék bekerült a kosárba!</b><br><br>Info eltűnik <br>" + timeout + "mp múlva...")
					Dialog.setInfoMessage("<br><br><b>A termék bekerült a kosárba!</b>") 
					setTimeout(infoTimeout, 1000) } 
				else Dialog.closeInfo() 
			} 
			openInfoDialog(); 
			
		}
		
		/**
		*
		* Eddigi rendeléseknél lévő AJAX-os kosárba tétel
		*
		*/	
		
		$("input[name='kosarba']").click(
			function() {
					var index = $("input[name='kosarba']").index(this);
					index++;
					
					var str = $("#formtest"+index).serialize();
					
					var formom = eval("fname"+index);
					//alert(formom.aradatlap.length);
					
					var errors = false;
					if(formom.aradatlap.length != undefined) {
						errors = true;
						for (i = 0; i < formom.aradatlap.length ;i++) {
						//	alert("i: "+i+" len: "+formom.aradatlap.length);
							
							if (formom.aradatlap[i].checked)  {
								//alert("itt a");
							   errors = false;
							}
						}
					}
					//alert(errors);
					if(errors){
						alert("Válassza ki az ár mellett lévő jelölő mezőre történő kattintással, hogy milyen áron vásárolja meg a terméket!");
					}
					else{
						
						var alapw = $("#loading").width();
						var alaph = $("#loading").height();
					
						var teljesWidth  = alapw + parseInt($("#loading").css("paddingLeft"))
						var teljesHeight  = alaph + parseInt($("#loading").css("paddingLeft"))
						
					
						
						$("#loading").css({
							left: Math.floor(document.body.clientWidth/2-teljesWidth)+"px",
							top: Math.floor((document.body.clientHeight/2-teljesHeight)+(document.body.scrollTop))+"px"
						});
						$("#loading").show();
						
						
						$.ajax({
							type: "POST",
							url: "shop.php",
							data: str + "&type=ajax",
							dataType: "text",
							cache: false,
							success: function(content){
									
									
	
									$("#loading").show();	
										
							
									},
							error: function(textStatus, errorThrown){
									alert('Teststat: '+textStatus +'Hiba: '+errorThrown);	
										
							
									},
							complete: function(textStatus){
									$("#loading").hide();
									kosarLoad(true);									
									//window.opener.location.reload();
									alertKosar();
									
							}
							})
					}
							
			})
	
		

		
		$("input[name='kosarbalistaz']").click(
			function() {
					var index = $("input[name='kosarbalistaz']").index(this);
					index++;
					var str = $("#formtest"+index).serialize();
					
					//alert(document.getElementById("formtest"+index).darab.value);
					
					if(document.getElementById("formtest"+index).darab.value == 0) {
						alert("Nullánál többet adjon meg!");
					}
					else{
					
						var alapw = $("#loading").width();
						var alaph = $("#loading").height();
					
						var teljesWidth  = alapw + parseInt($("#loading").css("paddingLeft"))
						var teljesHeight  = alaph + parseInt($("#loading").css("paddingLeft"))
						
					
						
						$("#loading").css({
							left: Math.floor(document.body.clientWidth/2-teljesWidth)+"px",
							top: Math.floor((document.body.clientHeight/2-teljesHeight)+(document.body.scrollTop)-100)+"px"
						});
						
					
						$("#loading").show();
						$.ajax({
							type: "POST",
							url: "shop.php",
							data: str + "&type=ajax",
							dataType: "text",
							cache: false,
							success: function(content){
									$("#loading").show();	
										
							
									},
							error: function(textStatus, errorThrown){
									alert('Teststat: '+textStatus +'Hiba: '+errorThrown);	
									return false;	
							
									},
							complete: function(textStatus){
									$("#loading").hide();
									kosarLoad();
									alertKosar();
									
							}
							})
					
					}		
			})
		
		var i = false; 
		$("#mybtn").toggle(
			function() {
				
				
				if(i == false) {
					i = true;
					$("#loader").show();
					$.ajax({
					type: "GET",
					url: "helyettesitok.php",
					data: "dID="+$("#dID").val(),
					dataType: "html",
					cache: false,
					success: function(content){
							$("#outWrite").html(content);	
							$("#outWrite").hide();
							$("#outWrite").animate({ height: 'show', opacity: 'show' }, 1500);		
					
							},
					complete: function(textStatus){
								$("#loader").hide();
							}
					})
			}
				else {
					$("#outWrite").animate({ height: 'show', opacity: 'show' }, 1500);		
				}	
			},
			function(){
				$("#outWrite").animate({ height: 'hide', opacity: 'hide' }, 'slow');
			}
		);
   		var j = false; 
		$("#top5btn").toggle(
			
			function() {
				var alapw = $("#loading").width();
						var alaph = $("#loading").height();
					
						var teljesWidth  = alapw + parseInt($("#loading").css("paddingLeft"))
						var teljesHeight  = alaph + parseInt($("#loading").css("paddingLeft"))
						
					
						
						$("#loading").css({
							left: Math.floor(document.body.clientWidth/2-teljesWidth)+"px",
							top: Math.floor((document.body.clientHeight/2-teljesHeight)+(document.body.scrollTop)-100)+"px"
						});
				if(j == false) {
					j = true;
					$("#ajanlo").hide();
					$("#banner_right").hide();
					$("#loading").show();
					$.ajax({
					type: "GET",
					url: "top5.php",
					dataType: "text",
					cache: false,
					success: function(content){
							$("#top5_container").html(content);	
							$("#top5_container").hide();
							$("#top5_container").animate({ height: 'show', opacity: 'show' }, 100);		
					
							},
					complete: function(textStatus){
								$("#loading").hide();
							}
					})
			}
				else {
					$("#ajanlo").hide();
					$("#banner_right").hide();
					$("#top5_container").animate({ height: 'show', opacity: 'show' }, 1500);		
				}	
			},
			function(){
				
				$("#top5_container").animate({ height: 'hide', opacity: 'hide' }, 'slow');
				$("#ajanlo").show();
				$("#banner_right").show();
			}
		);
   $("#szamlacim").hide();
   $("#szamlayes").click(
	   function(){
	     $("#szamlacim").animate({ height: 'show', opacity: 'show' }, 'slow');
	   }
	);
	$("#szamlano").click(
		function(){
		$("#szamlacim").animate({ height: 'hide', opacity: 'hide' }, 'slow');
	   }   
   );
    
	
	
	/**
	*
	* Vertikális menü vezérlője
	*
	*/
	
	//URL-ből visszaadja az almenühőz tartozó paramétert  
	function get_menu_id() {
		var param = document.getElementById("link_param").innerHTML;
		var tomb = param.split("/");
		var indx = tomb.length - 2;
		//alert(tomb[1])
		return tomb[0];
	}
	if(document.getElementById("link_param")) {
		var menuid = get_menu_id(); 
	}
	
	// ha almenüpontban vagyunk és átmegyünk egy másik almenübe, akkor lenyítja
	$("#sub_" + menuid).animate({ height: 'show', opacity: 'show' }, 'slow'); 
	//lenyított menü ID-ének megváltozatatása, azért, hogy tudjuk melyik van nyitva	
	$("#div_" + menuid).attr({id: "nyitva_"+ menuid}); 
	//automatikusan lenyíló menüpont CSS formázása	
	$("#nyitva_" + menuid).css(
		{ 
			backgroundColor: "#618E22",
			fontFamily: "Arial",
			fontSize: "10px",
			color: "FFFFFF",
			textDecoration: "none",
			textAlign: "left",
			padding: "2px 1px 2px 10px"
			
		
	});
	
	$("#" + menuid).css({
			fontWeight: "bold",
			color: "FFFFFF"
	});
	
	
	//A menüpontra kattintás vezérlője
   $("a[name='nyit']").toggle(
   		function() {		
			var divid = ($(this).attr("id"));
			
			if($("#div_" + divid).attr("id") == "div_" + divid){
				lenyit(divid);
				$("#nyitva_" + divid).css(
				{ 
					backgroundColor: "#618E22",
					fontFamily: "Arial",
					fontSize: "10px",
					color: "FFFFFF",
					textDecoration: "none",
					textAlign: "left",
					padding: "2px 1px 2px 10px"
					
				
				});
				$(this).css({
					fontWeight: "bold",
					color: "FFFFFF"
				})
			}
			else {
				becsuk(divid);
				$("#div_" + divid).css(
				{ 
					backgroundColor: "#D8EEB9",
					fontFamily: "Arial",
					fontSize: "10px",
					color: "FFFFFF",
					textDecoration: "none",
					textAlign: "left",
					padding: "2px 1px 2px 10px"
					
				
				});
				$(this).css({
					fontWeight: "normal",
					color: "#006600"
				})
			}

		},
		function() {
			var divid = ($(this).attr("id"));
			
			if($("#div_" + divid).attr("id") == "div_" + divid){				
				lenyit(divid);
				$("#nyitva_" + divid).css(
				{ 
					backgroundColor: "#618E22",
					fontFamily: "Arial",
					fontSize: "10px",
					color: "FFFFFF",
					textDecoration: "none",
					textAlign: "left",
					padding: "2px 1px 2px 10px"
					
				
				});
				$(this).css({
					fontWeight: "bold",
					color: "FFFFFF"
				})
			}
			else {
				becsuk(divid);
				$("#div_" + divid).css(
				{ 
					backgroundColor: "#D8EEB9",
					fontFamily: "Arial",
					fontSize: "10px",
					color: "FFFFFF",
					textDecoration: "none",
					textAlign: "left",
					padding: "2px 1px 2px 10px"
					
				
				});
				$(this).css({
					fontWeight: "normal",
					color: "#006600"
				})
				
			}

   		}
   );
   function lenyit(menuid) {
		$("#div_" + menuid).attr({id: "nyitva_"+ menuid});
		$("#sub_" + menuid).animate({ height: 'show', opacity: 'show' }, 'slow');
	     return true;
	     
	}
	function becsuk(menuid) {
		$("#nyitva_" + menuid).attr({id: "div_"+ menuid});
	    $("#sub_" + menuid).animate({ height: 'hide', opacity: 'hide' }, 'slow');
	   return true;
	}
   
   $("#zipfield").keyup(function(event) {
		//alert($(this).val());
		
		$.ajax({
				type: "POST",
				url: "get_cityname_ajax.php",
				data: "zipcode=" + $(this).val(),
				dataType: "text",
				cache: false,
				success: function(content){
						//alert(content);
						
						$("#citycontener").val(content);
										
				},
				error: function(textStatus, errorThrown){
						alert('Teststat: '+textStatus +'Hiba: '+errorThrown);	
							
							
				},
				complete: function(textStatus){
						
									
				}
		})
	
	});
	
	$("input[name='phone_district']").keyup(function() {
		//alert($(this).val());
		if($(this).val() == 1 || $(this).val().length == 2) {
			$("input[name='phone_num']").focus();
		}
		
	});
	
	
	// BANNER bezáródás kezeleő
	//számláló
	var lepes = $("#time_center").val();
	function countDownStart() {
		$(document).everyTime(1000, 'controlled', function(i) { delayer(i) }, lepes);
		function delayer(i) {
			var from = lepes - i;
			//$(".counter").html(from + " mp");	
			
			if(from == 0) {
				$(document).stopTime('controlled');
				$("#close_topbottom").trigger("click");		
				
			}
			
		}
	}
	countDownStart();
	$("#close_topbottom").toggle(function() {
		$(document).stopTime('controlled');
		$("#topbottom_contener").animate({ height: 'hide', opacity: 'hide' }, 1500);		
		$(".counter").hide();
		$(".separator").hide();
		$(this).html("Hírdetés megnyitása");	
	},
	function() {
		$("#topbottom_contener").animate({ height: 'show', opacity: 'show' }, 1500);
		$(".separator").show();
		$(this).html("Hírdetés bezárása");
		
	});
	
   
   
});     