nenhuma=0;  
reais=1;  
dolares=2;  
truncar=0;  
aproximar=1;  

function isNumeric(valor)
	{
	 if (valor.value < 0 || valor.value > 9 )
		{
		 alert("<%=lg_alert_so_numeros%>");
		 valor.select();
		}
		 
	}

function notString(valor)
	{
//alert(valor.value);
	 if (isNaN(valor.value) && valor.value != "/")
		{
		 alert("<%=lg_alert_so_numeros_barras%>");
		 valor.select();
		}
		 
	}

function ValidaDataHoje(dt)
{	
	var n_barras = 0; var d1 = ""; var m1 = ""; var a1 = ""; var d2 = ""; var m2 = ""; var a2 = "";
	//
	for(i=0; i<dt.length; i++) {
		c = dt.substring(i,i+1);
		if (c == "/") 
			n_barras++;
		else
		{
			if (n_barras > 1)  
				a2 += c;
			else
			{
				if (n_barras > 0)  
					m2 += c;
				else
					d2 += c;
			}
		}
	}
	//
	if(a1>a2)
		return false;
	if(a1==a2&&m1>m2)
		return false;
	if(a1==a2&&m1==m2&&d1>d2)
		return false;
	return true;
}


function validaTreino()
{
	erro = "";
	erro1 = "<%=lg_alert_campos_obr%>"
	//
	if(document.form1.txtminuto2.value == "")
		document.form1.txtminuto2.value = "00";
	if(document.form1.txthora2.value == "")
		document.form1.txthora2.value = "00";
	//
	if (document.form1.txtdata.value == "" )
	{
		 erro += "\n - Data do treinamento ";
	}

	if (document.form1.txthora.value == "" || document.form1.txtminuto.value == "")
	{
		 erro += "\n - Horario de inicio do treino (hh : mm)";
	}

	if (document.form1.txtminuto2.value == "00" && document.form1.txthora2.value == "00")
	{
		 erro += "\n - Tempo de duração (hh : mm)";
	}

	if (document.form1.descricao.value == "")
	{
		 erro += "\n - Descrição" ;
	}

	if(erro != "")
	{
		 alert(erro1 + erro);
		 return false;
	}

	if(ValidaData(document.form1.txtdata.value)!=true || ValidaDataTreino(document.form1.txtdata.value,document.form1.txtdataatu.value)!=true)
	{
		alert("Data do treinamento inválida!");
		document.form1.txtdata.focus();
		return false;
	}
	
	if(SoNumeros(document.form1.txthora.value)!=true || SoNumeros(document.form1.txtminuto.value)!=true
	    || document.form1.txthora.value>24 || document.form1.txtminuto.value>59)
	{
		alert("<%=lg_hora_erro%>");
		document.form1.txthora.focus();
		return false;
	}

	if(SoNumeros(document.form1.txthora2.value)!=true || SoNumeros(document.form1.txtminuto2.value)!=true
	    || document.form1.txthora2.value>24 || document.form1.txtminuto2.value>59
	    || document.form1.txthora2.value+document.form1.txtminuto2.value==0)
	{
		alert("<%=lg_hora_erro%>");
		document.form1.txthora2.focus();
		return false;
	}
	
} 
function formatamoeda(valor,moeda,metodo) {  
retorno="";  
if (moeda==reais){retorno="R$ "}  
if (moeda==dolares){retorno="US$ "}  
if (metodo==aproximar){valor=valor+.005}  
if(valor<0){  
retorno=retorno+"-";  
valor=-valor};  
if(valor<1){  
casas=1  
}else{  
for( casas = 0 ; Math.pow(1000,casas) < valor; casas++){};};  
strvalor=""+Math.floor(valor);  
dif= strvalor.length;  
dif=dif + 3- (casas*3);  
retorno=retorno+strvalor.substring(0,dif);  
for(x=0;x<=casas;x++){  
if(x<casas-1){retorno=retorno+"."};  
retorno=retorno+strvalor.substring((x*3)+dif,(x*3)+3+dif);};  
retorno=retorno+",";  
decimal=Math.floor((valor-Math.floor(valor))*100);  
if (decimal<10){retorno=retorno+"0"};  
retorno=retorno+decimal;  
return retorno;  
}; 


if (document.all){
	sender="event.srcElement"
}else{
	sender="e.target"
}

function inteiro(e){
	alvo=eval(sender)
	if (document.all){
		x=event.keyCode;
	}else{
		x=e.which
	}
	if (x>47 && x<58 || x==8){return true}else{return false}
}

function tudo(e){
	return true
}

function numero(e){
	obj=eval(sender)
	valor=obj.value;
	if (document.all){
		x=event.keyCode;
	}else{
		x=e.which
	}
	if(x==44){
		if(document.all && valor.indexOf(".")==-1){
			event.keyCode=46;
			return true
		}else{
		window.status="Use ponto como separador de centavos."}
	}
	if (x>47 && x<58 || x==8 || (x==46 && valor.indexOf(".")==-1)){return true}
	else{
		return false
	}
}



function mfoco(e){
	obj=eval(sender)
	if(eval("x"+obj.name)!=0){
		obj.value=eval("x"+obj.name)
	}else{
		obj.value=""
	}
}

function mperde(e){
	obj=eval(sender)
	valor=obj.value
	while(valor.indexOf("0")==0){
		valor=valor.substring(1,100)
	}
	if(valor!=0){
		eval("x"+obj.name+"="+valor)}
	else{
		eval("x"+obj.name+"=0")}
	obj.value=formatamoeda(eval("x"+obj.name),reais,truncar)
}

function xinput(campo,tipo,dinheiro){
	this.campo=campo
	this.tipo=tipo
	campo.onkeypress=eval(tipo)
	if (dinheiro){
		eval("x"+campo.name+"="+campo.value)
		campo.value=formatamoeda(eval("x"+campo.name),reais,truncar)
		campo.onfocus=mfoco
		campo.onblur=mperde
	}
}

function ispunct(c){
		if ((c == ',') || (c == '+') || (c == '\'') || (c == '\`') ||
			(c == '"') || (c == '\´') || (c == '(') ||
			(c == '$') || (c == '#') || (c == '!') || (c == '}') ||
			(c == '%') || (c == '&') || (c == '*') || (c == '\\') ||
			(c == ')') || (c == '=') || (c == '{') || (c == '<') || 
			(c == '[') || (c == ']') || (c == '/') || 
			(c == ':') || (c == ';') || (c == '>') || 
			(escape(c) == '%20') )
			return true;
		else
			return false;
}
//---------------------------------------------------------------------------------------------------
function isalpha(c){
		if ( ((c >= 'a') && (c <= 'z')) || 
		     ((c >= 'A') && (c <= 'Z')) ||
			 (c == 'ã') || (c == 'á') || (c == 'â') || (c == 'ä') ||
			 (c == 'Ã') || (c == 'Á') || (c == 'Â') || (c == 'Ä') ||
			 (c == 'é') || (c == 'ê') || (c == 'ë') ||
			 (c == 'É') || (c == 'Ê') || (c == 'Ë') ||
			 (c == 'í') || 
			 (c == 'Í') || 
			 (c == 'õ') || (c == 'ó') || (c == 'ô') || (c == 'ö') ||
			 (c == 'ú') || (c == 'ü') || (c == ' ') ||
			 (c == 'ç') || (c == 'Ç') || (c == 'ñ') || (c == 'Ñ') 
		  )
 			return true;
		else  
 			return false;
}
//---------------------------------------------------------------------------------------------------
function isdigit(c){
		if ((c >= '0') && (c <= '9'))
		 	return true;
		else
			return false;
}
//---------------------------------------------------------------------------------------------------
function isemail(c){
		if( ((c >= '0') && (c <= '9')) || 
		    ((c >= 'a') && (c <= 'z')) || 
		    ((c >= 'A') && (c <= 'Z')) ||
		    (c == '@') || (c == '_') || (c == '-') || (c == '.')
		  )
		 	return true;
		else
			return false;
}
//---------------------------------------------------------------------------------------------------
function ValidaTexto(s) {
		var i; var c;
		for (var i=0;i<s.length;i++) {	
				c = s.substring(i,i+1); 
				if (!( isalpha(c) || isdigit(c) || !ispunct(c) ) ) return false;
				 }						
return true;
}
//---------------------------------------------------------------------------------------------------
function ValidaEmail(email) {
 var achou_ponto=false; var achou_arroba=false; var achou_caracter=false; 
        for (var i=0; i<email.length; i++) {
                if (email.charAt(i)=="@") achou_arroba=true;
                else if (email.charAt(i)==".") achou_ponto=true;
                else if (email.charAt(i)!=" ") achou_caracter=true;
			}
return (achou_ponto & achou_arroba & achou_caracter);
} 

function ValidaSite(site) {
 var achou_ponto=false; var achou_caracter=false; var achou_arroba=true
        for (var i=0; i<site.length; i++) {
                if (site.charAt(i)=="@") achou_arroba=false;
                else if (site.charAt(i)==".") achou_ponto=true;
                else if (site.charAt(i)!=" ") achou_caracter=true;
			}
return (achou_ponto & achou_caracter & achou_arroba);
} 
//--------------------------------------------------------------------------------------------------
function ValidaData(s,lingua){
 var i; var c; var n_barras = 0; var data; var d = ""; var m = ""; var a = "";
 //if (s.length != 10)
 //  	 return false; 
 for(i=0; i<s.length; i++) {
   c = s.substring(i,i+1);
   if (c == "/") 
		n_barras++;
   if (n_barras > 2)  
		return false;	 
   if (!isdigit(c) && (c != "/"))  
		return false;
	if (lingua=="in")
	{
		if (n_barras == 0 && c != "/")
				m = m + c;
		if (n_barras == 1 && c != "/")
				d = d + c;
	}
	else
	{
		if (n_barras == 0 && c != "/")
				d = d + c;
		if (n_barras == 1 && c != "/")
				m = m + c;
	}
   if (n_barras == 2 && c != "/")
		a = a + c;
 }
 if (n_barras != 2)  
 	 return false;
//d = s.substring(0, 2)  //dia
//m = s.substring(3, 5)  //mes
//a = s.substring(6, 11) //ano
  if (m<1 || m>12) 
   return false;
 if (d<1 || d>31) 
 	return false;
 if (a<1900 || a>2050) 
 	return false;
 if (m==4 || m==6 || m==9 || m==11) {
   if (d==31) 
   	  return false;
 }
 if (m=="2" || m=="02")
 {
	var g=parseInt(a/4)
	if (isNaN(g))
		return false;
	else
	{
		if (d>29)
			return false;
		if (d==29 && ((a/4)!=parseInt(a/4))) 
			return false;
	}
 }
 return true;
}

function ValidaDataTreino(dtreino,datual)
{	
	var n_barras = 0; var d1 = ""; var m1 = ""; var a1 = ""; var d2 = ""; var m2 = ""; var a2 = "";
	//
	for(i=0; i<dtreino.length; i++) {
		c = dtreino.substring(i,i+1);
		if (c == "/") 
			n_barras++;
		else
		{
			if (n_barras > 1)  
				a1 += c;
			else
			{
				if (n_barras > 0)  
					m1 += c;
				else
					d1 += c;
			}
		}
	}
	n_barras=0;
	//
	for(i=0; i<datual.length; i++) {
		c = datual.substring(i,i+1);
		if (c == "/") 
			n_barras++;
		else
		{
			if (n_barras > 1)  
				a2 += c;
			else
			{
				if (n_barras > 0)  
					m2 += c;
				else
					d2 += c;
			}
		}
	}
	//
	if(a1>a2)
		return false;
	if(a1==a2&&m1>m2)
		return false;
	if(a1==a2&&m1==m2&&d1>d2)
		return false;
	return true;
}
//---------------------------------------------------------------------------------------------------
function ValidaCPF(s){
 var i; var c;  x = 0; soma = 0; dig1 = 0; dig2 = 0;  
 texto = ""; numcpf1=""; numcpf = "";
 for (i = 0; i < s.length; i++) {
 	 c = s.substring(i,i+1);
	 if (isdigit(c))
	 	numcpf = numcpf + c;
 }
 if (numcpf.length != 11) {
 	return false;
 }
 len = numcpf.length; x = len -1;
 for (var i=0; i <= len - 3; i++) {
  y = numcpf.substring(i,i+1);
  soma = soma + ( y * x);
  x = x - 1;
  texto = texto + y;
 }
 dig1 = 11 - (soma % 11);
 if (dig1 == 10) dig1=0 ;
 if (dig1 == 11) dig1=0 ;
 numcpf1 = numcpf.substring(0,len - 2) + dig1 ;
 x = 11; soma=0;
 for (var i=0; i <= len - 2; i++) {
  soma = soma + (numcpf1.substring(i,i+1) * x);
  x = x - 1;
 }
 dig2= 11 - (soma % 11);
 if (dig2 == 10) dig2=0;
 if (dig2 == 11) dig2=0;
  if ((dig1 + "" + dig2) == numcpf.substring(len,len-2)) {
  return true;
 }
 return false;
}
//---------------------------------------------------------------------------------------------------
function SoNumeros(s){
 for (var i=0;i<s.length;i++) { 
 	  c = s.substring(i,i+1); 
	  if (!isdigit(c)) 
	  	  return false;	  
 }
 return true;
}
//---------------------------------------------------------------------------------------------------
function SoDecimal(s){
 for (var i=0;i<s.length;i++) { 
 	  c = s.substring(i,i+1); 
	  if (!isdigit(c)&&c!=".") 
	  	  return false;	  
 }
 return true;
}
//---------------------------------------------------------------------------------------------------
function SoDecimal2(s){
 for (var i=0;i<s.length;i++) { 
 	  c = s.substring(i,i+1); 
	  if (!isdigit(c)&&c!=",") 
	  	  return false;	  
 }
 return true;
}
//---------------------------------------------------------------------------------------------------
function ValidaCEP(s){
 var i; var c; var achou;
 if (s.length != 9) 
 	 return false;
 achou = false;
 for (i=0; i<s.length; i++) {
 	 c = s.substring(i,i+1); 
     if ( !isdigit(c) && (c != '-') ) 					
	  	  return false;
     if (c == '-') {
	   if (!achou) achou = true;
	   else 
			  return false;
	 }  	 	
 }
 if (s.indexOf("-")!=5) 
 	 return false;
 return true;
}
//---------------------------------------------------------------------------------------------------
function ValidaFone(s){
 var i; var c; var achou = false;
 for (i=0; i<s.length; i++) {
 	 c = s.substring(i,i+1); 
     if ( !isdigit(c) && (c != '-') ) 
	  	  return false;
     if (c == '-') {
	   if (!achou) 
		achou = true;
	   else 
		return false;
	 }  	 	
 }
 return true;
}
//---------------------------------------------------------------------------------------------------
function SoNumerosLetras(s)
{
 for (var i=0;i<s.length;i++) { 
 	  c = s.substring(i,i+1); 
	  if (isdigit(c) && isalpha(c)) 
	  	  return false;	  
 }
 return true;
}
//---------------------------------------------------------------------------------------------------
function numerosdif(s)
{
var pc; var i;
pc = s.charAt(1);
i = 2;
while ((s.charAt(i)==pc) || (s.charAt(i)=="-")){
	i+=1;
	if (i==s.length) return false;
	}
return true;
}

//---------------------------------------------------------------------------------------------------
function validate(){	
 with (document.cadastroForm) {

// nome
	if (fnome.value == "") {
		alert("<%=lg_alert_nome_obr%>");
		fnome.focus();
		return false;
	}
	if (!ValidaTexto(fnome.value)) {
		alert("<%=lg_alert_nome_erro%>");
		fnome.focus();
		return false;
	}
// sobrenome
	if (fsobrenome.value == "") {
		alert("<%=lg_alert_sobrenome_obr%>");
		fsobrenome.focus();
		return false;
	}
	if (!ValidaTexto(fsobrenome.value)) {
		alert("<%=lg_alert_sobrenome_erro%>");
		fsobrenome.focus();
		return false;
	}
// doc
	if (fident_tipo_doc.selectedIndex < 1) {
		alert("<%=lg_alert_doc_obr%>");
		fident_tipo_doc.focus();
		return false;
	}
// número de identidade
	if (fident_num.value == "") {
		alert("<%=lg_alert_doc_obr%>");
		fident_num.focus();
		return false;
	}
	if (!ValidaTexto(fident_num.value)) {
		alert("<%=lg_alert_doc_erro%>");
		fident_num.focus();
		return false;
	}
	if (!numerosdif(fident_num.value)) {
		alert("<%=lg_alert_doc_erro%>");
		fident_num.focus();
		return false;
	}
// data nasc
	if (fdnasc.value == "") {
		alert("<%=lg_alert_data_obr%>");
		fdnasc.focus();
		return false;
	}
	if (!ValidaData(fdnasc.value)) {
		alert("<%=lg_alert_data_erro%>");
		fdnasc.focus();
		return false;
	}
// cpf
	if (fcpf.value == "") {
		alert("<%=lg_alert_cpf_obr%>");
		fcpf.focus();
		return false;
	}
	if (fcpf.value == "023452879-21") {
		alert("<%=lg_alert_cpf_erro%>");
		fcpf.focus();
		return false;
	}
	if (!ValidaCPF(fcpf.value)) {
		alert("<%=lg_alert_cpf_erro%>");
		fcpf.focus();
		return false;
	}
	if (!numerosdif(fcpf.value)) {
		alert("<%=lg_alert_cpf_erro%>");
		fcpf.focus();
		return false;
	}
// email
	if (femail.value == "") {
		alert("<%=lg_alert_email_obr%>");
		femail.focus();
		return false;
	}
	if (!ValidaTexto(femail.value)) {
		alert("<%=lg_alert_email_erro%>");
		femail.focus();
		return false;
	}
	if (!ValidaEmail(femail.value)) {
 		alert("<%=lg_alert_email_erro%>");
 		femail.focus();	
		return false;
 	}
// endereço
	if (fend.value == "") {
		alert("<%=lg_alert_end_obr%>");
		fend.focus();
		return false;
	}
	if (!ValidaTexto(fend.value)) {
		alert("<%=lg_alert_end_erro%>");
		fend.focus();
		return false;
	}
// numero do end
	if (fend_num.value == "") {
		alert("<%=lg_alert_num_end_obr%>");
		fend_num.focus();
		return false;
	}
	if (!SoNumeros(fend_num.value)) {
		alert("<%=lg_alert_so_numeros%>");
		fend_num.focus();
		return false;
	}	  	
// complemento										 
	if ((fend_comp.value != "") && !ValidaTexto(fend_comp.value)) {
		alert("<%=lg_alert_complemento_erro%>");
		fend_comp.focus();
		return false;
	}
// bairro
	if (fbairro.value == "") {
		alert("<%=lg_alert_bairro_obr%>");
		fbairro.focus();
		return false;
	}
	if (!ValidaTexto(fbairro.value)) {
		alert("<%=lg_alert_bairro_erro%>");
		fbairro.focus();
		return false;
	}
// cep
	if (fcep.value == "") {
		alert("<%=lg_alert_cep_obr%>");
		fcep.focus();
		return false;
	}
	if (!ValidaCEP(fcep.value)) {
		alert("<%=lg_alert_cep_erro%>");
		fcep.focus();
		return false;
	}
	if (!numerosdif(fcep.value)) {
		alert("<%=lg_alert_cep_erro%>");
		fcep.focus();
		return false;
	}
// cidade
	if (fcidade.value == "") {
		alert("<%=lg_alert_cid_obr%>");
		fcidade.focus();
		return false;
	}
	if (!ValidaTexto(fcidade.value)) {
		alert("<%=lg_alert_cid_erro%>");
		fcidade.focus();
		return false;
	}
// estado
	if (festado.selectedIndex < 1) {
		alert("Selecione a UF do seu endereço.");
		festado.focus();
		return false;
	}
// ddd
	if (fddd.value == "") {
		alert("Entre com o número do DDD.");
		fddd.focus();
		return false;
	}
	if ((fddd.value != "") && !SoNumeros(fddd.value)){
		alert("DDD do Telefone inválido.");
		fddd.focus();
		return false;
	}
// fone 
	if (ffone.value == "") {
		alert("Preenchimento do Telefone para contato é obrigatório.");
		ffone.focus();
		return false;
	}
	if ((ffone.value != "") && !ValidaFone(ffone.value)){
		alert("Número do Telefone inválido.");
		ffone.focus();
		return false;
	}
 }//final do with
return true;
}

//---------------------------------------------------------------------------------------------------
function ZeroAntes(s,quantNum){
 for (var i=1;i<s.length;i++)
 {
 	//alert("a" + i)
 }
 diferenca=quantNum-i
 //alert(diferenca)
 for (var j=0;j<diferenca;j++)
 {
 	s="0" + s;
 }
 return s;
}
//---------------------------------------------------------------------------------------------------
function QuantCaracter(quant_tem,quant_quero)
{
	if(quant_tem.length!=quant_quero)
	{
		return false;
	}
	else
	{
		return true;
	}
}
//---------------------------------------------------------------------------------------------------
/***************************************************************************************************************

x=new xinput(document.form1.input1,"inteiro",true)
y=new xinput(document.form1.input2,"numero",false)
z=new xinput(document.form1.input3,"tudo",false)

***************************************************************************************************************/


function Trim(str){return str.replace(/^\s+|\s+$/g,"");}


