/*# popup 
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}*/

/*# Exibe e oculta uma div */
function exibeOculta_div(show_hidden, id_div) {//alert(show_hidden+' = '+id_div);

  if(show_hidden == 'show'){
    document.getElementById(id_div).style.visibility = "visible";
    document.getElementById(id_div).style.display = "block";
  }

  if(show_hidden == 'hidden'){
    document.getElementById(id_div).style.display = "none";
    document.getElementById(id_div).style.visibility = "hidden";
  }
}

/*# VALIDA E-MAIL [expressão regular] */
function verficaEmail(campo) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(campo)) {
		return	'';
	}
	return '- O E-MAIL digitado é inválido\n';
}

/*# MASCARA */
function mascarar(vc_campo,vc_mascara) {
	var i		= vc_campo.value.length;
	var x		= vc_mascara.substring(0,1);
	var y		= vc_mascara.substring(i);

	if (y.substring(0,1) != x) {
		vc_campo.value += y.substring(0,1);
	}
}

/*# VERIFICA DATA #*/
function verificaData(vc_campo) {
	if (vc_campo.value.length > 0) {
		it_dia		= (vc_campo.value.substring(0,2));
		it_mes		= (vc_campo.value.substring(3,5));
		it_ano		= (vc_campo.value.substring(6,10));
		it_erro		= 0;

		if ((it_dia < 01) || (it_dia < 01 || it_dia > 30) && (it_mes == 04 || it_mes == 06 || it_mes == 09 || it_mes == 11 ) || it_dia > 31) {
			it_erro	= 1;
		}

		if (it_mes < 01 || it_mes > 12 ) {
			it_erro	= 1;
		}

		if (it_mes == 2 && (it_dia < 01 || it_dia > 29 || (it_dia > 28 && (parseInt(it_ano / 4) != it_ano / 4)))) {
			it_erro	= 1;
		}

		if ((it_ano < 1900) || (it_ano>2078)){
			it_erro	= 1;
		}

		if (it_erro == 1) {
			alert("Por favor, preencha uma data válida!");
			vc_campo.value	= '';
			vc_campo.focus();
		}
	}
}

function verificaData_data(vc_data) {
    vc_campo = vc_data;
    
	if (vc_campo.length > 0) {
		it_dia		= (vc_campo.substring(0,2));
		it_mes		= (vc_campo.substring(3,5));
		it_ano		= (vc_campo.substring(6,10));
		it_erro		= 0;

		if ((it_dia < 01) || (it_dia < 01 || it_dia > 30) && (it_mes == 04 || it_mes == 06 || it_mes == 09 || it_mes == 11 ) || it_dia > 31) {
			it_erro	= 1;
		}

		if (it_mes < 01 || it_mes > 12 ) {
			it_erro	= 1;
		}

		if (it_mes == 2 && (it_dia < 01 || it_dia > 29 || (it_dia > 28 && (parseInt(it_ano / 4) != it_ano / 4)))) {
			it_erro	= 1;
		}

		if ((it_ano < 1900) || (it_ano>2078)){
			it_erro	= 1;
		}

		if (it_erro == 1) {
			//alert("Por favor, preencha uma data válida!");
                 return false;
			//vc_campo.value	= '';
			//vc_campo.focus();
		}
                 return true;
	}
}

/*# aceita só números digitados num campo */
function soNumero(evtKeyPress) {
	var nTecla;
	nTecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;

	if((nTecla > 47 && nTecla < 58) || nTecla == 8 || nTecla == 9)
		return true;
	else
		return false;
}

function limpa_string(S){

    // Deixa só os digitos no numero

    var Digitos = "0123456789";

    var temp = "";

    var digito = "";



    for (var i=0; i<S.length; i++)    {

        digito = S.charAt(i);

        if (Digitos.indexOf(digito)>=0)    {

            temp=temp+digito    }

    } //for



    return temp

}


/* VALIDAR CPF */

function valida_CPF(s)    {

    var i;

    s = limpa_string(s);

    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;

	    }



		//VERIFICA SE TODOS OS NÚMEROS SÃO IGUAIS

		var aux = 0;

		for (i = 0; i < 11; i++){

	        if (s.charAt(0) == s.charAt(i)) {

				aux++;

			}

	    }

		if (aux == 11) {

			return false;

		}



	return true;

}



function favicon(url){
    var ua      = navigator.userAgent.toLowerCase();
    var isOpera = ua.indexOf("opera") > -1;
    var isIE    = !isOpera && ua.indexOf("msie") > -1;

if (isIE) {
    document.write("<link href=\""+url+"favicon.ico\" "+
                     "type='image/x-icon' rel='shortcut icon'/>");
      document.write("<link href=\""+url+"favicon.ico\" "+
                     "type='image/x-icon' rel='icon'/>");
    } else {
      document.write("<link href=\""+url+"favicon.gif\" "+
                     "type='image/gif' rel='shortcut icon'/>");
      document.write("<link href=\""+url+"favicon.gif\" "+
                     "type='image/gif' rel='icon'/>");
    }
}


/**** Limitador de caracteris em um campo text ou textarea ********************/
function progreso_tecla(obj, max, campo) {
var max=max+10;
var ancho=412;

  var progreso = document.getElementById(campo);
  if (obj.value.length < max) {
    progreso.style.backgroundColor = "#FFFFFF";
    progreso.style.backgroundImage = "url(imgCadastro/textarea_barra.png)";
    progreso.style.color = "#000000";
    var pos = ancho-parseInt((ancho*parseInt(obj.value.length))/(max-10));
    progreso.style.backgroundPosition = "-"+pos+"px 0px";
  } else {
    progreso.style.backgroundColor = "#CC0000";
    progreso.style.backgroundImage = "url()";
    progreso.style.color = "#FFFFFF";
  }
  progreso.innerHTML = "("+obj.value.length+" / "+(max-10)+")";
}


function Contador(field,MaxLength,campo) {
          obj = document.getElementById(campo);
          if (MaxLength !=0) {
                 if (obj.value.length > MaxLength)  {
                        obj.value = obj.value.substring(0, MaxLength);
                        //alert ("Número de caracteres excedidos! O limite máximo é de 3000 caracteres.");
                        }
          }
          document.formCadastro.contador.value = obj.value.length + '/' + (max-10);
   }
/******************************************************************************/
