function RP(URL) { window.location.href=URL; }

function CheckLogin(f)
{	if (f.customer_email.value=="" || f.customer_email.value=="email")
	{	alert('Zadejte emailovou adresu ...');
		f.customer_email.focus();
		return false;
	}
	if (f.customer_password.value=="" || f.customer_password.value=="heslo")
	{	alert('Zadejte heslo ...');
		f.customer_password.focus();
		return false;
	}
	return true;
}

function CheckSearch(f)
{	if (f.vyhledat.value=="")
	{	alert('Zadejte slovo pro vyhledávání ...');
		f.vyhledat.focus();
		return false;
	}
	return true;
}

function cislaplus(myfield, e, plus)
{	var key; var keychar;
	if (window.event) key = window.event.keyCode;
	else if (e) key = e.which; else return true;
	keychar = String.fromCharCode(key);
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) return true;
	else if ((("0123456789"+plus).indexOf(keychar) > -1)) return true; else return false;
}

function checkMail(email)
{	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(email);
}

isDate = function(y, m, d)
{	if (typeof y == "string" && m instanceof RegExp && d)
	{	if(!m.test(y)) return 1;
		y = RegExp["$" + d.y], m = RegExp["$" + d.m], d = RegExp["$" + d.d];
	}
	d = Math.abs(d) || 0, m = Math.abs(m) || 0, y = Math.abs(y) || 0;
	return arguments.length != 3 ? 1 : d < 1 || d > 31 ? 2 : m < 1 || m > 12 ? 3 : /4|6|9|11/.test(m) && d == 31 ? 4        : m == 2 && (d > ((y = !(y % 4) && (y % 1e2) || !(y % 4e2)) ? 29 : 28)) ? 5 + !!y : 0;
};

function numberformat(n,DECIMAL_POINT,THOUSANDS_SEP)
{	n += '';
	x = n.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? DECIMAL_POINT + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + THOUSANDS_SEP + '$2');
	}
	return x1 + x2;
}

function IntoBasket(product_id, option_set_id)
{	product_quantity=Number(document.forms.frm_amount.product_quantity.value);
	if (product_quantity<=0) product_quantity=1;
	window.location.href='/scripts/intobasket.php?product_id='+product_id+'&option_set_id='+option_set_id+'&product_quantity='+product_quantity;
}

function EmptyBasket()
{	if (confirm('Opravdu si přejete vyprázdnit nákupní košík ?')) window.location.href='/scripts/clear_basket.php';
}

function RemoveItem(product_id, option_set_id)
{	window.location.href='/scripts/recount_basket.php?product_id='+product_id+'&option_set_id='+option_set_id;
}

function PutRating(product_id, product_rating_nr)
{	window.location.href='/scripts/put_rating.php?product_id='+product_id+'&product_rating_nr='+product_rating_nr;
}

function SbmtManForm(manufacturer_name_url, f)
{	f.action="/vyrobce/"+manufacturer_name_url;
	f.submit();
}

function RemoveVoucher()
{	window.location.href='/scripts/discount_voucher.php?A=RemoveVoucher';
}
function CheckNLForm(frm)
{	if (frm.newsletter_email.value=="" || frm.newsletter_email.value=="@")
	{	alert('Zadejte prosím Vaši emailovou adresu ...');
		frm.newsletter_email.focus();
		return false;
	}
	if (!checkMail(frm.newsletter_email.value))
	{	alert('Zadejte prosím správnou emailovou adresu ...');
		frm.newsletter_email.focus();
		return false;
	}
	return true;
}
function SetCheck(i, image_id)
{	f=document.forms.frm_amount;
	if (f.option_set_id.length!=undefined) document.forms.frm_amount.option_set_id[i].checked=true;
	imgobj=document.getElementById('product_img');
	if (image_id==-1)
	{
	} else
	{	imgobj.src="/upload/image/M/"+a_option_set_img[image_id];
		if (imgobj.parentNode.href!=undefined) imgobj.parentNode.href="/upload/image/L/"+a_option_set_img[image_id];
		// document.getElementById('cena').innerHTML=document.getElementById('cena-'+i).innerHTML;
	}
}

function formatCurrency(num)
{	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if (cents==0) cents="-";
	if(cents<10) cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+'.'+num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + ',' + cents);
}

function ValidPSC(PSC)
{	PSC=PSC.replace(" ","");
	var re=new RegExp("^\\d{5}$");
	return (re.test(PSC));
}

function addLoadEvent(func)
{	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{	window.onload = func;
	}
	else
	{	window.onload = function()
		{	oldonload();
			func();
		}
	}
}

function fbs_click()
{	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}