function fechar()
	{
	window.close();
	}
// Aqui definimos o tempo para fechar o pop-up
function popup(url, nwidth, nheight) 
	{
	var width = nwidth;
	var height = nheight;
	var left = (screen.width - width)/2;
	var top = (screen.height - height)/2;
	var params = 'width='+width+', height='+height;
	params += ', top='+top+', left='+left;
	params += ', directories=no';
	params += ', location=no';
	params += ', menubar=no';
	params += ', resizable=yes';
	params += ', scrollbars=no';
	params += ', status=no';
	params += ', toolbar=no';
	newwin = window.open(url, 'titulo', params);
	if(window.focus) {
	newwin.focus();
	}
	return false;
	}

function valida_desc()
	{
	if(document.desc_cat.desc_categoria.value == '')
		{
		document.getElementById('msg_desc').innerHTML='Por Favor preencha o campo para efetuar o cadastro';
		document.desc_cat.desc_categoria.focus();
		return false;
		}
	}
function maskEvent2(field, event) 
	{
	var key ='';
	var aux='';
	var len=0;
	var i=0;
	var strCheck = '0123456789.,';
	var rcode = (window.Event) ? event.which : event.keyCode;
	if ((rcode == 13) || (rcode == 0) || (rcode == 8))
		{
		//Enter
		return true;
		}
	//Get key value from key code
	key=String.fromCharCode(rcode);
	if(strCheck.indexOf(key)==-1) 
		{
		//Not a valid key
		return false;
		}
	aux=field.value+key;
	//window.alert(aux);
	aux=mask(_mask,aux);
	//window.alert(aux);
	field.value=aux;	
	return false;
	}
function data(z)
	{
	v = z.value;
    v=v.replace(/\D/g,"") 
    v=v.replace(/(\d{2})(\d)/,"$1/$2") 
    v=v.replace(/(\d{2})(\d)/,"$1/$2") 
    z.value = v;
    }
function moeda(z)
	{  
    v = z.value;
    v=v.replace(/\D/g,"")  //permite digitar apenas números
    v=v.replace(/[0-9]{12}/,"inválido")   //limita pra máximo 999.999.999,99
    v=v.replace(/(\d{1})(\d{8})$/,"$1.$2")  //coloca ponto antes dos últimos 8 digitos
    v=v.replace(/(\d{1})(\d{5})$/,"$1.$2")  //coloca ponto antes dos últimos 5 digitos
    v=v.replace(/(\d{1})(\d{1,2})$/,"$1,$2")    //coloca virgula antes dos últimos 2 digitos
    z.value = v;
    }

function fone(z)
	{
	v = z.value;
	v=v.replace(/\D/g,"")  //permite digitar apenas números      
 	v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros 
	v=v.replace(/(\d{1})(\d{4})$/,"$1-$2")  //coloca Perentese antes dos últimos 10 digitos 
	z.value = v;
    }
function num(z) // Mascara p/ telefone
	{
	v = z.value;
	v=v.replace(/\D/g,"")  //permite digitar apenas números      
	z.value = v;
    }
function valida_check()
	{
	todos = document.getElementsByTagName('input'); 
    for(x = 0; x < todos.length; x++) 
    	{ 
		if (todos[x].checked) 
			{ 
			return true; 
			} 
   		}
	document.getElementById('msg_check').innerHTML='Selecione pelo menos um Produto para aparecer na Pagina Inicial.';
	return false;
	}
function valida_usado()
	{
	if(document.usado.nome_usado.value == "")
		{
		document.getElementById('msg_usado').innerHTML='Por Favor preencha o Campo Nome';
		document.usado.nome_usado.focus();
		return false;
		}
	if(document.usado.origem_usado.value == "")
		{
		document.getElementById('msg_usado').innerHTML='Por favor preencha o campo Origem';
		document.usado.origem_usado.focus();
		return false;
		}
	if(document.usado.descricao_usado.value == "")
		{
		document.getElementById('msg_usado').innerHTML='Por favor preencha o campo Descrição';
		document.usado.descricao_usado.focus();
		return false;
		}
	if(document.usado.data_ent_usado.value == "")
		{
		document.getElementById('msg_usado').innerHTML='*Por favor preencha o campo Data de Entrada.';
		document.usado.data_ent_usado.focus();
		return false;
		}
	if(document.usado.valor_ent_usado.value == "")
		{
		document.getElementById('msg_usado').innerHTML='*Por favor preencha o campo Valor de Entrada';
		document.usado.valor_ent_usado.focus();
		return false;
		}
	if(document.usado.valor_out_usado.value == "")
		{
		document.getElementById('msg_usado').innerHTML='*Por favor preencha o campo Valor de Saída';
		document.usado.valor_out_usado.focus();
		return false;
		}
	if(document.usado.status_ent_usado.value == "")
		{
		document.getElementById('msg_usado').innerHTML='*Por favor preencha o campo Status de Entrada';
		document.usado.status_ent_usado.focus();
		return false;
		}
	if(document.usado.status_usado.value == "")
		{
		document.getElementById('msg_usado').innerHTML='*Por favor preencha o campo Status';
		document.usado.status_usado.focus();
		return false;
		}
	}
function valida_campos()
	{
	if(document.form1.desc_galeria.value == "")
		{
		alert("preencha os campos obrigatorios");
		document.form1.desc_galeria.focus();
		return false;
		}
	}
function question(frase,endereco)
	{
	if (confirm(frase))
		{
		window.location=endereco;
		}
	}
function total_letras(input, input_restantes, limite)
	{
   	if (input.value.length > limite) input.value = input.value.substring(0, limite);
   	else input_restantes.value = limite - input.value.length;
	}
function MM_jumpMenu(targ,selObj,restore)
	{ //refresh na pagina
  	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
	}
function currencyFormat(fld, milSep, decSep, e) 
	{
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	for(i = 0; i < len; i++)
	if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	aux = '';
	for(; i < len; i++)
	if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) fld.value = '';
	if (len == 1) fld.value = '0'+ decSep + '0' + aux;
	if (len == 2) fld.value = '0'+ decSep + aux;
	if (len > 2) 
		{
		aux2 = '';
		for (j = 0, i = len - 3; i >= 0; i--) 
			{
			if (j == 3) 
				{
				aux2 += milSep;
				j = 0;
				}
			aux2 += aux.charAt(i);
			j++;
			}
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		fld.value += aux2.charAt(i);
		fld.value += decSep + aux.substr(len - 2, len);
		}
	return false;
	}
function valida_contato()
	{
	if (document.contato.nome.value == "") 
		{
		document.getElementById('msg').innerHTML='Por favor preencha o campo Nome.';
		document.contato.nome.focus();
		return false;
		}
	if(document.contato.email.value =="")
		{
		document.getElementById('msg').innerHTML='Por favor preencha o campo email.';
		document.contato.email.focus();
		return false;
		}
	if(document.contato.destino.value =="")
		{
		document.getElementById('msg').innerHTML='Por favor preencha o campo destino.';
		document.contato.destino.focus();
		return false;
		}
	if(document.contato.telefone.value == "")
		{
		document.getElementById('msg').innerHTML='Por favor preencha o campo telefone.';
		document.contato.telefone.focus();
		}
	else 
		{
		prim = document.contato.email.value.indexOf("@")
 		if(prim < 2) 
			{
			document.getElementById('msg').innerHTML='Erro! Email invalido!';
 			document.contato.email.focus();
			return false;
	 		}
 		if(document.contato.email.value.indexOf("@",prim + 1) != -1) 
			{
 			document.getElementById('msg').innerHTML='Erro! Email invalido!';
 			document.contato.email.focus();
 			return false;
 			}
 		if(document.contato.email.value.indexOf(".") < 1) 
			{
 			document.getElementById('msg').innerHTML='Erro! Email invalido!';
 			document.contato.email.focus();
 			return false;
 			}
 		if(document.contato.email.value.indexOf(" ") != -1) 
			{
			document.getElementById('msg').innerHTML='Erro! Email invalido!';
 			document.contato.email.focus();
 			return false;
 			}
		if(document.contato.email.value.indexOf("'") != -1) 
			{
			document.getElementById('msg').innerHTML='Erro! Email invalido!';
 			document.contato.email.focus();
 			return false;
 			}
 		if(document.contato.email.value.indexOf("zipmeil.com") > 0) 
			{
 			document.getElementById('msg').innerHTML='Erro! Email invalido!';
 			document.contato.email.focus();
 			return false;
 			}
 		if(document.contato.email.value.indexOf("hotmeil.com") > 0) 
			{
 			document.getElementById('msg').innerHTML='Erro! Email invalido!';
 			document.contato.email.focus();
 			return false;
 			}
 		if(document.contato.email.value.indexOf(".@") > 0) 
			{
 			document.getElementById('msg').innerHTML='Erro! Email invalido!';
 			document.contato.email.focus();
 			return false;
 			}
 		if(document.contato.email.value.indexOf("@.") > 0) 
			{
 			document.getElementById('msg').innerHTML='Erro! Email invalido!';
 			document.contato.email.focus();
 			return false;
 			}
 		if(document.contato.email.value.indexOf(".com.br.") > 0) 
			{
 			document.getElementById('msg').innerHTML='Erro! Email invalido!';
 			document.contato.email.focus();
 			return false;
 			}
 		if(document.contato.email.value.indexOf("/") > 0) 
			{
 			document.getElementById('msg').innerHTML='Erro! Email invalido!';
 			document.contato.email.focus();
 			return false;
 			}
 		if(document.contato.email.value.indexOf("[") > 0) 
			{
 			document.getElementById('msg').innerHTML='Erro! Email invalido!';
 			document.contato.email.focus();
 			return false;
 			}
 		if(document.contato.email.value.indexOf("]") > 0) 	
			{
 			document.getElementById('msg').innerHTML='Erro! Email invalido!';
 			document.contato.email.focus();
 			return false;
 			}
 		if(document.contato.email.value.indexOf("(") > 0) 
			{
 			document.getElementById('msg').innerHTML='Erro! Email invalido!';
 			document.contato.email.focus();
 			return false;
 			}
 		if(document.contato.email.value.indexOf(")") > 0) 
			{
 			document.getElementById('msg').innerHTML='Erro! Email invalido!';
 			document.contato.email.focus();
 			return false;
 			}
 		if(document.contato.email.value.indexOf("..") > 0) 
			{
 			document.getElementById('msg').innerHTML='Erro! Email invalido!';
 			document.contato.email.focus();
 			return false;
 			}
		}
		//fim da validação do email
	if(document.contato.assunto.value =="")
		{
		document.getElementById('msg').innerHTML='*Por favor, preencha o campo assunto.';
		document.contato.assunto.focus();
		return false;	
		}
	if(document.contato.mensagem.value =="")
		{
		document.getElementById('msg').innerHTML='*Por favor, preencha o campo mensagem.';
		document.contato.mensagem.focus();
		return false;	
		}
	}
//fim da função valida_contato
function valCategoria(div)
	{
	if(document.getElementById('desc_categoria').value == '')
		{
		document.getElementById(div).innerHTML='Favor informar a categoria.';
		document.getElementById('desc_categoria').focus();
		return false
		}
	}
function valLinha(div)
	{
	if(document.getElementById('desc_sub').value == '')
		{
		document.getElementById(div).innerHTML='Favor informar a linha.';
		document.getElementById('desc_sub').focus();
		return false
		}
	if(document.getElementById('id_categoria').value == '')
		{
		document.getElementById(div).innerHTML='Favor selecionar a categoria.';
		document.getElementById('id_categoria').focus();
		return false
		}
	}
function valLogin(div)
	{
	if(document.getElementById('login').value == '')	
		{
		document.getElementById('login').focus();
		document.getElementById(div).innerHTML='Favor informar login';
		return false;
		}
	if(document.getElementById('senha').value == '')
		{
		document.getElementById('senha').focus();
		document.getElementById(div).innerHTML='Favor informar a senha';
		return false;
		}
	var login = document.getElementById('login').value;
	if(login < 5)
		{
		document.getElementById('login').focus();
		document.getElementById(div).innerHTML='Favor informar o login corretamente.';
		return false;
		}
	var senha = document.getElementById('senha').value;
	if(senha < 5)
		{
		document.getElementById('senha').focus();
		document.getElementById(div).innerHTML='Favor informar a senha corretamente.';
		return false;
		}
	}
function valida_numeros(field, _mask, event) 
	{
	var key ='';
	var aux='';
	var len=0;
	var i=0;
	var strCheck = '0123456789';
	var rcode = (window.Event) ? event.which : event.keyCode;
	if ((rcode == 13) || (rcode == 0) || (rcode == 8))
		{
		//Enter
		return true;
		}
	//Get key value from key code
	key=String.fromCharCode(rcode);
	if(strCheck.indexOf(key)==-1) 
		{
		//Not a valid key
		return false;
		}
	aux=field.value+key;
	//window.alert(aux);
	aux=mask(_mask,aux);
	//window.alert(aux);
	field.value=aux;	
	return false;
	}
function OnEnter(evt)
	{
    var key_code = evt.keyCode  ? evt.keyCode  :
    evt.charCode ? evt.charCode :
    evt.which    ? evt.which    : void 0;
    if (key_code == 13)
    	{
        return true;
    	}
	}
function EnviaBusca(e)
	{
    if(OnEnter(e))
		{
		buscar('divList');
    	}
    else
    	{
        return true;
    	}
	}
function cadDown()
	{
	if(document.fdown.nome_down.value == '')
		{
		document.getElementById('divCadDown').innerHTML='Favor digitar o nome';
		document.fdown.nome_down.focus();
		return false;
		}
	if(document.fdown.link_down.value == '')
		{
		document.getElementById('divCadDown').innerHTML='Favor inserir o link de download';
		document.fdown.link_down.focus();
		return false;
		}
	if(document.fdown.id_categ_down.value== '')
		{
		document.getElementById('divCadDown').innerHTML='Favor selecionar a categoria';
		document.fdown.id_categ_down.focus();
		return false;
		}
	}
function categ_down()
	{
	if(document.fcateg.desc_categ.value == '')
		{
		document.getElementById('divCatDown').innerHTML='Favor digitar a descrição';
		document.fcateg.desc_categ.focus();
		return false;
		}
	}
function alt_categ_down(id, desc)
	{
	document.fcateg.desc_categ.value=desc;
	document.fcateg.id_categ_down.value=id;
	}
function VerificaData(digData,div) 
	{
	document.getElementById(div).innerHTML='';
	var bissexto = 0;
	var data = digData; 
	var tam = data.length;
	if (tam == 10) 
		{
		var dia = data.substr(0,2)
		var mes = data.substr(3,2)
		var ano = data.substr(6,4)
		if ((ano > 1900)||(ano < 2100))
			{
			switch (mes) 
				{
				case '01':
				case '03':
				case '05':
				case '07':
				case '08':
				case '10':
				case '12':
				if  (dia <= 31) {return true;}
				break
				case '04':              
				case '06':
				case '09':
				case '11':
				if  (dia <= 30) {return true;}
				break
				case '02':
				/* Validando ano Bissexto / fevereiro / dia */ 
				if ((ano % 4 == 0) || (ano % 100 == 0) || (ano % 400 == 0)) { bissexto = 1; } 
				if ((bissexto == 1) && (dia <= 29)) { return true; } 
				if ((bissexto != 1) && (dia <= 28)) { return true; }                       
				break                                           
				}
			}
		}       
	document.getElementById(div).innerHTML='Atenção a Data: '+data+' é Invalida!';
	return false;
	}
function OnEnter(evt)
	{
    var key_code = evt.keyCode  ? evt.keyCode  :
    evt.charCode ? evt.charCode :
    evt.which    ? evt.which    : void 0;
    if (key_code == 13)
    	{
        return true;
    	}
	}
function EnviaBusPr(e)
	{
    if(OnEnter(e))
		{
		barProduto('divList');
    	}
    else
    	{
        return true;
    	}
	}
function favoritos3() 
	{
	if ( navigator.appName != 'Microsoft Internet Explorer' )
		{ window.sidebar.addPanel("Madereira 3 Estados","http://www.3estados.com.br",""); }
else { window.external.AddFavorite("http://www.3estados.com.br","Madereira 3 Estados"); } }
function inicio(objk,direccion)
	{ 
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>3))
		{ 
		objk.style.behavior="url(#default#homepage)"; 
		objk.setHomePage(direccion); 
		} 
	else{ alert("Desculpe! Este recurso não está disponível para este navegador."); } 
	} 
