var xmlhttp0;
var pos_resultados = 0;
//var options = {modal:true};
var options;
Shadowbox.loadSkin('classic', 'includes/js/shadowbox/skin');

window.addEvent('domready',function(){
	Shadowbox.init(options);
});

function procurar_do() {
	if(pos_resultados) { // abre shadowbox
		v = document.getElementById('resultado_valor_' + pos_resultados).value;
		document.getElementById('search').value='';
		abre2(v);
	} else { //vai para a página procurar.php
		procurar_post();
	}
}
function procurar_post() {
	if(document.getElementById('search').value.length > 1) {
		var f=document.getElementById('form_procurar');
		f.action = './procurar';
		f.submit();
	}
}
function comprar(id) {
	  adicionar_cartao(id);
	  Shadowbox.open({player:'iframe', content:site_base+'includes/compras/info.php?id='+id, width:400, height:150});
}
function abre(j) {
	r = document.getElementById('resultados');
	r.innerHTML = ''; r.style.display='none';
	Shadowbox.open({player:'iframe',content:j,width:900,height:600});	
}
function abre2(j) {
	r = document.getElementById('resultados');
	r.innerHTML = ''; r.style.display='none';
	Shadowbox.open({player:'iframe',content:site_base+'includes/artigos/item.php?id='+j,width:900,height:600});	
}
function findPos(obj){
var posX = obj.offsetLeft;var posY = obj.offsetTop;
	while(obj.offsetParent){
	if(obj==document.getElementsByTagName('body')[0]){break}
	else{
	posX=posX+obj.offsetParent.offsetLeft;
	posY=posY+obj.offsetParent.offsetTop;
	obj=obj.offsetParent;
	}
}
var posArray=[posY]
return posArray;
}
function Change_Big_One(caixa_artigo){
	document.getElementById('imagem_' + caixa_artigo).src = document.getElementById('fotobig_'+caixa_artigo).value;
	overlay_id = document.getElementById("overlay_" + caixa_artigo);						
	overlay_id.style.display = "block";
	searchid = document.getElementById("caixa_artigo_" + caixa_artigo);
	divtop = findPos(searchid) - 36
	overlay_id.style.top = divtop + "px";	
}
function Change_to_normal(caixa_artigo){
	overlay_id = document.getElementById("overlay_" + caixa_artigo);	
	overlay_id.style.display = "none";
}		
function procurar(palavra, e){
	var r  = document.getElementById('resultados');
	var r1 = document.getElementById('resultado_1');
	
	//verifica as teclas cursor e enter
		if(window.event) {x = window.event.keyCode;} else {x = e.which;}

		if(x==40 && r1 && pos_resultados < document.getElementById('num_resultados').value) {
			pos_resultados ++;
			try{document.getElementById('resultado_' + pos_resultados).className='selected';} catch(error) {}
			try{document.getElementById('resultado_' + (pos_resultados-1)).className='unselected';} catch(error) {}
		} else if(x==38 && r1 && pos_resultados>0) {
			pos_resultados --;
			try{document.getElementById('resultado_' + pos_resultados).className='selected';} catch(error) {}
			try{document.getElementById('resultado_' + (pos_resultados+1)).className='unselected';} catch(error) {}
		}
		
		else if(x != 13) {
		//busca
			if(palavra.length>0) {
			xmlhttp0=null;
			if(window.XMLHttpRequest){xmlhttp0=new XMLHttpRequest();}else if (window.ActiveXObject){xmlhttp0=new ActiveXObject("Microsoft.XMLHTTP");}if (xmlhttp0!=null){xmlhttp0.onreadystatechange=state_Change0;xmlhttp0.open("GET",'includes/comum/procurar.php?p='+palavra,true);xmlhttp0.send(null);}else {alert("Your browser does not support XMLHTTP.");}
			} else {
				r.style.display = "none";
				pos_resultados = 0;
				}
	}
}

function state_Change0(){if (xmlhttp0.readyState==4) {
	var r=document.getElementById('resultados');
	if (xmlhttp0.status==200){
		r.style.display='block';
		r.innerHTML = xmlhttp0.responseText;pos_resultados = 0;
		Shadowbox.init({ skipSetup: true }); Shadowbox.setup();
		}else{alert("Problem retrieving data:" + xmlhttp0.statusText);}}
	}
	
function adicionar_cartao(id) {adiciona_ajax('includes/compras/adicionar_ao_cartao.php?id=' + id);}
var xmlhttp3;
function adiciona_ajax(url){xmlhttp3=null;if (window.XMLHttpRequest){xmlhttp3=new XMLHttpRequest();}else if (window.ActiveXObject){xmlhttp3=new ActiveXObject("Microsoft.XMLHTTP");}if (xmlhttp3!=null){xmlhttp3.onreadystatechange=state_Change3;xmlhttp3.open("GET",url,true);xmlhttp3.send(null);}else {alert("Your browser does not support XMLHTTP.");}}function state_Change3(){if (xmlhttp3.readyState==4)
{if (xmlhttp3.status==200){document.getElementById('cartao').innerHTML = xmlhttp3.responseText;}else{alert("Problem retrieving data:" + xmlhttp3.statusText);}}}
