function verificaCookie() {
  document.cookie = 'verifica_cookie';
  var testcookie = (document.cookie.indexOf('verifica_cookie') != -1) ? true : false;
  return testcookie;
}

function getCookie(NameOfCookie) {
  if (document.cookie.length > 0) { 
    begin = document.cookie.indexOf(NameOfCookie+"="); 
    if (begin != -1) { 
      begin += NameOfCookie.length+1; 
      end = document.cookie.indexOf(";", begin);
      if (end == -1) end = document.cookie.length;
      return unescape(document.cookie.substring(begin, end)); 
    } 
  }
  return null; 
}

function setCookie(NameOfCookie, value, expiredays) {
  var ExpireDate = new Date ();
  ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
  document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()) + "; path=/";
}

function ChangePageSize(pagina,categoria) {
	var test = verificaCookie();
	if (test == false) {
		alert('Per utilizzare questo filtro è necessario che il tuo browser accetti i cookie!');
	} else {		
		var indice = document.getElementById("PageSize").selectedIndex;
		var PageSize = document.getElementById("PageSize").options[indice].value;						
		setCookie("PageSize_ArancioClima",PageSize,30);			
		if (categoria!='')
			location.href=pagina + "?cat=" + categoria
		else
			location.href=pagina;
	}
}

function ChangeMarca(pagina,categoria) {
	var test = verificaCookie();
	if (test == false) {
		alert('Per utilizzare questo filtro è necessario che il tuo browser accetti i cookie!');
	} else {		
		var indice = document.getElementById("Marca").selectedIndex;
		var Marca = document.getElementById("Marca").options[indice].value;				
		if (categoria!='')
			location.href=pagina + "?cat=" + categoria
		else
			location.href=pagina;
	}
}

function ChangeDisponibilita(pagina,categoria) {
	var test = verificaCookie();
	if (test == false) {
		alert('Per utilizzare questo filtro è necessario che il tuo browser accetti i cookie!');
	} else {		
		var indice = document.getElementById("Disponibilita").selectedIndex;
		var Disponibilita = document.getElementById("Disponibilita").options[indice].value;				
		setCookie("Disponibilita_ArancioClima",Disponibilita,30);										
		if (categoria!='')
			location.href=pagina + "?cat=" + categoria
		else
			location.href=pagina;
	}
}

function ChangeOrdinamentoPerPrezzo(pagina,categoria) {
	var test = verificaCookie();
	if (test == false) {
		alert('Per utilizzare questo filtro è necessario che il tuo browser accetti i cookie!');
	} else {		
		var indice = document.getElementById("OrdinamentoPerPrezzo").selectedIndex;
		var OrdinamentoPerPrezzo = document.getElementById("OrdinamentoPerPrezzo").options[indice].value;				
		setCookie("OrdinamentoPerPrezzo_ArancioClima",OrdinamentoPerPrezzo,30);		
		if (categoria!='')
			location.href=pagina + "?cat=" + categoria
		else
			location.href=pagina;
	}
}		

function ChangeFiltroTipologia(pagina,categoria) {
	var test = verificaCookie();
	if (test == false) {
		alert('Per utilizzare questo filtro è necessario\nche il tuo browser accetti i cookie!');
	} else {	
		var indice = document.getElementById("FiltroTipologia").selectedIndex;
		var FiltroTipologia = document.getElementById("FiltroTipologia").options[indice].value;			
		setCookie("FiltroTipologia",FiltroTipologia,30);		
		if (categoria!='')
			location.href=pagina + "?cat=" + categoria
		else
			location.href=pagina;
	}
}		
