String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
function HighliteOptionSet()
{	$("#option_set_id").fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
	$("#select_option_set_id").css("background-color","#FF0000");
}
function CheckLogin(f)
{	if (f.customer_email.value=="" || f.customer_email.value=="@")
	{	alert(LANG[0]+' ...');
		f.customer_email.focus();
		return false;
	}
	if (f.customer_password.value=="" || f.customer_password.value=="heslo")
	{	alert(LANG[1]+' ...');
		f.customer_password.focus();
		return false;
	}
	return true;
}

function CheckSearch(f)
{	if (f.search_string.value=="")
	{	alert(LANG[2]+' ...');
		f.search_string.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 BasketAction(A)
{	switch (A)
	{	case "CASHDESK":
			document.forms.frm_basket.action.value='CASHDESK';
			document.forms.frm_basket.submit();
		break;
		case "RECOUNT":
			document.forms.frm_basket.action.value='RECOUNT';
			document.forms.frm_basket.submit();
		break;
		case "EMPTY":
			if (confirm(LANG[3])) window.location.href='/scripts/clear_basket.php';
		break;
	}
}

function RemoveItem(product_id, option_set_id, accessory_product_id, accessory_option_set_id, A)
{	window.location.href='/scripts/recount_basket.php?product_id='+product_id+'&option_set_id='+option_set_id+'&accessory_product_id='+accessory_product_id+'&accessory_option_set_id='+accessory_option_set_id+'&A='+A;
}

function RemoveVoucher(discount_voucher_id)
{	window.location.href='/scripts/recount_basket.php?A=RemoveVoucher&discount_voucher_id='+discount_voucher_id;
}
function RemoveSphere()
{	window.location.href='/scripts/recount_basket.php?A=RemoveSphere';
}

function CheckForm(frm)
{	if (frm.newsletter_email.value=="")
	{	alert(LANG[4]+" ...");
		frm.newsletter_email.focus();
		return false;
	}
	if (!checkMail(frm.newsletter_email.value))
	{	alert(LANG[5]+" ...");
		frm.newsletter_email.focus();
		return false;
	}
	return true;
}

function SwapCarusel(from,to)
{	$('#carusel_'+from).fadeToggle('fast', function () { 
		$('#carusel_'+to).fadeToggle('fast');
	});
}

function checkservisni(f)
{	if (f.nazev_vyrobku.value=="")
	{	alert(LANG[6]+" ...");
		f.nazev_vyrobku.focus();
		return false;
	}
	
	if (f.popis_zavady.value=="")
	{	alert(LANG[7]+" ...");
		f.popis_zavady.focus();
		return false;
	}
	if (f.cislo_nd.value=="")
	{	alert(LANG[14]+" ...");
		f.cislo_nd.focus();
		return false;
	}
	if (f.telefon.value=="")
	{	alert(LANG[8]+" ...");
		f.telefon.focus();
		return false;
	}
	if (f.Jmeno.value=="")
	{	alert(LANG[9]+" ...");
		f.Jmeno.focus();
		return false;
	}	
	if (f.ulice.value=="")
	{	alert(LANG[10]+" ...");
		f.ulice.focus();
		return false;
	}
	if (f.email.value=="")
	{	alert(LANG[11]+" ...");
		f.email.focus();
		return false;
	}
	if (f.obec.value=="")
	{	alert(LANG[12]+" ...");
		f.obec.focus();
		return false;
	}
	if (f.psc.value=="")
	{	alert(LANG[13]+" ...");
		f.psc.focus();
		return false;
	}		
	return true;
}

function SetSlider(silider_el, html_min_el, html_max_el, form_min_el, form_max_el, min_val, max_val, set_min_val, set_max_val, left_unit, right_unit)
{	silider_el.slider({
		range: true,
		min: min_val,
		max: max_val,
		values: [ set_min_val, set_max_val ],
		slide: function( event, ui ) {
			html_min_el.html( (left_unit?unit+' ':'')+ui.values[0] +(right_unit?' '+right_unit:'') );
			html_max_el.html( (left_unit?unit+' ':'')+ui.values[1] +(right_unit?' '+right_unit:'') );
			if (min_val==ui.values[0]) form_min_el.value=""; else form_min_el.value=ui.values[0];
			if (max_val==ui.values[1]) form_max_el.value=""; else form_max_el.value=ui.values[1];
		}
		,stop: function(event, ui) {
			
		}
	});
	html_min_el.html( (left_unit?unit+' ':'')+silider_el.slider( "values", 0 )+(right_unit?' '+right_unit:'') );
	html_max_el.html( (left_unit?unit+' ':'')+silider_el.slider( "values", 1 )+(right_unit?' '+right_unit:'') );
}

function set_and_submit(frm,fld,val)
{	fld.value=val;
	frm.submit();
	return true;
}
