// JavaScript Document
$(function(){
		   
$("#search").keypress(function (e) { if (e.which == '13') 	{ document.location='/kereses/'+$("#search").val();}  });




});

/////////////////////////////////////////////////////////////////////////////////////////////

function kereses(ert)
{ if(ert.length > 2){setTimeout("if(document.getElementById('search').value=='"+ert+"'){ document.location='/kereses/'+$(\"#search\").val();}",800); } }


function getNewsComment(id)
{
	$('#comment_ID'+id).slideDown(300);
	$.get("ajax.php",{command: "getnewscomment", newsid: id}, 
	  function(data) { $('#comment_ID'+id).html(data); });
}


function closeNewsComment(id)
{
	$('#comment_ID'+id).slideUp(600);
	$('.newscommentlink').show();

}

function putNewsComment(id,commenti)
{
	$('#comment_add_error_ID'+id).removeClass('comment_error').html('<img src="media/img/ajax-loader.gif" />').show();
	$('#comment_add_ID'+id).slideUp(300);
	$.get("ajax.php",{command: "putnewscomment", newsid: id, comment: commenti}, 
	  function(data) 
	  	{ 
		  if(data=='ok') 
		  	{ getNewsComment(id);
			setTimeout("scrollWin('#comment_ID"+id+"');",400);
			 
			}
		  else
			{
				if(data=='error'){$('#comment_add_error_ID'+id).addClass('comment_error').html('Hiba a mentés közben ');}
				else{$('#comment_add_error_ID'+id).addClass('comment_error').html(data);}
				setTimeout("$('#comment_add_ID"+id+"').slideDown(400);",1800);
			}
		});
}


function getFilesDeatails(id)
{
	//$('#pdetail').animate({opacity: 40}, 200);
	
	$.get("ajax.php",{command: "getfilesdetails", fileid: id}, 
	  function(data) 
	  	{  $("#pdetail").html(data).animate({opacity: "show"}, 800);	});
}

function getFilesComment(id)
{
	$('#comment_ID_box').slideDown(300);
	if(!comment_open)
		{
		$('img.replaced').animate({height: ($('img.replaced').attr('height')/3),width: ($('img.replaced').attr('width')/3)}, 'slow');
		comment_open=true;
		}
	$.get("ajax.php",{command: "getfilescomment", filesid: id}, 
	  function(data) { $('#comment_ID_box').html(data); });
}

function closeFilesComment()
{
	$('img.replaced').animate({height: ($('img.replaced').attr('height')*3),width: ($('img.replaced').attr('width')*3)}, 'slow');
	$('#comment_ID_box').slideUp(300);
	$('.imgcommentlink').show();
	comment_open=false;
}

function putFilesComment(id,commenti)
{
	$('#comment_add_error_ID').removeClass('comment_error').html('<img src="media/img/ajax-loader.gif" />').show();
	$('#comment_add_ID').slideUp(300);
	$.get("ajax.php",{command: "putfilescomment", filesid: id, comment: commenti}, 
	  function(data) 
	  	{ 
		  if(data=='ok') 
		  	{ getFilesComment(id);
			setTimeout("scrollWin('#comment_ID_box');",400);
			 
			}
		  else
			{
				if(data=='error'){$('#comment_add_error_ID').addClass('comment_error').html('Hiba a mentés közben ');}
				else{$('#comment_add_error_ID').addClass('comment_error').html(data);}
				setTimeout("$('#comment_add_ID').slideDown(400);",1200);
			}
		});
}



function postcard_check(id)
{
	
	$('#postcard_state').html('');
	
	if($('#send_name').val().length<3)
	{$('#postcard_state').append('Felad&oacute; neve hib&aacute;s vagy &ucirc;res<br />');}
	
	if(!checkemail($('#send_email').val()))
	{$('#postcard_state').append('Felad&oacute; e-mail c&iacute;me hib&aacute;s <br />');}
	
	if($('#rec_name').val().length<3)
	{$('#postcard_state').append('C&iacute;mzett neve hib&aacute;s vagy &uuml;res<br />');}
	
	if(!checkemail($('#rec_email').val()))
	{$('#postcard_state').append('C&iacute;mzett e-mail c&iacute;me hib&aacute;s<br />');}
	
	if($('#postcard_state').html()){return false;}
	
	$('#postcard_state').html('<img src="media/img/ajax-loader.gif" /> K&uuml;ld&eacute;s folyamatban');
	
	$.get("ajax.php",{command: "sendpostcard", filesid: id}, 
	  function(data) 
	  	{ 
		
		$('#postcard_state').html(data);
		$('#postcard_form').hide();
		
		});
	
	
	
		
}


function checkemail(id_e)
{
var testresult=false; var str=id_e; var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if(filter.test(str)){testresults=true;}
else{testresults=false}
return (testresults)
}


function getQueryVariable(variable,vurl) {
  var query = vurl.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }}
 	return 0;
} 


function scrollWin(toscroll){
$('html, body').animate({
scrollTop: $(toscroll).offset().top}, 1000);
}

function file_extension_check()
	{
		var fnev=$("#uploadedfile").val().toLowerCase();
		var fext=fnev.substr(fnev.length-4);
		switch(fext)
		{
		 case ".jpg": case ".jpeg": case ".gif": case ".png": case ".tiff": case ".pcx": 
			$('#upload_state').html('<img src="media/img/ajax-loader.gif" /> Feltöltés folyamatban... ');
			document.getElementById('file_upload_form').submit();
			return true;  break;
		default : 
			$("#upload_state").html('Ez a filetípus nem engedélyezett!');
			return false;
		}
	}
	
	
function login(emaili,passwordi)
{
//	alert(emaili+' - '+passwordi);
$('#login_state').show().html(' Azonosítás folyamatban.... <img src="media/img/ajax-loader.gif" />');
$.get("ajax.php",{command: "login", email: emaili, password: passwordi}, 
  function(data)
	{	
		if(data=="ok") 
		{	
			var url = new String(window.location);

			if(url.substr(url.length-6,6)!='logout' && url.substr(url.length-5,5)!='login' &&  url.substr(0,4)!='http' )
				{
				document.location='?'+url.substr(url.search("page="));
				}
			else 
				{
				document.location='?page=home';
				}
			return true;
		}
		else
		{	if(data=='error'){$('#login_state').html('A felhasználónév vagy jelszó nem megfelelő!');}
			else{$('#login_state').html(data);}
			return false;

		}		
		
	});
}

function registration(namei,emaili,passwordi)
{
//	alert(namei+' - '+passwordi+' - '+emaili);
$('#user_create_state').show().html(' Feldolgozás <img src="media/img/ajax-loader.gif" />');
if( !namei) { $('#user_create_state').show().html(' Nincs név megadva'); return false;  }
if( !checkemail(emaili)) { $('#user_create_state').show().html(' A megadott e-mail cím nem megfelelő'); return false;  }
if( $('#pw_state').text()!='A jelszavak egyeznek') { $('#user_create_state').show().html(' A jelszavak nem egyeznek'); return false;  }
$.get("ajax.php",{command: "user_reg",name:namei, email: emaili, password: passwordi}, 
  function(data)
	{	
		if(data=="ok") 
		{	
			$('#user_create_state').show().html(' Sikeres regisztáció. ');
			$('#new_user_create_form').hide();
			return true;
		}
		else
		{	if(data=='error'){$('#user_create_state').html('A felhasználónév vagy jelszó nem megfelelő!');}
			else{$('#user_create_state').html(data);}
			return false;

		}		
		
	});
}


function check_same_pw_at_reg()
{
	if($('#pw').val()==$('#pw2').val())
	{
		$('#pw_state').html('A jelszavak egyeznek');
	}
	else
	{
		$('#pw_state').html('A jelszavak nem egyeznek');
	}
}
	
//////////////////////////////////////////////////////////////////////////////////////////////


$(document).ready(function(){



//$('#img_main_link').hover(function(){ $('#img_sub_menu').slideDown(100).mouseleave(function(){ $('#img_sub_menu').slideUp(100)}); });


$("#menu li a img").hover(
		function()
		{
			if($(this).parent().children("span").attr('id') != "_kep")
				{
				$(this).parent().children("span").animate({opacity: "show"}, 320);
				$('#img_sub_menu').slideUp(100);
				}
			
		//	$(this).animate({ width: $(this).find("span").width()+25+"px" }, {queue:false, duration:50} );			
		},
		function()
                {
    //            $(this).animate({ width: "25px" }, {queue:false, duration:120} );
                $(this).parent().children("span").animate({opacity: "hide"},80);
               });




});


////////////////////////////////////////////////////////
