//fazer scroll
function toTop(id){ 
document.getElementById(id).scrollTop=0 
} 

defaultStep=1 
step=defaultStep 
function scrollDivDown(id){ 
document.getElementById(id).scrollTop+=step 
timerDown=setTimeout("scrollDivDown('"+id+"')",10) 
} 

function scrollDivUp(id){ 
document.getElementById(id).scrollTop-=step 
timerUp=setTimeout("scrollDivUp('"+id+"')",10) 
} 

function toBottom(id){ 
document.getElementById(id).scrollTop=document.getElementById(id).scrollHeight 
} 

function toPoint(id){ 
document.getElementById(id).scrollTop=100 
} 

//outros

function funcao_submit_newsletter(formulario){
 if (formulario.email.value.indexOf('@', 1) == -1 || formulario.email.value.length < 5 ) {
  alert("Deve indicar um email com formato válido: Entidade@dominio");
  return false
 }else{
	return true
 }
}

function regista_email(estado){
	 
    var xmlHttp;
    try{
	     //firefox, opera 8.0+,safari
	     xmlHttp=new XMLHttpRequest();
    } catch(e){
	     // internet explorer
	     try{
		     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e){
			 try{
				 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			 } catch (e) {
				 alert("Your browser does not support AJAX!");
				 return false;
		     }
	     }
	 }
	 
	 
	 xmlHttp.onreadystatechange=function(){
		 if(xmlHttp.readyState==4){
			 //alert(xmlHttp.responseText);
			 if(xmlHttp.responseText==1){alert("E-mail registado com sucesso."); self.document.newsletter.email.value=""}
			 if(xmlHttp.responseText==2){alert("Erro ao registar o e-mail, tente novamente ou contacte o administrador do site.");}
			 if(xmlHttp.responseText==3){alert("E-mail apagado com sucesso."); self.document.newsletter.email.value=""}
			 if(xmlHttp.responseText==4){alert("Erro ao apagar o e-mail, tente novamente ou contacte o administrador do site.");}
	     }
	 }
	 
	 url='grava_newsletter.php?email='+document.newsletter.email.value
	 url+='&data='+document.newsletter.data.value
	 url+='&estado='+estado
	 
	 
	 xmlHttp.open("GET",url,true);
	 xmlHttp.send(null);
}

/*encomendas*/
function mostrar_form(marca_modelo){
	//clearTimeout(t);
  document.getElementById('formulario').style.display='block';
  document.formulario_encomenda.produto.value=marca_modelo;
}

function fechar_janela(){
  document.getElementById('formulario').style.display='none';
}

function registo_encomenda(){	
	
    var xmlHttp;
    try{
	     //firefox, opera 8.0+,safari
	     xmlHttp=new XMLHttpRequest();
    } catch(e){
	     // internet explorer
	     try{
		     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e){
			 try{
				 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			 } catch (e) {
				 alert("Your browser does not support AJAX!");
				 return false;
		     }
	     }
	 }
	 
	 
	 xmlHttp.onreadystatechange=function(){
		 if(xmlHttp.readyState==4){
			 //alert(xmlHttp.responseText);
				 if(xmlHttp.responseText==''){
				 	alert('Enviado com sucesso!');
				 	document.getElementById('formulario').style.display='none';
				 }else{
					alert('Erro ao enviar!');
				 }
	     }
	 }
	 
	 url='conteudos/enviar_mail_formulario.php?';
	 url+='produto='+document.formulario_encomenda.produto.value;
	 url+='&quantidade='+document.formulario_encomenda.quantidade.value;
	 url+='&nome='+document.formulario_encomenda.nome.value;
	 url+='&morada='+document.formulario_encomenda.morada.value;
	 url+='&telefone='+document.formulario_encomenda.telefone.value;
	 url+='&email='+document.formulario_encomenda.email.value;
	 url+='&observacoes='+document.formulario_encomenda.observacoes.value;
	 
	 xmlHttp.open("GET",url,true);
	 xmlHttp.send(null);	
	
}

/*contactos*/

function registo_form_contactos(){	
	
    var xmlHttp;
    try{
	     //firefox, opera 8.0+,safari
	     xmlHttp=new XMLHttpRequest();
    } catch(e){
	     // internet explorer
	     try{
		     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e){
			 try{
				 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			 } catch (e) {
				 alert("Your browser does not support AJAX!");
				 return false;
		     }
	     }
	 }
	 
	 
	 xmlHttp.onreadystatechange=function(){
		 if(xmlHttp.readyState==4){
			 //alert(xmlHttp.responseText);
				 if(xmlHttp.responseText==''){
				 	alert('Enviado com sucesso!');
					document.formulario_contactos.nome.value='';
					document.formulario_contactos.email.value='';
					document.formulario_contactos.mensagem.value='';				 	
				 }else{
					alert('Erro ao enviar!');
				 }
	     }
	 }

	 
	 url='conteudos/enviar_mail_contactos.php?';
	 url+='nome='+document.formulario_contactos.nome.value;
	 url+='&email='+document.formulario_contactos.email.value;
	 url+='&mensagem='+document.formulario_contactos.mensagem.value;
	 
	 xmlHttp.open("GET",url,true);
	 xmlHttp.send(null);	
	
}

/*menu das galerias*/

function menu_hover(id){
	document.getElementById('sub_opc_'+id).style.background="url('layout/tira_sub_menu_sel.jpg') no-repeat left top";
	document.getElementById('a_sub_opc_'+id).style.color='#D8D8D5';	
}

function menu_out(id){
	document.getElementById('sub_opc_'+id).style.background="url('layout/tira_sub_menu_no_sel.jpg') no-repeat left top";
	document.getElementById('a_sub_opc_'+id).style.color='#7C7D74';	
}
