function ValidateForm(formId) {
	var isValid = true;
	var isValidEmail = true;
	var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	var focusFirst = true;
	$.each($(formId).find(".must"), function() {
		$(this).css("background", "");
		if($(this).attr("value") == "") {
			$(this).css("background", "#cf9f9f");
			isValid = false;
			if (focusFirst) {
				$(this).focus();
				focusFirst = false;
			}
		}
	});
	$.each($(formId).find(".mustEmail"), function() {
		$(this).css("background", "");
		if(!re.test($(this).attr("value"))) {
			$(this).css("background", "#cf9f9f");
			isValid = false;
			if (focusFirst) {
				$(this).focus();
				focusFirst = false;
			}
		}
	});
	if (!isValid) $("#form_alert").show();
	return isValid;
}

function NewsletterInfo() {
	var name = "codes";
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results != null ) {
		if (results[1] == 1) document.write("<p>Erre a listára jelenleg nem lehet feliratkozni. Ez a lista elérte a maximális létszámot.<\/p>");
		else if (results[1] == 2) document.write("<p>Sikertelen feliratkozás, nem minden kötelező mező lett kitöltve.<\/p>");
		else if (results[1] == 3) document.write("<p>Ez az e-mail cím már tagja a listának.<\/p>");
		else if (results[1] == 4) document.write("<p>Ez az e-mail cím már egyszer feldolgozásra került, de sose lett megerősítve.<\/p>");
		else if (results[1] == 5) document.write("<p>Ezt az e-mail címet nem lehet hozzáadni a listához.<\/p>");
		else if (results[1] == 6) document.write("<p>Feldolgoztuk az e-mail címet. A feliratkozás megerősítéséhez szükséget levelet elküldtük.<\/p>");
		else if (results[1] == 7) document.write("<p>Sikeresen feliratkozott a listára.<\/p>");
		else if (results[1] == 8) document.write("<p>Az e-mail cím érvénytelen.<\/p>");
		else if (results[1] == 9) document.write("<p>A feliratkozás sikertelen, mert nem választott ki listát. Kérjük válasszon egyet és próbálja újra.<\/p>");
		else if (results[1] == 10) document.write("<p>Feldolgoztuk az e-mail címet. A leíratkozás megerősítéséhez szükséges levelet elküldtük.<\/p>");
		else if (results[1] == 11) document.write("<p>A leíratkozás sikeres.<\/p>");
		else if (results[1] == 12) document.write("<p>Ez az e-mail cím nem volt feliratkozva.<\/p>");
		else if (results[1] == 13) document.write("<p>Köszönük, hogy megerősítette a feliratkozást.<\/p>");
		else if (results[1] == 14) document.write("<p>Köszönük, hogy megerősítette a leíratkozást.<\/p>");
		else if (results[1] == 15) document.write("<p>A változtatásokat elmentettük.<\/p>");
		else if (results[1] == 16) document.write("<p>A feliratkozás sikertelen, mert egy nevet mindenképpen meg kell adni.<\/p>");
		else if (results[1] == 17) document.write("<p>Ez az e-mail cím a globális tiltó listán van.<\/p>");
		else if (results[1] == 18) document.write("<p>Kérem a helyes szöveget írja be a kép alapján.<\/p>");
	}
}

function RotateText(id) {
	var e = $(id).children(".show");
	if (e.next().text() != "") {
		$(e).fadeOut("slow", function() {
			$(e).next().fadeIn("slow", function() {
				e.removeClass("show");
				e.addClass("hide");
				e.next().removeClass("hide");
				e.next().addClass("show");
			});
		});
	}
	else {
		$(e).fadeOut("slow", function() {
			$(id).children().first().fadeIn("slow", function() {
				e.removeClass("show");
				e.addClass("hide");
				$(id).children().first().removeClass("hide");
				$(id).children().first().addClass("show");
			});
		});
	}
}

function TimedEvents() {
	$(document).everyTime(2000, function() {
	  RotateText(".referenciak");
	});
}

$(function() {
	$("#menu ul li.menu-main").hover(
	  function () {
	    $(this).find("a").first().toggleClass("hover");
	    $(this).find("ul").toggleClass("hide");
	  }
	);
	$("#topstory .topstory-block").hover(
	  function () {
			$(this).children().children().stop().fadeTo("slow", 0.9);
			$(this).children().stop().animate({
				backgroundPosition: '-1px 0'
			}, 490, function() {});
			$(this).siblings().children().css("backgroundPosition", "-100px 0");
			$(this).siblings().stop().animate({
				width: '78px'
			}, 490, function() {});
			$(this).stop().animate({
				width: '400px'
			}, 500, function() {});
	  },
	  function () {
			$(this).children().children().stop().fadeOut("fast");
			$(this).stop().animate({
				width: '142px'
			}, 490, function() {});
			$(this).siblings().stop().animate({
				width: '142px'
			}, 500, function() {});
			$(this).children().stop().animate({
				backgroundPosition: '-100px 0'
			}, 500, function() {});
	  }
	);
	$(".referenciak").hover(function() {
		$(document).stopTime();
	},
	function() {
		TimedEvents();
	});
	$(document).ready(function() {
	  TimedEvents();
	});
});

