function get(obj)
{
	return document.getElementById(obj);
}

/*--------------------*/
/* Fornax függvényei */
/*------------------*/

function createform(inputs) {
	obj=document.createElement("FORM");
	document.body.appendChild(obj);
	obj.method='post';
	obj.enctype='multipart/form-data';
	obj.encoding = "multipart/form-data";

	for (i=0;i<inputs.length;i++) {
		obj2=document.createElement("INPUT");
		obj2.type='hidden';
		obj2.name=inputs[i][0];
		obj2.value=inputs[i][1];
		obj.appendChild(obj2);
	}	

	return obj;
}

/*---------------------*/
/* DonLaca függvényei */
/*-------------------*/

function isempty(str)
{
	r = new RegExp("^[ .*]$");
	return (r.test(str) || str.length == '');
}

function iecheck()
{
	var pos = navigator.userAgent.indexOf("MSIE ");
	if (pos == -1) return false;
	var version = navigator.userAgent.substring(pos + 5);
	return (((version.indexOf("5.5") == 0) || (version.indexOf("6") == 0)  || (version.indexOf("7") == 0)) && (navigator.platform == ("Win32")));
}

function ie_png_check()
{
	var pos = navigator.userAgent.indexOf("MSIE ");
	if (pos == -1) return false;
	var version = navigator.userAgent.substring(pos + 5);
	return ((version.indexOf("5.5") == 0) || (version.indexOf("6") == 0));
}

// PNG ALPHA CHANNEL IMG-RE //
function iepng_alphachannel(imgid,timg,size)
{
	if(ie_png_check())
	{
		d = document.getElementById(imgid);
		origsrc = d.src;
		d.src = timg;
		d.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + origsrc + "',sizingMethod='image')";
		d.width = size[0];
		d.height = size[1];
	}
}


function emailchange(obj,cim,inner)
{
	d = document.getElementById(obj);
	r = new RegExp("#");
	n = new RegExp("\\*","g");
	cim = cim.replace(r,"@");
	cim = cim.replace(n,".");
	d.href = "mailto:"+cim;
	if(inner) d.innerHTML = cim;
}

/*-------------------*/
/* közös függvények */
/*-----------------*/

function highlight(str,rpl) {	
	var exps=str.innerHTML.split(rpl);
	var ihtml='';
	var nyito;
	for (var i=0;i<exps.length;i++) {		
		for (var j=0;j<exps[i].length;j++) {
			if (exps[i].substr(j,1)=='<') nyito=true;
			if (exps[i].substr(j,1)=='>') nyito=false;
		}

		if (!nyito) {
			if (i<exps.length-1) ihtml+=exps[i]+"<span class='raise'>"+rpl+"</span>"; else ihtml+=exps[i];
		}
		else {
			if (i<exps.length-1) ihtml+=exps[i]+rpl; else ihtml+=exps[i];
		}
	}
	str.innerHTML=ihtml ;
}

function checkValidEmail(mailstr) {
	r = new RegExp("^[0-9a-zA-Z\\._\\-]{2,}@([0-9a-zA-Z_\\-]{2,}\\.){1,7}[a-zA-Z]{2,3}$");
	return r.test(mailstr);
}








function search_open() 
{
	obj = document.getElementById('kereso_box');
	if(obj.style.display == 'none') 
	{
		obj.style.display = 'block';
		document.getElementById('searchtext').value = '';
	} 
	else
	{
		obj.style.display = 'none';	
	}
}

function show_submenu(id) {
	obj = document.getElementById('submenu_'+id);
	if(obj.style.display == 'none')
	{
		obj.style.display = 'block';
		document.getElementById('link_'+id).className = 'menu_active';
	}
	else
	{
		obj.style.display = 'none';
		document.getElementById('link_'+id).className = '';
	}
}

function getAjax()
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				//A böngésző nem támogatja az ajaxot
				return false;
			}
		}
	}
	return xmlHttp;
}


function hirlevel_check()
{
	if(document.hirlevel.nev.value == 'Írja ide a nevét' || isempty(document.hirlevel.nev.value))
	{
		alert('Nem adta meg a nevét!');	
	}
	else if(!checkValidEmail(document.hirlevel.email.value))
	{
		alert('Érvénytelen e-mail cím formátum!');	
	} 
	else
	{	
		document.getElementById("hirlevel_loader").style.display = "inline";
		document.getElementById("hirlevel_gomb").style.display = "none";
		var xmlHttp = new getAjax();
		xmlHttp.onreadystatechange = function()
		{
			if(xmlHttp.readyState==4)
			{
				document.getElementById("hirlevel_loader").style.display = "none";
				document.getElementById("hirlevel_gomb").style.display = "inline";
				document.hirlevel.nev.value = 'Írja ide a nevét';
				document.hirlevel.email.value = 'Írja ide az e-mail címét';
				alert('Sikeresen feliratkozott a hírlevelünkre!');
			}
		}
		
		xmlHttp.open("POST","/takarekakademia/process/hirlevel_feliratkozas.php",true);
		xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=iso-8859-2");
		xmlHttp.setRequestHeader("Request-type","XMLHttpRequest");		
		if (xmlHttp.overrideMimeType)	xmlHttp.setRequestHeader("Connection","close");
		querystr = "nev="+document.hirlevel.nev.value+"&email="+document.hirlevel.email.value;
		xmlHttp.send(querystr);	
	}
}

function kereso_chk() 
{
	if(isempty(document.keresoform.keresett_szo.value))
	{
		alert('Nem adta meg a keresendő kifejezést!');		
	}
	else
	{
		document.keresoform.submit();	
	}
}

function swf_search()
{
	d = document.getElementsByTagName("DIV");
	r = new RegExp("^flash_[0-9]+$");
	for(var i = 0; i<d.length; i++)
	{
		if(r.test(d[i].id))
		{
			path = d[i].innerHTML;
			w = d[i].style.width.replace("px","");
			h = d[i].style.height.replace("px","");
			swf_insert(d[i].id,path,w,h);
		}
	}
}

function swf_insert(to,flash,w,h)
{
	var addflash='';
	if(iecheck()){
	addflash+='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+w+'" height="'+h+'">';
	addflash+='<param name="movie" value="'+flash+'">';
	addflash+='<param name="quality" value="high">';
	addflash+='<param name="wmode" value="opaque">';
	addflash+='</object>';
	}
	if (!iecheck()) {
		addflash+='<object data="'+flash+'" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'">';
		addflash+='<param pluginurl="http://www.macromedia.com/go/getflashplayer">';
		addflash+='<param name="quality" value="high">';
		addflash+='<param name="wmode" value="opaque">';
		addflash+='</object>';
	}
	document.getElementById(to).innerHTML=addflash;
}
