// Início do código de Aumentar/ Diminuir a letra
 
// Para usar coloque o comando: "javascript:mudaTamanho('tag_ou_id_alvo', -1);" para diminuir
// e o comando "javascript:mudaTamanho('tag_ou_id_alvo', +1);" para aumentar
function mudaTamanho( idAlvo,acao )
{
	var tagAlvo = new Array('p'); //pega todas as tags p//
 
	// Especificando os possíveis tamanhos de fontes, poderia ser: x-small, small...
	var tamanhos = new Array( '9px','10px','11px','12px','13px','14px','15px','16px' );
	var tamanhoInicial = 2;

	if (!document.getElementById)
	{
		return;
	}
	
	var selecionados = null,tamanho = tamanhoInicial,i,j,tagsAlvo;
	tamanho += acao;
	if ( tamanho < 0 )
	{
		tamanho = 0;
	}
	if ( tamanho > 6 )
	{
		tamanho = 6;
	}
	tamanhoInicial = tamanho;
	if ( !( selecionados = document.getElementById( idAlvo ) ) )
	{
		selecionados = document.getElementsByTagName( idAlvo )[ 0 ];
	}
  
	selecionados.style.fontSize = tamanhos[ tamanho ];
  
	for ( i = 0; i < tagAlvo.length; i++ )
	{
		tagsAlvo = selecionados.getElementsByTagName( tagAlvo[ i ] );
	
		for ( j = 0; j < tagsAlvo.length; j++ )
		{
			tagsAlvo[ j ].style.fontSize = tamanhos[ tamanho ];
		}
	}
}

function SomenteNumero(e)
{
    var tecla = (window.event) ? event.keyCode : e.which;
    if((tecla > 47 && tecla < 58))
	{
		return true;
    }
	else if (tecla != 8)
	{
		 return false;
    }
	else
	{
		return true;
    }
}

function validarOrcamento(form)
{
/*	Campos obrigatórios

	DADOS PESSOAIS
			1	tipo_pessoa
			2	nome
			3	email
			4	telefone
			5	cidade
			6	estado

	DADOS DO PEDIDO	
			7	midia
			8	impressao
			9	quantidade
			10	conteudo_gravado
			11	embalagem
			12	encarte_frontal
			13	encarte_extra
			14	manuseio
			15	lacre_shirink
*/
	var tipo_pessoa = form.tipo_pessoa;
	var nome = form.nome;
	var email = form.email;
	var tipo = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	var telefone = form.tel;
	var cidade = form.cidade;
	var estado = form.estado;
	var midia = form.midia; 
	var impressao = form.impressao; 
	var quantidade = form.quantidade; 
	var conteudo_gravado = form.conteudo_gravado; 
	var embalagem = form.embalagem; 
	var encarte_frontal = form.encarte_frontal; 
	var encarte_extra = form.encarte_extra; 
	var manuseio = form.manuseio; 
	var lacre_shirink = form.lacre_shirink; 

    if (tipo_pessoa[0].checked == false && tipo_pessoa[1].checked == false)
	{
		alert('Caro cliente, \nTipo de Pessoa é de seleção Obrigatória.');
    	tipo_pessoa[0].focus();
	    return false;
	}

    if (nome.value == "" || nome.value == " ")
    {   alert('Caro cliente, \nCampo Nome é de preenchimento obrigatório.');
	    nome.focus();
	    return false;
    }
    if (email.value == "") {
		alert('Caro cliente, \nCampo E-mail é de preenchimento obrigatório.');
	    email.focus();
	    return false;
	}
	else
		if (!tipo.test(email.value))
		{
			alert('Caro cliente, \nE-mail preenchido é inválido.');
			email.focus();
			return false;
		}

	if (telefone.value == "" || telefone.value == " ")
    {
		alert('Caro cliente, \nCampo Telefone é de preenchimento obrigatório.');
	    telefone.focus();
	    return false;
    }
	if (cidade.value == "" || cidade.value == " ")
    {
		alert('Caro cliente, \nCampo Cidade é de preenchimento obrigatório.');
	    cidade.focus();
	    return false;
    }

	if (estado.value == "" || estado.value == " ")
    {
		alert('Caro cliente, \nCampo Estado é de preenchimento obrigatório.');
	    estado.focus();
	    return false;
    }
	if (midia.value == "" || midia.value == " ")
    {
		alert('Caro cliente, \nCampo Mídia é de preenchimento obrigatório.');
	    midia.focus();
	    return false;
    }
	if (impressao.value == "" || impressao.value == " ")
    {
		alert('Caro cliente, \nCampo Impressão na Mídia é de preenchimento obrigatório.');
	    impressao.focus();
	    return false;
    }
	if (quantidade.value == "" || quantidade.value == " ")
    {
		alert('Caro cliente, \nCampo Quantidade é de preenchimento obrigatório.');
	    quantidade.focus();
	    return false;
    }
	if (conteudo_gravado.value == "" || conteudo_gravado.value == " ")
    {
		alert('Caro cliente, \nCampo Conteúdo Gravado é de preenchimento obrigatório.');
	    conteudo_gravado.focus();
	    return false;
    }
	if (embalagem.value == "" || embalagem.value == " ")
    {
		alert('Caro cliente, \nCampo Embalagem é de preenchimento obrigatório.');
	    embalagem.focus();
	    return false;
    }
	if (encarte_frontal.value == "" || encarte_frontal.value == " ")
    {
		alert('Caro cliente, \nCampo Encarte Frontal é de preenchimento obrigatório.');
	    encarte_frontal.focus();
	    return false;
    }
	if (encarte_extra.value == "" || encarte_extra.value == " ")
    {
		alert('Caro cliente, \nCampo Encarte Extra é de preenchimento obrigatório.');
	    encarte_extra.focus();
	    return false;
    }
	if (manuseio.value == "" || manuseio.value == " ")
    {
		alert('Caro cliente, \nCampo Manuseio de Encartes é de preenchimento obrigatório.');
	    manuseio.focus();
	    return false;
    }
	if (lacre_shirink.value == "" || lacre_shirink.value == " ")
    {
		alert('Caro cliente, \nCampo Lacre Shirink é de preenchimento obrigatório.');
	    lacre_shirink.focus();
	    return false;
    }
}

function validarProduto(form)
{
	var categoria_id = form.categoria_id;
	var nome_produto = form.nome_produto;
	var status = form.status;
//	var foto_principal = form.foto_principal;
	var nome_foto_principal = form.nome_foto_principal;

    if (categoria_id.value == "" || categoria_id.value == " ")
    {   alert('Selecione uma categoria');
	    categoria_id.focus();
	    return false;
    }
	
    if (nome_produto.value == "" || nome_produto.value == " ")
    {   alert('Preencha o campo Nome do Produto');
	    nome_produto.focus();
	    return false;
    }

    if (status.value == "" || status.value == " ")
    {   alert('Selecione um Status');
	    status.focus();
	    return false;
    }

/*    if (foto_principal.value == "" || foto_principal.value == " ")
    {   alert('Preencha o campo de Foto Principal');
	    foto_principal.focus();
	    return false;
    }
*/
    if (nome_foto_principal.value == "" || nome_foto_principal.value == " ")
    {   alert('Preencha o campo Nome da Foto Principal');
	    nome_foto_principal.focus();
	    return false;
    }
}

// Abre pop-up das Imagens
function fotoProduto( url )
{
	janela	= window.open( url, "Fotos do Produto", "width=660,height=550,scrollbars=yes" );
	janela.focus();						
}

function toggle_status(obj)
{		
	var img = new String( $(obj).attr('src') );
	var valor = img.substring(img.indexOf('.png') -1 , img.indexOf('.png'));
	
	if(valor==1)
	{
		valor = 0;
	}
	else
	{
		valor = 1;
	}
	
	var nova_imagem = img.substring(0, img.indexOf('.png') -1);
	nova_imagem = nova_imagem + valor + '.png';
	$(obj).attr('src', nova_imagem );
}

function change_status()
{
	$(".status").click(function(){
		var url = $(this).attr('href');
		var obj = $(this);
		$.ajax({
			url: url,
			success: function(data)
			{
				toggle_status($(obj).find('img'));
			},
			error : function()
			{
				alert('Não foi possível mudar o status');
			}
		});
		
		return false;
	});
}

$().ready(function(){
	change_status();
});

//Esconde DIV A e mostra DIV B
function show_hide(div_hide, div_show){
		div_hide = "#"+div_hide;
		div_show = "#"+div_show;
		$(div_hide).click(function () {
			  if($(this).css('display') == 'block'){
				$(this).css({'display': 'none'});
 				if(div_show != '')
				$(div_show).css({'display': 'block'});
			  }		
		});
}

function Validaformcont(formulario_consulta_pedidos){
 	var msg='Por favor corrija os seguintes campos:\n';
	 if (formulario_consulta_pedidos.id_cliente.value=='') 
	 	msg = msg+'os dados: CPF/CNPJ Obrigatório.\n';
	 if (formulario_consulta_pedidos.id_orc.value=='') 
	 	msg = msg+'O Nº do Orçamento é Obrigatório.\n';
	var tipo = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	if (msg!='Por favor corrija os seguintes campos:\n'){
		 alert(msg);
		 return false;
	}
	document.getElementById('oculto').style.display = 'block';
	if (!tipo.test(formulario_consulta_pedidos.email2.value)){
		 alert("Favor informar um email válido.")
		 return false;
	}
		 
	 return true;
}		
 
/*
function SoNumero(event){
 
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
 
	var caract = new RegExp(/^[0-9]+$/i);
 
	var caract = caract.test(String.fromCharCode(keyCode));
 
 
 
    if (keyCode != 9 && keyCode != 8 && keyCode != 46) // backspace
 
	if(!caract){
 
		keyCode=0;
 
		return false;
 
	}
 
}*/
