// Nota: questo js gestisce le funzioni comuni ai due carrelli: quello della colonna di destra e quello della pagina di riepilogo 

// contiene il sito attuale (it, en, int, ecc.). Viene compilato dai metodi init del carrello di destra e di dettaglio
var site;

// Overload del metodo clone di Element per gestire anche il suffisso da dare agli id degli elementi (come fa DWR)
function overloadElementClone() {
	Element.implement({
	    clone: function(contents, keepid, suffix){
			switch ($type(this)){
				case 'element':
					var attributes = {};
					for (var j = 0, l = this.attributes.length; j < l; j++){
						var attribute = this.attributes[j], key = attribute.nodeName.toLowerCase();
						if (Browser.Engine.trident && (/input/i).test(this.tagName) && (/width|height/).test(key)) continue;
						var value = (key == 'style' && this.style) ? this.style.cssText : attribute.nodeValue;
						if (!$chk(value) || key == 'uid' || (key == 'id' && !keepid && suffix == '')) continue;
						if (key == 'id' && suffix != '')
							value += suffix;
						if (value != 'inherit' && ['string', 'number'].contains($type(value))) attributes[key] = value;
					}
					var element = new Element(this.nodeName.toLowerCase(), attributes);
					element.inject(this, 'before');
					if (contents !== false){
						for (var i = 0, k = this.childNodes.length; i < k; i++){
							var child = Element.clone(this.childNodes[i], true, keepid, suffix);
							if (child) element.grab(child);
						}
					}
					return element;
				case 'textnode': return document.newTextNode(this.nodeValue);
			}
			return null;
		}
	});
}

// Aumenta la quantita indicata nell'elemento
function aumentaQuantita(elementId) {
	var value = document.getElementById(elementId).value; 
	if (value < 10){
		document.getElementById(elementId).value++;
		return true;
	}else{
		return false;
	}
}

//Decrementa la quantita indicata nell'elemento
function decrementaQuantita(elementId) {
	var value = document.getElementById(elementId).value; 
	if (value > 1){
		document.getElementById(elementId).value--;
		return true;
	}else{
		return false;
	}
	
}

function controllaNumeroFigurina(numeroFigurina) {
	if (!numeroFigurina.test(/^\d*$/)) {
		erroreNumeroFigurina = $('corniceInterna').get('erroreNumeroFigurina').replace('##', numeroFigurina);
		alert(erroreNumeroFigurina);
		return false;
	}
	return true;
}

