//somente numeros
function numero(e)
{
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
		if (tecla > 47 && tecla < 58 || tecla == 13) // numeros de 0 a 9 e tecla enter
			return true;
		else
			{
				if (tecla != 8) // backspace
					event.keyCode = 0;
					//return false;
				else
					return true;
			}
}

//valida usuario
function valida( usuario ){
	//nome completo
	if( usuario.nome.value == "" ){
		alert( "Por favor digite o nome completo!" );
		usuario.nome.focus();
		return false;
	}
	if( usuario.nome.value.length < 6 ){
		alert( "Número de caracteres insuficiente para o nome completo!" );
		usuario.nome.focus();
		return false;
	}
	//login	
	if( usuario.login.value == "" ){
		alert( "Por favor digite o login!" );
		usuario.login.focus();
		return false;
	}
	if( usuario.login.value.length < 4 ){
		alert( "Número de caracteres insuficiente para o login!" );
		usuario.login.focus();
		return false;
	}
	//senha		
	if( usuario.senha.value == "" ){
		alert( "Por favor digite a senha!" );
		usuario.senha.focus();
		return false;
	}

	if( usuario.senha.value.length < 4 ){
		alert( "Número de caracteres insuficiente para a senha!" );
		usuario.senha.focus();
		return false;
	}	
	
	if( usuario.senha2.value == "" ){
		alert( "Por favor digite a senha novamente!" );
		usuario.senha2.focus();
		return false;
	}

	if( usuario.senha.value != usuario.senha2.value ){
		alert( "As senhas estão diferentes, por favor digite novamente!" );
		usuario.senha2.focus();
		return false;
	}
	
	//e-mail
	if( usuario.email.value == "" ){
		alert( "Por favor informe o e-mail!" );
		usuario.email.focus();
		return false;
	}
	
	if( usuario.email.value.indexOf('@', 0) == -1 || usuario.email.value.indexOf('.', 0) == -1 ){
		alert( "E-mail inválido!" );
		usuario.email.focus();
		return false;
	}

}

//valida login
function validaLoginForm( loginform ){
	
	//login	
	if( loginform.log.value == "" ){
		alert( "Informe seu usuário!" );
		loginform.log.focus();
		return false;
	}
	if( loginform.log.value.length < 4 ){
		alert( "Número de caracteres insuficiente para o usuário!" );
		loginform.log.focus();
		return false;
	}
	//senha		
	if( loginform.pwd.value == "" ){
		alert( "Informe sua senha!" );
		loginform.pwd.focus();
		return false;
	}

	if( loginform.pwd.value.length < 4 ){
		alert( "Número de caracteres insuficiente para a senha!" );
		loginform.pwd.focus();
		return false;
	}		
}

//valida link
function validaLinkForm( formlink ){

	//nome do link	
	if( formlink.txtlinNome.value == "" ){
		alert( "Digite o nome do menu!" );
		formlink.txtlinNome.focus();
		return false;
	}
	if( formlink.txtlinNome.value.length < 3 ){
		alert( "Número de caracteres insuficientes!" );
		formlink.txtlinNome.focus();
		return false;
	}

	//posicao do link	
	if( formlink.txtlinPosicao.value == "" ){
		alert( "Digite a posição do menu!" );
		formlink.txtlinPosicao.focus();
		return false;
	}
		
}

//valida página
function validaPaginaForm( formpagina ){
	
	//link
	if( formpagina.txtlinCodigo.selectedIndex == 0 ){
		alert( "Selecione um link para a página!" );
		formpagina.txtlinCodigo.focus();
		return false;
	}	
	
	//nome do link	
	if( formpagina.txtpagNome.value == "" ){
		alert( "Informe um título para a página!" );
		formpagina.txtpagNome.focus();
		return false;
	}
	if( formpagina.txtpagNome.value.length < 3 ){
		alert( "Número de caracteres insuficiente!" );
		formpagina.txtpagNome.focus();
		return false;
	}
		
}

//valida categoria
function validaCategoria( categoria ){
	//nome completo
	if( categoria.subnome.value == "" ){
		alert( "Por favor digite o nome da categoria!" );
		categoria.subnome.focus();
		return false;
	}

	if( categoria.subnome.value.length < 1 ){
		alert( "Informe corretamente a categoria!" );
		categoria.subnome.focus();
		return false;
	}
	//descrição
	if( categoria.descricao.value == "" ){
		alert( "Por favor digite a descrição da categoria!" );
		categoria.descricao.focus();
		return false;
	}
	if( categoria.descricao.value.length < 1 ){
		alert( "Informe corretamente descrição da categoria!" );
		categoria.descricao.focus();
		return false;
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

//mostra imagem categoria
function mostra(){
	var img;
	img = categoria.imagem.value;
	window.open("mostra.php?imagem="+img+"","","scrollbars=yes,width=350,height=350");
}

//mostra imagem produto
function mostraProduto(){
	var img;
	img = produto.imagem.value;
	window.open("mostra.php?imagem="+img+"","","scrollbars=yes,width=350,height=350");
}

function formatar(src, mask) 
{

  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i)
if (texto.substring(0,1) != saida) 
  {
	src.value += texto.substring(0,1);
  }
}

//valida Produto

function validaProduto( produto ){
	//nome completo
	if( produto.nome.value == "" ){
		alert( "Por favor digite o nome do produto!" );
		produto.nome.focus();
		return false;
	}
	if( produto.nome.value.length < 4 ){
		alert( "Informe pelo menos 4 caracteres para o nome do produto!" );
		produto.nome.focus();
		return false;
	}

	//descrição	pequena
	if( produto.descricaoPequeno.value == "" ){
		alert( "Informe a descrição pequena!" );
		produto.descricaoPequeno.focus();
		return false;
	}
	if( produto.descricaoPequeno.value.length < 4 ){
		alert( "Informe a descrição corretamente!" );
		produto.descricaoPequeno.focus();
		return false;
	}	
	
	//produto
	if( produto.codigo_categoria.selectedIndex == 0 ){
		alert( "Por favor o produto deve estar vinculado a uma categoria!" );
		produto.codigo_categoria.focus();
		return false;
	}

	//compara os dois preços caso esteja preenchido
	if( produto.preco.value != "" && produto.preco_de.value != "" ){
		//alert(produto.preco.value);
		//alert(produto.preco_de.value);

		numero_de = new String(produto.preco_de.value);
		var exp = /^\$|\./g ;
		// retira $ e .
		numero_de = numero_de.replace(exp, "");
		//alert(numero_de);

		numero_por = new String(produto.preco.value);
		var exp = /^\$|\./g ;
		// retira $ e .
		numero_por = numero_por.replace(exp, "");
		//alert(numero_por);
				
		//return false;
		
		if( parseFloat(numero_por) > parseFloat(numero_de) ){
			alert("O Preço Por: não deve ser maior do que o Preço De:");
			produto.preco.focus();	
			return false;
		}
	}
		
	//destaque
	/*
	if( produto.destaque.selectedIndex == 0 ){
		alert( "Informe se o produto será destaque na home!" );
		produto.destaque.focus();
		return false;
	}	
	*/
}





/********************************************************************** 
Arquivo de funções em Java Script para validação de campos 

Desenvolvedor    : Leandro Silva Ferreira 
E-mail            : leandro@i9web.com.br 


Qualquer dúvida, sugestão ou melhoramento dos scripts, por favor 
me envie um e-mail. 

/**********************************************************************/ 

/********************************************************************** 
Função de formatação de valores numéricos na digitação 

Objetivos : 
    - Inclusão automática de . e , 

Parametros : 
    objeto        -> Nome do campo de formulário (Usar this) 
    teclapres    -> Tecla pressionada (Usar event) 
    tammax        -> Tamanho máximo de caracteres 
    decimais    -> Nº de casas decimais 

Exemplo: 
    OnKeyDown     FormataValor(this,event,17,0); 


/**********************************************************************/ 
function FormataValor(objeto,teclapres,tammax,decimais) 
{ 

    var tecla            = teclapres.keyCode; 
    var tamanhoObjeto    = objeto.value.length; 

    if ((tecla == 8) && (tamanhoObjeto == tammax)) 
    { 
        tamanhoObjeto = tamanhoObjeto - 1 ; 
    } 



if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) && ((tamanhoObjeto+1) <= tammax)) 
    { 

        vr    = objeto.value; 
        vr    = vr.replace( "/", "" ); 
        vr    = vr.replace( "/", "" ); 
        vr    = vr.replace( ",", "" ); 
        vr    = vr.replace( ".", "" ); 
        vr    = vr.replace( ".", "" ); 
        vr    = vr.replace( ".", "" ); 
        vr    = vr.replace( ".", "" ); 
        tam    = vr.length; 
         
        if (tam < tammax && tecla != 8) 
        { 
            tam = vr.length + 1 ; 
        } 

        if ((tecla == 8) && (tam > 1)) 
        { 
            tam = tam - 1 ; 
            vr = objeto.value; 
            vr = vr.replace( "/", "" ); 
            vr = vr.replace( "/", "" ); 
            vr = vr.replace( ",", "" ); 
            vr = vr.replace( ".", "" ); 
            vr = vr.replace( ".", "" ); 
            vr = vr.replace( ".", "" ); 
            vr = vr.replace( ".", "" ); 
        } 
     
        //Cálculo para casas decimais setadas por parametro 
        if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) 
        { 
            if (decimais > 0) 
            { 
                if ( (tam <= decimais) ) 
                { 
                    objeto.value = ("0," + vr) ; 
                } 
                if( (tam == (decimais + 1)) && (tecla == 8)) 
                { 
                    objeto.value = vr.substr( 0, (tam - decimais)) + ',' + vr.substr( tam - (decimais), tam ) ;     
                } 
                if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) == "0")) 
                { 
                    objeto.value = vr.substr( 1, (tam - (decimais+1))) + ',' + vr.substr( tam - (decimais), tam ) ; 
                } 
                if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) != "0")) 
                { 
                    objeto.value = vr.substr( 0, tam - decimais ) + ',' + vr.substr( tam - decimais, tam ) ; 
                } 
                if ( (tam >= (decimais + 4)) && (tam <= (decimais + 6)) ) 
                { 
                     objeto.value = vr.substr( 0, tam - (decimais + 3) ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ; 
                } 
                 if ( (tam >= (decimais + 7)) && (tam <= (decimais + 9)) ) 
                { 
                     objeto.value = vr.substr( 0, tam - (decimais + 6) ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ; 
                } 
                if ( (tam >= (decimais + 10)) && (tam <= (decimais + 12)) ) 
                { 
                     objeto.value = vr.substr( 0, tam - (decimais + 9) ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ; 
                } 
                if ( (tam >= (decimais + 13)) && (tam <= (decimais + 15)) ) 
                { 
                     objeto.value = vr.substr( 0, tam - (decimais + 12) ) + '.' + vr.substr( tam - (decimais + 12), 3 ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ; 
                } 
            } 
            else if(decimais == 0) 
            { 
                if ( tam <= 3 ) 
                { 
                     objeto.value = vr ; 
                } 
                if ( (tam >= 4) && (tam <= 6) ) 
                { 
                    if(tecla == 8) 
                    { 
                        objeto.value = vr.substr(0, tam); 
                        window.event.cancelBubble = true; 
                        window.event.returnValue = false; 
                    } 
                    objeto.value = vr.substr(0, tam - 3) + '.' + vr.substr( tam - 3, 3 ); 
                } 
                if ( (tam >= 7) && (tam <= 9) ) 
                { 
                    if(tecla == 8) 
                    { 
                        objeto.value = vr.substr(0, tam); 
                        window.event.cancelBubble = true; 
                        window.event.returnValue = false; 
                    } 
                    objeto.value = vr.substr( 0, tam - 6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
                } 
                if ( (tam >= 10) && (tam <= 12) ) 
                { 
                     if(tecla == 8) 
                    { 
                        objeto.value = vr.substr(0, tam); 
                        window.event.cancelBubble = true; 
                        window.event.returnValue = false; 
                    } 
                    objeto.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
                } 
                if ( (tam >= 13) && (tam <= 15) ) 
                { 
                    if(tecla == 8) 
                    { 
                        objeto.value = vr.substr(0, tam); 
                        window.event.cancelBubble = true; 
                        window.event.returnValue = false; 
                    } 
                    objeto.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ) ; 
                }             
            } 
        } 
    } 
    else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46)) 
        { 
            window.event.cancelBubble = true; 
            window.event.returnValue = false; 
        } 
} 
/********************************************************************** 
Função de formatação de campos tipo texto durante a digitação 

Objetivos : 
    - Mudar tudo para maiúsculo 
    - Não aceitar acentos nem Ç 

Parâmetros : 
    objeto        -> Nome do campo de formulário (Usar this) 

Exemplo : 
    OnKeyPress    FormataTexto(this); 
/**********************************************************************/ 
function FormataTexto(objeto) 
{ 
    var valor = objeto.value;     
    var LetrasArray = new Array(); 

    LetrasArray[1] = new Array(); 
    LetrasArray[2] = new Array(); 
     
    //Primeira Coluna : Letras Acentuadas e Símbolos 
    LetrasArray[1][1]='á'; 
    LetrasArray[1][2]='ã'; 
    LetrasArray[1][3]='à'; 
    LetrasArray[1][4]='â'; 
    LetrasArray[1][5]='ä'; 
    LetrasArray[1][6]='é'; 
    LetrasArray[1][7]='è'; 
    LetrasArray[1][8]='ê'; 
    LetrasArray[1][9]='ë'; 
    LetrasArray[1][10]='í'; 
    LetrasArray[1][11]='ì'; 
    LetrasArray[1][12]='î'; 
    LetrasArray[1][13]='ï'; 
    LetrasArray[1][14]='ó'; 
    LetrasArray[1][15]='õ'; 
    LetrasArray[1][16]='ò'; 
    LetrasArray[1][17]='ô'; 
    LetrasArray[1][18]='ö'; 
    LetrasArray[1][19]='ú'; 
    LetrasArray[1][20]='ù'; 
    LetrasArray[1][21]='û'; 
    LetrasArray[1][22]='ü'; 
    LetrasArray[1][23]='ç'; 
    LetrasArray[1][24]='Á'; 
    LetrasArray[1][25]='Ã'; 
    LetrasArray[1][26]='À'; 
    LetrasArray[1][27]='Â'; 
    LetrasArray[1][28]='Ä'; 
    LetrasArray[1][29]='É'; 
    LetrasArray[1][30]='È'; 
    LetrasArray[1][31]='Ê'; 
    LetrasArray[1][32]='Ë'; 
    LetrasArray[1][33]='Í'; 
    LetrasArray[1][34]='Ì'; 
    LetrasArray[1][35]='Î'; 
    LetrasArray[1][36]='Ï'; 
    LetrasArray[1][37]='Ó'; 
    LetrasArray[1][38]='Õ'; 
    LetrasArray[1][39]='Ò'; 
    LetrasArray[1][40]='Ô'; 
    LetrasArray[1][41]='Ö'; 
    LetrasArray[1][42]='Ú'; 
    LetrasArray[1][43]='Ù'; 
    LetrasArray[1][44]='Û'; 
    LetrasArray[1][45]='Ü'; 
    LetrasArray[1][46]='Ç'; 
    LetrasArray[1][47]='Ñ'; 
    LetrasArray[1][48]='ñ'; 
    LetrasArray[1][49]='~'; 
    LetrasArray[1][50]='^'; 
    LetrasArray[1][51]='´'; 
    LetrasArray[1][52]='`'; 
     
    //Segunda Coluna : Letras Equivalentes sem acentos 
    LetrasArray[2][1]='a'; 
    LetrasArray[2][2]='a'; 
    LetrasArray[2][3]='a'; 
    LetrasArray[2][4]='a'; 
    LetrasArray[2][5]='ä'; 
    LetrasArray[2][6]='e'; 
    LetrasArray[2][7]='e'; 
    LetrasArray[2][8]='e'; 
    LetrasArray[2][9]='e'; 
    LetrasArray[2][10]='i'; 
    LetrasArray[2][11]='i'; 
    LetrasArray[2][12]='i'; 
    LetrasArray[2][13]='i'; 
    LetrasArray[2][14]='o'; 
    LetrasArray[2][15]='o'; 
    LetrasArray[2][16]='o'; 
    LetrasArray[2][17]='o'; 
    LetrasArray[2][18]='o'; 
    LetrasArray[2][19]='u'; 
    LetrasArray[2][20]='u'; 
    LetrasArray[2][21]='u'; 
    LetrasArray[2][22]='u'; 
    LetrasArray[2][23]='c'; 
    LetrasArray[2][24]='A'; 
    LetrasArray[2][25]='A'; 
    LetrasArray[2][26]='A'; 
    LetrasArray[2][27]='A'; 
    LetrasArray[2][28]='Ä'; 
    LetrasArray[2][29]='E'; 
    LetrasArray[2][30]='E'; 
    LetrasArray[2][31]='E'; 
    LetrasArray[2][32]='E'; 
    LetrasArray[2][33]='I'; 
    LetrasArray[2][34]='I'; 
    LetrasArray[2][35]='I'; 
    LetrasArray[2][36]='I'; 
    LetrasArray[2][37]='O'; 
    LetrasArray[2][38]='O'; 
    LetrasArray[2][39]='O'; 
    LetrasArray[2][40]='O'; 
    LetrasArray[2][41]='O'; 
    LetrasArray[2][42]='U'; 
    LetrasArray[2][43]='U'; 
    LetrasArray[2][44]='U'; 
    LetrasArray[2][45]='U'; 
    LetrasArray[2][46]='C'; 
    LetrasArray[2][47]='N'; 
    LetrasArray[2][48]='n'; 
    LetrasArray[2][49]=''; 
    LetrasArray[2][50]=''; 
    LetrasArray[2][51]=''; 
    LetrasArray[2][52]=''; 

    temp = "" + valor + (String.fromCharCode(window.event.keyCode)); 

    for (i=1; i<=52 ; i++ ) 
    { 
        while (temp.indexOf((LetrasArray[1][i]))>-1) 
            { 
                pos= temp.indexOf((LetrasArray[1][i])); 
                temp = "" + (temp.substring(0, pos) + (LetrasArray[2][i]) + temp.substring((pos + (LetrasArray[1][i].length)), temp.length)); 
            } 
    } 
    if((window.event.keyCode) != 13) 
        { 
            objeto.value = (temp.toUpperCase()); 
            window.event.cancelBubble = true; 
            window.event.returnValue = false; 
        } 

} 

/********************************************************************** 
Função de validação de campos do tipo Data 

Objetivos : 
    - Aceitar somente datas do tipo : dd/mm/aaaa 

Parâmetros : 
    objeto        -> Nome do campo de formulário (Usar this) 

Exemplo : 
    OnChange    ValidaData(this); 
/**********************************************************************/ 
function ValidaData(objeto) 
{ 

    var DataString    = objeto.value; 
    var DataArray    = DataString.split("/");   
    var Flag=true; 

    if (DataArray.length != 3) 
        Flag=false; 
    else 
        { 
            if (DataArray.length==3) 
            { 
                var dia = DataArray[0], mes = DataArray[1], ano = DataArray[2]; 

                if (((Flag) && (ano<1000) || ano.length>4)) 
                    Flag=false; 
                 
                if (Flag) 
                { 
                    verifica_mes = new Date(mes+"/"+dia+"/"+ano); 
                    if (verifica_mes.getMonth() != (mes - 1)) 
                        Flag=false; 
                } 
            } 
            else 
                Flag=false; 
        } 
return Flag; 
} 

/********************************************************************** 
Função de formatação de campos do tipo Data 

Objetivos : 
    - Mascarar a entrada de dados no formato : dd/mm/aaaa 

Parâmetros : 
    objeto        -> Nome do campo de formulário (Usar this) 
    teclapress    -> Tecla pressionada (Usar event) 

Exemplo : 
    OnKeyDown    FormataData(this,event); 

Requirido : 
    Função ValidaData 
/**********************************************************************/ 
function FormataData(objeto,teclapress) 
{ 
    var tecla = teclapress.keyCode; 

    if(((window.event.keyCode == 13) || (window.event.keyCode == 9))&&objeto.value != "") 
    { 
        if(!(ValidaData(objeto))) 
            { 
                window.event.cancelBubble = true; 
                window.event.returnValue = false; 
                alert("Data Inválida"); 
                objeto.value = ""; 
                objeto.focus(); 
            } 
    } 

    if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )&& objeto.value.length < (10)) 
    { 
        vr = objeto.value; 
        vr = vr.replace( "/", "" ); 
        vr = vr.replace( "/", "" ); 
        tam = vr.length; 

        if (tam < 8) 
            { 
                if (tecla != 8) {tam = vr.length + 1 ;} 
            } 
        else 
            { 
                window.event.cancelBubble = true; 
                window.event.returnValue = false; 
            } 
         
        if ((tecla == 8) && (tam > 1)) 
            { 
                tam = tam - 1 ; 
                objeto.value = vr.substr(0,tam); 
                window.event.cancelBubble = true; 
                window.event.returnValue = false; 
            } 
                if ( tam <= 4 && tecla != 8){ 
                     objeto.value = vr ; } 

                if ( (tam >= 4) && (tam <= 6) ){ 
                     objeto.value = vr.substr(0, tam - 4) + '/' + vr.substr( tam - 4, 4 ); } 

                if ( (tam >= 6) && (tam <= 8) ){ 
                    objeto.value = vr.substr(0, tam - 6 ) + '/' + vr.substr( tam - 6, 2 ) + '/' + vr.substr( tam - 4, 4 ); } 

                if ((tam == (8)) && tecla != 8) 
                    { 
                        if(tecla >=96 && tecla <=105) 
                            { 
                                tecla = tecla - 48; 
                            } 

                        objeto.value = objeto.value + (String.fromCharCode(tecla)); 
                        window.event.cancelBubble = true; 
                        window.event.returnValue = false; 

                        if (!(ValidaData(objeto))) 
                            { 
                                alert("Data Inválida"); 
                                objeto.value = ""; 
                                objeto.focus(); 
                            } 
                    } 
    } 
    else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46)) 
        { 
            event.returnValue = false; 
        } 
} 


/********************************************************************** 
Função de validação de campos do tipo Data Hora 

Objetivos : 
    - Aceitar somente datas do tipo : dd/mm/aaaa hh:mm:ss 

Parâmetros : 
    objeto        -> Nome do campo de formulário (Usar this) 

Exemplo : 
    OnChange    ValidaDataHora(this); 
/**********************************************************************/ 
function ValidaDataHora(objeto) 
{         
    var DataHoraString    = objeto.value; 
    var Flag            = true; 
     
    if(DataHoraString != "" &&((DataHoraString.indexOf("/")!= -1) && (DataHoraString.indexOf(" ")!= -1) && (DataHoraString.indexOf(":")!= -1))) 
    { 
//        dd/mm/aaaa hh:mm:ss 
        var DataArray    = DataHoraString.split("/");   
//        DataArray[0]    = dd; 
//        DataArray[1]    = mm;     
//        DataArray[2]    = aaaa hh:mm:ss    ; 

        var AuxArray    = DataArray[2].split(" "); 
//        AuxArray[0]        = aaaa; 
//        AuxArray[1]        = hh:mm:ss; 
     
        DataArray[2]    = AuxArray[0]; 
     
        var HoraArray    = AuxArray[1].split(":"); 
//        HoraArray[0]    = hh; 
//        HoraArray[1]    = mm; 
//        HoraArray[2]    = ss; 

        if(HoraArray[2] >= 0){Flag = true;} 
    } 
    else {Flag= false;} 

if(Flag) 
    { 
        //Valida a data 
        if (DataArray.length != 3) 
            Flag=false; 
        else 
            { 
                if (DataArray.length==3) 
                { 
                    var dia = DataArray[0], mes = DataArray[1], ano = DataArray[2]; 
     
                    if (((Flag) && (ano<1000) || ano.length>4)) 
                        Flag=false; 
                     
                    if (Flag) 
                    { 
                        verifica_mes = new Date(mes+"/"+dia+"/"+ano); 
                        if (verifica_mes.getMonth() != (mes - 1)) 
                            Flag=false; 
                    } 
                } 
                else 
                    Flag=false; 
            } 
     
        //Valida a hora 
        if (HoraArray.length != 3) 
            Flag=false; 
        else 
            { 
                if (HoraArray.length==3) 
                { 
                    var hora = HoraArray[0], min = HoraArray[1], seg = HoraArray[2]; 
                     
                    if(!((hora>=0 && hora <=23) && (min>=0 && min<=59) && (seg>=0 && seg<=59))) 
                        Flag=false; 
                } 
                else 
                    Flag=false; 
            } 
    }         
return Flag; 
} 

/********************************************************************** 
Função de formatação de campos do tipo Data Hora 

Objetivos : 
    - Mascarar a entrada de dados no formato : dd/mm/aaaa hh:mm:ss 

Parâmetros : 
    objeto        -> Nome do campo de formulário (Usar this) 
    teclapress    -> Tecla pressionada (Usar event) 

Exemplo : 
    OnKeyPress    FormataDataHora(this); 

Requirido : 
    Função ValidaDataHora(objeto); 
/**********************************************************************/ 
function FormataDataHora(objeto,teclapress) 
{ 
    var tecla = teclapress.keyCode; 

    if(((window.event.keyCode == 13) || (window.event.keyCode == 9))&&objeto.value != "") 
    { 
        if(!(ValidaDataHora(objeto))) 
            { 
                window.event.cancelBubble = true; 
                window.event.returnValue = false; 
                alert("Data Hora Inválida"); 
                objeto.value = ""; 
                objeto.focus(); 
            } 
    } 

    if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )&& objeto.value.length <= (19)) 
    { 
        vr = objeto.value; 
        vr = vr.replace( "/", "" ); 
        vr = vr.replace( "/", "" ); 
        vr = vr.replace( " ", "" ); 
        vr = vr.replace( ":", "" ); 
        vr = vr.replace( ":", "" ); 
        tam = vr.length; 

        if (tam < 14) 
            { 
                if (tecla != 8) {tam = vr.length + 1 ;} 
            } 
        else 
            { 
                window.event.cancelBubble = true; 
                window.event.returnValue = false; 
            } 
         
        if ((tecla == 8) && (tam > 1)) 
            { 
                tam = tam - 1 ; 
                objeto.value = vr.substr(0,tam); 
                window.event.cancelBubble = true; 
                window.event.returnValue = false; 
            } 
                if ( tam <= 2 && tecla != 8){ 
                     objeto.value = vr ; } 

                if ( (tam >= 2) && (tam <= 4) ){ 
                     objeto.value = vr.substr(0, tam - 2) + ':' + vr.substr( tam - 2, 2 ); } 

                if ( (tam >= 4) && (tam <= 6) ){ 
                    objeto.value = vr.substr(0, tam - 4 ) + ':' + vr.substr( tam - 4, 2 ) + ':' + vr.substr( tam - 2, 2 ); } 

                if ( (tam >= 6) && (tam <= 10) ){ 
                    objeto.value = vr.substr(0, tam - 6 ) + ' ' + vr.substr( tam - 6, 2 ) + ':' + vr.substr( tam - 4, 2 ) + ':' + vr.substr( tam - 2, 2 ); } 


                if ( (tam >= 10) && (tam <= 12) ){ 
                    objeto.value = vr.substr(0, tam - 10 ) + '/' + vr.substr( tam - 10, 4 ) + ' ' + vr.substr( tam - 6, 2 ) + ':' + vr.substr( tam - 4, 2 ) + ':' + vr.substr( tam - 2, 2 ) ;}             

                if ( (tam >= 12) && (tam <= 14) ){ 
                    objeto.value = vr.substr(0, tam - 12 ) + '/' + vr.substr( tam - 12, 2 ) + '/' + vr.substr( tam - 10, 4 ) + ' ' + vr.substr( tam - 6, 2 ) + ':' + vr.substr( tam - 4, 2 ) + ':' + vr.substr( tam - 2, 2 ) ;}             

                if ((tam == (14)) && tecla != 8) 
                    { 
                        if (!(ValidaDataHora(objeto))) 
                            { 
                                if(tecla >=96 && tecla <=105){tecla = tecla - 48;} 
                                objeto.value = objeto.value + (String.fromCharCode(tecla)); 
                                window.event.cancelBubble = true; 
                                window.event.returnValue = false; 
                                alert("Data Hora Inválida"); 
                                objeto.value = ""; 
                                objeto.focus(); 
                            } 
                    } 
    } 
    else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46)) 
        { 
            event.returnValue = false; 
        } 
} 







/*valida cliente*/
// Calculo do CNPJ 
function valida_cnpj(cnpj) {
	var erro = true; 
	var aux_cnpj = "";	
	var cnpj1=0,cnpj2=0;
	for(j=0;j<cnpj.length;j++)
		if(cnpj.substr(j,1)>="0" && cnpj.substr(j,1)<="9")
			aux_cnpj += cnpj.substr(j,1);
	if(aux_cnpj.length!=14)
		erro = false;
	else {
		cnpj1 = aux_cnpj.substr(0,12);
		cnpj2 = aux_cnpj.substr(aux_cnpj.length-2,2);
		fator = "543298765432";
		controle = "";
		for(j=0;j<2;j++) {
			soma = 0;
			for(i=0;i<12;i++) 
				soma += cnpj1.substr(i,1) * fator.substr(i,1);
			if(j==1) soma += digito * 2;
			digito = (soma * 10) % 11;
			if(digito==10) digito = 0;
			controle += digito;
			fator = "654329876543";
		} 
		if(controle!=cnpj2)
			erro = false;
	} 
	return erro;
}

// Valida&ccedil;&atilde;o do CPF
function valida_cpf(cpf) {
	var cpf = new String(cpf);
    var aux_cpf = "";
	
	if(cpf.length!=11)
		return false;	
		
    for(j=0;j<cpf.length;j++)
  		if(cpf.substr(j,1)>="0" && cpf.substr(j,1)<="9")
   			aux_cpf += cpf.substr(j,1);
	if(aux_cpf.length!=11)
		return false;
    else {
    	var cpf1 = String(aux_cpf);
    	var cpf2 = cpf.substr(cpf.length-2,2);
      	var controle = "";
      	var start = 2;
      	var end = 10;
      	for(var i=1;i<=2;i++) {
      		var soma = 0;
      		for(j=start;j<=end;j++)
      			soma += cpf1.substr((j-i-1),1)*(end+1+i-j);
        	if(i==2)
          		soma += digito * 2;
        	digito = (soma * 10) % 11;
        	if(digito==10)
          		digito = 0;
        	controle += digito;
        	start = 3;
        	end = 11;
      	}
      	if(controle!=cpf2)
        	return false;
    }
	
	return true;
}

// verifica se um ano é bissexto
function ano_bi(ano) {
	if (ano % 100 == 0) {
		if (ano % 400 == 0) 
			return true; 
	}
	else 
		if ((ano % 4) == 0) 
			return true; 
	return false;
}


function valida_data(data) {
	
	var datePat = /^(\d{1,2})(\/|-|.)(\d{1,2})\2(\d{4})$/;

	var datadiv = data.match(datePat);

	var minhaDataAtual = new Date();
	
	dia_atual = minhaDataAtual.getDate() 
	mes_atual = parseInt(minhaDataAtual.getMonth()) + 1 
	ano_atual = minhaDataAtual.getFullYear() 

   	if (datadiv==null){
		return false;
	}
	
	var dia = datadiv[1];
	var mes = datadiv[3];
	var ano = datadiv[4];


	if(mes==02)
		if(dia>29)
			return false;
		else
			if(dia==29 && !ano_bi(ano))
				return false;
	

	if( (ano > ano_atual) ){
		return false;		
	}

	if( mes > mes_atual && ano > ano_atual){
		return false;
	}

	if(dia<1 || dia>31 || mes<1 || mes>12 || ano < (ano_atual-120)){
		return false;
	}

	if ((mes==4 || mes==6 || mes==9 || mes==11) && dia>30) {
		return false;
	}

	var dataPassada = new Date(ano,mes-1,dia);
	


	if(dataPassada>minhaDataAtual){	
		return false;
	}
	
	
	return true;

}

function valida_numero(numero,inteiro) {
	numero = new String(numero);
	
	if(numero.length==0)
		return false;
		
	var exp = /^\$|\./g ;

	// retira $ e .
	numero = numero.replace(exp, "");
	
	exp = /,/g ;
	
	// troca , por .
	numero = numero.replace(exp,".");

	numero = parseFloat(numero);
	
	if(isNaN(numero))
		return false;

	if(inteiro && numero!=Math.round(numero))
		return false;
		
	return true;

}

/*valida endereco*/
function endereco(cliente){
	//endereco
	if( cliente.endereco.value == "" ){
		alert( "Por favor digite o endereço!" );
		cliente.endereco.focus();
		return false;
	}
	//cli_bairro
	/*
	if( cliente.bairro.value == "" ){
		alert( "Por favor digite o bairro!" );
		cliente.bairro.focus();
		return false;
	}
	*/
	//cidade
	if( cliente.cidade.value == "" ){
		alert( "Por favor digite a cidade!" );
		cliente.cidade.focus();
		return false;
	}
	//uf
	if( cliente.uf.selectedIndex == 0 ){
		alert( "Por favor informe o estado!" );
		cliente.uf.focus();
		return false;
	}	
	//pais
	if( cliente.pais.selectedIndex == 0 ){
		alert( "Por favor informe o pais!" );
		cliente.pais.focus();
		return false;
	}		

	//cep
	if( cliente.cep.value == "" ){
		alert( "Por favor digite o cep!" );
		cliente.cep.focus();
		return false;
	}

	if( cliente.cep.value.length < 8 ){
		alert( "O cep deve possuir 8 dígitos!" );
		cliente.cep.focus();
		return false;
	}
		
	if(!valida_numero(cliente.cep.value,false)){
		alert( "O cep esta inválido!" );
		cliente.cep.focus();
		return false;
	}
	
	return true;
}

/*valida contato*/
function contato(cliente){

	if(cliente.email.value=="" && cliente.dddTel.value == "" && cliente.tel.value == "" && cliente.dddFax.value == "" && cliente.fax.value == "" && cliente.dddCel.value == "" && cliente.cel.value == ""){

	alert( "Por favor informe pelo menos um contato!" );
	cliente.email.focus();
	return false;		
	
	}
	//e-mail		
	if( cliente.email.value != "" ){
		if( cliente.email.value.indexOf('@', 0) == -1 || cliente.email.value.indexOf('.', 0) == -1 ){
			alert( "E-mail inválido!" );
			cliente.email.focus();
			return false;
		}
	}
	
	//dddTel
	if( cliente.dddTel.value != "" || cliente.tel.value != ""){
		
		if( cliente.dddTel.value.length < 2 ){
			alert( "Informe o DDD corretamente!" );
			cliente.dddTel.focus();
			return false;
		}

		if(!valida_numero(cliente.dddTel.value,false)){
			alert( "O ddd esta inválido!" );
			cliente.dddTel.focus();
			return false;
		}	

		//telefone
		if( cliente.tel.value == "" ){
			alert( "Informe o telefone de contato!" );
			cliente.tel.focus();
			return false;
		}
	
		if( cliente.tel.value.length < 7 ){
			alert( "Informe o Telefone corretamente!" );
			cliente.tel.focus();
			return false;
		}
		
		if(!valida_numero(cliente.tel.value,false)){
			alert( "O telefone esta inválido!" );
			cliente.tel.focus();
			return false;
		}	
		
	}

	//dddFax
	if( cliente.dddFax.value != "" || cliente.fax.value != ""  ){

		if( cliente.dddFax.value.length < 2 ){
			alert( "Informe o DDD corretamente!" );
			cliente.dddFax.focus();
			return false;
		}
		
		if(!valida_numero(cliente.dddFax.value,false)){
			alert( "O ddd esta inválido!" );
			cliente.dddFax.focus();
			return false;
		}	
		
		if( cliente.fax.value.length < 7 ){
			alert( "Informe o fax  corretamente!" );
			cliente.fax.focus();
			return false;
		}
		
		if(!valida_numero(cliente.fax.value,false)){
			alert( "O fax está inválido!" );
			cliente.fax.focus();
			return false;
		}	

	}

	//dddCel

	if(cliente.dddCel.value != "" || cliente.cel.value != ""){
	
		if( cliente.dddCel.value.length < 2 ){
			alert( "Informe o DDD corretamente!" );
			cliente.dddCel.focus();
			return false;
		}
		
		if(!valida_numero(cliente.dddCel.value,false)){
			alert( "O ddd esta inválido!" );
			cliente.dddCel.focus();
			return false;
		}
	
	
		//celular
		if( cliente.cel.value.length < 8 ){
			alert( "Informe o Celular corretamente!" );
			cliente.cel.focus();
			return false;
		}
		
		if(!valida_numero(cliente.cel.value,false)){
			alert( "O celular esta inválido!" );
			cliente.cel.focus();
			return false;
		}	
	
	}
	
		
	
	return true;

}
/*valida cliente*/
function validaCliente( cliente, pessoa, mSexo, mData, mEndereco, mContato ){
	
	if(pessoa=="F"){//inicio pessoa fisica
		//nome
		if( cliente.nome.value == "" ){
			alert( "Por favor digite o nome completo!" );
			cliente.nome.focus();
			return false;
		}
		//sexo
		if(mSexo=="S"){
			if( cliente.sexo.selectedIndex == 0 ){
				alert( "Por favor informe o sexo!" );
				cliente.sexo.focus();
				return false;
			}
		}
		//nascimento
		if(mData=="S"){
			if(cliente.nascimento.value!=""){
				if(!valida_data(cliente.nascimento.value)){
					alert( "Data Inválida" );
					cliente.nascimento.focus();
					return false;
				}
			}
		}
		/****endereco****/
		if(mEndereco=="S"){
			if(!endereco(cliente)){
				return false;
			}
		}
		/****contato****/
		if(mContato=="S"){
			if(!contato(cliente)){
				return false;
			}
		}
		
	}//final pessoa física
	
	if(pessoa=="J"){
		//nome
		if( cliente.nome.value == "" ){
			alert( "Por favor digite a Razão Social!" );
			cliente.nome.focus();
			return false;
		}
		//contato
		if( cliente.contato.value == "" ){
			alert( "Por favor digite o nome do Contato!" );
			cliente.contato.focus();
			return false;
		}		
		/****endereco****/
		if(mEndereco=="S"){
			if(!endereco(cliente)){
				return false;
			}
		}
		/****contato****/
		if(mContato=="S"){
			if(!contato(cliente)){
				return false;
			}
		}
	}	

	//tipo
	if( cliente.tipo.value == "" ){
		alert( "O tipo é obrigatório para critério de pesquisa!" );
		cliente.tipo.focus();
		return false;
	}

	//status
	if( cliente.ativo.selectedIndex < 0 ){
		alert( "Por favor informe o status!" );
		cliente.ativo.focus();
		return false;
	}	
	
	return true;


}

function desabilita_juridica(){
	
	cliente.cpf.disabled=false;
	cliente.cpf.value=cliente.cpf.value;
	cliente.rg.disabled=false;
	cliente.nascimento.disabled=false;	
	cliente.sexo.disabled=false;	
	//cliente.sexo.selectedIndex = 0;

	cliente.cnpj.disabled=true;
	cliente.ie.disabled=true;
	cliente.contato.disabled=true;	

	cliente.cnpj.value="";
	cliente.ie.value="";
	cliente.contato.value="";	
	
	cliente.nascimento.value="";
	
}

function desabilita_fisica(){

	cliente.cnpj.disabled=false;
	cliente.cnpj.value=cliente.cnpj.value;
	cliente.ie.disabled=false;
	cliente.ie.value=cliente.ie.value;
	cliente.contato.disabled=false;	

	cliente.cpf.value="";
	cliente.rg.value="";
	cliente.nascimento.value="";
	cliente.sexo.selectedIndex = 0;
	
	cliente.cpf.disabled=true;	
	cliente.rg.disabled=true;
	cliente.nascimento.disabled=true;	
	cliente.sexo.disabled=true;	
	
}


/*mail list*/
function val() {

	var total;
	var selecionado;
	selecionado = false;
	total = document.frm_cliente.elements.length;
	for (var i=0;i<total;i++) {
		/*
		var x = document.frm_cliente.elements[i];
		if (x.name == "email[]") {
			checa = frm_cliente.elements[i].checked==true;
			if(!checa){
				alert("Selecione pelo menos um cliente.");
				return false;
			}
			return true;
		}
		*/
		//alterado por fabio martins
		//problema: o for só verificava o primeiro elemento checado
		checa = frm_cliente.elements[i].checked;
		
		if(checa==true){
			selecionado=true;
		}

	}
	
	if(selecionado){
		return true;
	}else{
		alert("Selecione pelo menos um cliente.");
		return false;
	}
	
	

}


cont = 0;
function CheckAll() {

	for (var i=0;i<document.frm_cliente.elements.length;i++) {
		var x = document.frm_cliente.elements[i];
		if (x.name == 'email[]') {
			x.checked = document.frm_cliente.selall.checked;
		}
	}

	if (cont == 0){   
		var elem = document.getElementById("checar");
		elem.innerHTML = " Marcar todos";
		cont = 1;
	} else {
		var elem = document.getElementById("checar");
		elem.innerHTML = " Marcar todos";
		cont = 0;
	}

}
//-->

function validaMailList( email ){

	//nome completo
	if( email.assunto.value == "" ){
		alert( "Por favor digite o Assunto!" );
		email.assunto.focus();
		return false;
	}
	if( email.assunto.length < 3 ){
		alert( "Número de caracteres insuficiente para o assunto!" );
		email.assunto.focus();
		return false;
	}
}

/*valida fale conosco*/
function validaFaleConosco(formfaleconosco){

	//nome
	if(formfaleconosco.nome.value==""){
		alert("Informe seu nome!");
		formfaleconosco.nome.focus();
		return false;
	}

	//e-mail
	if(formfaleconosco.email.value==""){
		alert("Informe seu E-mail!");
		formfaleconosco.email.focus();
		return false;
	}

	if(formfaleconosco.email.value.indexOf('@',0)==-1 || formfaleconosco.email.value.indexOf('.',0)==-1){
		alert("E-mail inválido!");
		formfaleconosco.email.focus();
		return false;
	}
	
	//mensagem
	if(formfaleconosco.mensagem.value==""){
		alert("Informe sua mensagem!");
		formfaleconosco.mensagem.focus();
		return false;
	}	
}

/*valida Logo*/
function validaLogo( formlogo, acao ){
	
	//nome completo
	if( formlogo.txtLogNome.value == "" ){
		alert( "Por favor digite o nome logo!" );
		formlogo.txtLogNome.focus();
		return false;
	}
	if( formlogo.txtLogNome.value.length < 2 ){
		alert( "Informe o nome corretetamente!" );
		musica.txtLogNome.focus();
		return false;
	}
	
	if(acao=="I"){
		//arquivo	
		if( formlogo.txtLogArquivo.value == "" ){
			alert( "Por favor selecione o arquivo do logo!" );
			formlogo.txtLogArquivo.focus();
			return false;
		}
	}

}


//valida senha
function validaSenha( senha ){

	//senha		
	if( senha.senha.value == "" ){
		alert( "Por favor digite a senha!" );
		senha.senha.focus();
		return false;
	}

	if( senha.senha.value.length < 4 ){
		alert( "Número de caracteres insuficiente para a senha!" );
		senha.senha.focus();
		return false;
	}	
	
	if( senha.senha2.value == "" ){
		alert( "Por favor digite a senha novamente!" );
		senha.senha2.focus();
		return false;
	}

	if( senha.senha.value != senha.senha2.value ){
		alert( "As senhas estão diferentes, por favor digite novamente!" );
		senha.senha2.focus();
		return false;
	}

}

/*valida popup*/
function validaPopup( promocao ){
	//nome completo
	if( promocao.nome.value == "" ){
		alert( "Por favor digite o nome do Popup!" );
		promocao.nome.focus();
		return false;
	}
	if( promocao.nome.value.length < 3 ){
		alert( "Nome inválido!" );
		promocao.nome.focus();
		return false;
	}
	if( promocao.largura.value == "" ){
		alert( "Informa a largura do Popup!" );
		promocao.largura.focus();
		return false;
	}
	if( promocao.altura.value == "" ){
		alert( "Informa a altura do Popup!" );
		promocao.altura.focus();
		return false;
	}	
}

/*valida pdf*/
function validaPdf( pdf, acao ){
	//nome completo
	if( pdf.nome.value == "" ){
		alert( "Por favor digite o nome do PDF!" );
		pdf.nome.focus();
		return false;
	}
	if( pdf.nome.value.length < 3 ){
		alert( "Nome inválido!" );
		pdf.nome.focus();
		return false;
	}
	if(acao=="I"){
		//arquivo	
		if( pdf.arquivo.value == "" ){
			alert( "Por favor selecione o arquivo para upload!" );
			pdf.arquivo.focus();
			return false;
		}
	}
}

/*valida topo*/
function validaTopo( topo, acao ){
	//nome completo
	if( topo.nome.value == "" ){
		alert( "Por favor digite o nome do Arquivo!" );
		topo.nome.focus();
		return false;
	}
	if( topo.nome.value.length < 3 ){
		alert( "Nome inválido!" );
		topo.nome.focus();
		return false;
	}
	if(acao=="I"){
		//arquivo	
		if( topo.arquivo.value == "" ){
			alert( "Por favor selecione o arquivo para upload!" );
			topo.arquivo.focus();
			return false;
		}
	}
}

/*valida interesse*/
function validaInteresse( interesse, acao ){
	//nome completo
	if( interesse.nome.value == "" ){
		alert( "Por favor digite o nome!" );
		interesse.nome.focus();
		return false;
	}
	if( interesse.nome.value.length < 3 ){
		alert( "Nome inválido!" );
		interesse.nome.focus();
		return false;
	}

}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
