$(document).ready(function(){

	$(".head_box_search .input_bg input").focusin(function(){
		if($(this).val() == 'Keresés') {
			$(this).val('');
		}
	});
	
	$(".head_box_search .input_bg input[name=search]").focusout(function(){
		if($(this).val() == '')
			$(this).val('Keresés');
	});


	$(".hirlevel .hirlevel_r input[name=hirlevel_nev]").focusin(function(){
		if($(this).val() == 'Név:')
			$(this).val('');
	});
	
	$(".hirlevel .hirlevel_r input[name=hirlevel_nev]").focusout(function(){
		if($(this).val() == '')
			$(this).val('Név:');
	});

	$(".hirlevel .hirlevel_r input[name=hirlevel_email]").focusin(function(){
		if($(this).val() == 'E-mail:')
			$(this).val('');
	});
	
	$(".hirlevel .hirlevel_r input[name=hirlevel_email]").focusout(function(){
		if($(this).val() == '')
			$(this).val('E-mail:');
	});

	notifyMsg();

});

function notifyMsg (strData) {
	if (strData) {
		$("div.notify_area").html(strData);
	}

	var msg = $("div.notify_area").html();
	if (msg != "") {
		$("div.notify_area").fadeIn(400);
		$("div.notify_area").css('position','fixed');
		$("div.notify_area").delay(4000).fadeOut(1000);
	}
}

function trim (str) {
	if(str){
		var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
		while (ws.test(str.charAt(--i)));
		return str.slice(0, i + 1);
	}
}

function hirlevel_feliratkozas(){
	var strName = $('.hirlevel .hirlevel_r input[name=hirlevel_nev]').val();
	var strEmail = $('.hirlevel .hirlevel_r input[name=hirlevel_email]').val();
	
	var emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
	
	if ( trim(strName) == '' || trim(strName) == 'Név:' ) {
		notifyMsg("Kérem adja meg a nevét is!");
		return false;
	}else if ( !emailRegExp.test(strEmail) ) {
		notifyMsg("Nem megfelelő az e-mail cím!");
		return false;	
	} 
	
	var strurl = "ws_modul.php?s=newsletter_subscribe&name="+strName+"&email="+strEmail;

	$.ajax({
		async: false,
		type: "POST",
		url: strurl,
		success: function (msg) {
			if(msg=='OK'){
				notifyMsg("Sikeres feliratkozás!");
			}else if(msg=='ERROR'){
				notifyMsg("Sikertelen feliratkozás, kérem próbálja újra!");
			}else if(msg=='USED'){
				notifyMsg("Ezzel az e-mail címmel már korábban feliratkozott!");			
			}
			$(".hirlevel .hirlevel_r input[name=hirlevel_nev]").val("Név:");
			$(".hirlevel .hirlevel_r input[name=hirlevel_email]").val("E-mail:");
		}
	});
	return true;
}

function winloc(url){
	window.location = url;
}

