var _str = "";
var _timeout = 0;

function cbboxSearch(sel, e) {
    var i=0, c=true;
    _str = _str + String.fromCharCode(e.keyCode);
    _str = _str.toLowerCase();
    while (c) {
        var textOpt = sel.options[i].text.toLowerCase();
        var strOpt = textOpt.substr(0, (_str.length));
        if (strOpt == _str) {
            sel.options[i].selected = true;
            c = false;
        }
        if (i >= (sel.options.length - 1)) {
            c = false;
        }
        i++;
    }
    clearTimeout(_timeout);
    _timeout = setTimeout("cbboxSearchRestart()", 2000);
}

function cbboxSearchRestart() {
    clearTimeout(_timeout);
    _str = "";
}

function CampoNumerico()
{

  if (parseInt(event.keyCode) < 48 || parseInt(event.keyCode) > 57)
   {
	 event.keyCode = null;
   }
}

function CampoDecimal()
{

  if (parseInt(event.keyCode) < 44 || parseInt(event.keyCode) == 45 || parseInt(event.keyCode) == 46 || parseInt(event.keyCode) == 46 || parseInt(event.keyCode) == 47 || parseInt(event.keyCode) > 57)
  
   {
	 event.keyCode = null;
   }
}

function LimpaCombo(campo) {
var z;
z = campo.length
	for (x=0;x<=z;x++) {
		campo.remove(0);
	}
}
function chamarAjaxCombo(valor,tabela1,tabela2,elemento,nomeDIV, mostrar, selecionar){	

	
	if (elemento == null ) {
		elemento = document.form3.municipio
	}
	
	
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";
	sxml = sxml + "<chave>" + valor + "</chave><tabela1>" + tabela1 + "</tabela1><tabela2>" + tabela2 + "</tabela2><mostrar>" + mostrar + "</mostrar>";
	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");

	xmldoc.loadXML(sxml);
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.Open("POST",'../../plataforma/includes/xmlCombo.ASP', false);
	xmlhttp.Send(xmldoc);
	var xmlTemp = xmlhttp.responseXML;		
	LimpaCombo(elemento);
	objOption = document.createElement("OPTION");
	objOption.text =  "Selecione o(a) "+tabela2
	objOption.value = "0"
	elemento.options.add(objOption)
	lop = 0;
	total = xmlTemp.documentElement.childNodes.length - 1
		
	while(lop <= total)
	{
		objOption = document.createElement("OPTION");
		objOption.text =  xmlTemp.getElementsByTagName("descricao")[lop].childNodes[0].nodeValue;
		objOption.value = xmlTemp.getElementsByTagName("codigo")[lop].childNodes[0].nodeValue;
		elemento.options.add(objOption)
		if (selecionar == objOption.value) {
			elemento.options[lop+1].selected = true
		}
		lop++;
	}
	
	
	if (total > 0){
		if (nomeDIV != 'nao') {
			
			document.getElementById(nomeDIV).style.display = 'none'
			document.getElementById(nomeDIV).style.display = 'block'
			elemento.disabled = false;
			
		}
	}
}

function chamarAjaxTexto(valor,tabela1,tabela2,elemento,nomeDIV, mostrar)
{	
	if (elemento == null ) {
		return 
	}
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";
	sxml = sxml + "<chave>" + valor + "</chave><tabela1>" + tabela1 + "</tabela1><tabela2>" + tabela2 + "</tabela2><mostrar>" + mostrar + "</mostrar>";
	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");
	xmldoc.loadXML(sxml);
		
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.Open("POST",'../../plataforma/includes/xmlCombo.ASP', false);
	xmlhttp.Send(xmldoc);
	var xmlTemp = xmlhttp.responseXML;		
	elemento.value= '';
	elemento.value= xmlTemp.getElementsByTagName("descricao")[0].childNodes[0].nodeValue;
	
	if (total > 0){
		if (nomeDIV != 'nao') {
			document.getElementById(nomeDIV).style.display = 'block'
			elemento.disabled = false;
		}
	}
}

function SelectGeralSimples(valor,metodo,combo, div) {;

	if (valor == '' ){
		return false
	}
	
	if (tabela == '' ){
		return false
	}
	
	if (combo == '' ){
		return false
	}
	
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";
	sxml = sxml + "<valor>" + valor + "</valor>";
	sxml = sxml + "<metodo>" + metodo + "</metodo>";
	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");
	xmldoc.loadXML(sxml);
		
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	
	xmlhttp.Open("POST",'../../plataforma/includes/novo_xmlCombo', false);	xmlhttp.Send(xmldoc);
	
	var xmlTemp = xmlhttp.responseXML;	

	if (div != '' ) {;
		document.getElementById(div).style.display = 'block'
	}else{;
		document.getElementById(div).style.display = 'none'

	}

}

function AtualizaMunicipio() {

total = document.formUfsSelect.iIdMun.length - 1;
lop=1 ;
x=0;
	while(lop <= total)
	
	{
		
		
		
		nome= document.formUfsSelect.iIdMun[lop].text
		codigo= document.formUfsSelect.iIdMun[lop].value
		
			
		if (nome != '' && codigo != '' ) {
		
			var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
			xmldoc.async = false;
			var sxml;	
			sxml = "<ROOT>";
			sxml = sxml + "<nome>" + nome + "</nome>";
			sxml = sxml + "<codigo>" + codigo + "</codigo>";
			sxml = sxml + "</ROOT>";
			sxml = sxml.replace("&","&amp;");
			xmldoc.loadXML(sxml);
			
			var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		
			xmlhttp.Open("POST",'../../plataforma/includes/xmlMunicipio.asp', false);
			xmlhttp.Send(xmldoc);
			var xmlTemp = xmlhttp.responseXML;	
			
			cod= xmlTemp.getElementsByTagName("codigo")[0].childNodes[0].nodeValue;
			
			if (cod == '0' ) {
				alert(nome);
				x= x + 1
			}
		}
		lop++;
	}
	
    alert(x)

}

function PegaCodigoIBGE_CNM(codigo) {
	    
	document.form1.ibge.value = 0
	document.form1.cnm.value = 0
		
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";
	sxml = sxml + "<codigo>" + codigo + "</codigo>";
	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");
	xmldoc.loadXML(sxml);
			
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		
	xmlhttp.Open("POST",'../../plataforma/includes/xmlMunicipio2.asp', false);
	xmlhttp.Send(xmldoc);
	var xmlTemp = xmlhttp.responseXML;	
	document.form1.ibge.value = xmlTemp.getElementsByTagName("ibge")[0].childNodes[0].nodeValue;
	document.form1.cnm.value = xmlTemp.getElementsByTagName("cnm")[0].childNodes[0].nodeValue;
	
	
			
}

function getCheckedValue(radioObj) {
	
   if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";

	
}

function EscolheOpcaoMunicipio(opcao) {
	
	if (opcao == '1'){
		if (document.form1.ibge.value != '' || document.form1.ibge.value != '0' ) {
			document.getElementById('div1').src='http://www.ibge.gov.br/cidadesat/xtras/perfil.php?codmun='+ document.form1.ibge.value + '&r=2' ;
		}else{
			alert('escolha o estado e município');
			document.form1.municipio.focus();
		}
	}else if (opcao == '2') {
		if (document.form1.cnm.value != '' || document.form1.cnm.value != '0' ) {
			document.getElementById('div1').src='http://www.cnm.org.br/dado_geral/mumain.asp?iIdMun='+ document.form1.cnm.value  ;
		}else{
			alert('escolha o estado e município');
			document.form1.municipio.focus();
		}
	}else if (opcao == '3') {
		if (document.form1.ibge.value != '' || document.form1.ibge.value != '0' ) {
			document.getElementById('div1').src='http://cnes.datasus.gov.br/Lista_Es_Municipio.asp?VEstado=29&VCodMunicipio='+ document.form1.ibge.value  ;
		}else{
			alert('escolha o estado e município');
			document.form1.municipio.focus();
		}
	}else if (opcao == '4') {
		if (document.form1.ibge.value != '' || document.form1.ibge.value != '0' ) {
			if (document.form1.estado.value == "1" ) {
				document.form1.uf.value = 'AC'
			}else if (document.form1.estado.value == "2" ) {
				document.form1.uf.value = 'AL'    
			}else if (document.form1.estado.value == "3" ) {
				document.form1.uf.value = 'AM'   
			}else if (document.form1.estado.value == "4" ) {
				document.form1.uf.value = 'AM'   
            }else if (document.form1.estado.value == "5" ) {
				document.form1.uf.value = 'BA'       
            }else if (document.form1.estado.value == "6" ) {
				document.form1.uf.value = 'CE'          
            }else if (document.form1.estado.value == "7" ) {
				document.form1.uf.value = 'DF'         
            }else if (document.form1.estado.value == "8" ) {
				document.form1.uf.value = 'ES'     
            }else if (document.form1.estado.value == "9" ) {
				document.form1.uf.value = 'GO'         
            }else if (document.form1.estado.value == "10" ) {
				document.form1.uf.value = 'MA'         
            }else if (document.form1.estado.value == "11" ) {
				document.form1.uf.value = 'MG'         
            }else if (document.form1.estado.value == "12" ) {
				document.form1.uf.value = 'MS'        
            }else if (document.form1.estado.value == "13" ) {
				document.form1.uf.value = 'MT'        
            }else if (document.form1.estado.value == "14" ) {
				document.form1.uf.value = 'PA' 
			}else if (document.form1.estado.value == "15" ) {
				document.form1.uf.value = 'PB'   
            }else if (document.form1.estado.value == "16" ) {
				document.form1.uf.value = 'PE'    
			}else if (document.form1.estado.value == "17" ) {
				document.form1.uf.value = 'PI'   
            }else if (document.form1.estado.value == "18" ) {
				document.form1.uf.value = 'PR'   
            }else if (document.form1.estado.value == "19" ) {
				document.form1.uf.value = 'RJ'          
			}else if (document.form1.estado.value == "20" ) {
				document.form1.uf.value = 'RN'                     
			}else if (document.form1.estado.value == "21" ) {
				document.form1.uf.value = 'RO'                     
            }else if (document.form1.estado.value == "22" ) {
				document.form1.uf.value = 'RR'        
            }else if (document.form1.estado.value == "23" ) {
				document.form1.uf.value = 'RS'         
            }else if (document.form1.estado.value == "24" ) {
				document.form1.uf.value = 'SC'        
            }else if (document.form1.estado.value == "25" ) {
				document.form1.uf.value = 'SE'         
            }else if (document.form1.estado.value == "26" ) {
				document.form1.uf.value = 'SP'         
			}else if (document.form1.estado.value == "27" ) {
				document.form1.uf.value = 'TO'                     
			}
			
			//document.getElementById('div1').src='http://www.tse.gov.br/sieeeleitoradoweb/eleitorado/sexo_grau/redireciona.jsp?uf=BA' ;
			//document.getElementById('div1').src='http://www.tse.gov.br/sieeeleitoradoweb/eleitorado/sexo_faixa_etaria/resultado.jsp'
			//document.getElementById('div1').src='http://www.tse.gov.br/sieeeleitoradoweb/eleitorado/sexo_faixa_etaria/redireciona.jsp?tipo_pesquisa=UF'
			//document.getElementById('div1').src='http://www.tse.gov.br/sieeeleitoradoweb/eleitorado/sexo_faixa_etaria/resultado.jsp'
			//http://www.tse.gov.br/internet/eleicoes/2006/result_vot_blank.htm
			document.getElementById('div1').src='municipio_tse.asp?' + document.form1.municipio.value + '&nome2=' + nome2
			
		}else{
			alert('escolha o estado e município');
			document.form1.municipio.focus();
		}
		
	}else if (opcao == '5') {
		obj= document.form1.municipio;
		nome2=  obj.options[obj.selectedIndex].text;
		document.getElementById('div1').src='municipio3.asp?municipio=' + document.form1.municipio.value + '&nome2=' + nome2
		
	}else if (opcao == '6') {
		obj= document.form1.municipio;
		nome2=  obj.options[obj.selectedIndex].text;
		document.getElementById('div1').src='http://www.stn.fazenda.gov.br/estados_municipios/municipios.asp'
	}else if (opcao == '7') {
		document.getElementById('div1').src='http://tabnet.datasus.gov.br/tabdata/cadernos/cadernosmap.htm?saude=http%3A%2F%2Ftabnet.datasus.gov.br%2Ftabdata%2Fcadernos%2Fcadernosmap.htm&botaook=OK&obj=http%3A%2F%2Ftabnet.datasus.gov.br%2Ftabdata%2Fcadernos%2Fcadernosmap.htm'
	}else if (opcao == '99') {
		obj= document.form1.municipio;
		nome2=  obj.options[obj.selectedIndex].text;
		document.getElementById('div1').src='formatar2.asp?municipio=' + document.form1.municipio.value + '&nome2=' + nome2

	}

	
}

function CalculaAmostra() {
	
	N = document.form1.NN.value;
	Eo = document.form1.Eo.value;
	
	Eo =  Eo/ 100 *  Eo/100;
	no =  1 / Eo;
	no = Math.round(no);
	document.form1.no.value = no;
	
	n1= eval(N) * eval(document.form1.no.value) ;
	n2= eval(N) + eval(document.form1.no.value);
	n= n1/n2;
	n = Math.round(n);
	
	document.form1.a.value = n;

}

function CalculaErroAmostral() {
	
	no = document.form1.a.value ;
		
	e2 = Math.sqrt(1,2);
	e3=  Math.sqrt(eval(no),2);
	
	e4=  (e2/e3) *100;
	
	//e4 = Math.ceil(e4);
	e4= e4.toString();	
	document.form1.e2.value= e4.substring(0,3);

}

function CalculaEntrevista() {
	
	if (document.form1.senha.value == '' || document.form1.senha.value != 'WIN' ) {
		
		e = eval(document.form1.entrevista.value);
		valor= 0;
		
		for(var i = 1; i < e; i++) {
			
			if ( i >= 1 && i <= 10 ) {
				
				valor= valor + 0.5
				
			}else if ( i >= 11 && i <= 20 ) {
				
				valor= valor + 0.55
				
			}else if ( i >= 21 && i <= 30 ) {
				
				valor= valor + 0.60
				
			}else if ( i >= 31 && i <= 40 ) {
				
				valor= valor + 0.65
				
			}else if ( i >= 41 && i <= 50 ) {
				
				valor= valor + 0.70
			
			}else if ( i >= 51 && i <= 60 ) {
				
				valor= valor + 0.75
				
			}else if ( i >= 61 && i <= 70 ) {
				
				valor= valor + 0.80
				
			}else if ( i >= 71 && i <= 80 ) {
				
				valor= valor + 0.85
				
			}else if ( i >= 81 && i <= 90 ) {
				
				valor= valor + 0.90
			
			}else if ( i >= 91 && i <= 100 ) {
				
				valor= valor + 0.95
				
			}else if ( i >= 101 && i <= 110 ) {
	
				valor= valor + 1.00
				
			}else if ( i >= 111 && i <= 120 ) {
				
				valor= valor + 1.05
				
			}else if ( i >= 121 && i <= 130 ) {
				
				valor= valor + 1.10
				
			}else if ( i >= 131 && i <= 140 ) {
				
				valor= valor + 1.15
				
			}else if ( i >= 141 && i <= 150 ) {
				
				valor= valor +  1.20
			
			
			}
			
		}
		
		valor= Math.round(valor)
		
		document.form1.valor.value=  valor;
		
	}else{
		
		alert('Senha inválida');
		
		document.form1.senha.focus();
		
	}
	

}

function CadastraPopulacao() {
	
	ibge= document.form1.ibge.value;
	populacao= document.form1.pop2007.value;
	
	if (ibge == '') {
	
		alert('informe o municipio') ;
		
		parent.document.form1.estado.focus();
		
		return false
		
	}
	
	if (populacao == '' || populacao == 0) {
	
		alert('informe a populacao') ;
		
		document.form1.pop2007.focus();
		
		return false
		
	}
	
	if (document.form1.senha.value == '' || document.form1.senha.value != 'WIN' ) {
		
		alert('informe a senha') ;
		
		document.form1.senha.focus();
		
		return false
		
	}
	
	
	populacao = populacao.replace('.' , '' )
	
	populacao = populacao.replace('.' , '' )
	
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";
	sxml = sxml + "<ibge>" + ibge + "</ibge>";
	sxml = sxml + "<populacao>" + populacao + "</populacao>";

	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");
	xmldoc.loadXML(sxml);
			
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		
	xmlhttp.Open("POST",'../../plataforma/includes/xmlMunicipio3.asp', false);
	xmlhttp.Send(xmldoc);
	var xmlTemp = xmlhttp.responseXML;	
			
	if (xmlTemp.getElementsByTagName("ibge")[0].childNodes[0].nodeValue == '0') {;
	
		alert('Registro atualizado com sucesso!')
	}
	
	obj= parent.document.form1.municipio;
	nome2=  obj.options[obj.selectedIndex].text;
	parent.document.getElementById('div1').src='municipio2.asp?ibge=' + document.form1.ibge.value + '&nome2=' + nome2

	
	
}

function CampoDecimal()
{

  if (parseInt(event.keyCode) < 44 || parseInt(event.keyCode) == 45 || parseInt(event.keyCode) == 46 || parseInt(event.keyCode) == 46 || parseInt(event.keyCode) == 47 || parseInt(event.keyCode) > 57)
  
   {
	 event.keyCode = null;
   }
}

function CampoNumerico()
{

  if (parseInt(event.keyCode) < 48 || parseInt(event.keyCode) > 57)
   {
	 event.keyCode = null;
   }
}

function CadastraPesquisa() {
	
	municipio = document.form1.nome.value;
	exposto= document.form1.NN.value;
	amostrainicial= document.form1.no.value;
	amostrafinal= document.form1.a.value;
	erroamostral= document.form1.Eo.value;
	
	nomePesquisa= document.form1.nomePesquisa.value;
	tipopesquisa= document.form1.tipopesquisa.value;
	empresa= document.form1.empresa.value;
	cliente= document.form1.cliente.value;
	usuario= document.form1.usuario.value;
	datainicial= document.form1.datainicial.value;
	datafinal= document.form1.datafinal.value;
	
	//
	
	apresentacao= document.form1.apresentacao.value;
	objeto= document.form1.objeto.value;
	metodologia= document.form1.metodologia.value;
	localizacao= document.form1.localizacao.value;
	universo= document.form1.universo.value;
	amostra= document.form1.amostra.value;
	variaveis= document.form1.variaveis.value;
	coleta= document.form1.coleta.value;
	qualidade= document.form1.qualidade.value;
	conclusao= document.form1.conclusao.value;
	registro= document.form1.registro.value;
	ordem= document.form1.ordem.value;
	
	//
	
	publicar= document.form1.publicar.checked;
	enquete= document.form1.enquete.checked;
	telemarketing= document.form1.telemarketing.checked;
	destaque= document.form1.destaque.checked;
	prova= document.form1.prova.checked;
	criterio= document.form1.criterio.checked;
	site= document.form1.site.checked;
	
	z = document.form1.tabelas.value;
	y=0
	cString= ""
	cString2= ""
	
	
	if (municipio == '') { 
	
		alert('Escolha o município');
		
		parent.document.form1.municipio.focus();
		
		return false;
		
	}

	if (exposto == '') { 
	
		alert('Informe o número de expostos para a pesquisa');
		
		document.form1.NN.focus();
		
		return false;
		
	}
	
	if (amostrainicial == '') { 
	
		alert('Informe a amostra inicial para a pesquisa');
		
		document.form1.no.focus();
		
		return false;
		
	}
	
	if (amostrafinal == '') { 
	
		alert('Informe a amostra final para a pesquisa');
		
		document.form1.a.focus();
		
		return false;
		
	}
	
	if (erroamostral == '') { 
	
		alert('Informe o erro amostral para a pesquisa');
		
		document.form1.Eo.focus();
		
		return false;
		
	}
	
	if (nomePesquisa == '') { 
	
		alert('Informe o nome  para a pesquisa');
		
		document.form1.nomePesquisa.focus();
		
		return false;
		
	}
	
	if (tipopesquisa == '0') { 
	
		alert('Informe o tipo de pesquisa  para a pesquisa');
		
		document.form1.tipopesquisa.focus();
		
		return false;
		
	}
	
	if (empresa == '0') { 
	
		alert('Informe a empresa  para a pesquisa');
		
		document.form1.empresa.focus();
		
		return false;
		
	}
	
	if (cliente == '0') { 
	
		alert('Informe o cliente  para a pesquisa');
		
		document.form1.cliente.focus();
		
		return false;
		
	}
	
	if (usuario == '0') { 
	
		alert('Informe o usuario  para a pesquisa');
		
		document.form1.usuario.focus();
		
		return false;
		
	}
	
	if (datainicial != '') { 
	
		if ( validaData(document.form1.datainicial,datainicial) == false ) {
		
			document.form1.datainicial.focus();
		
			return false;
		}
		
	}
	
	if (datafinal != '') { 
	
		if ( validaData(document.form1.datafinal,datafinal) == false ) {
			
					
			document.form1.datafinal.focus();
		
			return false;
		}
		
	}
	
	
	if (ordem == '0') { 
	
		alert('Informe a ordem  para a pesquisa');
		
		document.form1.ordem.focus();
		
		return false;
		
	}
	
	if (publicar == true) { 
	
		publicar = 1
		
	}else{
		
		publicar = 0
	
		
	}
	
	alert(publicar)
	

	
	if (enquete == true) { 
	
		enquete = 1
		
	}else{
		
		enquete = 0
	
		
	}
	
	if (telemarketing == true) { 
	
		telemarketing = 1
		
	}else{
		
		telemarketing = 0
	
		
	}
	
	if (destaque == true) { 
	
		destaque = 1
		
	}else{
		
		destaque = 0
	
		
	}
	
	if (prova == true) { 
	
		prova = 1
		
	}else{
		
		prova = 0
	
		
	}

	if (criterio == true) { 
	
		criterio = 1
		
	}else{
		
		criterio = 0
	
		
	}
	
	if (site == true) { 
	
		site = 1
		
	}else{
		
		site = 0
	
		
	}
	
	for (x=1;x<=z;x++) {
		
		y++
		s = eval('document.form1.T' + y.toString() + '.checked')
		t = eval('document.form1.T' + y.toString() + '.value')
		o = eval('document.form1.O' + y.toString() + '.value')
		
		if (s == true) {
			//cString = cString + t + "/" + o +  ";"
			cString = cString + t +   ","
			cString2 = cString2 + o +   ","
		}
	}
	
	if (y== 0 ) {
		
		alert('Você não informou nenhuma pergunta sociológica');
			
		document.form1.datafinal.focus();
		
		return false;
		
	}
		

	
	
	if (!confirm('Deseja incluir uma nova pesquisa para o municipio de '+ municipio)) {
		
		return false
	}
	
	
	
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";
	sxml = sxml + "<municipio>" + municipio + "</municipio>";
	sxml = sxml + "<exposto>" + exposto + "</exposto>";
	sxml = sxml + "<amostrainicial>" + amostrainicial + "</amostrainicial>";
	sxml = sxml + "<amostrafinal>" + amostrafinal + "</amostrafinal>";
	sxml = sxml + "<erroamostral>" + erroamostral + "</erroamostral>";
			
	sxml = sxml + "<nomePesquisa>" + nomePesquisa + "</nomePesquisa>";
	sxml = sxml + "<tipopesquisa>" + tipopesquisa + "</tipopesquisa>";
	sxml = sxml + "<empresa>" + empresa + "</empresa>";
	sxml = sxml + "<cliente>" + cliente + "</cliente>";
	sxml = sxml + "<usuario>" + usuario + "</usuario>";
	sxml = sxml + "<datainicial>" + datainicial + "</datainicial>";
	sxml = sxml + "<datafinal>" + datafinal + "</datafinal>";
	sxml = sxml + "<cString>" + cString + "</cString>";
	sxml = sxml + "<cString2>" + cString2 + "</cString2>";
	
	sxml = sxml + "<apresentacao>" +apresentacao+ "</apresentacao>";
	sxml = sxml + "<objeto>" +objeto+ "</objeto>";;
	sxml = sxml + "<metodologia>" +metodologia+ "</metodologia>";
	sxml = sxml + "<localizacao>" +localizacao+ "</localizacao>";
	sxml = sxml + "<universo>" +universo+ "</universo>";
	sxml = sxml + "<amostra>" +amostra+ "</amostra>";
	sxml = sxml + "<variaveis>" +variaveis+ "</variaveis>";
	sxml = sxml + "<coleta>" +coleta+ "</coleta>";;
	sxml = sxml + "<qualidade>" +qualidade+ "</qualidade>";
	sxml = sxml + "<conclusao>" +conclusao+ "</conclusao>";
	sxml = sxml + "<registro>" +registro+ "</registro>";
	
	//
	
	sxml = sxml + "<publicar>" +publicar+ "</publicar>";
	sxml = sxml + "<enquete>" +enquete+ "</enquete>";
	sxml = sxml + "<telemarketing>" +telemarketing+ "</telemarketing>";
	sxml = sxml + "<destaque>" +destaque+ "</destaque>";
	sxml = sxml + "<prova>" +prova+ "</prova>";
	sxml = sxml + "<criterio>" +criterio+ "</criterio>";
	sxml = sxml + "<site>" +site+ "</site>";
	sxml = sxml + "<ordem>" +ordem+ "</ordem>";

	
	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");
	xmldoc.loadXML(sxml);
			
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		
	xmlhttp.Open("POST",'../../plataforma/includes/xmlPesquisa.asp', false);
	xmlhttp.Send(xmldoc);
	var xmlTemp = xmlhttp.responseXML;	
	
		
	if (xmlTemp.getElementsByTagName("pesquisa")[0].childNodes[0].nodeValue != '0') {;
	
		alert('Pesquisa criada com sucesso! ' +  xmlTemp.getElementsByTagName("pesquisa")[0].childNodes[0].nodeValue)
		
		ChamarPesquisa(xmlTemp.getElementsByTagName("pesquisa")[0].childNodes[0].nodeValue)
		
		ChamarAjaxTabela('pesquisa', document.form1.pesquisa, 1, xmlTemp.getElementsByTagName("pesquisa")[0].childNodes[0].nodeValue)
	}
	
}
function ChamarAjaxTabelaSociologica(tabela, elemento, nomeDIV, ordem) {
	
		
	if (elemento == null ) {
		return 
	}
	
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";
	sxml = sxml + "<tabela>" +tabela + "</tabela>";
	sxml = sxml + "<ordem>" + ordem + "</ordem>";
	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");
	
	xmldoc.loadXML(sxml);
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.Open("POST",'../../plataforma/includes/xmlSociologica.ASP', false);
	xmlhttp.Send(xmldoc);
	var xmlTemp = xmlhttp.responseXML;		
	LimpaCombo(elemento);
	objOption = document.createElement("OPTION");
	objOption.text =  "Desmarque para nao incluir"
	objOption.value = "0"
	elemento.options.add(objOption)
	lop = 0;
	total = xmlTemp.documentElement.childNodes.length - 1
	
	while(lop <= total)
	{
		
		objOption = document.createElement("OPTION");
		objOption.text =  xmlTemp.getElementsByTagName("descricao")[lop].childNodes[0].nodeValue;
		objOption.value = xmlTemp.getElementsByTagName("codigo")[lop].childNodes[0].nodeValue;
		elemento.options.add(objOption)
		elemento.options[lop+1].selected = true
		pergunta= xmlTemp.getElementsByTagName("pergunta")[lop].childNodes[0].nodeValue

		lop++;
	}
	

	if (total > 0){
		if (nomeDIV != 'nao') {
			document.getElementById(nomeDIV).style.display = 'none'
			document.getElementById(nomeDIV).style.display = 'block'
			elemento.disabled = false;
			
		}
	}
	
	//obj= document.form1.sociologica_pergunta;
	//document.form1.texto.value= pergunta //obj.options[obj.selectedIndex].text;
}
	
function CadastraPerguntaSociologica() {
	
	pesquisa = document.form1.pesquisa.value;
	pergunta= document.form1.texto.value;
	len= document.form1.opcaosociologica.length ;
	obj= document.form1.opcaosociologica;
	document.form1.pesquisaCod.value = pesquisa
	
	ordem= document.form1.ordem.value;
	qualitativa = document.form1.qualitativa.checked;
	obrigatorio= document.form1.obrigatorio.checked;
	sociologica= document.form1.sociologica.checked;
	cceb= document.form1.cceb.checked;
	cruzamento=document.form1.cruzamento.checked;
	
	if (qualitativa == true) {
		
		qualitativa = 1;
		
	}else{
		
		qualitativa = 0;
		
	}
	
	if (obrigatorio == true) {
		
		obrigatorio = 1;
		
	}else{
		
		obrigatorio = 0;
		
	}
	
	if (sociologica == true) {
		
		sociologica = 1;
		
	}else{
		
		sociologica = 0;
		
	}
	
	if (cceb == true) {
		
		cceb = 1;
		
	}else{
		
		cceb = 0;
		
	}
	
	if (cruzamento == true) {
		
		cruzamento = 1;
		
	}else{
		
		cruzamento = 0;
		
	}
	
	
	
	if (pesquisa == '' ) {
		
		alert('Selecione a pesquisa');
		
		return false
	}
	
	if (pergunta == '' ) {
		
		alert('Selecione a pergunta');
		
		return false
	}
	
	
	
	opcoes= '';
	for(var i = 1; i < len; i++) {
		if(obj[i].selected) {
			opcoes = opcoes + obj.options[i].text + ','
			
		}
	}
	len= opcoes.length
	opcoes = opcoes.substring(0, len - 1)
	
	if (opcoes == '' ) {
		
		alert('Selecione pelo menos uma opcao');
		
		return false
		
	}

	if (!confirm('Deseja incluir pergunta sociologica ? ')) {
		
		return false
	}
	
	
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";
	

	sxml = sxml + "<pesquisa>" + pesquisa + "</pesquisa>";
	sxml = sxml + "<pergunta>" + pergunta + "</pergunta>";
	sxml = sxml + "<opcoes>"   + opcoes   + "</opcoes>";
	sxml = sxml + "<ordem>"   + ordem   + "</ordem>";
	sxml = sxml + "<qualitativa>"   + qualitativa   + "</qualitativa>";
	sxml = sxml + "<obrigatorio>"   + obrigatorio   + "</obrigatorio>";
	sxml = sxml + "<sociologica>"   + sociologica   + "</sociologica>";
	sxml = sxml + "<cceb>"   + cceb   + "</cceb>";
	sxml = sxml + "<cruzamento>"   + cruzamento   + "</cruzamento>";
	
	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");
	xmldoc.loadXML(sxml);
			
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		
	xmlhttp.Open("POST",'../../plataforma/includes/xmlIncluirSociologica.asp', false);
	xmlhttp.Send(xmldoc);
	var xmlTemp = xmlhttp.responseXML;	
			
	if (xmlTemp.getElementsByTagName("pergunta")[0].childNodes[0].nodeValue != '0') {;
	
		alert('Pergunta e opcoes criadas  com sucesso!')
		
		document.form1.ordem.value= eval(ordem) + 1
	}
	
	chamarAjaxCombo(pesquisa,'pesquisa','pergunta',document.form1.pergunta,'perguntaDIV', '1')
}

function SelecionaEstatistica(pesquisa, estatistica ) {
	
		document.form1.estatistica.value= estatistica;
						
		if (document.form1.estatistica.value !=  '' ) {
		
			//location.href = '../plataforma/questionario4.asp?pesquisaCod=' + pesquisa +   '&param=pesq&estatistica=' + estatistica 
			document.getElementById('questionario').src='../plataforma/questionario4a.asp?pesquisaCod=' + pesquisa +   '&param=pesq&estatistica=' + estatistica 
		
		}
				
	
}

function SelecionaQualidade(pesquisa, estatistica ) {
	
		document.form1.estatistica.value= estatistica;
						
		if (document.form1.estatistica.value !=  '' ) {
		
			//location.href = '../plataforma/questionario4.asp?pesquisaCod=' + pesquisa +   '&param=pesq&estatistica=' + estatistica 
			document.getElementById('questionario').src='../plataforma/questionario4c.asp?pesquisaCod=' + pesquisa +   '&param=pesq&estatistica=' + estatistica 
		
		}
				
	
}
function CadastrarSubOpcao(pesquisa, pergunta, opcao, pesquisaNome, estatistica, usuario, controle, elemento) {
	
	so= opcao.toString()
	
	nome = eval('document.form1.S' + so + '.value' ) ;
	
		
	if (nome == '' ) {
		
		alert('Informe o nome da subopcao');
		
		return false
	}
	
	if (pesquisa == '' ) {
		
		alert('Selecione a pesquisa');
		
		return false
	}
	
	if (pergunta == '' ) {
		
		alert('Selecione a pergunta');
		
		return false
	}	
	
	if (opcao == '' ) {
		
		alert('Selecione a pergunta');
		
		return false
	}	
	
	if (!confirm('Deseja incluir uma subopcao para esta opcao ? ')) {
		
		return false
	}
	// verificação da busca
	
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";

	sxml = sxml + "<nome>" + nome + "</nome>";
	sxml = sxml + "<pesquisa>" + pesquisa + "</pesquisa>";
	sxml = sxml + "<pergunta>" + pergunta + "</pergunta>";
	sxml = sxml + "<opcao>"   + opcao   + "</opcao>";
	
	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");
	xmldoc.loadXML(sxml);
			
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		
	xmlhttp.Open("POST",'../../plataforma/includes/xmlSubOpcao3.asp', false);
	xmlhttp.Send(xmldoc);
	var xmlTemp = xmlhttp.responseXML;	
			
	if (xmlTemp.getElementsByTagName("codigo")[0].childNodes[0].nodeValue == '0') {;
	
		alert('ATENÇÃO: SubOpcao solicitada já existe!') ;
		
		if (!confirm('Deseja incluir a subopção para esta opção mesmo assim ? ')) {
		
			return false
		}
		
	}
	
		
	// inclusao
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";

	sxml = sxml + "<nome>" + nome + "</nome>";
	sxml = sxml + "<pesquisa>" + pesquisa + "</pesquisa>";
	sxml = sxml + "<pergunta>" + pergunta + "</pergunta>";
	sxml = sxml + "<opcao>"   + opcao   + "</opcao>";
	
	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");
	xmldoc.loadXML(sxml);
			
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		
	xmlhttp.Open("POST",'../../plataforma/includes/xmlSubOpcao.asp', false);
	xmlhttp.Send(xmldoc);
	var xmlTemp = xmlhttp.responseXML;	
			
	if (xmlTemp.getElementsByTagName("descricao")[0].childNodes[0].nodeValue != '0') {;
	
		alert('SubOpcao criada com sucesso!') ;
			
		document.form1.estatistica.value= estatistica;
		
		document.form1.pesquisaNome.value= pesquisaNome;	
		
		document.form1.usuario.value= usuario;
		
		document.form1.controle.value = controle;
		
		elemento = eval(elemento);
		
		if (elemento != null) {
		
			// seleção
			var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
			xmldoc.async = false;
			var sxml;	
			sxml = "<ROOT>";
		
			sxml = sxml + "<pesquisa>" + pesquisa + "</pesquisa>";
			sxml = sxml + "<pergunta>" + pergunta + "</pergunta>";
			sxml = sxml + "<opcao>"   + opcao   + "</opcao>";
			
			sxml = sxml + "</ROOT>";
			sxml = sxml.replace("&","&amp;");
			xmldoc.loadXML(sxml);
					
			var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				
			xmlhttp.Open("POST",'../../plataforma/includes/xmlSubOpcao2.asp', false);
			xmlhttp.Send(xmldoc);
			var xmlTemp = xmlhttp.responseXML;	
			
			
			
			
			LimpaCombo(elemento);
			objOption = document.createElement("OPTION");
			objOption.text =  "Selecione a sub-opção "
			objOption.value = "0"
			elemento.options.add(objOption)
			lop = 0;
			total = xmlTemp.documentElement.childNodes.length - 1
			while(lop <= total)
			{
				objOption = document.createElement("OPTION");
				objOption.text =  xmlTemp.getElementsByTagName("descricao")[lop].childNodes[0].nodeValue;
				objOption.value = xmlTemp.getElementsByTagName("codigo")[lop].childNodes[0].nodeValue;
				elemento.options.add(objOption)
				nome2 = xmlTemp.getElementsByTagName("descricao")[lop].childNodes[0].nodeValue .replace(/^\s+|\s+$/g,"");
				nome= nome.replace(/^\s+|\s+$/g,"");
				if ( nome2 == nome ) {
					elemento.options[lop + 1].selected = true
					//elemento.value= nome2
				}
				lop++;
			}
		
		}else {
				
			if (document.form1.estatistica.value !=  '' ) {
			
				location.href = '../plataforma/questionario4a.asp?pesquisaCod=' + pesquisa +  '&pesquisaNome=' +  pesquisaNome + '&logo=0' + '&param=pesq&estatistica=' + estatistica + '&usuario=' + usuario +  '&controle=' + controle
				
			}else{
				
				location.href = '../plataforma/questionario4a.asp?pesquisaCod=' + pesquisa +  "&pesquisaNome=" +  pesquisaNome + "&logo=0" 
				
			}
		
		}
	}
	
	eval('document.form1.S' + so + '.focus()' ) ;
}

function SelecionaEstatisticaPergunta(pesquisa, pergunta) {
	

						
		if (pergunta !=  '' ) {
		
			location.href = '../plataforma/questionario4.asp?pesquisaCod=' + pesquisa +   '&param=perg&pergunta=' + pergunta 
			
		
		}
				
	
}

function CopiaResposta(resposta, subopcao) {
	
	subopcao.value = resposta.value
	
}

function CadastraPesquisaSelecionada() {
	
	municipio = document.form1.nome.value;
	exposto= document.form1.NN.value;
	amostrainicial= document.form1.no.value;
	amostrafinal= document.form1.a.value;
	erroamostral= document.form1.Eo.value;
	pesquisa= document.form1.pesquisa.value;
	
	if (municipio == '') { 
	
		alert('Escolha o município');
		
		parent.document.form1.municipio.focus();
		
		return false;
		
	}

	if (exposto == '') { 
	
		alert('Informe o número de expostos para a pesquisa');
		
		document.form1.NN.focus();
		
		return false;
		
	}
	
	if (amostrainicial == '') { 
	
		alert('Informe a amostra inicial para a pesquisa');
		
		document.form1.no.focus();
		
		return false;
		
	}
	
	if (amostrafinal == '') { 
	
		alert('Informe a amostra final para a pesquisa');
		
		document.form1.a.focus();
		
		return false;
		
	}
	
	if (erroamostral == '') { 
	
		alert('Informe o erro amostral para a pesquisa');
		
		document.form1.Eo.focus();
		
		return false;
		
	}
	
	if (pesquisa == '') { 
	
		alert('Informe a pesquisa de base para a nova');
		
		document.form1.pesquisa.focus();
		
		return false;
		
	}
	
	if (!confirm('Deseja incluir uma nova pesquisa para o municipio de '+ municipio)) {
		
		return false
	}
	
	
	
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";
	sxml = sxml + "<municipio>" + municipio + "</municipio>";
	sxml = sxml + "<exposto>" + exposto + "</exposto>";
	sxml = sxml + "<amostrainicial>" + amostrainicial + "</amostrainicial>";
	sxml = sxml + "<amostrafinal>" + amostrafinal + "</amostrafinal>";
	sxml = sxml + "<erroamostral>" + erroamostral + "</erroamostral>";
	sxml = sxml + "<erroamostral>" + erroamostral + "</erroamostral>";
	sxml = sxml + "<pesquisa>" + pesquisa + "</pesquisa>";

	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");
	xmldoc.loadXML(sxml);
			
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		
	xmlhttp.Open("POST",'../../plataforma/includes/xmlPesquisa2.asp', false);
	xmlhttp.Send(xmldoc);
	var xmlTemp = xmlhttp.responseXML;	
			
	if (xmlTemp.getElementsByTagName("pesquisa")[0].childNodes[0].nodeValue > '0' ) {;
	
		alert('Pesquisa criada com sucesso com o numero:' + xmlTemp.getElementsByTagName("pesquisa")[0].childNodes[0].nodeValue )
	}
	
}

function CadastraEntrevistador() {
	
	
	
	nome= document.form3.nome.value
	
	if (nome == '') {
		
		alert('Nome nao pode ser em branco')
		
		document.form3.nome.focus()
		
		return false
		
	}
	
	sexo= document.form3.sexo.value
	
	if (sexo == '0') {
		
		alert('Selecione o Sexo')
		
		document.form3.sexo.focus()
		
		return false
		
	}
	
	dia= document.form3.dia.value
	
		
	if (dia == '0') {
		
		alert('Selecione o dia de aniversario')
		
		document.form3.dia.focus()
		
		return false
		
	}
	
	mes= document.form3.mes.value
	
	if (mes == '0') {
		
		alert('Selecione o mes de aniversario')
		
		document.form3.mes.focus()
		
		return false
		
	}
	
	ano= document.form3.ano.value
	
	if (ano == '0') {
		
		alert('Selecione o ano de aniversario')
		
		document.form3.ano.focus()
		
		return false
		
	}
	
	valor = dia + '/' + mes + '/' + ano
	campo = document.form3.dia
	
	lRet= validaData(campo,valor)
	
	if (lRet == false) {
		
		return false
		
	}
	
	nacionalidade= document.form3.nacionalidade.value
	
	if (nacionalidade == '0') {
		
		alert('Selecione a nacionalidade')
		
		document.form3.nacionalidade.focus()
		
		return false
		
	}
	
	
	
	cpf= document.form3.cpf.value
	
	if (cpf == '') {
		
		alert('CPF nao pode ser em branco')
		
		document.form1.cpf.focus()
		
		return false
		
	}
	
		
	
	lRetorno = validaCPF(cpf)
	
	if (lRetorno == false) {
		
		alert('CPF incorreto')
		
		document.form1.cpf.focus()
		
		return false
	}
	
	civil= document.form3.civil.value
	
	if (civil == '0') {
		
		alert('Selecione o estado civil')
		
		document.form3.civil.focus()
		
		return false
		
	}
	
	
		
	filho= document.form3.filho.value
	
	if (filho == '0') {
		
		alert('Selecione o número de filhos')
		
		document.form3.filho.focus()
		
		return false
		
	}
	
	escolaridade= document.form3.escolaridade.value
	
	if (escolaridade == '0') {
		
		alert('Selecione o grau de instrução')
		
		document.form3.escolaridade.focus()
		
		return false
		
	}
	
	endereco= document.form3.endereco.value
	
	if (endereco == '') {
		
		alert('Informe o endereco')
		
		document.form3.endereco.focus()
		
		return false
		
	}
		
	numero= document.form3.numero.value
	
	if (numero == '') {
		
		alert('Informe o numero do endereco')
		
		document.form3.numero.focus()
		
		return false
		
	}
	
	bairro= document.form3.bairro.value
	
	if (bairro == '') {
		
		alert('Informe o endereco')
		
		document.form3.bairro.focus()
		
		return false
		
	}
	
	telefone1= document.form3.telefone1.value

	telefone2= document.form3.telefone2.value
	
	if (telefone2 == '') {
		
		alert('Informe o telefone celular')
		
		document.form3.telefone2.focus()
		
		return false
		
	}
	
	email= document.form3.email.value
	
	if (email == '') {
		
		alert('Informe o email')
		
		document.form3.email.focus()
		
		return false
		
	}
	
	lRet= checkMail(email)
	
	if (lRet == false) {
		
		alert('Email invalido')
		
		document.form3.email.focus()
		
		return false
		
	}
	
	estado= document.form3.estado.value
	
	if (estado == '') {
		
		alert('Informe o estado')
		
		document.form3.estado.focus()
		
		return false
		
	}
	
	municipio= document.form3.municipio.value
	
	if (municipio == '') {
		
		alert('Informe o municipio')
		
		document.form3.municipio.focus()
		
		return false
		
	}
	
	cep= document.form3.cep.value
	
	if (cep == '') {
		
		alert('Informe o cep')
		
		document.form3.cep.focus()
		
		return false
		
	}
	
	
		
	filiacao= document.form3.filiacao.value
	
	if (filiacao == '0') {
		
		alert('Selecione a filiacao')
		
		document.form3.filiacao.focus()
		
		return false
		
	}
	
	amigo= document.form3.amigo.value
	
	if (amigo == '0') {
		
		alert('Selecione se tem amigo atuando como politico')
		
		document.form3.amigo.focus()
		
		return false
		
	}
	
		
	
	ingles= document.form3.ingles.value
	
	if (ingles == '0') {
		
		alert('Selecione se fala ingles')
		
		document.form3.ingles.focus()
		
		return false
		
	}
	
	espanhol= document.form3.espanhol.value
	
	if (espanhol == '0') {
		
		alert('Selecione se fala espanhol')
		
		document.form3.espanhol.focus()
		
		return false
		
	}
	
	informatica= document.form3.informatica.value
	
	if (informatica == '0') {
		
		alert('Selecione se tem curso de informatica')
		
		document.form3.informatica.focus()
		
		return false
		
	}
	
	viagem= document.form3.viagem.value
	
	if (viagem == '0') {
		
		alert('Selecione se pode viajar')
		
		document.form3.viagem.focus()
		
		return false
		
	}
	
	
	
	comportamento= document.form3.comportamento.value
	sustento= document.form3.sustento.value
	esporte= document.form3.esporte.value
	doenca= document.form3.doenca.value
	curriculo= document.form3.curriculo.value
	//imagem= foto2.document.form5.imagem.value // foto2 é o nome do DIV ANIMAL
	imagem=''
		
	
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";
	sxml = sxml + "<nome>" + nome + "</nome>"
	sxml = sxml + "<sexo>" + sexo + "</sexo>"
	sxml = sxml + "<dia>" + dia + "</dia>"
	sxml = sxml + "<mes>" + mes + "</mes>"
	sxml = sxml + "<ano>" + ano + "</ano>"
	sxml = sxml + "<nacionalidade>" + nacionalidade + "</nacionalidade>"
	sxml = sxml + "<cpf>" + cpf + "</cpf>"
	sxml = sxml + "<civil>" + civil + "</civil>"
	sxml = sxml + "<filho>" + filho + "</filho>"
	sxml = sxml + "<escolaridade>" + escolaridade + "</escolaridade>"
	sxml = sxml + "<endereco>" + endereco + "</endereco>"
	sxml = sxml + "<numero>" + numero + "</numero>"
	sxml = sxml + "<bairro>" + bairro + "</bairro>"
	sxml = sxml + "<telefone1>" + telefone1 + "</telefone1>"
	sxml = sxml + "<telefone2>" + telefone2 + "</telefone2>"
	sxml = sxml + "<email>" + email + "</email>"
	sxml = sxml + "<estado>" + estado + "</estado>"
	sxml = sxml + "<municipio>" + municipio + "</municipio>"
	sxml = sxml + "<cep>" + cep + "</cep>"
	sxml = sxml + "<filiacao>" + filiacao + "</filiacao>"
	sxml = sxml + "<amigo>" + amigo + "</amigo>"
	sxml = sxml + "<ingles>" + ingles + "</ingles>"
	sxml = sxml + "<espanhol>" + espanhol + "</espanhol>"
	sxml = sxml + "<informatica>" + informatica + "</informatica>"
	sxml = sxml + "<viagem>" + viagem + "</viagem>"
	sxml = sxml + "<comportamento>" + comportamento + "</comportamento>"
	sxml = sxml + "<sustento>" + sustento + "</sustento>"
	sxml = sxml + "<esporte>" + esporte + "</esporte>"
	sxml = sxml + "<doenca>" + doenca + "</doenca>"
	sxml = sxml + "<curriculo>" + curriculo + "</curriculo>"
	sxml = sxml + "<imagem>" + imagem + "</imagem>"


	
	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");
	
	xmldoc.loadXML(sxml);
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.Open("POST",'../../plataforma/includes/xmlEntrevistador.ASP', false);
	xmlhttp.Send(xmldoc);
	var xmlTemp = xmlhttp.responseXML;		
	
	entrevistador =  xmlTemp.getElementsByTagName("entrevistador")[0].childNodes[0].nodeValue;
	cadastro =  xmlTemp.getElementsByTagName("cadastro")[0].childNodes[0].nodeValue;

		
	if (cadastro == 0 ) {
		
		document.form3.entrevistador.value = entrevistador

		alert('Seu cadastro foi enviado com sucesso! \n A confirmacao foi enviada para o email informado. \n O proximo passo sera enviar sua foto.' )
		
		window.open('foto_entrevistador.asp?entrevistador=' + entrevistador ,'Drtex','500','300','yes','center');return false
		
	}else{
		
		alert('Entrevistador ja existe. CPF ' + cpf + ' ja cadastrado!')
		
		window.open('foto_entrevistador.asp?entrevistador=' + entrevistador ,'Drtex','500','300','yes','center');return false
		
	}
	
}

function validaCPF(cpf) {
                 
                 erro = new String;
                 if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
                 var nonNumbers = /\D/;
                 if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n"; 
                 if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
                         erro += "Numero de CPF invalido!"
               }
               var a = [];
               var b = new Number;
               var c = 11;
               for (i=0; i<11; i++){
                       a[i] = cpf.charAt(i);
                       if (i < 9) b += (a[i] * --c);
               }
               if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
               b = 0;
               c = 11;
               for (y=0; y<10; y++) b += (a[y] * c--); 
               if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
               if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
                       erro +="Digito verificador com problema!";
               }
               if (erro.length > 0){
                       alert(erro);
                       return false;
               }
               return true;
       }

function checkMail(mail){
      var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	  //var er = new RegExp("^[\\w\\.=-]+@[\\w\\.-]+\\.[\\w\\.-]{2,4}$");
        
	if(er.test(mail)){ 
	
		if (mail.match(/^[a-zA-Z0-9]{1}([\._a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+){1,3}$/)) {
	
			
			return true;
			
		}else{
		
			return false;
		}
		
	}else{
		
		return false;	
	}
    
	
}


function SelecionaTextoCombo(sel, campo) {

	campo.value = sel;
	

}

function SelecionaCep(cep) {
	
	fechar = 1
		
	if (cep == '' || cep == 0 ) {
			
		fechar = 0
		
		cep=0 
			
	}
		
	window.open('cep.asp?cep=' + cep + '&fechar=' + fechar,'Drtex','400','200','yes','center');return false
	
}

function validaData(campo,valor) {
	var date=valor;
	var ardt=new Array;
	var ExpReg=new RegExp("(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/[12][0-9]{3}");
	ardt=date.split("/");
	erro=false;
	if ( date.search(ExpReg)==-1){
		erro = true;
		}
	else if (((ardt[1]==4)||(ardt[1]==6)||(ardt[1]==9)||(ardt[1]==11))&&(ardt[0]>30))
		erro = true;
	else if ( ardt[1]==2) {
		if ((ardt[0]>28)&&((ardt[2]%4)!=0))
			erro = true;
		if ((ardt[0]>29)&&((ardt[2]%4)==0))
			erro = true;
	}
	if (erro) {
		alert("\"" + valor + "\" nao e uma data valida!!!");
		campo.focus();
		//campo.value = "";
		return false;
	}
	return true;
}

function AtualizaEntrevistador(entrevistador) {
	
	z= entrevistador.toString()
	
	a = eval('document.form1.A' + z + '.checked')
	
	if (a == false) {
		
		a = 0
		
	}else{
		
		a = 1
		
	}
	
	s = eval('document.form1.S' + z + '.checked')
	
	if (s == false) {
		
		s = 0
		
	}else{
		
		s = 1
		
	}
	
	c = eval('document.form1.C' + z + '.checked')
	
	if (c == false) {
		
		c = 0
		
	}else{
		
		c = 1
		
	}
	
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";
	
	sxml = sxml + "<entrevistador>" + entrevistador + "</entrevistador>"
	sxml = sxml + "<ativo>" + a + "</ativo>"
	sxml = sxml + "<selecionado>" + s + "</selecionado>"
	sxml = sxml + "<coordenador>" + c + "</coordenador>"
	
	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");
	
	xmldoc.loadXML(sxml);
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.Open("POST",'../../plataforma/includes/xmlEntrevistador2.ASP', false);
	xmlhttp.Send(xmldoc);
	var xmlTemp = xmlhttp.responseXML;		
	
	alert('Registro alterado com sucesso')
	
	
}

function ChamarPesquisa(pesquisa) {
	
	
	document.getElementById('div2').src='questionario_formatar.asp?pesquisaCod=' + pesquisa
	
	return true
}

function MostraFoto(entrevistador) {
	
	window.open('../foto_entrevistador.asp?entrevistador=' + entrevistador ,'Drtex','500','300','yes','center');return false
	
}

function MudaImagem(imagem, diretorio) {
	
	cadastro= document.form1.cadastro.checked
	tabela= document.form1.tabela.value
	cod= document.form1.cod.value
	
	
	if (cadastro == true) {
		
		var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
		xmldoc.async = false;
		var sxml;	
		sxml = "<ROOT>";
		sxml = sxml + "<tabela>" + tabela + "</tabela>";
		sxml = sxml + "<cod>" + cod + "</cod>";
		sxml = sxml + "<imagem>" + imagem + "</imagem>";

		sxml = sxml + "</ROOT>";
		sxml = sxml.replace("&","&amp;");
		xmldoc.loadXML(sxml);
				
		var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			
		xmlhttp.Open("POST",'../../plataforma/includes/xmlImagem.asp', false);
		xmlhttp.Send(xmldoc);
		var xmlTemp = xmlhttp.responseXML;	
		alert('Registro alterado com sucesso')
		document.getElementById('imagem_capturar').src='imagem.asp?cod=' + cod + '&tabela=' + tabela + '&atualizar=1' 
		
	}
		
   document.getElementById('imagem_original').src='imagem_original.asp?imagem=' + imagem + '&diretorio=' + diretorio 
	
}

function CarregaArquivo(tipo, tabela, cod, diretorio) {
	
	if (tipo != 0 ) {
	
		location.href = '../plataforma/imagem_configurar.asp?tipo=' + tipo + '&tabela=' + tabela + '&cod=' + cod + '&diretorio=' + diretorio 
		
		
	}
}


function MostraFotoNova() {
	
	// tabela
	tabela = document.form1.tabela.value
	cod = document.form1.cod.value
	diretorio = document.form1.diretorio.value
	
	// imagem
	escala= document.form1.escala.value
	altura= document.form1.altura.value
	largura= document.form1.largura.value
	brilho= document.form1.brilho.value
	contraste= document.form1.contraste.value
	vermelho= document.form1.vermelho.value
	verde= document.form1.verde.value
	azul= document.form1.azul.value
	preto_branco= document.form1.preto_branco.checked
	escala_256= document.form1.escala_256.checked
	polarizacao_azul= document.form1.polarizacao_azul.checked
	
	// texto
	nome= document.form1.nome.value
	nome= nome.replace("É","&Eacute;");
	fonte_tamanho = document.form1.fonte_tamanho.value
	fonte_tipo = document.form1.fonte_tipo.value
	fonte_fundo= document.form1.fonte_fundo.checked
	fonte_cor_fundo= document.form1.fonte_cor_fundo.value
	fonte_cor_letra= document.form1.fonte_cor_letra.value
	fonte_negrito= document.form1.fonte_negrito.checked
	fonte_italico= document.form1.fonte_italico.checked
	fonte_sublinhado= document.form1.fonte_sublinhado.checked
	fonte_riscado= document.form1.fonte_riscado.checked
	fonte_x= document.form1.fonte_x.value
	fonte_y= document.form1.fonte_y.value
	fonte_angulo= document.form1.fonte_angulo.value
	fonte_pular_linha= document.form1.fonte_pular_linha.checked
	
	// retangulo
	
	retangulo_imagem= document.form1.retangulo_imagem.checked
	retangulo_x1= document.form1.retangulo_x1.value
	retangulo_x2= document.form1.retangulo_x2.value
	retangulo_y1= document.form1.retangulo_y1.value
	retangulo_y2= document.form1.retangulo_y2.value
	retangulo_borda = document.form1.retangulo_borda.value
	retangulo_fundo = document.form1.retangulo_fundo.value
	retangulo_cor_fundo = document.form1.retangulo_cor_fundo.value
	retangulo_cor_borda = document.form1.retangulo_cor_borda.value
	
	

	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";
	sxml = sxml + "<tabela>" + tabela + "</tabela>";
	sxml = sxml + "<cod>" + cod + "</cod>";
	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");
	xmldoc.loadXML(sxml);
	
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.Open("POST",'../../plataforma/includes/xmlImagem2.asp', false);
	xmlhttp.Send(xmldoc);                          
	var xmlTemp = xmlhttp.responseXML;
	imagem=  xmlTemp.getElementsByTagName("imagem")[0].childNodes[0].nodeValue;
	
	if (imagem == "0") {
		
		alert('Nao existe imagem arquivada')
		
		return false
		
	} 
	
	
	
	document.getElementById('imagem_nova').src='imagem_nova.asp?diretorio=' + diretorio + '&tabela=' + tabela + '&cod=' + cod + '&imagem=' + imagem + '&escala=' + escala + '&altura=' + altura + '&largura=' + largura   +  '&nome=' + nome + '&brilho=' + brilho + '&contraste=' + contraste + '&vermelho=' + vermelho  + '&verde=' + verde + '&azul=' + azul + '&preto_branco=' + preto_branco + '&escala_256=' + escala_256 + '&polarizacao_azul=' + polarizacao_azul + '&fonte_tamanho=' + fonte_tamanho + '&fonte_tipo=' + fonte_tipo + '&fonte_fundo=' + fonte_fundo + '&fonte_cor_fundo=' + fonte_cor_fundo + '&fonte_cor_letra=' + fonte_cor_letra + '&fonte_negrito=' + fonte_negrito + '&fonte_italico=' + fonte_italico + '&fonte_sublinhado=' + fonte_sublinhado + '&fonte_riscado=' + fonte_riscado + '&fonte_x=' + fonte_x + '&fonte_y=' + fonte_y + '&fonte_angulo=' + fonte_angulo + '&fonte_pular_linha=' + fonte_pular_linha + '&retangulo_imagem=' + retangulo_imagem + '&retangulo_x1=' + retangulo_x1 + '&retangulo_x2=' + retangulo_x2 + '&retangulo_y1=' + retangulo_y1 + '&retangulo_y2=' + retangulo_y2 + '&retangulo_borda=' + retangulo_borda + '&retangulo_fundo=' + retangulo_fundo  + '&retangulo_cor_fundo=' + retangulo_cor_fundo + '&retangulo_cor_borda=' + retangulo_cor_borda
	
	 
	
}

function openModal(pUrl, pWidth, pHeight) {
	if (window.showModalDialog) {
		return window.showModalDialog(pUrl, window,
		  "dialogWidth:" + pWidth + "px;dialogHeight:" + pHeight + "px");
	} else {
		try {
			netscape.security.PrivilegeManager.enablePrivilege(
			  "UniversalBrowserWrite");
			window.open(pUrl, "wndModal", "width=" + pWidth
			  + ",height=" + pHeight + ",resizable=no,modal=yes");
			return true;
		}
		catch (e) {
			alert("Script não confiável, não é possível abrir janela modal.");
			return false;
		}
	}
}

function  InformaCor(cor) {
	
	
	parent.document.form1.fonte_cor_fundo.value = cor
}

function CalculaMedidasPercentual() {
	
document.form1.altura.value= Math.round(document.form1.altura.value * document.form1.escala.value / 100)
document.form1.largura.value= Math.round(document.form1.largura.value * document.form1.escala.value / 100)

}

function getPosicaoElemento(elemID){
	
	// onde elemID é o id do objeto que quero detectar a posicao no meu caso a imagem.   
	var offsetTrail = document.getElementById(elemID);   
	var i = 0;  
	var offsetLeft = 0;   
	var offsetTop = 0;   
	while (offsetTrail || i>1) {     
	offsetLeft += offsetTrail.offsetLeft;     
	offsetTop += offsetTrail.offsetTop;       
	offsetTrail = offsetTrail.offsetParent;   
	}   
	if (navigator.userAgent.indexOf("Mac") != -1 &&   typeof document.body.leftMargin != "undefined") {    
	offsetLeft += document.body.leftMargin;      
	offsetTop += document.body.topMargin;    } 
	 return {left:offsetLeft, top:offsetTop};  
	 alert(offsetLeft+"----"+offsetTop);
} 
 
function PreencheCoordenadasAssociadoTexto() {
	
	if (document.form1.retangulo_imagem.checked == true ) {
		document.form1.retangulo_x1.value= document.form1.fonte_x.value
		document.form1.retangulo_y1.value= document.form1.fonte_y.value
	
	}
	
}

function MostraFotoPublicacao() {
	
	// tabela
	tabela = document.form1.tabela.value
	cod = document.form1.cod.value
	
	document.getElementById('imagem_nova').src='imagem_publicacao.asp?tabela=' + tabela + '&cod=' + cod 
	
	
}

function SelecionarTodosEmail(selecionados) {
	
	var n= 0;
	var i= 0;
	acao= document.form1.todos.checked
		
	avetor = selecionados.split('/');
	n= avetor.length - 1
	while (i < n) {
		
		
		str = eval('document.form1.C' + avetor[i].toString() )
		
		str.checked = acao
		
		i++
		
	}
		
}

function SelecionaEstado(uf) {
	
	
	parent.document.form1.uf.value= uf
	est=0
	
	if (parent.document.form1.uf.value == 'AC' ) {
		parent.document.form1.estado.options[1].selected = true
		est = 1
	}else if (parent.document.form1.uf.value == 'AL' ) {
		parent.document.form1.estado.options[2].selected = true   
		est = 2
	}else if (parent.document.form1.uf.value == 'AM'  ) {
		parent.document.form1.estado.options[3].selected = true
		est = 3
	}else if (parent.document.form1.uf.value == 'AM' ) {
		parent.document.form1.estado.options[4].selected = true
		est = 4
    }else if (parent.document.form1.uf.value == 'BA') {
		parent.document.form1.estado.options[5].selected = true
		est = 5
   	}else if (parent.document.form1.uf.value == 'CE') {
		parent.document.form1.estado.options[6].selected = true
		est = 6
    }else if (parent.document.form1.uf.value == 'DF' ) {
		parent.document.form1.estado.options[7].selected = true
		est = 7
    }else if (parent.document.form1.uf.value == 'ES' ) {
		parent.document.form1.estado.options[8].selected = true
		est = 8
    }else if (parent.document.form1.uf.value == 'GO' ) {
		parent.document.form1.estado.options[9].selected = true 
		est = 9
    }else if (parent.document.form1.uf.value == 'MA'  ) {
		parent.document.form1.estado.options[10].selected = true
		est = 10
     }else if (parent.document.form1.uf.value == 'MG' ) {
		 parent.document.form1.estado.options[11].selected = true
		 est = 11
     }else if (parent.document.form1.uf.value == 'MS' ) {
		 parent.document.form1.estado.options[12].selected = true
		 est = 12
     }else if (parent.document.form1.uf.value == 'MT' ) {
	    parent.document.form1.estado.options[13].selected = true
		est = 13
     }else if (parent.document.form1.uf.value == 'PA'  ) {
		parent.document.form1.estado.options[14].selected = true
		est = 14
	 }else if (parent.document.form1.uf.value == 'PB' ) {
	  	parent.document.form1.estado.options[15].selected = true
		est = 15
     }else if (parent.document.form1.uf.value == 'PE') {
		parent.document.form1.estado.options[16].selected = true
		est = 16
	 }else if (parent.document.form1.uf.value == 'PI' ) {
		parent.document.form1.estado.options[17].selected = true
		est = 17
     }else if (parent.document.form1.uf.value == 'PR'  ) {
		parent.document.form1.estado.options[18].selected = true
		est = 18
     }else if (parent.document.form1.uf.value == 'RJ' ) {
		parent.document.form1.estado.options[19].selected = true   
		est = 19
	 }else if (parent.document.form1.uf.value == 'RN' ) {
		parent.document.form1.estado.options[20].selected = true 
		est = 20
	 }else if (parent.document.form1.uf.value == 'RO' ) {
		parent.document.form1.estado.options[21].selected = true     
		est = 21
     }else if (parent.document.form1.uf.value == 'RR')    {
		parent.document.form1.estado.options[22].selected = true
		est = 22
     }else if (parent.document.form1.uf.value == 'RS' ) {
		parent.document.form1.estado.options[23].selected = true
		est = 23
     }else if (parent.document.form1.uf.value == 'SC')  {
		parent.document.form1.estado.options[24].selected = true
		est = 24
     }else if (parent.document.form1.uf.value == 'SE'  ) {
		parent.document.form1.estado.options[25].selected = true
		est = 25
     }else if (parent.document.form1.uf.value == 'SP'  ) {
		parent.document.form1.estado.options[26].selected = true 
		est = 26
	 }else if (parent.document.form1.uf.value == 'TO' ) {
	    parent.document.form1.estado.options[27].selected = true 
		est = 27
	 }
			
	
	parent.chamarAjaxCombo(est,'estado','municipio',parent.document.form1.municipio,'municipioDIV', '1')		
	
}

function ChamarAjaxTabela(tabela,elemento, ordem, selecionar){	

	
	if (elemento == null ) {
		return false
	}
	
		
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";
	sxml = sxml + "<tabela>" + tabela + "</tabela>";
	sxml = sxml + "<ordem>" + ordem + "</ordem>";

	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");

	xmldoc.loadXML(sxml);
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.Open("POST",'../../plataforma/includes/xmlTabela.ASP', false);
	xmlhttp.Send(xmldoc);
	var xmlTemp = xmlhttp.responseXML;		
	LimpaCombo(elemento);
	objOption = document.createElement("OPTION");
	objOption.text =  "Selecione o(a) "+tabela
	objOption.value = "0"
	elemento.options.add(objOption)
	lop = 0;
	total = xmlTemp.documentElement.childNodes.length - 1
	while(lop <= total)
	{
		objOption = document.createElement("OPTION");
		objOption.text =  xmlTemp.getElementsByTagName("descricao")[lop].childNodes[0].nodeValue;
		objOption.value = xmlTemp.getElementsByTagName("codigo")[lop].childNodes[0].nodeValue;
		elemento.options.add(objOption)
		if (selecionar == objOption.value) {
			elemento.options[lop+1].selected = true
		}
		
		lop++;
	}
	

	
	
}

function CadastrarOrdemOpcao(opcao) {
	
	ordem = eval('document.form1.PP' + opcao.toString() + '.value' )
	
	
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";
	sxml = sxml + "<opcao>" + opcao + "</opcao>";
	sxml = sxml + "<ordem>" + ordem + "</ordem>";
	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");
	xmldoc.loadXML(sxml);
	
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.Open("POST",'../../plataforma/includes/xmlOpcao.asp', false);
	xmlhttp.Send(xmldoc);                          
	var xmlTemp = xmlhttp.responseXML;
	opcao=  xmlTemp.getElementsByTagName("opcao")[0].childNodes[0].nodeValue;
	
	
	if (opcao >  "0") {
		
		alert('Ordem da opcao atualizada com sucesso')
		
				
	} 
	
	
}

function GerarAutorizacao() {
	
	var grupodivulgacao = document.form1.grupodivulgacao.value // tipo 5 na procedure
	var estado = document.form1.estado.value // tipo 3 na procedure
	var municipio = document.form1.municipio.value // 8 na prodeure
	var tipo = 0
	var pesquisa = document.form1.pesquisaCod.value
	var nome = document.form1.nome.value
	var email2 = document.form1.email2.value
	var basetotal = 0
	var autorizados = 0
	var quantidade = 0
	var divulgacao = 0
	var cVetor = ''
	var n= 0
	
	// tipo 1 - grupo, estado e municipio
	// tipo 2 - grupo, estado
	// tipo 3 - estado
	// tipo 4 - estado e municipio
	// tipo 5 - grupo
	// tipo 6 - like nome
	// tipo 7 - like emial
	
	if (grupodivulgacao == 0 & estado == 0 && municipio == 0 ) {
		
		alert('Escolha pelo menos Grupo Divulgacao ou Estado')
		
		return false
		
	}
	
	if (grupodivulgacao != 0 & estado != 0 && municipio != 0 ) {
		
		tipo = 1
		
	}
	
	
	if (grupodivulgacao != 0 & estado != 0 && municipio == 0 ) {
		
		tipo = 2
		
	}
	
	if (grupodivulgacao == 0 & estado != 0 && municipio == 0 ) {
		
		tipo = 3
		
	}
	
	if (grupodivulgacao == 0 & estado != 0 && municipio != 0 ) {
		
		tipo = 4
		
	}
	
	if (grupodivulgacao != 0 & estado == 0 && municipio == 0 ) {
		
		tipo = 5
		
	}
	
	quantidade = document.form1.quantidade.value
	
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";
	sxml = sxml + "<grupodivulgacao>" + grupodivulgacao + "</grupodivulgacao>";
	sxml = sxml + "<estado>" + estado + "</estado>";
	sxml = sxml + "<municipio>" + municipio + "</municipio>";
	sxml = sxml + "<nome>" + nome + "</nome>";
	sxml = sxml + "<email2>" + email2 + "</email2>";
	sxml = sxml + "<pesquisa>" + pesquisa + "</pesquisa>";
	sxml = sxml + "<tipo>" + tipo + "</tipo>";
	sxml = sxml + "<quantidade>" + quantidade + "</quantidade>";
	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");
	xmldoc.loadXML(sxml);
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.Open("POST",'../../plataforma/includes/xmlAutorizacao.asp', false);
	xmlhttp.Send(xmldoc);                          
	var xmlTemp = xmlhttp.responseXML;
	lop = 0;
	total = xmlTemp.documentElement.childNodes.length - 1
	
	
	
	while(lop <= total)
	{
		
		divulgacao =  xmlTemp.getElementsByTagName("divulgacao")[lop].childNodes[0].nodeValue;
			
		lop++;
		
		var t=setTimeout(lop,5000);

		document.form1.basetotal.value = lop
	}
		
	
	
}

function EnviarEmailAutorizados() {
	
	var pesquisa = document.form1.pesquisaCod.value
	
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";
	sxml = sxml + "<pesquisa>" + pesquisa + "</pesquisa>";
	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");

	xmldoc.loadXML(sxml);
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.Open("POST",'../../plataforma/includes/xmlAutorizacao2.ASP', false);
	xmlhttp.Send(xmldoc);
	var xmlTemp = xmlhttp.responseXML;		
	lop = 0;
	total = xmlTemp.documentElement.childNodes.length - 1
	while(lop <= total)
	{
		
		nome =  xmlTemp.getElementsByTagName("nome")[lop].childNodes[0].nodeValue;
		email = xmlTemp.getElementsByTagName("email")[lop].childNodes[0].nodeValue;
		
		lop++;
		
		document.form1.enviados.value = lop
	}
	

	alert('Fim do Processo')
	
	
}

function ChamaWins() {
	
	email= document.form3.email2.value
	
	if (email == '') {
		
		alert('Informe o email')
		
		document.form3.email2.focus()
		
		return false
		
	}
	
	lRet= checkMail(email)
	
	if (lRet == false) {
		
		alert('Email invalido')
		
		document.form3.email2.focus()
		
		return false
		
	}
	
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";
	sxml = sxml + "<email>" + email + "</email>";
	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");
	xmldoc.loadXML(sxml);
	
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.Open("POST",'../../plataforma/includes/xmlWins.asp', false);
	xmlhttp.Send(xmldoc);                          
	var xmlTemp = xmlhttp.responseXML;
	mensagem=  xmlTemp.getElementsByTagName("mensagem")[0].childNodes[0].nodeValue;
	
	alert(mensagem)
	
}
function MudaPerguntaPesquisaOnLine() {
	
	var pergunta = document.form2.pergunta.value
	var pesquisa = document.form2.pesquisa.value
	
	if (pesquisa == '' || pergunta == 0 ) {
		
		alert('Escolha a pergunta para alterar')
		
		return false
	
	}
	
	var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	xmldoc.async = false;
	var sxml;	
	sxml = "<ROOT>";
	sxml = sxml + "<pesquisa>" + pesquisa + "</pesquisa>";
	sxml = sxml + "<pergunta>" + pergunta + "</pergunta>";
	sxml = sxml + "</ROOT>";
	sxml = sxml.replace("&","&amp;");
	xmldoc.loadXML(sxml);
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.Open("POST",'../plataforma/includes/xmlMudaPerguntaPesquisaOnLine.asp', false);
	xmlhttp.Send(xmldoc);                          
	var xmlTemp = xmlhttp.responseXML;
	mensagem=  xmlTemp.getElementsByTagName("mensagem")[0].childNodes[0].nodeValue;
	
	alert(mensagem)
	
}