function cerca_modello(id_marca) {
	get('/wp-content/themes/cellulari/includes/selectmodello.php?id='+id_marca,'compara_modello')
}

function removeallcompare (){
		eraseCookie('cellulari');
		location.reload(true);
	};

function get(url,id) {
	  if (document.getElementById) {
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	  }
	  if (x) {
		x.onreadystatechange = function() {
		  if (x.readyState == 4 && x.status == 200) {
			el = document.getElementById(id);
			el.innerHTML = x.responseText;
		  }
		}
		x.open("GET", url, true);
		x.send(null);
	  }
}

function countonchange(thissel) {
var selCount = 0;
	for (var i=0; i<thissel.length; i++) {
	  if (thissel[i].selected) {
	    selCount += 1;
    	}
	  }
	if(selCount>5)
		alert("Puoi scegliere massimo 5 telefoni");
}

var counter = 0;

function addCompareBox(mycode){	
	counter++;
	
	if (counter <= 5) {
		
		// save cookie
		if (readCookie('cellulari') != null) mycookie = readCookie('cellulari') +','+ mycode;
		else mycookie = mycode;
		
		createCookie('cellulari', mycookie, 100);
	}
	else {
		// write a message
		$('#frm-compare').prepend('<div class="alert">Possono essere confrontati al massimo <strong>5 cellulari</strong> per volta!</div>')
		$('#frm-compare .alert').css({ opacity: 0.95 });
		
		window.setTimeout("$('#frm-compare .alert').fadeOut(1000, function(){ $(this).remove(); });", 2000);
		counter = 5;
	}
}