function AbreAtualizacao(){
	window.open("atualizarcadastro.asp","AtualizarCadastro","width=600,heigth=400,top=0,left=0,scrollbars=1,resizable=1");
}

function isDate(data){

    pos = InStr(data,"/");
    if (pos=="NotFound"){
        return false;
    }else{
        dia = data.substring(0,pos);
        data = data.substring(pos+1,data.length);
        pos = InStr(data,"/");
        if (pos=="NotFound"){
            return false;
        }else{
          mes = data.substring(0,pos);
          ano = data.substring(pos+1,data.length);
		  if (isNaN(dia)){
			 return false;
		  }else{
			 //dia = parseInt(dia);
			 if (isNaN(mes)){
				    return false;
			 }else{
				    if (isNaN(ano)){
					   return false;
				    }else{
					   //ano = parseInt(ano);
					   //mes = parseInt(mes);
					   if (mes<13 && mes>0){
						  if (mes==01 || mes==03 || mes==05 || mes==07 || mes==08 || mes==10 || mes==12){
							 if (dia<32 && dia>0){
								    return true;
							 }else{
								    return false;
							 }
						  }else{
							 if (mes==04 || mes==06 || mes==09 || mes==11){
								    if (dia<31 && dia>0){
									   return true;
								    }else{
									   return false;
								    }
							 }else{
								    anoint = ano/4;
								    anox = parseInt(ano/4);
								    if (anoint==anox){
									   //bissexto
									   if (dia<30 && dia>0){
										  return true;
									   }else{
										  return false;
									   }
								    }else{
									   //nao bissexto
									   if (dia<29 && dia>0){
										  return true;
									   }else{
										  return false;
									   }
								    }
							 }
						  }
					   }else{
						  //alert(mes);
						  return false;
					   }
                    }
				}
			}
		}
	}
}

function Trim(texto){
	pos = 0;
	tamanho = texto.length;
	
	for (a=0;a<=tamanho;a++){
		if (texto.substring(a,a+1)!=" "){
			pos = a;
		}
	}
	
	if (pos==0){
		pos = tamanho;
	}
	
	for (b=0;b<=pos;b++){
		if (texto.substring(0,1)==" "){
			texto = texto.substring(1,texto.length);
		}
	}
	
	return texto;
}

function InStr(texto,string){
	for(x=0;x<=texto.length-1;x++){
		if (texto.substring(x,x+string.length)==string){
			return x;
		}
	}
	return "NotFound";
}

function InStrRev(texto,string){
	for(x=texto.length;x>0;x--){
		if (texto.substring(x,x+string.length)==string){
			return x;
		}
	}
	return "NotFound";
}

function isValue(vlr){
	pos=InStr(vlr,",");
	if(pos=="NotFound"){
		pos=InStr(vlr,".");
	}
	if (pos!="NotFound"){
		esq = vlr.substring(0,pos);
		dir = vlr.substring(pos+1,vlr.length);
		if (isNaN(esq) || isNaN(dir)){
			return "NotNumber";
		}else{
			if (dir.length>2){
				dir = dir.substring(0,2);
			}
			if (dir.length<2){
				x = dir.length;
				for (a=0;a<2;a++){
					if (dir.length<2){
						dir = dir + "0";
					}
				}
			}
			if (Trim(esq)==""){
				esq = "0";
			}
			vlr = esq + "," + dir;
		}
	}else{
		if (isNaN(vlr)){
			return "NotNumber";
		}
		if (vlr.length==0){
			vlr = "0,00"
		}else{
			vlr = vlr + ",00";
		}
	}
	return vlr;
}

function isValueX(vlr,cdecimais){
	pos=InStr(vlr,",");
	if(pos=="NotFound"){
		pos=InStr(vlr,".");
	}
	if (pos!="NotFound"){
		esq = vlr.substring(0,pos);
		dir = vlr.substring(pos+1,vlr.length);
		if (isNaN(esq) || isNaN(dir)){
			return "NotNumber";
		}else{
			if (dir.length>cdecimais){
				dir = dir.substring(0,cdecimais);
			}
			if (dir.length<cdecimais){
				x = dir.length;
				for (a=0;a<cdecimais;a++){
					if (dir.length<cdecimais){
						dir = dir + "0";
					}
				}
			}
			if (Trim(esq)==""){
				esq = "0";
			}
			if (cdecimais>0){
				vlr = esq + "," + dir;
			}else{
				vlr = esq
			}
		}
	}else{
		if (isNaN(vlr)){
			return "NotNumber";
		}
		if (vlr.length==0){
			vlr = "0";
			if (cdecimais>0){
				vlr = vlr + ",";
			}
		}else{
			if (cdecimais>0){
				vlr = vlr + ",";
			}
		}
		for(h=1; h<=cdecimais; h++){
			vlr = vlr + "0";
		}
	}
	return vlr;
}

function TestaPeriodos(data1,data2){
	ano1 = data1.substring(6,10);
	ano2 = data2.substring(6,10);
	mes1 = data1.substring(3,5);
	mes2 = data2.substring(3,5);
	dia1 = data1.substring(0,2);
	dia2 = data2.substring(0,2);
	if (ano2>ano1 || ano2==ano1){
		if (ano2==ano1){
			if (mes2>mes1 || mes2==mes1){
				if (mes2==mes1){
					if (dia2>dia1 || dia2==dia1){
						return true;
					}else{
						return false;
					}
				}else{
					return true;
				}
			}else{
				return false;
			}
		}else{
			return true;
		}
	}else{
		return false;
	}
}

function isHour(hora){
	if (hora.length>5 || hora.length<5){
		return false;
	}
	pos = InStr(hora,":")
	if (pos=="NotFound"){
		return false;
	}
	hh = hora.substring(0,2);
	mm = hora.substring(3,5);
	posh = InStr(hh,".");
	posm = InStr(mm,".");
	if (posh!="NotFound" || posm!="NotFound"){
		return false;
	}
	if (isNaN(hh) || isNaN(mm)){
		return false;
	}
	if (parseInt(hh)<0 || parseInt(hh)>23){
		return false;
	}
	if (parseInt(mm)<0 || parseInt(mm)>59){
		return false;
	}
	return true;
}

function ValidEMail(mail){
	if (Trim(mail)==""){
		return false;
	}
	posa = InStr(mail,"@");
	if (posa=="NotFound"){
		return false;
	}
	if (posa==mail.length-1){
		return false;
	}
	posp = InStr(mail,".");
	if (posp=="NotFound"){
		return false;
	}
	if (posp==mail.length-1){
		return false;
	}
	pos=InStrRev(mail,".");
	if (posa>=pos){
		return false;
	}
	return true;
}

function Compara(mx,mn,parametro){

	pos=InStr(mx,",");
	if(pos!="NotFound"){
		esq = mx.substring(0,pos);
		dir = mx.substring(pos+1,mx.length);
		if (dir.length>0){
			mx = esq + "." + dir
		}else{
			mx = esq
		}
	}

	pos=InStr(mn,",");
	if(pos!="NotFound"){
		esq = mn.substring(0,pos);
		dir = mn.substring(pos+1,mn.length);
		if (dir.length>0){
			mn = esq + "." + dir
		}else{
			mn = esq
		}
	}

	if (parametro=="Maior"){
		if (parseFloat(mx)>parseFloat(mn)){
			return true;
		}else{
			return false;
		}
	}
	if (parametro=="MaiorIgual"){
		if (parseFloat(mx)>=parseFloat(mn)){
			return true;
		}else{
			return false;
		}
	}
	if (parametro=="Igual"){
		if (parseFloat(mx)==parseFloat(mn)){
			return true;
		}else{
			return false;
		}
	}
	if (parametro=="MenorIgual"){
		if (parseFloat(mx)<=parseFloat(mn)){
			return true;
		}else{
			return false;
		}
	}
	if (parametro=="Menor"){
		if (parseFloat(mx)<parseFloat(mn)){
			return true;
		}else{
			return false;
		}
	}
}

function Valida(CNUMB,CTYPE){
	var qtde = 0;
	if (CTYPE=='CNPJ'){
		qtde=14;
	}else{
		qtde = 11;
	}
	 if (CNUMB!='' && CNUMB.length==qtde && isNaN(CNUMB)!=true){
		  if (Verify(CNUMB, CTYPE)){
			return true;  
		  }else{
			return false;
		  }
	 }else{
		return false;
	 }
}

function Verify(CNUMB,CTYPE){
  CNUMB=ParseNumb(CNUMB);
  if(CNUMB == 0)
  {
	return(false);
  }
  else
  {
	g=CNUMB.length-2;
	if(TestDigit(CNUMB,CTYPE,g))
	{
	  g=CNUMB.length-1;
	  if(TestDigit(CNUMB,CTYPE,g))
	  {	
		return(true);
	  }
	  else
	  {
		return(false);
	  }
	}
	else
	{
	  return(false);
	}
  }
}

function TestDigit(CNUMB,CTYPE,g)
{
  var dig=0;
  var ind=2;
  for(f=g;f>0;f--)
  {
	dig+=parseInt(CNUMB.charAt(f-1))*ind;
	if (CTYPE=='CNPJ')
	{ if(ind>8) {ind=2} else {ind++} }
	else
	{ ind++ }
  }
  dig%=11;
  if(dig<2)
  {
	dig=0;
  }
  else
  {
	dig=11-dig;
  }
  if(dig!=parseInt(CNUMB.charAt(g)))
  {
	return(false);
  }
  else
  {
	return(true);
  }
}

function ParseNumb(c)
{
  c=ClearStr(c,'-');
  c=ClearStr(c,'/');
  c=ClearStr(c,',');
  c=ClearStr(c,'.');
  c=ClearStr(c,'(');
  c=ClearStr(c,')');
  c=ClearStr(c,' ');
  if((parseFloat(c) / c != 1))
  {
	if(parseFloat(c) * c == 0)
	{
	  return(c);
	}
	else
	{
	  return(0);
	}
  }
  else
  {
	return(c);
  }
}

function ClearStr(str, char)
{
  while((cx=str.indexOf(char))!=-1)
  {		
	str = str.substring(0,cx)+str.substring(cx+1);
  }
  return(str);
}