	function addFavorito(id){
		supportBusinessLogic.addAnuncioMotoFavorito(id+0, retornoAdd);
	}
	function retornoAdd(favorito){
		if (favorito.statusOperacao == "true"){
			var idAnunc = favorito.anuncioId;
			document.getElementById("favLink"+idAnunc).innerHTML = "<span class=\"ico-trans bg-bt-adc-fav\"></span> Remover dos meus favoritos";
			document.getElementById("favLink"+idAnunc).href = "javascript:removeFavorito("+idAnunc+")";
		}else{
			alert(favorito.message);
		}
	}
	function removeFavorito(id){
		supportBusinessLogic.removeFavorito(id, retornoRemove);
	}
	function retornoRemove(data){
		if (data[0] == "true"){
			var idAnunc = data[1];
			document.getElementById("favLink"+idAnunc).innerHTML = "<span class=\"ico-trans bg-bt-adc-fav\"></span> Adicionar aos favoritos";
			document.getElementById("favLink"+idAnunc).href = "javascript:addFavorito("+idAnunc+")";
		}else{
			alert(data[1]);
		}	
	}

	function compareAnuncio(id){
		if (document.getElementById("chk"+id).checked == true){
			addComparador(id);
		}else{
			removeComparador(id);
		}
	}
	
	function addComparador(idAnunc){
		supportBusinessLogic.addComparador(idAnunc, retornoComparador);
	}

	function retornoComparador(comparador){
		if (comparador.status == true){
			if (document.getElementById('compImg') != null){
				var element = document.getElementById('compImg');
				element.src = "/" + comparador.anuncioImagePath;
				element.width="60"; 
				element.height="46";
				element.alt=comparador.anuncioDesc;
				element.title=comparador.anuncioDesc;
				element.id = comparador.anuncioId;
			}
			if (document.getElementById('removeImg') != null){
				var element = document.getElementById('removeImg');
				element.className = "remove";
				element.id = "remove"+comparador.anuncioId;
			}
			if (document.getElementById('linkRemove')!= null){
				var element = document.getElementById('linkRemove');
				element.href = "javascript:removeComparador("+comparador.anuncioId+");";
				element.id = "link"+comparador.anuncioId;
			}
			
		}else{
			document.getElementById("chk"+comparador.anuncioId).checked = false;
			alert(comparador.message);
		}	
	}

	function removeComparador(idAnunc){
		supportBusinessLogic.removeComparador(idAnunc, retornoRemoveComparador);
	}

	function retornoRemoveComparador(comparador){
			var img = document.getElementById(comparador.anuncioId);
			var td = img.parentNode;
			var tr = td.parentNode;
			var tdId = td.id;
			td.removeChild(img);
		
			var span = document.getElementById("remove"+comparador.anuncioId);
			var aSpan = span.parentNode;
			aSpan.removeChild(span);
			var tdLink = aSpan.parentNode;
			
			img.src = "/img/x.gif";
			img.width="60"; 
			img.height="46";
			img.alt="Adicione uma moto";
			img.title="Adicione uma moto";
			img.id = 'compImg';

			span.className = "semRemove";
			span.id = "removeImg";
			
			aSpan.id = "linkRemove";
			aSpan.appendChild(span);
			
			td.parentNode.removeChild(td);
			tdLink.parentNode.removeChild(tdLink);
			
			var newtd = tr.insertCell(8);
			newtd.className = "conteudo-img";
			newtd.appendChild(img);
			
			var newtd = tr.insertCell(9);
			newtd.appendChild(aSpan);
			
			if (document.getElementById('chk'+comparador.anuncioId) != null){
				document.getElementById('chk'+comparador.anuncioId).checked = false;
			}
			
			
	}
	function abre(url,janela,larg,alt,scroll,pos1,pos2){
        window.open(url,janela,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scroll+',resizable=no,copyhistory=no,top="+pos1+",left="+pos2+",screenY="+pos1+",screenX="+pos2+",width="+larg+",height="+alt);
    }
	
	function goToComparador(retorno){
		if(retorno == true){
			window.location = "/anunciosv2/comparaAnuncioMoto.html";
		}else{
			alert("Selecione os anúncio que deseja comparar!");
		}
	}
	
