var RE_E_MAIL = /[\w\d\-_.]+@[\w\d\-_.]+?\.\w\w\w*/g;

$(document).ready(function() {
	$('a')
		.filter('.help_opener').each(function() {
				var wrapped = $(this);
				var href = wrapped.attr('href');
				wrapped.attr('href', 'javascript:void(0)');
				wrapped.removeAttr('target');
				wrapped.click(function() {
					return open_help_window(href);
				})
			}).end()
		.filter('.print_opener').each(function() {
				var wrapped = $(this);
				var href = wrapped.attr('href');
				wrapped.attr('href', 'javascript:void(0)');
				wrapped.removeAttr('target');
				wrapped.click(function() {
					return open_print_window(href);
				})
			}).end()
		.filter('[href=#]').click(function() {
				alert('A kért hivatkozás fejlesztés alatt áll, ezért '
					+ 'jelenleg nem elérhető.');
				return false;
			})

	if (typeof history != 'undefined'
			&& history.length > 0)
		$('div.insert_back_link').before(
			'<div class="indented"><a href="javascript:history.go(-1)" class="back">Vissza</a></div>'
		);

/*
	$('img').each(function() {
		var src = $(this).attr('src');
	});
*/
});

function open_help_window(path)
{
	var help_win = window.open(
		path,
		'help_win',
		'height=500,width=570,resizable=yes,scrollbars=yes');
	help_win.focus();
	return false;
}

function open_print_window(path)
{
	var print_win = window.open(
		path,
		'print_win',
		'height=570,width=750,resizable=yes,scrollbars=yes');
	print_win.focus();
	return false;
}

function format_number(num, separator)
{
	var formatted = '';

	if (typeof separator == 'undefined') separator = ' ';
	num = trim(num);
	var len = num.length;
	var n =  len % 3;
	var i = 0;
	while(i < len)
	{
		for (j = 0; j < n; ++j, ++ i)
			formatted += num.charAt(i);
		formatted += separator;
		n = 3;
	}
	formatted = formatted.substr(0, formatted.length - 1);
	return formatted;
}

function trim(str)
{
	String(str).match(/^[\s ]*(.*?)[\s ]*$/gi)
	return RegExp.$1;
}

function is_email_valid(str)
{
	return str.match(/[\w\d\-_.]+@[\w\d\-_.]+?\.\w\w\w*/g);
}

function is_phone_number_valid(str)
{
	return str.match(
		/^(|(^(|\+36|0036|06)[\-/\( ]*(((|1|20|30|70)[\-/\) ]*[0-9\- ]{7,})|\d{2}[\-/\) ]*[0-9\- ]{6,})))$/g);
}

function popup(u, w, h)
{
	var x = (screen.availWidth - w) / 2;
	if (x < 0) x = 0;
	var y = (screen.availHeight - h) / 2;
	if (y < 0) y = 0;
	popupwin = window.open(u,"popupwin","width="+w+",height="+h+",left="+x+",top="+y);

	popupwin.focus();
}

