jQuery(function( $ ){		
	$('.oldaldoboz a').click(function(){
		$.scrollTo( this.hash, 500);0
			return false;
	});
});

$(document).ready(function() {

// KÖSZÖNJÜK ABLAK BEZÁR

	$('#koszonjuk-bezar.nylv').click(function() {
		$('#koszonjuk-keret.nylv').fadeOut();
		$('#nyelvek_nagy_keret').css('visibility', 'visible');
	});
	$('#koszonjuk-bezar.nylv').hover(function() {
		$(this).css('text-decoration', 'underline');
		$(this).css('cursor', 'pointer');
	}, function() {
		$(this).css('text-decoration', 'none');		
	});


// MEGÍROM AZ IGÉNYEMET

	$('#irja_meg').click(function() {
		$('.igeny').slideDown('normal');
	});

// ÉRDEKEL AZ AKTUÁLIS TANFOLYAM

	$('p.akt_tanfolyam').click(function() {
		$(this).prev('.erdeklodo').slideDown('normal');
	});

// MÉGSEM ÉRDEKEL AZ AKTUÁLIS TANFOLYAM

	$('div.megsemigenylo').click(function() {
		$(this).parent().parent().parent().slideUp('normal');
	});
	$('div.megsem').click(function() {
		$(this).parent().parent().slideUp('normal');
	});

	$(".hoverfade").hover(function(){
		$(this).fadeOut("normal")
			return false;
		},function(){
	});
	
	$(".text.nev").blur(function () {
		nevCheck(this);
    });

	$(".text.email").blur(function () {
		validate(this);
    });
	
	$(".text.telefon").blur(function () {
 		telefonCheck(this);
    });

	$(".text.nev").focus(function(){
		$(this).siblings("span").fadeOut("normal")
			return false;
		},function(){
	});

	$(".text.email").focus(function(){
		$(this).siblings("span").fadeOut("normal")
			return false;
		},function(){
	});

	$(".text.telefon").focus(function(){
		$(this).siblings("span").fadeOut("normal")
			return false;
		},function(){
	});
	
//  NÉV
	function nevCheck(ez)
		{
		var nev = $(ez).val();
		if (nev.length < 4)
			{
			$(ez).siblings("span").fadeIn("normal");
			return false;
			}
		else
			{
   	    	return true;
			}
		}

//  EMAIL

	function validate(ez) {
		var email = $(ez).val();
    	if (! emailCheck(email)) {
			$(ez).siblings("span").fadeIn("normal");
        	return false;
 		}
		else {
   	    	return true;
		}
  	}
  	
  	function emailCheck(email, required) {
	    if (required==undefined) {   // if not specified, assume it's required
	        required=true;
	    }
	    if (email==null) {
	        if (required) {
	           return false;
	        }
	        return true;
	    }
	    if (email.length==0) {  
	        if (required) {
	            return false;
	        }
	        return true;
	    }
	    if (! allValidChars(email)) {  // check to make sure all characters are valid
	        return false;
	    }
	    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
	        return false;
	    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
	        return false;
	    } else if (email.indexOf("@") == email.length-1) {  // @ must not be the last character
	        return false;
	    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
		return false;
	    } else if (email.indexOf(".") == email.length-1) {  // . must not be the last character
		return false;
	    }
	    return true;
	}
	
	function allValidChars(email) {
	  var parsed = true;
	  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
	  for (var i=0; i < email.length; i++) {
	    var letter = email.charAt(i).toLowerCase();
	    if (validchars.indexOf(letter) != -1)
	      continue;
	    parsed = false;
	    break;
	  }
	  return parsed;
	}

//  TELEFON

	function telefonCheck(ez)
		{
		var telefon = $(ez).val();
		if (telefon.length < 7)
			{
			$(ez).siblings("span").fadeIn("normal");
			return false;
			}
		else
			{
	    	return true;
			}
		}


//  FORM  

    $("form").submit(function() {
        var nevinput =  $(this).children('.beviteli_sor').children(".text.nev");
		var emailinput =  $(this).children('.beviteli_sor').children(".text.email");
		var telefoninput =  $(this).children('.beviteli_sor').children(".text.telefon");
		
		nevCheck(nevinput);
 		telefonCheck(telefoninput);
		validate(emailinput);
 		if (validate(emailinput) && nevCheck(nevinput) && telefonCheck(telefoninput))
 			{
 			return true;
 			}
 		else
 			{
 			return false;
 			}
    });
    
// AKTUÁLIS TANFOLYAMOK LENYITÁSA-CSUKÁSA
    $("#nyelvek_nagy_keret div.tanfolyamok-tesztek.aktualis-tanfolyamok p.cim").toggle(
            function(){
                var tartalom = $(this).siblings().children()[0];
                $(tartalom).slideDown("normal");
                $(this).css('background-image', 'url(style/img/arrow_up.gif)');
            }, function() {
                var tartalom = $(this).siblings().children()[0];
                $(tartalom).slideUp("normal");
                $(this).css('background-image', 'url(style/img/arrow_down.gif)')
    });
    
    $("#nyelvek_nagy_keret div.tanfolyamok-tesztek.aktualis-tanfolyamok p.cim").hover(function(){
        $(this).css('color', '#17320d');
        $(this).css('cursor', 'pointer');
    },
        function() {$(this).css('color', 'white');
    });
});