function ajaxx(type,div) {
	$("#s_info").hide();
	$("#search_type").val(type);
	var adata=$('#searchform').serialize();
	//alert(adata);
	$.post(servercime+'_formsubmit_.php',adata,
		function(data){  			
				if (data.substring(0,2)=='OK') {
					$("#"+div).html(data.substring(3));
				
					if (type=='toltes') {
						ajaxx('kers4','searchdiv4');	
					} else if ((type=='kers4')) {
						ajaxx('kers2','searchdiv2');				
					} else if ((type=='kers2')) {
						ajaxx('kers3','searchdiv3');
					} else if ((type=='kers3')) {
						ajaxx('kers1','searchdiv1');
					} else if ((type=='nincs')) {
					}					
	 		} else {
	 			$("#s_info").html(data.substring(5));			 			
				$("#s_info").show();
	 		}		 		
			if ($('#intheshop').val()!=1) {
				if ($("#searchdiv1").html().length*1==0 && 
					$("#searchdiv2").html().length*1==0 && 
					$("#searchdiv3").html().length*1==0 &&
					$("#searchdiv4").html().length*1==0) {
					//ajaxx('nincs','main');
				}
			} else {				
				if ($("#searchdiv1").html().length*1==0 && $("#searchdiv2").html().length*1==0 && $("#searchdiv3").html().length*1==0) {				
					//ajaxx('nincs','center');
				}
			}							
		}
	);		
}

function keresd(ez) {
	$("#search_input").val($(ez).html());
	if ($('#intheshop').val()!=1) {
		ajaxx('toltes','main');
	} else {
		ajaxx('toltes','center');
	}
	return false;
}


$(document).ready(function() {

		$('a.to_basket').unbind('click').bind('click', function(e){
				kosarba(this);				
			}
		);
		
		$('#db_lap').bind('change', function(e){			
			$('#_dblap').val($(this).val());
			$('#lapozo').submit();
		});

		$('a.pagerlink, img.pagerlink').bind('click', function(e){
			//alert($(this).attr('id'));
			
			switch ($(this).attr('pid')) {
				case 'elso' : // első tétel
					$('#_tol').val(0);
				break;
							
				case 'utolso' : // utolsó tétel					
					$('#_tol').val(Math.floor($('#_sum').val()*1/$('#_dblap').val()*1)*$('#_dblap').val()*1);
				break;					
				
				case 'elozo' : // előző tétel
					if ($('#_tol').val()*1-$('#_dblap').val()*1>0) {
						$('#_tol').val($('#_tol').val()*1-$('#_dblap').val()*1);	
					} else {
						$('#_tol').val(0);	
					}					
				break;					
				
				case 'kovetkezo' : // következő tétel
					if ($('#_tol').val()*1+$('#_dblap').val()*1<=$('#_sum').val()*1) {
						$('#_tol').val($('#_tol').val()*1+$('#_dblap').val()*1);	
					} else {
						$('#_tol').val($('#_sum').val()*1-$('#_dblap').val()*1);
					}
					
				break;									
				default : 
					if (!isNaN(parseFloat($(this).attr('id')))) {
						$('#_tol').val(($(this).attr('id')*1-1)*$('#_dblap').val()*1);
					}
					
				break;
			}
			
			$('#lapozo').submit();
			return false;
			
		});
		
		
		
		/*
		
		if (cl=='f') {
		if ($(ez).hasClass('gomb')) {
			$('#_tol').val(0);
			go=true;
		} else {
			inakt();
		}
	} else if (cl=='h') {
		if ($(ez).hasClass('gomb')) {
			if ($('#_tol').val()*1-$('#_dblap').val()*1>=0) {
				$('#_tol').val($('#_tol').val()*1-$('#_dblap').val()*1);
			} else {
				$('#_tol').val($('#_sum').val()*1-$('#_tol').val()*1-$('#_dblap').val()*1);
			}
			go=true;
		} else {
			inakt();
		}
	} else if (cl=='e') {
		if ($(ez).hasClass('gomb')) {
			if (($('#_tol').val()*1+$('#_dblap').val()*1)<$('#_sum').val()*1) {
				$('#_tol').val($('#_tol').val()*1+$('#_dblap').val()*1);
			} else {
				$('#_tol').val(0);
			}
			go=true;
		} else {
			inakt();
		}
	} else if (cl=='l') {
		if ($(ez).hasClass('gomb')) {
			$('#_tol').val($('#_sum').val()*1-$('#_dblap').val()*1);
			go=true;
		} else {
			inakt();
		}
	} else if (cl=='lista') {
		document.location.href=servercime+'lista/'+az+'.html';
	} else  {
		if ($('#_tol').val()*1==0) {		
			gtilt("nav_elso",true);	
		} else {
			gtilt("nav_elso",false);	
		}
		if ($('#_dblap').val()*1>=$('#_sum').val()*1) {
			gtilt("nav_elore",true);
			gtilt("nav_hatra",true);		
		} else {
			gtilt("nav_elore",false);
			gtilt("nav_hatra",false);		
		}
		if ($('#_tol').val()*1+$('#_dblap').val()*1>=$('#_sum').val()*1) {		
			gtilt("nav_utolso",true);	
		} else {
			gtilt("nav_utolso",false);	
		}
		
	}		
		
		
		*/
		
	
		$('#searchform').bind('submit', function(e){
			return false;
			}
		);
		
		$(".gyakker").bind('click', function(e){
			keresd(this);
			}
		);
				
		$('#searchsubmit').bind('click', function(e){			
			$("#s_info").hide();
			if ($("#search_input").val().length<4) {
				$("#s_info").html('A keresendő szövegnek legalább 4 karakter hosszúnak kell lennie.');
				$("#s_info").show();
			} else {
				if ($('#intheshop').val()!=1) {
					ajaxx('toltes','main');
				} else {
					ajaxx('toltes','center');
				}
			}
	});
});
