function openCat(catID)
{
	var actList = document.getElementById(catID);
	if (actList.style.display != 'block')
	{
		var allList = document.getElementsByTagName('ul');
		for (i=0; i<allList.length; i++)
		{
			var actElmntId = allList[i].id;
			if (actElmntId.indexOf('cat_') != -1 && actElmntId.indexOf('subcat_') == -1)
				allList[i].style.display = 'none';
		}
		actList.style.display = 'block';
	}
	else
		actList.style.display = 'none';
}

function openSubCat(subcatID)
{
	var actList = document.getElementById(subcatID);
	if (actList.style.display != 'block')
	{
		var allList = document.getElementsByTagName('ul');
		for (i=0; i<allList.length; i++)
		{
			var actElmntId = allList[i].id;
			if (actElmntId.indexOf('subcat_') != -1)
				allList[i].style.display = 'none';
		}
		document.getElementById(subcatID).style.display = 'block';
	}
	else
		actList.style.display = 'none';
}

function submitSearchForm()
{
	var f = document.getElementById('searchform2');
	//f.action = "/index.php?m=productlist&mode=search";
	f.submit();
}

function submitSearchFormText(e)
{
	var k_code = e.keyCode || e.which;
	if (k_code == 13)
		submitSearchForm();
}

function vote()
{
	var f = document.getElementById('voteform');
	
	var radio_choice = false;	for (counter = 0; counter < f.voteanswer.length; counter++)	{		if (f.voteanswer[counter].checked)			radio_choice = true; 	}	if (!radio_choice)	{		alert("Kérjük válasszon egy szavazási opciót!")	}
	else {
		f.submit();
	}}	
	
function cartsubmit(productID)
{
//	alert($('count_'+productID).value);
	var kosar_req = {
					 product_id: productID,
					 count: $('count_'+productID).value,
					 mode: "ajax"					 
					}
	req = $H(kosar_req);
	url = "/process.php?m=addcart";
	
	pars = req.toQueryString();

	var myAjax = new Ajax.Request( 
		url, 
			{ 
			method: 'post', 
			parameters: pars, 
			onComplete: showBasketResponse 
		});

	//document.getElementById('addtocart_' + productID).submit();
}

function showBasketResponse(req){
	temp = req.responseText.split("%end%");
	
	alert("A termék bekerült a kosarába!");
	$('items').innerHTML = 'Jelenleg <span class="orangebold">'+temp[0]+'</span> tétel';
	$('price').innerHTML = 'Összeg: <span class="orangebold">'+temp[1]+'</span>';
}

function loginformSubmit()
{
	var f = document.getElementById('loginform');
	f.submit();
}

function formatPrice(price)
{
	var cnt = 0;
	var newprice = "";
	
	for (i=price.length - 1; i>=0; i--)
	{
		cnt++;
		newprice = price.charAt(i) + newprice;
		if (cnt == 3)
		{
			newprice = " " + newprice;
			cnt = 0;
		}
	}
	
	return newprice;
}

function prepNewsletterSubmit()
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var f = document.getElementById('newsletterform');
	if (!filter.test(f.email.value))
		alert("A beírt e-mail cím szintaktikailag nem megfelelő!");
	else
		f.submit();
}

function SetCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) {
		nDays=1;
	}
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue) + ";path=/;expires="+expire.toGMTString();
}

function hideBeuszo(){
	document.getElementById("popup_layer").style.display="none";
	SetCookie("PetnetPopup", 1, 7);
}
