<!--


google.load("jquery", "1.3.1");
google.setOnLoadCallback(function()
{
	// Fade out the suggestions box when not active
	 $("barra").blur(function(){
	 	$('#resultados').fadeOut();
	 });
});

function lookup(inputString) {
	if(inputString.length == 0) {
		$('#resultados').fadeOut(); // Hide the suggestions box
	} else {
		$.post("rpc.php", {queryString: ""+inputString+""}, function(data) { // Do an AJAX call
			$('#resultados').fadeIn(); // Show the suggestions box
			$('#resultados').html(data); // Fill the suggestions box
		});
	}
}
	function mostraResposta(p){
		for(i=1;i<=18;i++){
			document.getElementById('p'+i).style.display = 'none';
		}
		document.getElementById('p'+p).style.display = 'block';
	}

function ajax(url) 
{ 

//alert(nick); 
//alert(dest); 
//alert(msg); 

req = null; 
// Procura por um objeto nativo (Mozilla/Safari) 
if (window.XMLHttpRequest) { 
req = new XMLHttpRequest(); 
req.onreadystatechange = processReqChange; 
req.open("GET",url,true); 
req.send(null); 
// Procura por uma versão ActiveX (IE) 
} else if (window.ActiveXObject) { 
req = new ActiveXObject("Microsoft.XMLHTTP"); 
if (req) { 

req.onreadystatechange = processReqChange; 
req.open("GET",url,true); 

req.send(); 
} 
} 
} 

function processReqChange() 
{ 

// apenas quando o estado for "completado" 
if (req.readyState == 4) { 

// apenas se o servidor retornar "OK" 

if (req.status ==200) { 

// procura pela div id="pagina" e insere o conteudo 
// retornado nela, como texto HTML 

document.getElementById('pagina').innerHTML = req.responseText; 

} else { 
alert("Houve um problema ao obter os dados:n" + req.statusText); 
} 
} 
} 


	function ajaxInit(){
		var xmlhttp;
		try{ xmlhttp = new XMLHttpRequest(); }
		catch(ee) {
			try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
			catch(e) {
				try{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
				catch(E){ xmlhttp = false ;	}
			}
		}
		return xmlhttp;
	}
	
function Dados(valor) {
		try { ajax = new ActiveXObject("Microsoft.XMLHTTP"); } 
		catch(e) { 
			try { ajax = new ActiveXObject("Msxml2.XMLHTTP"); }
			catch(ex) {
				try { ajax = new XMLHttpRequest(); }
				catch(exc) { alert("Esse browser não tem recursos para uso do Ajax"); ajax = null; }
			}
		}
		if(ajax) {
			document.getElementById('cidade').options.length = 1;
			alert(document.getElementById('cidade').options.length);
			idOpcao  = document.getElementById("opcoes");
			ajax.open("POST", "cidades.php", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 1) { idOpcao.innerHTML = "Carregando..."; }
				if(ajax.readyState == 4 ) {
				   if(ajax.responseXML) { processXML(ajax.responseXML); }
				   else { idOpcao.innerHTML = "Primeiro selecione o estado."; }
				}
			}
			var params = "estado="+valor;
			ajax.send(params);
		} else { alert('Não entrou.'); }
	}




	function processXML(obj){
		var dataArray = obj.getElementsByTagName("cidade");
		if(dataArray.length > 0) {
			for(var i = 0 ; i < dataArray.length ; i++) {
				var item = dataArray[i];
				var codigo =  item.getElementsByTagName("codigo")[0].firstChild.nodeValue;
				var nome   =  item.getElementsByTagName("nome")[0].firstChild.nodeValue;
				idOpcao.innerHTML = "";
				var novo = document.createElement("option");
					novo.setAttribute("id", "opcoes");
					novo.value = codigo;
					novo.text  = nome;
					document.getElementById('cidade').options.add(novo);
			}
		} else { idOpcao.innerHTML = ""; }
	}

	function carregar(formulario, pagina, local) {
		ajax = ajaxInit();
		document.getElementById(local).innerHTML += "Carregando ...";
		if(ajax){
			ajax.open('POST', pagina+'.php', true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.onreadystatechange = function(){
				if(ajax.readyState == 1) { idOpcao.innerHTML = "Carregando..."; }
				if(ajax.readyState == 4) {
					if(ajax.status == 200) {
						document.getElementById(local).innerHTML = ajax.responseText;
					}
				}
			}
			var params = capturaDados(formulario);
			ajax.send(params);
			document.getElementById(local).innerHTML = '';
		}
	}

	function capturaDados(formulario){
		var arrayFormulario = document.getElementsByTagName('form');
		var campos = '';
		var navegador = navigator.appName;
		if(navegador == 'Netscape'){
			inicioArray = arrayFormulario[formulario].length;
			i=1;
			for(chaves in arrayFormulario[formulario]){ 
				if(i <= inicioArray ){
					if(campos!=''){ campos = campos + '&' }
					campos = campos + chaves + '=' + arrayFormulario[formulario][chaves].value;
				}i++;
			}
		} else {
			nCampos = arrayFormulario[formulario].length;
			totalArray=1;
			for(chaves in arrayFormulario[formulario]){ totalArray++; }
			inicioArray = totalArray-nCampos;
			i=1;
			for(chaves in arrayFormulario[formulario]){ 
				if(i >= inicioArray ){
					if(campos!=''){ campos = campos + '&' }
					campos = campos + chaves + '=' + arrayFormulario[formulario][chaves].value;
				}i++;
			}
		}
		return campos;
	}

	function numeros(e,src){
		if(window.event) { _TXT = e.keyCode; } 
			else if(e.which) { _TXT = e.which; }
			if(_TXT > 47 && _TXT < 58) { 
				return true;
			} else {
				if (_TXT != 8) { return false; } 
				else { return true; }
		}
	}


	function escreve_flash(nome,largura,altura){
		document.write('<object id="localFlash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+largura+'" height="'+altura+'" id="'+nome+'" align="middle">');
		document.write('<param name="allowScriptAccess" value="sameDomain" />');
		document.write('<param name="movie" value="tvs_flash/'+nome+'.swf" />');
		document.write('<param name="wmode" value="transparent" />'); 
		document.write('<param name="quality" value="high" />');
		document.write('<embed wmode="transparent" src="tvs_flash/'+nome+'.swf" quality="high" bgcolor="#ffffff" width="'+largura+'" height="'+altura+'" name="'+nome+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
		document.write('</object>');
	}

	function escreve_boxes(nome,largura,altura){
		document.write('<object id="localFlash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+largura+'" height="'+altura+'" id="'+nome+'" align="middle">');
		document.write('<param name="allowScriptAccess" value="sameDomain" />');
		document.write('<param name="movie" value="box_lateral/'+nome+'.swf" />');
		document.write('<param name="wmode" value="transparent" />'); 
		document.write('<param name="quality" value="high" />');
		document.write('<embed wmode="transparent" src="box_lateral/'+nome+'.swf" quality="high" bgcolor="#ffffff" width="'+largura+'" height="'+altura+'" name="'+nome+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
		document.write('</object>');
	}

	
	
	function MM_preloadImages() {
	  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_swapImgRestore() {
	  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_findObj(n, d) {
	  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_swapImage() {
	  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 MM_format(e,src,mask) {
		if(window.event) { _TXT = e.keyCode; } 
		else if(e.which) { _TXT = e.which; }
		if(_TXT > 47 && _TXT < 58) { 
			var i = src.value.length; var saida = mask.substring(0,1); var texto = mask.substring(i)
			if (texto.substring(0,1) != saida) {
				src.value += texto.substring(0,1);
			} 
			return true;
			} else {
				if (_TXT != 8) { return false; } 
				else { return true; }
		}
	}

	function mostraCampoDocumento(valor){
		switch(valor){
			case 'cpf': campo = 'campo_01'; break;
			case 'cnpj': campo = 'campo_02'; break;
		}
		document.getElementById('campo_01').style.display = 'none';
		document.getElementById('campo_02').style.display = 'none';
		document.getElementById(campo).value='';
		document.getElementById(campo).style.display = 'block';
		
		if(valor == ''){ document.getElementById(campo).style.display = 'none'; }
	}

	function pula(campo, qtde, nextCampo){	if(campo.length == qtde){ document.getElementById(nextCampo).focus(); } }
	
		function validacaoCadastroEmail(){
		var d = document.formContato;
		var frase = ' é de preenchimento obrigatório!';
		if(d.nome.value == ''){ 
		alert('O campo "Nome"' + frase); 
		d.nome.focus(); 
		return false; 
		}
		if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(d.email.value))) { 
		alert("Dados inválidos no campo Email. Favor verificar!"); 
		d.email.focus(); 
		return false; 
		}
		return true;
	}
	
	function validacaoContato(){
		var d = document.formContato;
		var frase = ' é de preenchimento obrigatório!';
		if(d.nome.value == ''){ alert('O campo "Nome"' + frase);d.nome.focus();return false;}
		if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(d.email.value))) { 
		alert("Dados inválidos no campo Email. Favor verificar!"); 
		d.email.focus(); 
		return false; 
		}
		if(d.mensagem.value == ''){ 
		alert('O campo "Mensagem"' + frase); 
		d.mensagem.focus(); 
		return false; 
		}
		return true;
	}
	
		function validacaoContato1(){
		var d = document.formContato;
		var frase = ' é de preenchimento obrigatório!';
		if(d.nome.value == ''){ alert('O campo "Nome"' + frase); d.nome.focus(); return false; }
		if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(d.email.value))) { alert("Dados inválidos no campo Email. Favor verificar!"); d.email.focus(); return false; }
		if(d.mensagem.value == ''){ alert('O campo "Mensagem"' + frase); d.mensagem.focus(); return false; }
		carregar('formContato', 'ajax', 'respostaContato');
		d.reset();
	}
		
	function ValidaCPF(numcpf){
		if(numcpf != "" ){
			numcpf = numcpf.substr(0, 3) + numcpf.substr(4, 3) + numcpf.substr(8, 3) + numcpf.substr(12, 2);
			if (numcpf == "00000000000" || 
				numcpf == "11111111111" || 
				numcpf == "22222222222" || 
				numcpf == "33333333333" || 
				numcpf == "44444444444" || 
				numcpf == "55555555555" || 
				numcpf == "66666666666" || 
				numcpf == "77777777777" || 
				numcpf == "88888888888" || 
				numcpf == "99999999999") {
				return false;
			} else {
				x = 0;
				soma = 0;
				dig1 = 0;
				dig2 = 0;
				texto = "";
				numcpf1="";
				len = numcpf.length;
				x = len -1;
				for (var i=0; i <= len - 3; i++) {
					y = numcpf.substring(i,i+1);
					soma = soma + ( y * x);
					x = x - 1;
					texto = texto + y;
				}
				dig1 = 11 - (soma % 11);
				if (dig1 == 10) dig1=0 ;
				if (dig1 == 11) dig1=0 ;
				numcpf1 = numcpf.substring(0,len - 2) + dig1 ;
				x = 11; soma=0;
				for (var i=0; i <= len - 2; i++) {
					soma = soma + (numcpf1.substring(i,i+1) * x);
					x = x - 1;
				}
				dig2= 11 - (soma % 11);
				if (dig2 == 10) dig2=0;
				if (dig2 == 11) dig2=0;
				if ((dig1 + "" + dig2) == numcpf.substring(len,len-2)) {
					return true;
				}
				return false;
			}
		} else { return false; }
	}

	function ValidarCNPJ1(Cnpj){
        var cnpj = Cnpj.value;
        var valida = new Array(6,5,4,3,2,9,8,7,6,5,4,3,2);
        var dig1= new Number;
        var dig2= new Number;
        
        exp = /\.|\-|\//g
        cnpj = cnpj.toString().replace( exp, "" ); 
        var digito = new Number(eval(cnpj.charAt(12)+cnpj.charAt(13)));
                
        for(i = 0; i<valida.length; i++){
                dig1 += (i>0? (cnpj.charAt(i-1)*valida[i]):0);  
                dig2 += cnpj.charAt(i)*valida[i];       
        }
        dig1 = (((dig1%11)<2)? 0:(11-(dig1%11)));
        dig2 = (((dig2%11)<2)? 0:(11-(dig2%11)));
        
        if(((dig1*10)+dig2) != digito){
        return false;                  
}      
else{
return true;
}
}

function validaCNPJ(CNPJ){
		if (CNPJ.length < 18) { return false; }
		if ((CNPJ.charAt(3) != ".") || (CNPJ.charAt(7) != ".") || (CNPJ.charAt(11) != "/") || (CNPJ.charAt(16) != "-")){ return false; } 
        if(document.layers && parseInt(navigator.appVersion) == 4){
			x = CNPJ.substring(0,3);
			x += CNPJ. substring (3,7);
			x += CNPJ. substring (7,11);
			x += CNPJ. substring (11,16);
			x += CNPJ. substring (16,18);
			CNPJ = x;
		} else {
			CNPJ = CNPJ. replace (".","");
			CNPJ = CNPJ. replace (".","");
			CNPJ = CNPJ. replace ("-","");
			CNPJ = CNPJ. replace ("/","");
		}
		var nonNumbers = /\D/;
		if (nonNumbers.test(CNPJ)) { return false; }
       	tot  = 0; peso = 2; 
		for (i = 0;  i <= 12;  i++){ 
			tot += peso * parseInt(CNPJ.charAt(12 - i)); 
			peso++; 
			if(peso == 10){ peso = 2; } 
		} 
		if ((tot * 10 % 11 % 10) != parseInt(CNPJ.charAt(13))) { return false; } else { return true; }
	}

	function mostraForm(formulario){
		document.getElementById('formPA').style.display = 'none';
		document.getElementById('formJC').style.display = 'none';
		document.getElementById('tabelaDmais').style.display = 'block';
		document.getElementById('form'+formulario).style.display = 'block';
		document.formLogin.reset;
		document.getElementById('p').value = formulario;
	}
	
	function validacaoCadastro(){
		var d = document.formCadastro;
		var tipo = document.getElementById('p').value;
		var frase = ' deve ser preenchido!';
		switch(tipo){
			case 'PF':
				if(d.nome.value == ""){ alert('O campo "Nome"' + frase); d.nome.focus(); return false; }
				if(d.sobrenome.value == ""){ alert('O campo "Sobrenome"' + frase); d.sobrenome.focus(); return false; }
				if(!ValidaCPF(d.cpf.value)){ alert("O campo 'CPF'" + frase); d.cpf.focus(); return false; }
				if(d.rg.value == ""){ alert("O campo 'RG'" + frase); d.rg.focus(); return false; }
                if(d.ddd01.value == ""){ alert('O campo "DDD" do Telefone' + frase); d.ddd01.focus(); return false; }
				if(d.tel01.value == ""){ alert('O campo "Telefone"' + frase); d.tel01.focus(); return false; }
				if(d.ddd02.value == ""){ alert('O campo "DDD" Celular' + frase); d.ddd02.focus(); return false; }
				if(d.tel02.value == ""){ alert('O campo "Celular"' + frase); d.tel02.focus(); return false; }
				if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(d.email.value))){ alert('Dados inválidos no campo "Email"! Favor verificar.'); d.email.focus(); return false; }
				if(d.endereco.value == ""){ alert('O campo "Endereco"' + frase); d.endereco.focus(); return false; }
				if(d.bairro.value == ""){ alert('O campo "Bairro"' + frase); d.bairro.focus(); return false; }
				if(d.cep.value == ""){ alert('O campo "CEP"' + frase); d.cep.focus(); return false; }
				if(d.estado.value == ""){ alert('O campo "Estado"' + frase); d.estado.focus(); return false; }
				if(d.cidade.value == ""){ alert('O campo "Cidade"' + frase); d.cidade.focus(); return false; }
			break;

			case 'PJ':
				if(d.razao.value == ""){ alert('O campo "Razão"' + frase); d.razao.focus(); return false; }
				if(d.fantasia.value == ""){ alert('O campo "Fantasia"' + frase); d.fantasia.focus(); return false; }
				if(!validaCNPJ(d.cnpj.value)){ alert('O campo "CNPJ"' + frase); d.fantasia.focus(); return false; }
				if(d.abertura.value == ""){ alert('O campo "Abertura"' + frase); d.abertura.focus(); return false; }
                if(d.ddd01.value == ""){ alert('O campo "DDD" do Telefone' + frase); d.ddd01.focus(); return false; }
				if(d.tel01.value == ""){ alert('O campo "Telefone"' + frase); d.tel01.focus(); return false; }
				if(d.ddd02.value == ""){ alert('O campo "DDD" Celular' + frase); d.ddd02.focus(); return false; }
				if(d.tel02.value == ""){ alert('O campo "Celular"' + frase); d.tel02.focus(); return false; }
				if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(d.email.value))){ alert('Dados inválidos no campo "Email"! Favor verificar.'); d.email.focus(); return false; }
				if(d.endereco.value == ""){ alert('O campo "Endereco"' + frase); d.endereco.focus(); return false; }
				if(d.bairro.value == ""){ alert('O campo "Bairro"' + frase); d.bairro.focus(); return false; }
				if(d.cep.value == ""){ alert('O campo "CEP"' + frase); d.cep.focus(); return false; }
				if(d.estado.value == ""){ alert('O campo "Estado"' + frase); d.estado.focus(); return false; }
				if(d.cidade.value == ""){ alert('O campo "Cidade"' + frase); d.cidade.focus(); return false; }			
			break;
		}
				
		return true;
	}
	
function soCaracteresValidos(event)
{
	var keypress = ((navigator.appName.indexOf('Netscape')==-1)? window.event.keyCode : event.which);
	var cancela=false;
				
	if (navigator.appName.indexOf('Netscape')==-1)
		window.event.returnValue = false;
	else
		cancela = true;

		switch(keypress) {
			case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 9: case 10: case 11: case 12: case 14: case 15: case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31: case 33: case 34: case 35: case 36: case 37: case 38: case 39: case 40: case 41: case 42: case 43: case 44: case 45: case 46: case 47: case 58: case 59: case 60: case 61: case 62: case 63: case 64: case 91: case 92: case 93: case 94: case 95: case 96: break;
			case 123: case 124: case 125: case 126: case 127: case 128: case 129: case 130: case 131: case 132: case 133: case 134: case 135: case 136: case 137: case 138: case 139: case 140: case 141: case 142: case 143: case 144: case 145: case 146: case 147: case 148: case 149: case 150: case 151: case 152: case 153: case 154: case 155: case 156: case 157: case 158: case 159: case 160: case 161: case 162: case 163: case 164: case 165: case 166: case 167: case 168: case 169: case 170: case 171: case 172: case 173: case 174: case 175: case 176: case 177: case 178: case 179: case 180: case 181: case 182: case 183: case 184: case 185: case 186: case 187: case 188: case 189: case 190: case 191: case 197: case 198: case 208: case 215: case 216: case 222: case 223: case 247: break;
			default:
				if (navigator.appName.indexOf('Netscape')==-1)
					window.event.returnValue = true;
					cancela = false;
		}
				
		if (cancela == true)
			event.preventDefault();
}

function soCaracteresValidosOnChange(campo)
{
	var str_out = '';
	
		if(campo.value.length > 0)
		{
			for(i=0;i<campo.value.length;i++)
			{
				switch(campo.value.charCodeAt(i)) {
					case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31: case 33: case 34: case 35: case 36: case 37: case 38: case 39: case 40: case 41: case 42: case 43: case 44: case 45: case 46: case 47: case 58: case 59: case 60: case 61: case 62: case 63: case 64: case 91: case 92: case 93: case 94: case 95: case 96: break;
					case 123: case 124: case 125: case 126: case 127: case 128: case 129: case 130: case 131: case 132: case 133: case 134: case 135: case 136: case 137: case 138: case 139: case 140: case 141: case 142: case 143: case 144: case 145: case 146: case 147: case 148: case 149: case 150: case 151: case 152: case 153: case 154: case 155: case 156: case 157: case 158: case 159: case 160: case 161: case 162: case 163: case 164: case 165: case 166: case 167: case 168: case 169: case 170: case 171: case 172: case 173: case 174: case 175: case 176: case 177: case 178: case 179: case 180: case 181: case 182: case 183: case 184: case 185: case 186: case 187: case 188: case 189: case 190: case 191: case 197: case 198: case 208: case 215: case 216: case 222: case 223: case 247: break;
					default:
						str_out+=campo.value.substring(i,i+1);
				}
				
			}
			campo.value = str_out;
		}


}
