;(function( $ ){

regellenorzo = function(nev)
{
	if(nev.match(/[^a-z0-9\._-]/i))
	{
		$("input[id*=regnev]").each ( function () {
												
			this.style.color = 'red';
			}
			
		);
	}
	else
	{
			$.post("/PHP/form_feldolgozo.php",{'elagazas': 'usernev_ellenor_ajax', 'nev':nev}, function(data){
				if(data != 'ok')
				{
					$("input[id*=regnev]").each ( function () {
								this.style.color = 'red';
						}			
					);
				}
				else
				{
					$("input[id*=regnev]").each ( function () {
								this.style.color = '#A1A1A1';
						}			
					);
				}
			});
	}
	
}
})(jQuery);

 

regellenorzo_mail = function(nev)
{
	if(nev.match(/^[0-9a-z\._-]+@([0-9a-z-_]+\.)+[a-z]{2,4}$/i))
	{
		$("input[id*=regemil]").each ( function () {
												
			this.style.color = '#A1A1A1';
			}
			
		);
	}
	else
	{
		$("input[id*=regemil]").each ( function () {
												
			this.style.color = 'red';
			}
			
		);
	}
	
}


var ajax;               

if(window.XMLHttpRequest){
ajax = new XMLHttpRequest;
}                            
else{                        
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}                                                

univissza = function(){
if(ajax.readyState == 4){
	if((ajax.status == 200) || (ajax.status == 304)){
		if(ajax.responseText.substr(0,1) != "*"){

			$("div[id*="+vissza+"]").each ( function () {
												   
				this.innerHTML=ajax.responseText;
				}
				
			);
		}
	}                                                
}                                                   
}

lastpost_kitesz = function(){
if(ajax.readyState == 4){
	if((ajax.status == 200) || (ajax.status == 304)){
		if(ajax.responseText.substr(0,1) != "*"){
			if(ajax.responseText != "")
			{
				
				var pos = jQuery(kepobj).offset();
			  	document.getElementById("last_post").innerHTML = ajax.responseText; 
				document.getElementById("last_post").style.position = 'absolute'; 
				document.getElementById("last_post").style.display = 'block';
	 			jQuery('#last_post').css("top", pos.top+10+"px").css("left", pos.left+"px").show();
				}
				
		}
	}                                                
}                                                   
}

lastpost = function(azon,obj)
{
	kepobj = obj;
	ajax.open("POST", "/PHP/utsopost.php", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("id="+azon);                                      
	ajax.onreadystatechange = lastpost_kitesz;
}

lastpost_hide = function()
{
	ellenorzes="";
	jQuery('#last_post').css("display","none");
}


former = function(azonosito)
{
	vissza = azonosito;
	var t = document.getElementById('facebox');

	var inputok = t.getElementsByTagName('input');

	var selectek = t.getElementsByTagName('select');

	var textareak = t.getElementsByTagName('textarea');

	var sendstring = '';
	
	for (i=0; i < inputok.length; i++)
	{
		if (inputok[i].type != 'radio')
		{
		if (sendstring != '')
		{
			sendstring = sendstring + '&';
		}
		sendstring = sendstring + inputok[i].name + "=" + inputok[i].value;
		}
		else
		{
			if (inputok[i].checked)
			{
			if (sendstring != '')
			{
				sendstring = sendstring + '&';
			}
			sendstring = sendstring + inputok[i].name + "=" + inputok[i].value;
			}
		}
	}

	for (i=0; i < selectek.length; i++)
	{
		if (sendstring != '')
		{
			sendstring = sendstring + '&';
		}
		sendstring = sendstring + selectek[i].name + "=" + selectek[i].value;
	}

	for (i=0; i < textareak.length; i++)
	{
		if (sendstring != '')
		{
			sendstring = sendstring + '&';
		}
		sendstring = sendstring + textareak[i].name + "=" + textareak[i].value;
	}

	ajax.open("POST", "/PHP/form_feldolgozo.php", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(sendstring);           
	ajax.onreadystatechange = univissza;
}




;(function( $ ){
	
	ujatlag = function(){
	
	var atlagpont = 0;
	var atlagdb = 0;
	var szavazat= 0;
	var szin="d9_red";
	
	$(".d9_rate_headline").each(function(i){
			
	var pont = $(this).find(".d9_rate_headline_point").text();
	szavazat = szavazat + parseInt($(this).find(".d9_db").text());
	pont=parseFloat(pont);
	
	if (pont !== 0) { atlagpont = atlagpont+pont; atlagdb=atlagdb+1; }

	});
	
	var atlag = (atlagdb != 0) ? atlagpont / atlagdb : 0;
	atlag=Math.round(atlag*10)/10;
	
	if (atlag > 3) szin="d9_yellow";
	if (atlag > 7) szin="d9_green";
	
	
	atlag=atlag.toString();
	
	if(atlag.length<3) { atlag= atlag+".0" }
	
	var kiiras ="<font class='"+szin+"'>"+atlag+"</font><br><span>"+szavazat+" szavazat alapján</span>";
	
	
	if( $(".d9_rate_summa_point") )
	{

	$(".d9_rate_summa_point").html(kiiras);
	}
}
	
})(jQuery);


;(function( $ ){
	news_animate = function(i)
	{
		var prev = (i > 1) ? i-1 : d9_sl_max; 
		$('.d9_scroller_info').each(function(j){
			if (j != (i-1))
			{
				if( $(this).hasClass('active'))
				{
					prev = j+1;
					$(this).removeClass('active');

					$('#scroller_img_'+i).animate({opacity:'1'},{duration: 1, queue: "global2", preDelay: 999, postDelay:1000, complete: function () {
						$(this).css({"z-index":9});
						$('#scroller_img_'+prev).css({"z-index":10});
						$(".d9_scroller_info_box .d9_scroller_info span").animate({color:"#FFFFFF"},{duration:500});
						$(".d9_scroller_info_box span:eq("+(i-1)+")").animate({color:"#2a8bcb"},{duration:500});
						$('#scroller_text_'+prev).fadeOut({duration:500, queue: "global1"});
						$('#scroller_text_'+i).fadeIn({duration:500, queue: "global1"});
						}
						});
							
					$('#scroller_img_'+prev).animate({opacity:'0'},{duration: 1000, queue: "global", preDelay: 1000, complete: function () {
						$(this).css({"z-index":8,opacity:1});
							}
						});

				}
			}
			else
			{
				$(this).addClass('active');
			}
		});


		d9_sl = i;
		clearTimeout(d9_timer);
		d9_timer = setTimeout(function(){
			d9_sl = (d9_sl < d9_sl_max) ? d9_sl+1 : 1;
			news_animate(d9_sl);
		},15000);

	}
})(jQuery);


;(function( $ ){
	newsline_animate = function(i)
	{
		var prev = (i > 1) ? i-1 : d9_nl_max; 
		$('.d9_news_page').each(function(j){
			if( j != (i-1))
			{
				if( $(this).hasClass('active'))
				{
					prev = j+1;
					$(this).removeClass('active');

					$('#nl_'+prev).hide();

					$('#nl_'+i).fadeIn();
				}
			}
			else
			{
				$(this).addClass('active');
			}
		});

		d9_nl = i;
		clearTimeout(d9_timer2);
		d9_timer2 = setTimeout(function(){
			d9_nl = (d9_nl < d9_nl_max) ? d9_nl+1 : 1;
			newsline_animate(d9_nl);
		},15000);

	}
})(jQuery);

var d9_timer;
var d9_sl = 1;
var d9_sl_max = 3;

var d9_timer2;
var d9_nl = 1;
var d9_nl_max = 5;

;(function( $ ){
	adatlap_bovito = function(mit,azon,tipus,oldalszam)
	{
		$.post("/PHP/adatlap_bovito.php",{fn: mit, "id": azon, "type": tipus, oldal: oldalszam},function(data){
			$('#bovito_gomb').remove();
			$('#bovito').append(data);
		});
	}
})(jQuery);

;(function( $ ){
	userlap_bovito = function(mit,azon,tipus,oldalszam)
	{
		$.post("/PHP/userlap_bovito.php",{fn: mit, "id": azon, "type": tipus, oldal: oldalszam},function(data){
			$('#bovito_gomb').remove();
			$('#bovito').append(data);
		});
	}
})(jQuery);

;(function( $ ){
	rendezes_valto = function(uj,tipus)
	{
		$.post("/PHP/rendezo_suti.php",{mire: uj, mit: tipus},function(data){
			window.location.reload();
		});
	}
})(jQuery);


top9kiir = function(){
if(ajax.readyState == 4){
	if((ajax.status == 200) || (ajax.status == 304)){
		if(ajax.responseText.substr(0,1) != "*"){
			document.getElementById('top9div').innerHTML = ajax.responseText; 
			jQuery('.img_tooltip').tooltip({
				track: true,
				delay: 0,
				fade: 250,
				showURL: false,
				bodyHandler: function() {
					return jQuery("<img/>").attr("src", this.rel);
				}
			});
		}
	}                                                
}                                                   
}

reltabskiir = function(){
if(ajax.readyState == 4){
	if((ajax.status == 200) || (ajax.status == 304)){
		if(ajax.responseText.substr(0,1) != "*"){
			document.getElementById('reltabsdiv').innerHTML = ajax.responseText; 
		}
	}                                                
}                                                   
}



megjelenites = function(){
if(ajax.readyState == 4){
	if((ajax.status == 200) || (ajax.status == 304)){
		if(ajax.responseText.substr(0,1) != "*"){
			document.getElementById(vissza).innerHTML = ajax.responseText; 
			ujatlag();
		}
	}                                                
}                                                   
}


ertekel = function(sor,csillag)
{
	vissza = sor;
	ajax.open("POST", "/PHP/ertekel.php", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("sor="+sor+"&szavazat="+csillag);                        
	ajax.onreadystatechange = megjelenites;
}


top9 = function(num)
{
	ajax.open("POST", "/PHP/top9.php", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("v="+num);                        
	ajax.onreadystatechange = top9kiir;
}

reltabs = function(tip,site)
{
	ajax.open("POST", "/PHP/reltabs.php", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("v="+tip+"&fs="+site);                        
	ajax.onreadystatechange = reltabskiir;
}

premiertabs = function(tip)
{
	ajax.open("POST", "/PHP/premiertabs.php", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("v="+tip);                        
	ajax.onreadystatechange = reltabskiir;
}


;(function($){
	$(document).ready(function(){


	 $('.jumpto a').click(function(){
	 $.scrollTo( this.hash, 1500, { easing:'elasout' });
	 $(this.hash).find('span.message').text( this.title );
	 return false;
	 });

						   

	if(	$(".csatorna_valaszto_input").length ==1 )
	{
		$(".csatorna_valaszto_input").selectmenu({maxHeight: 300, style:'dropdown', width:226});
	}
	

	if(	$("select#varos").length ==1 )
	{	
	$("select#varos").selectmenu({maxHeight: 198, style:'dropdown', width:226});
	$("select#mozi").selectmenu({maxHeight: 154, style:'dropdown', width:226});
	$("select#datum").selectmenu({maxHeight: 200, style:'dropdown', width:226});
	$("select#napszak").selectmenu({maxHeight: 120, style:'dropdown', width:118});
	}

	
	if(	$(".tv_past_header").length ==1 )
	{	
	$(".tv_past_header").click(function(){
	$(".tv_past").slideToggle({duration:500, easing:'easeOutBounce' } );	
	});
	
	$(".d9_tv_show_item, .d9_tv_show_item_past, .d9_tv_show_item_now").hover(function(){
		$(this).find(".d9_item_longtext").slideToggle(150)
		},function(){
		$(this).find(".d9_item_longtext").slideToggle(150)
	});
	
	
	}
	
	
	
	$(".d9_rate_stars_active").hover(function(){
		$(this).stop().find(".d9_rate_stars_point").fadeTo(200, 0.0); 
		},function(){

		var position= "0px";
		$(this).find(".d9_rate_stars_rate").css({"width":position});
	
		$(this).stop().find(".d9_rate_stars_point").fadeTo(200, 1.0); 
		
		});
	
	
	$(".d9_rate_stars_active .d9_rate_stars_bg").mousemove(function(e){
		
		var x = e.pageX - this.offsetLeft;		
		var position= x+"px";
		//var position = (Math.ceil((e.pageX - this.offsetLeft)/23))*23+"px";
// 		alert(e.pageX + 'offset meg: '+this.offsetLeft);
		$(this).find(".d9_rate_stars_rate").css({"width":position});
	
		});
		
	$(".d9_rate_stars_active .d9_rate_stars_bg").click(function(f){

		var position = (Math.ceil((f.pageX - this.offsetLeft)/23))*23+"px";
		$(this).find(".d9_rate_stars_rate").css({"width":position});
		
		var pont = Math.ceil((f.pageX - this.offsetLeft)/23);
		var id = $(this).parent().parent().attr('id')
	
		ertekel(id, pont);
	
		});
	
	$('a[rel*=modal]').facebox();

	d9_sl_max = $('.d9_scroller_img').length;
	d9_nl_max = $('.d9_news_news').length;

	$("#head_closer").click(function(){
		if($(this).text() == 'fejléc nyitása')
		{
			$('.d9_top_content').animate({height:'394px'},{queue:false, duration:600, easing: 'easeOutBounce'});
// 			$('.d9_news_scroller').slideDown().animate({height:'310px'},{queue:false, duration:600, easing: 'easeOutBounce'});
			$(this).text('fejléc bezárása');
			$.post("/PHP/header_closer.php",{fn : 'nyitva'}, function(data){
			});
			if(d9_sl_max > 1)
			{
				d9_timer = setTimeout(function(){
					d9_sl = (d9_sl < d9_sl_max) ? d9_sl+1 : 1;
					news_animate(d9_sl);
				},15000);
			}
		}
		else
		{
			clearTimeout(d9_timer);
// 			$('.d9_news_scroller').slideUp();
			$('.d9_top_content').animate({height:'76px'},{queue:false, duration:600, easing: 'easeOutBounce'});
			$(this).text('fejléc nyitása');
			$.post("/PHP/header_closer.php",{fn : 'zarva'}, function(data){
			});
		}
	});


	if($('#head_closer').text() == 'fejléc bezárása' && d9_sl_max > 1)
	{
		d9_timer = setTimeout(function(){
			d9_sl = (d9_sl < d9_sl_max) ? d9_sl+1 : 1;
			news_animate(d9_sl);
		},15000);
	}

	if(d9_nl_max > 1)
	{
		d9_timer2 = setTimeout(function(){
			d9_nl = (d9_nl < d9_nl_max) ? d9_nl+1 : 1;
			newsline_animate(d9_nl);
		},15000);
	}


	if($( "#d9_slider" ).length != 0)
	{
		var minslide =  new Number($('#d9_slider_min').val());
		var maxslide = new Number($('#d9_slider_max').val());
		var minslide1 =  new Number($('#d9_slider1').val());
		var maxslide1 = new Number($('#d9_slider2').val());
		$( "#d9_slider" ).slider({
				range: true,
				min: minslide,
				max: maxslide,
				values: [ minslide1, maxslide1 ],
				animate: true,
				
				slide: function(event,ui){
           					$( "#d9_slider1" ).val( ui.values[ 0 ] );
							$( "#d9_slider2" ).val( ui.values[ 1 ] );
							$( "#d9_slider_text" ).html(ui.values[0] + ' - ' + ui.values[1]);		
						    },
		});
	}


	if($('.d9_box').length != 0)
	{
		$('.d9_box').each(function(i){
			var btn_num = $(this).find('.next').length;
			if(btn_num !== 0)
			{
				var slide_num = $(this).find('.d9_box_headline_slide').length;
				var slide_width = $(this).find('.d9_box_content_slide').css("width");
				var sl_width = slide_width.replace(/px/g,'');
				sl_width = sl_width - 238;
				var curr_slide = 0;
				
				$(this).find('.next').click(function(){
					var next_slide = (curr_slide < (slide_num-1)) ? curr_slide+1 : 0;
					$(this).parents('.d9_box').find('.d9_box_headline_slide').each(function(j){
						if(j == curr_slide)
						{
							$(this).css({"z-index":8});
						}
						else if(j == next_slide)
						{
							$(this).css({"z-index":10});
						}					
					});
					if(next_slide != 0)
					{
						$(this).parents('.d9_box').find('.d9_box_content_slide').animate({left: '-=238px'},{duration: 500, queue: 'boxque'+i});
					}
					else
					{
						$(this).parents('.d9_box').find('.d9_box_content_slide').animate({left: '0px'},{duration: 500, queue: 'boxque'+i});
					}
					curr_slide = next_slide;
				});
	
				$(this).find('.prev').click(function(){
					var prev_slide = (curr_slide > 0) ? curr_slide-1 : slide_num-1;
					$(this).parents('.d9_box').find('.d9_box_headline_slide').each(function(j){
						if(j == curr_slide)
						{
							$(this).css({"z-index":8});
						}
						else if(j == prev_slide)
						{
							$(this).css({"z-index":10});
						}					
					});
					if(prev_slide != (slide_num-1))
					{
						$(this).parents('.d9_box').find('.d9_box_content_slide').animate({left: '+=238px'},{duration: 500, queue: 'boxque'+i});
					}
					else
					{
						var mozgas = '-='+sl_width + 'px';
						$(this).parents('.d9_box').find('.d9_box_content_slide').animate({left: mozgas },{duration: 500, queue: 'boxque'+i});
					}
					curr_slide = prev_slide;
				});
			}

		});

	}
}); 
	
})(jQuery);
