function formcheck_order()
{
	var error_text = 'ok';
    if(document.getElementById('confirm').checked!=true)
    {
    	error_text='A Szállítási és fizetési feltételek elolvasása kötelező!';
    }
	return error_text;
}
	    
function addToCart(id, url)
{
	//count = document.getElementById('count_' + id).options[document.getElementById('count_' + id).selectedIndex].value;
	count = 1;
	saveCount(id, count, false);
	if (url) 
	    refreshCart(url);
	else
	    refreshCart();
}

function refreshCart(url) 
{ 
	$.get("webshop_ajax.php?action=getcart", {
	}, function(data) 
	{
		cart = document.getElementById('webshop_cart');
		if (cart)
		    cart.innerHTML = data;
		if (url)
    		    window.location = url;
/*		else
		    alert('Vásárláshoz kérjük regisztrálja magát ill. jelentkezzen be!'); */ 
	});
}
		
function saveCount(id, count, update)
{
	if (!count || count=="")
		return;
	$.get("webshop_save.php", {
	   		id : id ,
	   		count : count ,
	   		update : update
	  		}, function(data) 
	    		{
	  			totalPriceRefresh();
	    		});
//	productPriceRefresh(id);
}

function productPriceRefresh(id)
{
	$.get("webshop_ajax.php", {
			action: 'getproductprice',
			id : id
		}, function(data) 
		{
//			if (document.getElementById('price_' + id))
//				document.getElementById('price_' + id).innerHTML = number_format(data);
		});
}

function removeProduct(id)
{
	$.get("webshop_ajax.php", {
		action: 'removeproduct',
		id : id
	}, function(data) 
	{		
		refreshCart();
	});
}

function removeFromCart(id)
{
	if (!confirm('Biztosan törölni szeretné?'))
		return;
	$.get("webshop_ajax.php", {
		action: 'removeproduct',
		id : id
	}, function(data) 
	{		
		document.location = "index.php?pg=order";
	});
}

function totalPriceRefresh()

{
	$.get("webshop_ajax.php", {
			action: 'gettotalprice'
	}, function(data) 
	{
		totalSum=parseInt(data);
		grandSum=parseInt(data);
		
		var discount="";
		
		if(grandSum>50000)
		{
		    totalSum2=Math.round(totalSum*0.98);
		    totalSum2=number_format(totalSum-totalSum2);
		    discount = '<b><br /><br />Árengedmény: 2% ['+totalSum2+' Ft]</b>';
		}
		
		if(totalSum<10000)
		{
		    restSum=number_format(10000-totalSum);
		    document.getElementById('shipping_info').innerHTML = '<div><b>Postaköltség: 1 250 Ft</b></div><div>Vásároljon még <b>'+restSum+' Ft</b> összegben az ingyenes házhozszállításhoz.</div>'+discount;
		}
		else
		{
		    document.getElementById('shipping_info').innerHTML = '<b>Elérte a 10 000 Ft -os összeget, az Ön által rendelt termékek díjtalanul kerülnek kiszállításra.</b>'+discount;
		}

		if (document.getElementById('price_sum'))
		    document.getElementById('price_sum').innerHTML = number_format(data);
		if (document.getElementById('order_price_sum'))
		    document.getElementById('order_price_sum').innerHTML = number_format(data);
	});
}
	    
function isInteger(s) 
{
	return (s.toString().search(/^-?[0-9]+$/) == 0);
}
		
function onlyNumbers(e)
{
	var keynum
    var keychar
    var numcheck
        
    if(window.event) // IE
    {
    	keynum = e.keyCode 
    }                                                                                           
    else if(e.which) // Netscape/Firefox/Opera
    {
    	keynum = e.which
    }
                                                                                                        
    keychar = String.fromCharCode(keynum);
    numcheck = /\d/;
    return (numcheck.test(keychar)||keynum==8||keynum==9||(keynum>95&&keynum<106));
}

function number_format(v)
{
	var val = v.toString();
	var result = "";
	var len = val.length;
	while (len > 3){
		result = " " + val.substr(len-3,3) + result;
		len -=3;
	}
	return val.substr(0,len)+result;
}

function printCart() 
{
	myRef = window.open('print.php?item=cart','mywin','left=20,top=20,width=500,height=500,scrollbars=1,toolbar=0,resizable=0');
}

