/*******************************************************/
/*autenticação do sistema*/
/*******************************************************/

function DetectEnter(campo){
	var ascii = event.keyCode;
	if (ascii == 13) { 
	   autentica();	
    }
}


function autentica() {

	erro = "";
	
	if (document.form.login.value == "") {	
		erro = erro + "Informe seu Login\n";	
	}
	
	if (document.form.senha.value == "") {
		erro = erro + "Informe sua Senha";
	}
	
	if (erro == "") {
		document.form.submit();
	} else {
		alert(erro);
	}

}

/*******************************************************/
/*help*/
/*******************************************************/

function admHelp() {
	
	erro = "";
	
	if (document.form.login.value == "") {	
		erro = erro + "Informe seu Login\n";	
	}
	
	if (document.form.email.value == "") {
	
		erro = erro + "Digite um e-mail válido\n";	
	
	} else {
		
		var re = new RegExp;
		re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var mailArr = re.exec(document.form.email.value);
	
		if (mailArr == null) {
			erro = erro + "O email digitado não é válido\n";
		}
		
	}
	
	if (erro == "") {
		document.form.submit();
	} else {
		alert(erro);
	}
	
}


/*******************************************************/
/*abre popup*/
/*******************************************************/

function openPopup(url,name,features) {
  window.open(url,name,features);
}

/*******************************************************/
/*limpa campo*/
/*******************************************************/

function clearField(campo) { 
  campo.value = "";
}

/*******************************************************/
/*limpa o formulário*/
/*******************************************************/

function clearForm(pagina) {
	
	window.location = pagina;
	
}

/*******************************************************/
/* Fotos */
/*******************************************************/

function escImg(pos,tag) {	
	document.getElementById('img' + pos).innerHTML = tag;
}

function clearImg(imgField,imgName,pos) {	
	
	if (imgField.value != "") {
		window.delImg.location = "foto_del.php?picUrl=" + imgField.value;
	}
	
	imgField.value = "";
	document.getElementById('img' + pos).innerHTML = "<img src='images/sem_imagem.gif' width='90' height='50'>";

}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function upImage() {
	
	if (document.form.imagem.value != "") {
		 MM_showHideLayers('enviando','','show');
		document.form.submit();
	} else {
		alert('Selecione uma foto antes de enviar');
	}
	
}



/*******************************************************/
/* Produtos */
/*******************************************************/

function filtroProdutos(valor) {

	tabela = new Array("tb_nome","tb_tipo","tb_marca","tb_palavra","tb_status");
	
	n = tabela.length;
	
	for (i=0; i<n; i++) {
	
		if (valor == i) {
				
			document.getElementById(tabela[i]).style.display = "inline";
			document.formFiltros.numFiltro.value = valor;
			document.formFiltros.pc_nome.value = "";
			document.formFiltros.pc_tipo.value = "";
			document.formFiltros.pc_marca.value = "";
			document.formFiltros.pc_palavra.value = "";
			document.formFiltros.pc_status.value = "";
			
		} else {		
			
			document.getElementById(tabela[i]).style.display = "none";		
		
		}
	
	}

}


function delProduto(acao,alvo,funcao,ini,cod,nome) {

	if (confirm('Você realmente deseja excluir o Produto:\n' + nome)) {
	
		document.formActions.codProduto.value = cod;
		document.formActions.ini.value = ini;
		document.formActions.acao.value = funcao;
		document.formActions.target = alvo;
		document.formActions.action = acao;
		document.formActions.submit();
	
	}

}

function changeProduto(val1,val2) {

	document.formActions.ini.value = val1;
	document.formActions.codProduto.value = val2;
	document.formActions.target = "_parent";
	document.formActions.action = "produtos_altera.php";
	document.formActions.submit();

}

/*******************************************************/
/* Textos */
/*******************************************************/

function delTexto(val1,val2,nome) {

	if (confirm('Você realmente deseja excluir o Texto:\n' + nome)) {
	
		document.formActions.ini.value = val1;
		document.formActions.codTexto.value = val2;
		document.formActions.acao.value = "excluir";
		document.formActions.target = "_self";
		document.formActions.action = "textos_lista.php";
		document.formActions.submit();
	
	}

}

function changeTexto(val1,val2) {

	document.formActions.ini.value = val1;
	document.formActions.codTexto.value = val2;
	document.formActions.target = "_parent";
	document.formActions.action = "textos_altera.php";
	document.formActions.submit();

}

function navigate(acao,alvo,ini) {

	document.formActions.ini.value = ini;
	document.formActions.target = alvo;
	document.formActions.action = acao;
	document.formActions.submit();

}
