// JavaScript Skin 2.0

//Tag Loc Lomadee - Inicio
function getValorTagEliminandoTagsNoValor(tag) {
      if (tag != undefined) {
            var value = tag.innerHTML.replace(new RegExp('</[^>]+>|<[^>]+>', 'g'),'');
            return value;
      }
      return null;
}

function getValorIntegerAPartirCookie(nomeCookie, nomePropriedade) {
      var valorCookie = getCookieValue(nomeCookie);
      if (valorCookie == null || valorCookie == '') {
            return null;
      }
      var valorSplited = valorCookie.split(nomePropriedade + '=')
      if (valorSplited[1] != null) {
            return valorSplited[1].match(/\d+/);
      }
      
      return null;
}

function getRefinosLoc() {
   var refinos = null;
   if (window.location.href.indexOf('?') > -1){
	   refinos = window.location.href.split('?')[1];
   }
   return refinos;
}

function getCookieValue(name) {
 var start = document.cookie.indexOf( name + "=" );
 var len = start + name.length + 1;
 if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {return null;}
 if ( start == -1 ) return null;
 var end = document.cookie.indexOf(";",len);
 if ( end == -1 ) end = document.cookie.length;
 return unescape( document.cookie.substring(len,end));
}
//Loc Lomadee - Fim

function expandrefino(){ref=document.getElementById('refinojs');tit=document.getElementById('titulojs');if(ref.style.display=='none'){ref.style.display='inline';tit.style.display='none';}else{ref.style.display='none';tit.style.display='inline';}}

function showBox(idcarac){var divmais = document.getElementById('div_mais_'+idcarac);var divmenos =document.getElementById('div_menos_'+idcarac);if(divmais.show!=true){divmais.style.display='block';divmenos.style.display='none';divmais.show=true;}else{divmais.style.display='none';divmenos.style.display='block';divmais.show=false;}}function showMore(idcarac){var divmais = document.getElementById('div_seis_mais_'+idcarac);var divmenos =document.getElementById('div_seis_menos_'+idcarac);if(divmais.show!=true){divmais.style.display='block';divmenos.style.display='none';divmais.show=true;}else{divmais.style.display='none';divmenos.style.display='block';divmais.show=false;}}

function toogleRefino(n) {
	if(n=='1') {
		document.getElementById('refinojs').style.display = "block";
		document.getElementById('titulojs').style.display = "none";
	}	
	else {
		document.getElementById('refinojs').style.display = "none";
		document.getElementById('titulojs').style.display = "block";
	}
}

$(function(){
	$('div.prod_ref_int h3').click(function(){
	h3 = this;
	$(h3).parent().find('div').slideToggle('fast', function(){$(h3).toggleClass("bg_mais")});
	})
	$('div.prod_ref_int_u h3 ').click(function(){
	h3 = this;
	$(h3).parent().find('div').slideToggle('fast', function(){$(h3).toggleClass("bg_mais")});
	})
	$('div.refino_resp h3').click(function(){
	h3 = this;
	$(h3).parent().find('form').slideToggle('fast', function(){$(h3).toggleClass("bg_mais")});
	})
});

function checkChars(o) {
	if(o.value.length==1) {
	if(o.value.charAt(0) == " ") o.value="";
	}
	if(o.value.length>1) { 
	for(var i=0; i<=o.value.length; i++) {				
	if(o.value.charAt(i)==" " && o.value.charAt(i-1)==" ") {
	o.value = o.value.substring(0, o.value.length-1); 
	}
	}
	}	
}

function has2Chars(o, msg) {
	if(o.value.length < 2){
		alert(msg || 'Por favor, digite alguma palavra-chave');
		o.focus();
		return false;
	}
	else return true;
}

function DoSearch(formname) {
	d = eval(formname);
	var x= d.text.value;
	x = x.replace(/^\s*(.*)/, "$1");
	x = x.replace(/(.*?)\s*$/, "$1");
}

function notfound(imagem, country){
	imagem.onerror = null;
	var width = Math.round(imagem.width / 50) * 50;
	width = Math.min(200, width);
	
	imagem.src = (country == 'pt_BR') ? 'http://imagem.buscape.com.br/bp7/indisponivel_' + width +'.gif' 
									  : 'http://image.buscape.com/nodisponible_'+ width +'.gif';
	
}

function rarray(id){var	height;eval("height=document.img"+id+".height;"); if(height==0)var timer=setTimeout("rarray("+id+");",100); else if(height>=100)eval("document.img"+id+".height=100;");}
function reorganizar_procura(imagem){var nome=imagem.name;var p=new RegExp("img([0-9]+)","ig");var m=p.exec(nome);if(m.length==2)var timer=setTimeout("rarray("+m[1]+");",100);}
function disp(){document.getElementById("querydescription").style.display="block";   }

//Função dos banners
function write_adserver(id){
if( id != '-1' ){
	var txt=id;
	if(txt.length <= 5){
		document.writeln ("<script language='JavaScript' type='text/javascript'>");
		document.writeln ("<!--");
		document.writeln ("if (!document.phpAds_used) document.phpAds_used = ',';");
		document.writeln ("phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);");
		document.writeln ("document.write (\"<\" + \"script language='JavaScript' type='text/javascript' src='\");");
		document.writeln ("document.write (\"http://tuaviso.net/adserverX/adjs.php?n=\" + phpAds_random);");
		document.writeln ("document.write (\"&amp;what=zone:" + id + "\");");
		document.writeln ("document.write (\"&amp;exclude=\" + document.phpAds_used);");
		document.writeln ("if (document.referrer)");
		document.writeln ("document.write (\"&amp;referer=\" + escape(document.referrer));");
		document.writeln ("document.write (\"'><\" + \"/script>\");");
		document.writeln ("//-->");
		document.writeln (" <\/script> ");
	}else{
			
		mas = "'";
		if(typeof(words) != 'undefined'){
			mas += "&kw_autos=" + words;
			mas += "&kw_computadora=" + words;
		}			
	
		document.writeln ('<scr'+'ipt type="text/javascript" language="JavaScript1.1">');
		document.writeln ('<!--');
		document.writeln ('var rnd = (new String(Math.random())).substring(2,8) + (((new Date()).getTime()) & 262143);');
		document.writeln ("document.write('<scri' + 'pt language=\"JavaScript1.1\" type=\"text/javascript\" src=\"http://ads.us.e-planning.net/"+ txt +"?o=j&rnd=' + rnd + "+mas+"\"></scr' + 'ipt>');");
		document.writeln ('// -->');
		document.writeln ('</scr'+'ipt>');
		
	}
	}
}

/* PROC UNICO */

function OpenSel(op) {
	if (op == 1) {
		document.getElementById('precoescondido').style.display="none";
		document.getElementById('precoamostra').style.display="block";
	} else {
		document.getElementById('precoescondido').style.display="block";
		document.getElementById('precoamostra').style.display="none";
	}
}

function OpenSel(op) {
	if (op == 1) {
		document.getElementById('precoescondido').style.display="none";
		document.getElementById('precoamostra').style.display="block";

	}else {
		document.getElementById('precoescondido').style.display="block";
		document.getElementById('precoamostra').style.display="none";
	}
}

$(function(){	
	// Toggle dos filtros
	$('#filtros h3').click(function() {
		$(this).parent().toggleClass("closed");
	});
	
	// Exibição completa da listagem
	$('#filtros .mais').click(function(e) {
		$(this).parent().parent().hide();
		$(this).parent().parent().parent().find(".filtro-mais").show();
		e.preventDefault();
	});
	
	// Exibição completa da listagem
	$('#filtros .menos').click(function(e) {
		$(this).parent().parent().hide();
		$(this).parent().parent().parent().find(".filtro-menos").show();
		e.preventDefault();
	});			
	
	// Tooltips
	$(".tooltip").hover(
		function () { $(this).find(".tooltip-text").css('display', 'block'); }, 
		function () { $(this).find(".tooltip-text").hide(); }
	);
	
	// Endereços, expandir
	$("#endereco-mais .mais").click(function(e){
		$(this).parent().parent().find(".endereco-mais").show();
		e.preventDefault();
	});
	
	// Voto opinião útil
	$("#opiniao-voto .bt-voto").click(function(e){
		var $opiniaoVoto = $("#opiniao-voto"),
			opiniaoId = $opiniaoVoto.find("#id_opiniao").val(),
			votoId = $(this).attr("id"),
			voto = votoId.substring(votoId.length - 1),
			target = $(this).parent().attr("action");
		
		$("#opiniao-voto").slideUp("fast");
		
		$.ajax({
		  type: "POST",
		  url: target,
		  data: {id_opiniao: opiniaoId, voto: voto, response: 'json'},
		  success: function(data, textStatus, jqXHR) {
			if(data.resultado){
				if(data.resultado != false) $("#opiniao-voto-sucesso").slideDown("slow");
			  	else  $("#opiniao-voto-erro").slideDown("slow");
			} else $("#opiniao-voto-erro").slideDown("slow");
		  },
		  error: function(jqXHR, textStatus, errorThrown){
			  $("#opiniao-voto-erro").slideDown("slow");
		  }
		});
		e.preventDefault();
	});	
});

function saveCookieAndShowContent(cookieName){
	if(cookieName == undefined || cookieName == null)
		cookieName = "u18A";
	
	createCookie(cookieName,"1",1);
	$("#disclaimer").hide();
	$(".disclaimerContent").show();
}

