function addCarrinho( _id_produto, _preco, _referencia, _tipo, _especificacoes) {
	
	
	$.post("sessionCheck.php", {}, function(data){
	if( data == "fw" ) { 

		$('#produtosAdd'+_id_produto+""+_tipo).ajaxSend(function(){
		$('#produtosAdd'+_id_produto+""+_tipo).html("<img src=\"imgs/outros/adicionando.jpg\" width=\"190\" height=\"25\" border=\"0\">"); 
	});


		if ( _tipo == "LC" ) {
			
			// AGUARDE //////////////////////////////////////////////

			
			var _olhos = $('#olhos option:selected').val(); 
			var _diametro = $('#diametro option:selected').val(); 
			var _cb = $('#cb option:selected').val(); 
			var _pe = $('#pe option:selected').val(); 
			var _pc = $('#pc option:selected').val(); 
			var _eixo = $('#eixo option:selected').val(); 
			var _cores = $('#cores option:selected').val(); 
			var _adicoes = $('#adicoes option:selected').val(); 
			var _specs = "olhos:"+_olhos+"_|_diametro:"+_diametro+"_|_rc:"+_cb+"_|_pc:"+_pc+"_|_pe:"+_pe+"_|_eixo:"+_eixo+"_|_cores:"+_cores+"_|_adicoes:"+_adicoes;
			$.post("adiciona_carrinho.php", {id_produto:_id_produto, tipo:_tipo, referencia:_referencia, 
				   preco:_preco, especificacoes:_specs}, function(data){
					 window.location = "cesto.php";});  
		} else {
			$.post("adiciona_carrinho.php", {id_produto:_id_produto, tipo:_tipo, referencia:_referencia, 
				   preco:_preco, especificacoes:_especificacoes}, function(data){
					 window.location = "cesto.php";});  
		}
		
	} else { 
		window.location = "login.php";
	}
	});  

}


function addCarrinho2( _id_produto, _preco, _referencia, _tipo, _especificacoes) {
	
	
	$.post("sessionCheck.php", {}, function(data){
	if( data == "fw" ) { 

		$('#produtosAdd'+_id_produto+""+_tipo).ajaxSend(function(){
		$('#produtosAdd'+_id_produto+""+_tipo).html("<img src=\"imgs/outros/adicionandoG.jpg\" width=\"249\" height=\"25\" border=\"0\">"); 
	});


		if ( _tipo == "LC" ) {
			
			// AGUARDE //////////////////////////////////////////////

			
			var _olhos = $('#olhos option:selected').val(); 
			var _diametro = $('#diametro option:selected').val(); 
			var _cb = $('#cb option:selected').val(); 
			var _pe = $('#pe option:selected').val(); 
			var _pc = $('#pc option:selected').val(); 
			var _eixo = $('#eixo option:selected').val(); 
			var _cores = $('#cores option:selected').val(); 
			var _adicoes = $('#adicoes option:selected').val(); 
			var _specs = "olhos:"+_olhos+"_|_diametro:"+_diametro+"_|_rc:"+_cb+"_|_pc:"+_pc+"_|_pe:"+_pe+"_|_eixo:"+_eixo+"_|_cores:"+_cores+"_|_adicoes:"+_adicoes;
			$.post("adiciona_carrinho.php", {id_produto:_id_produto, tipo:_tipo, referencia:_referencia, 
				   preco:_preco, especificacoes:_specs}, function(data){
					 window.location = "cesto.php";});  
		} else {
			$.post("adiciona_carrinho.php", {id_produto:_id_produto, tipo:_tipo, referencia:_referencia, 
				   preco:_preco, especificacoes:_especificacoes}, function(data){
					 window.location = "cesto.php";});  
		}
		
	} else { 
		window.location = "login.php";
	}
	});  

}

function loadPagamento(){
//submete todos os forms para ver se existem produtos k cheguem
// se alguma div warn tiver conteudo nao submete para pagamento.php
		$('#dadosEnv').ajaxSend(function(){
		$('#dadosEnv').html("<img src=\"imgs/bts/ajax-loader.gif\" />"); 
	});


$.post("pagamento.php", {}, function(data){ 
					$("#carro").html(data);
});  
}
function loadConfirma(){
			$('#lconfirma').ajaxSend(function(){
		$('#lconfirma').html("<img src=\"imgs/bts/ajax-loader.gif\" />"); 
	});

	var _nome = $('#nome').val();
	var _morada_factura = $('#morada_factura').val();
	var _morada_envio = $('#morada_envio').val();
	var _telefone = $('#telefone').val();
	var _email = $('#email').val();
	var _nif = $('#nif').val();
	var _pagamento =   $('input[name=pagamento]:checked').val(); 


	//var _pagamento = $('#pagamento').val();
	
$.post("confirma_encomenda.php", {nome:_nome, morada_factura:_morada_factura, morada_envio:_morada_envio, 
	                     telefone:_telefone, email:_email, nif:_nif, pagamento:_pagamento }, function(data){ 
					$("#carro").html(data);
});  
}
function loadAddPagamento(){
			$('#lap').ajaxSend(function(){
		$('#lap').html("<img src=\"imgs/bts/ajax-loader.gif\" />"); 
	});

	var _nome = $('#nome').val();
	var _morada_factura = $('#morada_factura').val();
	var _morada_envio = $('#morada_envio').val();
	var _telefone = $('#telefone').val();
	var _email = $('#email').val();
	var _nif = $('#nif').val();
	var _pagamento = $('#pagamento').val();
	var _portes = $('#portes').val();
	var _data = $('#data').val();

$.post("add_dados_pagamento.php", {nome:_nome, morada_factura:_morada_factura, morada_envio:_morada_envio, 
	                     telefone:_telefone, email:_email, nif:_nif, pagamento:_pagamento, portes:_portes, data:_data}, function(data){ 
					$("#carro").html(data);
});  
}
function updatePage(url) {
var _r = $('#resultados option:selected').val(); 
window.location = "categorias.php?"+url+"&op="+_r;
}
function updatePage5(url) {
var _r = $('#tiposlentes option:selected').val(); 
window.location = "categorias.php?"+url+"&finaltipo="+_r;
}
function updatePage3(url) {
var _r = $('#resultados option:selected').val(); 
window.location = "lentes_tipo.php?"+url+"&op="+_r;
}
function updatePage2(url) {
var _r = $('#resultados option:selected').val(); 
window.location = "pesquisarC.php?"+url+"&op="+_r;
}
function updatePage6(url) {
var _r = $('#tiposlentes option:selected').val(); 
window.location = "pesquisarC.php?"+url+"&finaltipo="+_r;
}
function updatePage4(url) {
var _r = $('#resultados option:selected').val(); 
window.location = "pesquisarCT.php?"+url+"&op="+_r;
}

function activa() {
	var _nome = $("#NOME").val();
	var _email = $("#EMAIL").val();
	if ( _nome != "" && _nome != "Coloque o seu nome" ) {
		if ( _email != "" && _email != "Coloque o seu email" ) {
			p =_email.indexOf('@');
            if (p <1 || p == (_email.length-1)) {
				alert("Introduza um email válido");
			} else {
				$.post("subscreve.php", { nome: _nome, email:_email},
					function(data){
    					$("#content").html(data);
  					});
			}
		} else {
			alert("Preencha o seu email");
		}
	} else {
		alert("Preencha o seu nome");
	}
}
function desactiva() {
	var _nome = $("#NOME").val();
	var _email = $("#EMAIL").val();
	if ( _nome != "" && _nome != "Coloque o seu nome" ) {
		if ( _email != "" && _email != "Coloque o seu email" ) {
			p =_email.indexOf('@');
            if (p <1 || p == (_email.length-1)) {
				alert("Introduza um email válido");
			} else {
				$.post("unsubscreve.php", { nome: _nome, email:_email},
					function(data){
    					$("#content").html(data);
  					});
			}
		} else {
			alert("Preencha o seu email");
		}
	} else {
		alert("Preencha o seu nome");
	}
}


