// JavaScript Document

function sair(){
	
	if(confirm("Tem certeza que deseja sair?")){
		window.location = "index.php?p=sair";
	}
	
}

function config(){
	
	window.location = "index.php?p=config";
	
}


function onFocus(id,text){
	
	if(document.getElementById(id).value == text){
		document.getElementById(id).value = "";
	}
	
}


function onBlur(id,text){

	if(document.getElementById(id).value == ""){
		document.getElementById(id).value = text;
	}

}
 
 
function esqueciSenha(){
	
	varEmail = $('email').value;
	
	if(varEmail == "" || varEmail == "Login"){
		alert("Por favor informe o e-mail!");
	}else{
		new Ajax.Request('ajax/esqueci_senha.php',{
                method: 'get',
                parameters: {
                    email : varEmail,
                    r :Math.random()
                },
                onSuccess: function(transport){
					alert(transport.responseText);
					
					if(transport.responseText == "ok"){
						alert("Senha enviada para o e-mail!");
					} else if(transport.responseText == "erro") {
						alert("Erro ao enviar e-mail!");
					}else{
						alert("E-mail não cadastrado!");
					}
			}});
	}
}

function populaProduto(varIdProduto, varPagina){
	
	new Ajax.Request('corpo/verifica_login.php', {
        method:'get',
        parameters: {},
        onSuccess: function(transport){

            if(transport.responseText == "OK"){
				
	document.getElementById('produtos').style.display = 'none';
	document.getElementById('pagina').style.display = 'none';
	
	new Ajax.Updater('produto_selecionado','ajax/produto_selecionado.php',{
                method: 'get',
                parameters: {
                    id_prod : varIdProduto,
					pagina : varPagina,
                    r :Math.random()
                },
                onSuccess: function(transport){
					
			}});
	
	} else {
	   alert("Para visualizar outras informações é necessário acessar a área restrita, através de seu usuário e senha");
			}

        },
        onFailure: function(){
            alert('Something went wrong...')
        }
    });

}

function descricao(i){
	
	 if(document.getElementById('desc_'+i).style.display == 'none'){
	 	document.getElementById('desc_'+i).style.display = 'block';
	 } else {
		 document.getElementById('desc_'+i).style.display = 'none';
	 }

}

function populaCategoria(varIdProduto, varIdCategoria, varPagina ){
	
	new Ajax.Request('corpo/verifica_login.php', {
        method:'get',
        parameters: {},
        onSuccess: function(transport){

            if(transport.responseText == "OK"){
			
				document.getElementById('produtos').style.display = 'none';
				document.getElementById('pagina').style.display = 'none';
				
				new Ajax.Updater('busca_categoria','ajax/produto_selecionado.php',{
							method: 'get',
							parameters: {
								id_prod : varIdProduto,
								id_cat : varIdCategoria,
								pagina : varPagina,
								r :Math.random()
							},
							onSuccess: function(transport){
								
						}});
			
			} else {
				alert("Para visualizar outras informações é necessário acessar a área restrita, através de seu usuário e senha");
			}

        },
        onFailure: function(){
            alert('Something went wrong...')
        }
    });

}

function InputOnFocusUsuario()
{
	if(document.getElementById('txtUsuario').value == "Usuario") {	  	
	  document.getElementById('txtUsuario').value = ""; 
	  }
}

function InputOnFocusNome()
{	
	
	if(document.getElementById('txtNome').value == "Nome") {	  	
	  document.getElementById('txtNome').value = ""; 
	  }
}
	
function InputOnFocusEmail()
{
	if(document.getElementById('txtEmail').value == "Email") {	  	
	  document.getElementById('txtEmail').value = ""; 
	  }
}

function InputOnBlurUsuario()
{
	if(document.getElementById('txtUsuario').value == "") {
		document.getElementById('txtUsuario').value = "Usuario";
		}
}

function InputOnBlurNome()
{
		
	if(document.getElementById('txtNome').value == "") {
		document.getElementById('txtNome').value = "Nome";
		}
}
	
function InputOnBlurEmail()
{	
	if(document.getElementById('txtEmail').value == "") {
		document.getElementById('txtEmail').value = "Email";
		}

}

function imprimePagina(){

	document.getElementById('imprimir').style.display = 'none';
	window.print();
	document.getElementById('imprimir').style.display = 'block';

}


function populadescricao(varId){
	new Ajax.Updater('descricao','ajax/busca_descricao.php',{
                method: 'get',
                parameters: {
                    id : varId,
                    r :Math.random()
                },
                onSuccess: function(transport){
			}});

}



function populaImagem(varId){
	new Ajax.Updater('imagem','ajax/busca_imagem.php',{
                method: 'get',
                parameters: {
                    id : varId,
                    r :Math.random()
                },
                onSuccess: function(transport){
			}});

}

