// ---------------------------------------------------------------

// Funções automáticas para trocar imagens

// ---------------------------------------------------------------



	function MM_preloadImages() { //v3.0

		var d=document; 

		if(d.images){ 

			if(!d.MM_p) d.MM_p=new Array();

			var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 

			for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}

		}

	}



	function MM_findObj(n, d) { //v4.01

		var p,i,x;  

		if(!d) d=document; 

		if((p=n.indexOf("?"))>0&&parent.frames.length) {

			d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);

		}

		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

		if(!x && d.getElementById) x=d.getElementById(n); return x;

	}



	function MM_swapImgRestore() { //v3.0

		var i,x,a=document.MM_sr; 

		for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

	}



	function MM_swapImage() { //v3.0

		var i,j=0,x,a=MM_swapImage.arguments; 

		document.MM_sr=new Array; 

		for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

	}



// ---------------------------------------------------------------



	function validaData(dia,mes,ano){

		v_mes = mes.value;

		v_ano = ano.value;

		v_dia = dia.value;

		dia.length=0;

		ultimo_dia=new Date(v_ano, v_mes, 00 , 00, 00, 00)    //Next millennium start date

		s_ultimo_dia = new String(ultimo_dia)

		s_ultimo_dia = s_ultimo_dia.substr(8,2);

		v_ultimo_dia = 0;

		v_ultimo_dia = parseInt(s_ultimo_dia);

		for (i=1; i<=v_ultimo_dia; i++){

			if(i<10){

				dia.options.add(new Option('0'+i,'0'+i));

			}else{

				dia.options.add(new Option(i,i));

			}

		}

		dia.options[v_dia-1].selected = true;



		return true;

	

	}



	function validaDocumento(documento){



		if (documento.length == 11) {

			if ( ( documento == '00000000000' ) ||

			     ( documento == '11111111111' ) || 

			     ( documento == '22222222222' ) || 

			     ( documento == '33333333333' ) || 

			     ( documento == '44444444444' ) || 

			     ( documento == '55555555555' ) || 

		 	     ( documento == '66666666666' ) || 

	 		     ( documento == '77777777777' ) || 

			     ( documento == '88888888888' ) || 

			     ( documento == '99999999999' ) || 

			     ( documento == '12345678909' ) ) {

				return(false);

			} else {

				total = 0;

				soma = 0;

				for (i=1; i<=9; ++i) {

					numero = documento.charAt(i-1);

					total = total + (numero * (11 - i));

					soma = soma + numero;

				}



				resto = total % 11;



				if (resto > 1) {

					dv1 = 11 - resto;

				} else {

					dv1 = 0;

				}



				total = 0;

				soma = 0;



				for (i=1; i<=10; ++i) {

					numero = documento.charAt(i-1);

					total = total + (numero * (12 - i));

					soma = soma + numero;

				}



				resto = total % 11;



				if (resto > 1) {

					dv2 = 11 - resto;

				} else {

					dv2 = 0;

				}



				if ((dv1 == documento.charAt(9)) && (dv2 == documento.charAt(10))) {

					return(true);

				} else {

					return(false);

				}

			}

		}else{



			var i

			var j

			var soma

			var aux

			var digito

			var ind



			if (documento.length != 14){

				// alert('Número do CNPJ Inválido !')

				return false;

			}



			if ( ( documento == "00000000000000" ) || 

			     ( documento == "11111111111111" ) || 

			     ( documento == "22222222222222" ) || 

			     ( documento == "33333333333333" ) || 

			     ( documento == "44444444444444" ) || 

			     ( documento == "55555555555555" ) || 

			     ( documento == "66666666666666" ) || 

			     ( documento == "77777777777777" ) || 

			     ( documento == "88888888888888" ) || 

			     ( documento == "99999999999999" ) ) {

				// alert('Número do CNPJ Inválido !')

				return false;

			}



			aux = documento.substr(0, documento.length-2);

			for (j=1; j<=2; j++){

				soma = 0;

				ind = 2

				for (i=0; i<=aux.length-1; i++){

					soma = soma + (aux.substr(aux.length - 1 - i, 1) * ind * 10);

					if (ind == 9) ind = 2; else ind++;

				}

				aux = aux + "01234567890".substr((soma % 11), 1);

			}



			if (aux != documento){

				return false;}

			if (aux == documento){

				return true;

			}

		}

	}



	function toMoney(valor,v_casas_decimais) {



		if ( isNaN(valor) ) {

			valor = 0;

		} else {

			valor = valor/1;

		}



		for (v=0;v<v_casas_decimais;v++) {

			valor=valor*10;

		}

		if ( valor > 0 ) {

			valor = valor+0.00000000001;

		}



		var inteiro 	= '';

		var decimal 	= '';



		valor = parseInt(valor);



		valor = valor.toString();



		tamanho = valor.length;



		decimal = valor.substr(tamanho-v_casas_decimais,v_casas_decimais);

		while (decimal.length < v_casas_decimais) { 

			decimal = '0'+decimal;

		}

		inteiro = valor.substr(0,tamanho-v_casas_decimais);

		tamanho = inteiro.length;

		if ( tamanho == 0 ) {

			inteiro = '0';

		} else {

			if ( tamanho > 3 ) {

				variavel_inteiro = inteiro.substr(tamanho-3,3);

				tamanho_milhar = tamanho - variavel_inteiro.length;

				milhar = inteiro.substr(0,tamanho_milhar);

				inteiro = milhar+'.'+variavel_inteiro;

			}

		}

		if ( v_casas_decimais == 0 ) {
			valor = inteiro;
		} else {
			valor = inteiro+','+decimal;
		}

		return valor;

	}





	function mostrarBoleto(v_id_inscricao) {

		abrePopUp('boleto.php?id_inscricao='+v_id_inscricao,'700','400','yes');

	}





	function abrePopUp(arquivo,largura,altura,scroll) {

		data = new Date();

		numero = data.getSeconds();

		window.open(arquivo,'PopUp'+numero,'width='+largura+',height='+altura+',toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars='+scroll+',resizable=yes');

	}





	function toValue(valor) {

		valor = valor.replace(' ','');

		valor = valor.replace('.','');

		valor = valor.replace(',','.');

		valor = parseFloat(valor);

		//valor.ParseFloat();

		if ( isNaN(valor) ) {

			valor='0';

		}

		return valor;

	}



	function toValueNulo(valor) {

		valor = valor.replace(' ','');

		valor = valor.replace('.','');

		valor = valor.replace(',','.');

		valor = parseFloat(valor);

		//valor.ParseFloat();

		if ( isNaN(valor) ) {

			valor='';

		}

		return valor;

	}



	function toHoraMinuto(valor) {

		valor = toValue(valor);

		if ( ( valor > 0 ) && ( valor < 10 ) ) {

			valor='0'+valor;

		} else {

			if ( ( valor > 9 ) && ( valor < 99 ) ) {

				// mantem o mesmo numero

			} else {

				if ( valor == '0' ) {

					valor = '00';

				} else {

					valor = '';

				}

			}

		}

		return(valor);

		

	}



	function validaEmail(email) {

		if (email.indexOf('@', 0) == -1

		|| email.indexOf('.', 0) == -1

		|| email.indexOf('"', 0) != -1

		|| email.indexOf("'", 0) != -1 ) {

			return false;

		} else {

			return true;

		}

		return true;

	}



	function validaDia(v_dia) {

		v_dia = parseInt(v_dia);

		if ( ( v_dia > 31 ) || ( v_dia < 1 ) || ( isNaN(v_dia) ) ) {

			return(false);

		} else {

			return(true);

		}

	}



	function validaMes(v_mes) {

		v_mes = parseInt(v_mes);

		if ( ( v_mes > 12 ) || ( v_mes < 1 ) || ( isNaN(v_mes) ) ) {

			return(false);

		} else {

			return(true);

		}

	}



	function validaAno(v_ano) {

		v_ano = parseInt(v_ano);

		if ( ( v_ano > 2010 ) || ( v_ano < 1900 ) || ( isNaN(v_ano) ) ) {

			return(false);

		} else {

			return(true);

		}

	}



	function mostraOcultaItem(v_id_item) {

		Tabela = document.getElementById(v_id_item);

		if(Tabela.style.display=="none"){

			Tabela.style.display = "block";

		}else{

			Tabela.style.display = "none";

		}

	}



	function mostraItem(v_id_item) {

		Tabela = document.getElementById(v_id_item);

		Tabela.style.display = "block";

	}



	function ocultaItem(v_id_item) {

		Tabela = document.getElementById(v_id_item);

		Tabela.style.display = "none";

	}



	function preencheValorCampo(v_valor,v_texto){

		if (v_valor == v_texto) {

			return('');

		} else {

			if ( v_valor == '' ) {

				return(v_texto);

			} else {

				return(v_valor);

			}

		}

	}


