function submitInBackground(s, f) {$(f).send({onSuccess: function(r){$(s).update(r.responseText);}});return false;}
function addToCart(card) {
    var xhr = new Xhr('/addToCart.php', {
        params: {card: card},
        onSuccess: function(r) {
            if (r.successful()) {
                Lightbox.show(r.responseText);
            }
        }
    });
    xhr.send();
}
function removeFromCart(id) {
    var xhr = new Xhr('/deleteProductFromCart.php', {
        params: {id: id},
        onSuccess: function(r) {
            if (r.successful()) {
                window.location = window.location;
            }
        }
    });
    xhr.send();
}

function updateCart(cartForm){
    $(cartForm).send({
        onSuccess: function(r){window.location = window.location;}
    });    
}

function nev(f,n,m) {
    var v=trim(f[n].value);
    if (v==null || v.length<=0) {
        showValidationError(f,n,m);
        return false;
    }
    return true;
}

function showValidationError(f,n,m) {
    var el = $(f[n]);
    var t = new Tooltip(el);
    t.setText(m);
    t.show();
    el.focus();
    el.onChange(function(){
        t.hide();
    });
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
document.write('<div id="spinner" style="display:none;"><img src="/img/spinner.gif"/></div>');
Xhr.Options.spinner = 'spinner';

