function isMail(mailField){
  strMail = mailField.value;
  var re = new RegExp;
  re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  var arr = re.exec(strMail);
  if (arr == null)
    return(false);
  else
    return(true);
}

function minLen(txtField, minVal){
  strExp = txtField.value;
  l = strExp.length;
  if (l < minVal)
    return(true);
  else
    return(false);
}
function radio1(nform) {
	//validacao de radio buttons sem saber quantos sao
	marcado = -1
	for (i=0; i<nform.length; i++) {
		if (nform[i].checked) {
			marcado = i
			resposta = nform[i].value
		}
	}
      // se não houver valor checked ele permanesse negativo
	if (marcado == -1) {
nform[0].focus();

		return true;

	}
    else { //esse else so foi colocado para evitar que o form desse o submit


    return false;
	}

}

function maxLen(txtField, maxVal){
  strExp = txtField.value;
  l = strExp.length;
  if (l > maxVal)
    return(true);
  else
    return(false);
}

function isBlank(txtField){
  if (txtField.value)
    return (false);
  else
    return(true);
}

function isSelectedZero(txtField){
  selected = txtField.selectedIndex;
  if (selected == 0)
    return(true);
  else
    return(false);
}

function isNumber(txtField){
  numExp = txtField.value;
  if (isNaN(numExp) || (numExp.length == 0))
    return (false);
  else
    return(true);
}

function iscnpj(txtField){
 CNPJ= txtField.value;  

       // CNPJ = document.getElementById("cnpj").value;
        erro = new String;
		if (CNPJ == "") {
		return true;
		}
        if (CNPJ.length < 18 || CNPJ == "00.000.000/0000-00" || CNPJ == "00.000.000/0000-000") 
		erro += "Por favor digite um CNPJ válido! \n\n";
        //substituir os caracteres que nao sao numeros
        if(document.layers && parseInt(navigator.appVersion) == 4){
            x = CNPJ.substring(0,2);
            x += CNPJ.substring(3,6);
            x += CNPJ.substring(7,10);
            x += CNPJ.substring(11,15);
            x += CNPJ.substring(16,18);
            CNPJ = x;    
        } else {
            CNPJ = CNPJ.replace(".","");
            CNPJ = CNPJ.replace(".","");
            CNPJ = CNPJ.replace("-","");
            CNPJ = CNPJ.replace("/","");
        }
        var nonNumbers = /\D/;
        if (nonNumbers.test(CNPJ)) erro += "Por favor digite um CNPJ válido! \n\n"; 
        var a = [];
        var b = new Number;
        var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
        for (i=0; i<12; i++){
            a[i] = CNPJ.charAt(i);
            b += a[i] * c[i+1];
        }
        if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
        b = 0;
        for (y=0; y<13; y++) {
            b += (a[y] * c[y]); 
        }
        if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
        if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
            erro +="Por favor digite um CNPJ válido!";
		}
        if (erro.length > 0){
          //alert(erro);
			//document.getElementById('cnpj').value = '';
            return true;
        } else {
  return false;
        }
      
    
	
		   }
		   
		   
		   
		   
		   
		   
function isCPF(txtField){ 

  var i; 
  s = txtField.value;  
  s = s.replace(".","");
            s = s.replace(".","");
            s = s.replace("-","");

  var c = s.substr(0,9); 
  var dv = s.substr(9,2); 
  var d1 = 0; 
  
  for (i = 0; i < 9; i++){ 
    d1 += c.charAt(i)*(10-i); 
  } 
  
  if (d1 == 0) return false;   
  
  d1 = 11 - (d1 % 11); 
  
  if (d1 > 9) d1 = 0; 
  
  if (dv.charAt(0) != d1) return false; 
  
  d1 *= 2; 
  
  for (i = 0; i < 9; i++){ 
    d1 += c.charAt(i)*(11-i);   
  } 
  
  d1 = 11 - (d1 % 11); 
  
  if (d1 > 9) d1 = 0; 
  
  if (dv.charAt(1) != d1) return false; 
  
  return true; 
  
}
