function handleHttpResponse() {
	if (http.readyState == 4) {
		results = http.responseText;
		if (document.all) {
			obj = eval("document.getElementById('carrinho')");
		} else {
			obj = eval("document.getElementById('carrinho')");
		}
		obj.innerHTML = results;
	}
}

function getHTTPObject() {
	var xmlhttp;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	
	return xmlhttp;
}
http = getHTTPObject();
http1 = getHTTPObject();

//----------------------------------------------------------------------------------
function muda(valor) {
	document.pesquisa.referencia.value = valor;
	document.getElementById('referencias').innerHTML = "";
	document.getElementById('referencias').style.display = "none";
}
function mostrar_referencias() {
	valor = document.pesquisa.referencia.value;
	http.open("GET","../ajax/mostrar_referencias.php?valor="+valor,true);
	http.onreadystatechange=function() {
		if (http.readyState == 4) {
			results = http.responseText;
			if (results!="") {
				document.getElementById('referencias').innerHTML = results;
				document.getElementById('referencias').style.display = "";
			} else {
				document.getElementById('referencias').innerHTML = "";
				document.getElementById('referencias').style.display = "none";
			}
		}
	}
	http.send(null);
}
function mudar_foto(id,tabela,indice,seccao,lai) {
	http.open("GET","../site/mudar_foto.php?b51p2DzOlPctela9Xr1="+id+"&rR8P6T1maisSXtfItela9Xr1="+tabela+"&sgxWZpymorwtela9Xr1="+indice+"&79XyOT1maisfLJv4tela9Xr1="+seccao,true);
	http.onreadystatechange = function() {
		if(http.readyState == 4) {
			results = http.responseText;
			if (document.all) {
				obj = eval("document.all['"+lai+"']");
			} else {
				obj = eval("document.getElementById('"+lai+"')");
			}
			obj.innerHTML = results;
		}
	}
	http.send(null);
}
function handleCarrinhoUpdate() {
	if (http.readyState == 4) {
		results = http.responseText;
		//alert(results);
		eval(results);
		if (document.all) {
			//obj = eval("document.getElementById('shop')");
		} else {
			//obj = eval("document.getElementById('shop')");
		}
		//obj.innerHTML = results;
	}
}
function limpar_combo(campo,escolha) {
	obj = eval("document."+campo);
	obj.length = 0;
	if (escolha=="1") {
		obj.options[0] = new Option("escolha...","");
	}
}
function mudar_qtd(id_produto) {
	obj = eval("document.carrinho.qtd_"+id_produto);
	qtd = obj.value;
	if (validate_qtd(qtd)) {
		http.open("GET","../site/mudar_qtd_carrinho.php?id="+id_produto+"&qtd="+qtd,true);
		http.onreadystatechange = handleCarrinhoUpdate;
		http.send(null);
	}
}
function mostrar_capa(campo,id_edicao) {
	//document.location.href="../site/capa.php?"+campo+"="+id_edicao;
	//return;
	http.open("GET","../site/capa.php?"+campo+"="+id_edicao,true);
	http.onreadystatechange = function() {
		if(http.readyState == 4) {
			results = http.responseText;
			if (document.all) {
				obj = eval("document.all['lai_capa']");
			} else {
				obj = eval("document.getElementById('lai_capa')");
			}
			obj.innerHTML = results;
		}
	}
	http.send(null);
}
function mudar_calendario(data,data_currente) {
	http.open("GET","../ajax/get_calendario.php?{cript('data')}="+data+"&{cript('data_cur')}="+data_currente,true);
	http.onreadystatechange = function() {
		if(http.readyState == 4) {
			results = http.responseText;
			if (document.all) {
				obj = eval("document.all['lai_calendario']");
			} else {
				obj = eval("document.getElementById('lai_calendario')");
			}
			obj.innerHTML = results;
			
		}
	}
	http.send(null);		
}
function muda_pesquisa_parcerias(seleccionado) {
	valor = document.pesquisa_parceria.marca.value;
	if (valor!="") {
		http.open("GET","../ajax/muda_pesquisa_parcerias.php?valor="+valor+"&selected="+seleccionado,true);
		http.onreadystatechange=function() {
			if (http.readyState == 4) {
				results = http.responseText;
				if (results!="") {
					document.getElementById('modelos').innerHTML = results;
					document.getElementById('modelos').style.display = "";
				} else {
					document.getElementById('modelos').innerHTML = "";
					document.getElementById('modelos').style.display = "none";
				}
			}
		}
	}
	http.send(null);
}
function validate_qtd(qtd) {
	if (isNaN(qtd)) {
		alert("Quantidade deverá ser um valor numérico!");
		return false;
	} else {
		valor = eval(qtd);
		valor = parseInt(valor);
		if (valor<0) {
			alert("O valor de quantidade não deverá ser inferior a zero!");
			return false;
		}
	}
	return true;
}
function adicionar_carrinho(id_artigo,is_kit) {
	if (is_kit=="1") {
		qtd = document.getElementById('qtd_kit').value;
		if (qtd=="") {
			qtd="1";
		}
		tamanho = document.getElementById('tamanho_kit').value;
	} else {
		qtd = document.getElementById('qtd_artigo').value;
		if (qtd=="") {
			qtd="1";
		}
		tamanho = document.getElementById('tamanho_artigo').value;
	}
	if (validate_qtd(qtd)) {
		http.open("GET","../site/update_carrinho.php?id=" + id_artigo + "&qtd=" + qtd+"&is_kit="+is_kit+"&tamanho="+tamanho,true);
		http.onreadystatechange = handleCarrinhoUpdate;
		http.send(null);
	}
}
function adicionar_carrinho1(id_artigo,id_indice,tipo,remove) {
	qtd = document.getElementById(tipo+'_'+id_indice+'_qtd').value;
	if (qtd=="") {
		qtd="1";
	}
	tamanho = document.getElementById(tipo+'_'+id_indice+'_tam').value;
	
	if (remove=='1') {
		qtd = "0";
	}
	
	if (validate_qtd(qtd)) {
		http.open("GET","../site/update_carrinho1.php?id="+id_artigo+"&indice="+id_indice+"&qtd="+qtd+"&tipo="+tipo+"&tamanho="+tamanho,true);
		http.onreadystatechange = handleCarrinhoUpdate;
		http.send(null);
	}
}
function cancelar_carrinho() {
	http.open("GET","../site/cancelar_carrinho.php",true);
	http.onreadystatechange = handleCarrinhoUpdate;
	http.send(null);
}
function refaz_lista(tabela,campo){
	valor2=document.assinaturas.destino.value;
// vai refazer a lista do preço consoante o radio button que foi seleccionado	
	http.open("GET","ajax/refaz.php?tabela="+tabela+"&campo="+campo+"&pais="+valor2,true);
	http.onreadystatechange=function() {
	if (http.readyState == 4) {
			results = http.responseText;
			//alert(results);
			document.assinaturas.prazo.options.length = 0;
			document.assinaturas.prazo.options.length = 1;
			document.assinaturas.prazo.options[0].text = "escolha...";
			document.assinaturas.prazo.options[0].value = "";
			tmp = results.split("<->");
			for (i=0;i<tmp.length;i++) {
				str = tmp[i];
				tmp1 = str.split("|-|");
				id = tmp1[0];
				designacao = tmp1[1];
				document.assinaturas.prazo.options[document.assinaturas.prazo.options.length] = new Option(designacao, id);
			}
		}
	}
	http.send(null);
}
function refaz_conta(){
		de_rev=document.getElementById('de_rev').value;
		http.open("GET","ajax/contar.php?de_rev="+de_rev,true);
		http.onreadystatechange = function() {
			if(http.readyState == 4) {
				results = http.responseText;
				document.getElementById('primeira_revista').value=results;
			}
		}
		http.send(null);		
}
function alterar_form(tipo,tem_login){
	http.open("GET","ajax/mudar.php?tipo="+tipo,true);
	http.onreadystatechange = function() {
		if(http.readyState == 4) {
			results = http.responseText;
			tmp = results.split("<->")
			mudar = tmp[0];
			mensagem = tmp[1];
			mensagem1 = tmp[2];
			preco=tmp[3];
			id_prazo=tmp[4];
				if(mudar==0){
						notificacao=mensagem;
						mostrar_submeter("sim");	
						document.getElementById('prazo').value=id_prazo;						
						document.getElementById('div_multi').style.display="";	
				}if(mudar==1){
						notificacao=mensagem;						
						mostrar_submeter("sim");	
						document.getElementById('prazo').value=id_prazo;						
						document.getElementById('div_multi').style.display="";	
				}
		}
	}
	http.send(null);		
}
function mostrar_submeter(permite){
	switch(permite){
		case "sim":
			input = document.getElementById('submit_assinatura');
			input.style.display="";		
		break;
		case "nao":
			input = document.getElementById('submit_assinatura');
			input.style.display="none";		
		break;
	}
	return(input);
}
