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) != '#') 
  	{
			  		src.value += texto.substring(0,1);
  	}			
}
function requerido(which)
{
		var pass=true;
		if (document.images) 
		{
			for (i=0;i<which.length;i++) 
			{
				var tempobj=which.elements[i];
			if (tempobj.name.substring(0,9)=='required_') 
			{
				if (((tempobj.type=='text'||tempobj.type=='textarea')&& tempobj.value=='')||(tempobj.type.toString().charAt(0)=='s'&& tempobj.selectedIndex==0)) 
				{
					pass=false;
					break;
				}
			}
		}
	}
	if (!pass) 
	{
		shortFieldName=tempobj.name.substring(9,50).toUpperCase();
		alert('O campo '+shortFieldName+' deve ser preenchido.');
		return false;
	}
	else return true;
}

function AlertaSenha(dias){
	alert("Sua senha irá expirar em " + dias + " dias!");
	return true;
}
function validacpf(cpf,botao){
 
	var i;	 
	var s = cpf;
	if(s.length > 0){
		var c = s.substr(0,3) + s.substr(4,3) + s.substr(8,3);	 
		var dv = s.substr(12,2);	 
		var d1 = 0;	 
		for (i = 0; i < 9; i++){
			d1 += c.charAt(i)*(10-i);
		}	 
		if (d1 == 0){
			alert("CPF Invalido")
		 	if(botao != "") document.getElementById(botao).disabled=true;
			return false;
		}	 
		d1 = 11 - (d1 % 11);
		if (d1 > 9) d1 = 0;
		if (dv.charAt(0) != d1){
		 	alert("CPF Invalido")
			if(botao != "") document.getElementById(botao).disabled=true;
		 	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){
			alert("CPF Invalido");
			if(botao != "") document.getElementById(botao).disabled=true;
			return false;
		}
	}
	if(botao != "") document.getElementById(botao).disabled=false;
	return true; 
}

function buscaMunicipio(name,value,cpEstado,cpFkMunicipio,cpPais){
	if(document.form.procurarMunicipio.value == 1) { 
		window.open('Sis_BuscaMunicipio.php?municipio='+value+'&campo='+name+'&cpEstado='+cpEstado+'&cpPais='+cpPais+'&cpFkMunicipio='+cpFkMunicipio,'Municipios','width=500,height=300,scrollbars=YES');
	}
}

function enviaDados(municipio, estado, pais, fk_municipio, cpMunicipio, cpFkMunicipio, cpPais, cpEstado){
	window.opener.document.getElementById(cpMunicipio).value = municipio;
	window.opener.document.getElementById(cpEstado).value = estado;
	window.opener.document.getElementById(cpPais).value = pais;
	window.opener.document.getElementById(cpFkMunicipio).value = fk_municipio;
	window.opener.document.getElementById(cpMunicipio).focus();
	this.close();
}

function validaEmail(nomeCampo){
	var valor;
	valor = document.getElementById(nomeCampo).value;
	if(valor.length > 0){
		if(document.getElementById(nomeCampo).value=='&quot;&quot;' || document.getElementById(nomeCampo).value.indexOf('@')==-1 || document.getElementById(nomeCampo).value.indexOf('.')==-1 ){
			alert('Formato de E-mail inválido! Favor consertar.');
			document.getElementById(nomeCampo).value = "";
			document.getElementById(nomeCampo).focus();
			return false;
		}
	}
}
