// JavaScript Document
	function menu(id, cor){
  		//id.style.cursor		= "pointer";
  		id.style.background = cor;
  	}
	// VALIDANDO CPF
	function valida_cpf(pcpf){
		pcpf = pcpf.replace('.',''); // CPF 000.000.000-00
		pcpf = pcpf.replace('.',''); 
		pcpf = pcpf.replace('-','');
		if (pcpf == "00000000000"){
			return false;
		}else{
			if (pcpf.length != 11){
				sim=false
			}else{
				sim=true
			}
			//verifica se os numeros digitados são iguais
			if (sim){
				i = 1;
				while(pcpf.charAt(i) == pcpf.charAt(i -1) && i < 10){
				i++;
				}
				if(i == 10) sim=false
				else sim=true
			}
			if (sim){
				for (i=0; i<=(pcpf.length-1) && sim; i++){
					val = pcpf.charAt(i)
					if((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4")&&(
					val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {sim=false}
				}
				if (sim){
					soma = 0
					for (i=0;i<=8;i++){
						val = eval(pcpf.charAt(i))
						soma = soma + (val*(i+1))
					}
					resto = soma % 11
					if (resto>9) dig = resto -10
					else dig = resto
					if (dig != eval(pcpf.charAt(9))) { sim=false }
					else{
						soma = 0
						for (i=0;i<=7;i++){
							val = eval(pcpf.charAt(i+1))
							soma = soma + (val*(i+1))
						}
						soma = soma + (dig * 9)
						resto = soma % 11
						if (resto>9) dig = resto -10
						else dig = resto
						if (dig != eval(pcpf.charAt(10))) { sim = false }
						else sim = true
					}
				}
			}
			if (sim) {
				//alert("CPF Ok");
				return true;
			}
			else {
				return false;
				//alert("CPF inválido");
			}
		}
	}
	// VALIDANDO CNPJ
	function valida_cnpj(campo) {
		erro = new String;
		if (campo.length == 14){
			//substituir os caracteres que não são números
			if(document.layers && parseInt(navigator.appVersion) == 4){
				x = campo.substring(0,2);
				x += campo.substring (3,6);
				x += campo.substring (7,10);
				x += campo.substring (11,15);
				x += campo.substring (16,18);
				campo = x; 
			} else {
				campo = campo.replace (".","");
				campo = campo.replace (".","");
				campo = campo.replace ("-","");
				campo = campo.replace ("/","");
			}
			var nonNumbers = /\D/;
			if (nonNumbers.test(campo)) erro += "A verificação de CNPJ suporta apenas números! \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] = campo.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 ((campo.charAt(12) != a[12]) || (campo.charAt(13) != a[13])){
				erro +="Dígito verificador com problema!";
			}
			if (erro.length > 0){
				//alert(erro);
				return false;
			}else return true;
		}else{
			//alert('O CNPJ [ '+campo.value+' ] está incorreto.');
			//campo.focus();
			return false;
		}
	}
	function mascara_cpf_cnpj(obj, acao){
		var mycpf = (obj.value);
		auxcpf = mycpf.replace(/[\.\-\/]/g,"");
		if (auxcpf.length == 11){
			if (valida_cpf(auxcpf)){
				if (acao == "sair"){
					mycpflen = auxcpf.length;
					mycpf = auxcpf.substr(mycpflen-11, 3)+'.'+auxcpf.substr(mycpflen-8, 3)+'.'+auxcpf.substr(mycpflen-5, 3)+'-'+auxcpf.substr(mycpflen-2, 2);
					obj.value = mycpf;
				}else{
					obj.value = auxcpf;
					obj.select();
				}
				document.getElementsByName("pessoa")[0].checked = true;
			}else{
				alert("NÚMERO DE CPF INVÁLIDO");
				obj.value = "";
				obj.focus();
			}
		}else{
			if (auxcpf.length == 14){ // 00.000.000/0000-00 -> 00.000.0000/000-00
				if (valida_cnpj(auxcpf)){
					if (acao == "sair"){
						mycpflen = auxcpf.length;
						mycpf = auxcpf.substr(mycpflen-14, 2)+'.'+auxcpf.substr(mycpflen-12, 3)+'.'+auxcpf.substr(mycpflen-9, 3)+'/'+auxcpf.substr(mycpflen-6, 4)+'-'+auxcpf.substr(mycpflen-2, 2);
						obj.value = mycpf;
					}else{
						obj.value = auxcpf;
						obj.select();
					}
				}else{
					alert("NÚMERO DE CNPJ INVÁLIDO");
					obj.value = "";
					obj.focus();
				}
				document.getElementsByName("pessoa")[1].checked = true;
			}else{
				//alert(auxcpf.length);
				obj.value = "";
				//obj.focus();	
			}
		}
	}
	// MASCARA DATA
	function mascara_data(obj, acao){
		var mycep = (obj.value);
		auxcep = mycep.replace(/[\.\-\/]/g,"");
		if (auxcep.length == 8){ // 00/00/0000
			if (acao == "sair"){
				myceplen = auxcep.length;
				mycep = auxcep.substr(myceplen-8, 2)+'/'+auxcep.substr(myceplen-6, 2)+'/'+auxcep.substr(myceplen-4, 4);
				obj.value = mycep;
			}else{
				obj.value = auxcep;
				obj.select();
			}
		}else{
			obj.value = "";
		}
	}
	// MASCARA CEP
	function mascara_cep(obj, acao){
		var mycep = (obj.value);
		auxcep = mycep.replace(/[\.\-\/]/g,"");
		if (auxcep.length == 8){
			if (acao == "sair"){
				myceplen = auxcep.length;
				mycep = auxcep.substr(myceplen-8, 5)+'-'+auxcep.substr(myceplen-3, 3);
				obj.value = mycep;
			}else{
				obj.value = auxcep;
				obj.select();
			}
		}else{
			obj.value = "";
		}
	}
	// MASCARA FONE
	function mascara_fone(obj, acao){
		var myfone = (obj.value);
		auxfone = myfone.replace(/[\.\-\/\' '\)\(]/g,"");
		//alert(auxfone);
		if (auxfone.length >= 9){ // (11) 1234-1234
			if (acao == "sair"){
				myfonelen = auxfone.length;
				myfone = '('+auxfone.substr(myfonelen-10, 2)+') '+auxfone.substr(myfonelen-8, 4)+'-'+auxfone.substr(myfonelen-4, 4);
				obj.value = myfone;
			}else{
				obj.value = auxfone;
				obj.select();
			}
		}else{
			obj.value = "";
		}
	}
	// ABRINDO JANELAS FILHO
	function abre_janela(wLink, wNome, wW, wH, wS){
		s = ",width="+wW+",height="+wH+",scrollbars="+wS;
		xWindow = window;		
		xWindow = window.open( wLink , wNome, "fullscreen=0,toolbar=0,location=0,directories=0,status=1,menubar=0,resizable=1,modal=yes"+s);
		var xLargura = window.screen.width;
		var xAltura = window.screen.height;
		var Esquerda = ((xLargura / 4) - (wW / 4));
		var Topo = ((xAltura / 4) - (wH / 4));
		xWindow.moveTo(Esquerda, Topo);
		xWindow.focus();
		return xWindow;
	}
	// VERIFICA SE É SÓ NUMEROS
	function so_numero(nCampo){
		//nCampo.className = "fonte-10-simples";
		var nAux = '';
		nAux = nAux + nCampo.value;
		//nAux = nValor.value;
		if ((nAux != '')&&(isNaN(nAux.substr(nAux.length-1,1)))){
			alert('Digite somente números neste campo !'
				+'\n\nPara CPF utilize o formato [ 12345678900 ] '
				+'\nPara CNPF utilize o formato [ 12345678912345 ] '
				+'\nPara Data utilize o formato [ 01012001 ] '
				+'\nPara CEP utilize o formato [ 00000000 ] '
				+'\nPara Endereço utilize o [ COMPLEMENTO ] '
				+'\nPara Telefone utilize o formato [ 0012345678 ] ');
			nCampo.value = '';
			nCampo.focus();
			//nCampo.className = "fonte-10-simples";
			return false;
		}
	}
	// FUNCOES PARA O TOOLTIP
	/**
	*
	* Javascript Tooltip
	*
	* @author Rogerio Alencar Lino Filho
	* @url http://rogeriolino.wordpress.com
	*
	*/
	/* Configuração */
	var id = "minhaTooltip";
	var background = "#000000";
	var border = "1px solid #999999";
	var display = "none";
	var font = "10px Verdana, Arial, Sans-serif";
	var color = "#ffffff";
	var marginX = 13; //distancia do mouse em x
	var marginY = 5; //distancia do mouse em y
	var opacity = 80; // 0 a 100
	var padding = "2px 5px";
	var position = "absolute";
	var _x = -10;
	var _y = -10;
	//
	function setPos(event) {
		if (document.all) {//IE
			_x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
			_y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
			_x += (window.event.clientX+marginX);
			_y += (window.event.clientY+marginY);
		} else {//Good Browsers
			_x = (event.pageX+marginX);
			_y = (event.pageY+marginY);
		}
	}
	//
	function showTip(text) {
		var t = document.getElementById(id);
		t.style.display = "block";
		document.onmousemove = function(event) {
			setPos(event);
			t.innerHTML = text;
			t.style.left = _x+"px";
			t.style.top = _y+"px";
		}
	}
	//
	function hideTip() {
		var t = document.getElementById(id).style;
		t.display = "none";
	}
	//
	function tooltip(elemento) {
		//alert("vai");
		var body = document.getElementsByTagName("body");
		body = body[0];
		body.innerHTML += "<div id='"+id+"'></div>";
		var t = document.getElementById(id).style;
		t.background = background;
		t.border = border;
		t.display = display;
		t.font = font;
		t.color = color;
		t.opacity = opacity/100;
		t.filter = "alpha(opacity="+opacity+")";
		t.padding = padding;
		t.position = position;
		var links = document.getElementsByTagName(elemento);
		for (i=0; i<links.length; i++) {
			var title = links[i].getAttribute("title");
			//links[i].setAttribute("class", "imagem-link");
			if (title) {
				links[i].setAttribute("tptitle", title);
				links[i].removeAttribute("title");
				links[i].onmouseover = function() { showTip(this.getAttribute("tptitle")+"<br />"); }
			} else {
				//links[i].onmouseover = function() { showTip(this.href); }
			}
			links[i].onmouseout = function() { hideTip(); }
		}
		var links = document.getElementsByTagName("img");
		for (i=0; i<links.length; i++) {
			var title = links[i].getAttribute("title");
			//links[i].setAttribute("class", "imagem-link");
			if (title) {
				links[i].setAttribute("tptitle", title);
				links[i].removeAttribute("title");
				links[i].onmouseover = function() { showTip(this.getAttribute("tptitle")+"<br />"); }
			} else {
				//links[i].onmouseover = function() { showTip(this.href); }
			}
			links[i].onmouseout = function() { hideTip(); }
		}
		var links = document.getElementsByTagName("a");
		for (i=0; i<links.length; i++) {
			var title = links[i].getAttribute("title");
			//links[i].setAttribute("class", "imagem-link");
			if (title) {
				links[i].setAttribute("tptitle", title);
				links[i].removeAttribute("title");
				links[i].onmouseover = function() { showTip(this.getAttribute("tptitle")+"<br />"); }
			} else {
				//links[i].onmouseover = function() { showTip(this.href); }
			}
			links[i].onmouseout = function() { hideTip(); }
		}
		var links = document.getElementsByTagName("strong");
		for (i=0; i<links.length; i++) {
			var title = links[i].getAttribute("title");
			//links[i].setAttribute("class", "imagem-link");
			if (title) {
				links[i].setAttribute("tptitle", title);
				links[i].removeAttribute("title");
				links[i].onmouseover = function() { showTip(this.getAttribute("tptitle")+"<br />"); }
			} else {
				//links[i].onmouseover = function() { showTip(this.href); }
			}
			links[i].onmouseout = function() { hideTip(); }
		}
		var links = document.getElementsByTagName("font");
		for (i=0; i<links.length; i++) {
			var title = links[i].getAttribute("title");
			//links[i].setAttribute("class", "imagem-link");
			if (title) {
				links[i].setAttribute("tptitle", title);
				links[i].removeAttribute("title");
				links[i].onmouseover = function() { showTip(this.getAttribute("tptitle")+"<br />"); }
			} else {
				//links[i].onmouseover = function() { showTip(this.href); }
			}
			links[i].onmouseout = function() { hideTip(); }
		}
		var links = document.getElementsByTagName("span");
		for (i=0; i<links.length; i++) {
			var title = links[i].getAttribute("title");
			//links[i].setAttribute("class", "imagem-link");
			if (title) {
				links[i].setAttribute("tptitle", title);
				links[i].removeAttribute("title");
				links[i].onmouseover = function() { showTip(this.getAttribute("tptitle")+"<br />"); }
			} else {
				//links[i].onmouseover = function() { showTip(this.href); }
			}
			links[i].onmouseout = function() { hideTip(); }
		}
	}
	/// fim
	// MASCARA ANUNCIO
	function mascara_anuncio(obj, acao){
		var myanuncio = (obj.value);
		//alert(myanuncio);
		var auxanuncio = myanuncio.replace(/[cm" "\-\/]/g,"");
		//alert(auxanuncio);
		if (auxanuncio.length == 11){
			if (acao == "sair"){
				myanunciolen = auxanuncio.length;
				myanuncio = auxanuncio.substr(myanunciolen-11, 2)+','
				+auxanuncio.substr(myanunciolen-8, 2)
				+' x '+auxanuncio.substr(myanunciolen-5, 2)
				+','+auxanuncio.substr(myanunciolen-2, 2)+" cm";
				obj.value = myanuncio;
			}else{
				obj.value = auxanuncio;
				obj.select();
			}
		}else{
			obj.value = "";
			//obj.value = auxanuncio;
			obj.select();
		}
	}
	// hint personalizado
	//window.onload = function() {
	//	tooltip('td');
		//document.getElementById('s').focus();
	//}