function verifyRadioGroup(all_options){
	var isChecked = false;
	var count = 0;
	while( all_options[count] != null && isChecked == false ){
		if( all_options[count].checked ){
			isChecked = true;
		}
		count = count + 1;
	}
	
	return isChecked;
}

function validateName(nome){
	var reNome = /^[A-Z,a-z, ,Á,É,Í,Ó,Ú,á,é,í,ó,ú,ã,õ,ä,ë,ö,ü,è,ç]+$/;
	return reNome.test( nome );
}

function validateEmail(email){
	var reEmail = /([0-9,a-z,A-Z]+)([.,_]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])?/;
	return reEmail.test( email );
}

function validateCNPJ(cnpj){
	cnpj = cnpj.replace( /\D/g,"" );
	var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
	digitos_iguais = 1;
	  
	if( cnpj.length < 14 && cnpj.length < 15 )
		return false;
		
	for (i = 0; i < cnpj.length - 1; i++)
		if( cnpj.charAt(i) != cnpj.charAt(i + 1) ){
			digitos_iguais = 0;
			break;
		}
		
	if( !digitos_iguais ){
		tamanho = cnpj.length - 2
		numeros = cnpj.substring(0,tamanho);
		digitos = cnpj.substring(tamanho);
		soma = 0;
		pos = tamanho - 7;
		for( i = tamanho; i >= 1; i-- ){
			soma += numeros.charAt(tamanho - i) * pos--;
			if (pos < 2)
				pos = 9;
		}
		
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if( resultado != digitos.charAt(0) )
			return false;
		
		tamanho = tamanho + 1;
		numeros = cnpj.substring(0,tamanho);
		soma = 0;
		pos = tamanho - 7;
		for( i = tamanho; i >= 1; i-- ){
			soma += numeros.charAt(tamanho - i) * pos--;
			if( pos < 2 )
				pos = 9;
		}
		
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(1))
			return false;
		
		return true;
	}
	else
		return false;
}

function validateCPF(cpf){
	cpf = cpf.replace( /\D/g,"" );
	var numeros, digitos, soma, i, resultado, digitos_iguais;
	digitos_iguais = 1;
	
	if( cpf.length < 11 )
		return false;
		
	for( i = 0; i < cpf.length - 1; i++ )
		if( cpf.charAt(i) != cpf.charAt(i + 1) ){
			digitos_iguais = 0;
			break;
		}
		
	if( !digitos_iguais ){
		numeros = cpf.substring(0,9);
		digitos = cpf.substring(9);
		soma = 0;
		for (i = 10; i > 1; i--)
			soma += numeros.charAt(10 - i) * i;
			
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if( resultado != digitos.charAt(0) )
			return false;
		
		numeros = cpf.substring(0,10);
		soma = 0;
		for( i = 11; i > 1; i-- )
			soma += numeros.charAt(11 - i) * i;
		
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if( resultado != digitos.charAt(1) )
			return false;
			
		return true;
	}
	else
		return false;
}


function validateDate(value){
	var erro = null;
	var	regExp = /^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[1-2][0-9]\d{2})$/;
	var dia = value.substring(0,2);
	var mes = value.substring(3,5);
	var ano = value.substring(6,10);
	
	if( value.match(regExp) ){
		if( (mes==4 || mes==6 || mes==9 || mes==11) && dia > 30 ){
			erro = "O mês especificado contém 30 dias";
		} 
		else if( mes == 2  ){
			if( ano%4 != 0 && dia > 28 ){
				erro = "O mês especificado contém 28 dias";
			}
			else if ( ano%4==0 && dia > 29 ){
				erro = "O mês especificado contém 29 dias";
			}
		}// else if ( mes == 2  )
	}
	else{
		erro = "Data com Formato (dd/mm/aaaa) Inv&aacute;lido";
	}
	
	return erro;
}

// email
function checkEmail (strng) {
	var error="";
	if (strng == "") {
	   error = "You didn't enter an email address.\n";
	}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
	return error;    
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
	var error = "";
	if (strng == "") {
	   error = "You didn't enter a phone number.\n";
	}
	
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
  
    }
    if (!(stripped.length == 10)) {
	error = "The phone number is the wrong length. Make sure you included an area code.\n";
    } 
	return error;
}


// password - between 6-8 chars, uppercase, lowercase, and numeral
function checkPassword (strng) {
	var error = "";
	if (strng == "") {
	   error = "You didn't enter a password.\n";
	}
	
	    var illegalChars = /[\W_]/; // allow only letters and numbers
	    
	    if ((strng.length < 6) || (strng.length > 8)) {
	       error = "The password is the wrong length.\n";
	    }
	    else if (illegalChars.test(strng)) {
	      error = "The password contains illegal characters.\n";
	    } 
	    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
	       error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
	    }  
	return error;    
}    


// username - 4-10 chars, uc, lc, and underscore only.
function checkUsername (strng) {
	var error = "";
	if (strng == "") {
	   error = "You didn't enter a username.\n";
	}
	
	
	    var illegalChars = /\W/; // allow letters, numbers, and underscores
	    if ((strng.length < 4) || (strng.length > 10)) {
	       error = "The username is the wrong length.\n";
	    }
	    else if (illegalChars.test(strng)) {
	    error = "The username contains illegal characters.\n";
	    } 
	return error;
} 


