// JavaScript Document
function confirmaExclusao(id,nome,filtro){
	if (confirm("Deseja realmente excluir "+nome+"?")){
		if (filtro == ""){
			document.location.href = "contatos.php?id="+id+"&acao=remover";
		} else {
			document.location.href = "contatos.php?id="+id+"&filtro="+filtro+"&acao=remover";
		}
	} else {
		return false;
	}	
}
//<input name="cep" type="text" id="cep" onkeypress="return formataCampo(event,this,'#####-###');" size="10" maxlength="9" autocomplete="off">
function formataCampo(e,src,mask) {
	var _TXT = (e.which) ? e.which : e.keyCode;
	
    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 {
		// 8 = backspace, 9 = Tab, 37 = seta esquerda, 39 = seta direita, 46 = delete
		if ((_TXT != 8) && (_TXT != 9) && (_TXT != 0) && (_TXT != 37) && (_TXT != 39) && (_TXT != 46)) { return false; }
		else { return true; }
    }
}
function formataMoeda(objTextBox, limite, SeparadorMilesimo, SeparadorDecimal, e){
	if (objTextBox.value.length > limite){
		objTextBox.value = objTextBox.value.substr(1,limite);
	}
	//máscara de moeda 0.000.000,00
	SeparadorMilesimo='.';
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which: e.keyCode;
    // 13=enter, 8=backspace as demais retornam 0(zero)
    // whichCode==0 faz com que seja possivel usar todas as teclas como delete, setas, etc    
    if ((whichCode == 13) || (whichCode == 0) || (whichCode == 8))
    	return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave 
 
    if (strCheck.indexOf(key) == -1) 
    	return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) 
        	break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) 
        	aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) 
    	objTextBox.value = '';
    if (len == 1) 
    	objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) 
    	objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        	objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}
function verificaDDD(componente){
	if(componente.value.length == 2){
		document.getElementById('telefone').focus();
	}
}
function mostraDiv(id){
	if (document.getElementById(id).style.display == 'none'){
		document.getElementById(id).style.display = 'block';
	} else {		
		document.getElementById(id).style.display = 'none';
	}
	return true;
}

function mostraSwf(id,id2){
	if (document.getElementById(id).style.display == 'none'){
		document.getElementById(id).style.display = 'block';
		document.getElementById(id2).style.display = 'none';
		document.getElementById("msg").style.display = 'none';
	} else {		
		document.getElementById(id).style.display = 'none';
		document.getElementById("msg").style.display = 'block';
		
	}
	return true;
}
function remover_espacos(str){
	r = "";
	for(i = 0; i < str.length; i++){
		if(str.charAt(i) != ' '){
			r += str.charAt(i);
		}
	}
	return r;
}
function validaCNPJ(CNPJ) {
	erro = new String;
	if (CNPJ.length < 18) erro += "É necessario preencher corretamente o número do CNPJ! \n\n";
	if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
		if (erro.length == 0) erro += "É necessário preencher corretamente o número do CNPJ! \n\n";
	}
	//substituir os caracteres que não são números
	if(document.layers && parseInt(navigator.appVersion) == 4){
		   x = CNPJ.substring(0,2);
		   x += CNPJ. substring (3,6);
		   x += CNPJ. substring (7,10);
		   x += CNPJ. substring (11,15);
		   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)) 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] = CNPJ.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 ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
		erro +="Dígito verificador com problema!";
	}
	if (erro.length > 0){
	   //alert(erro);
	   return erro;
	} else {
	  // alert("CNPJ valido!");
		return "";
	}
}
function check_date(DATA) {
    var expReg = /^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[1-2][0-9]\d{2})$/;
	var msgErro = 'Formato inválido de data.';
	var vdt = new Date();
	var vdia = vdt.getDate();
	var vmes = vdt.getMonth()+1;
	var vano = vdt.getFullYear();
	
	if ((DATA.value.match(expReg)) && (DATA.value!='')){
		var dia = DATA.value.substring(0,2);
		var mes = DATA.value.substring(3,5);
		var ano = DATA.value.substring(6,10);
		if((mes==04 && dia > 30) || (mes==06 && dia > 30) || (mes==9 && dia > 30) || (mes==11 && dia > 30)){
			//alert("Dia incorreto !!! O mês especificado contém no máximo 30 dias.");
			DATA.focus();
			return false;
		} else{ //1
			if(ano%4!=0 && mes==2 && dia>28){
				//alert("Data incorreta!! O mês especificado contém no máximo 28 dias.");
				DATA.focus();
				return false;
			} else{ //2
				if(ano%4==0 && mes==2 && dia>29){
					//alert("Data incorreta!! O mês especificado contém no máximo 29 dias.");
					DATA.focus();
					return false;
				} else{ //3
					if (ano > vano) {
						//alert("Data incorreta!! Ano informado maior que ano atual.");
						DATA.focus();
						return false;
					}else{ //4
						//alert ("Data correta!");
						return true;
					} //4-else
				} //3-else
			}//2-else
		}//1-else                       
	} else { //5
		//alert(msgErro);
		DATA.focus();
		return false;
	} //5-else
}
function validaCPF(cpf){
	var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
	if(!filtro.test(cpf)){
		return false;
	}
	
	cpf = remove(cpf, ".");
	cpf = remove(cpf, "-");
	
	if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
	  	cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
	 	cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
	  	cpf == "88888888888" || cpf == "99999999999"){
	  	return false;
	}
	
	soma = 0;
	for(i = 0; i < 9; i++)
		soma += parseInt(cpf.charAt(i)) * (10 - i);
	resto = 11 - (soma % 11);
	if(resto == 10 || resto == 11)
		resto = 0;
	if(resto != parseInt(cpf.charAt(9))){
		return false;
	}
	soma = 0;
	for(i = 0; i < 10; i ++)
	 	soma += parseInt(cpf.charAt(i)) * (11 - i);
	resto = 11 - (soma % 11);
	if(resto == 10 || resto == 11)
	 	resto = 0;
	if(resto != parseInt(cpf.charAt(10))){
	 	return false;
	}
	return true;
}
 
function remove(str, sub) {
	i = str.indexOf(sub);
   	r = "";
   	if (i == -1) return str;
   	r += str.substring(0,i) + remove(str.substring(i + sub.length), sub);
   	return r;
}
/*function ajaxInit() {
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
	  ajax=new XMLHttpRequest();
	} else {// code for IE6, IE5
	  ajax=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return ajax;
} */
function ajaxInit() {
    var req;
    
    try {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	} catch(e) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(ex) {
			try {
				req = new XMLHttpRequest();
			} catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				req = null;
			}
		}
    }
    
    return req;
}

function getNavigator(){
	var navegador = navigator.appName;
	var agent = navigator.userAgent;
	
	if (navegador == "Microsoft Internet Explorer"){
		var inicio = agent.indexOf("MSIE");
		var fim = agent.indexOf(";",inicio);
		
		return agent.substr(inicio,fim-inicio);
	} else if (navegador == "Netscape"){
		var inicio = agent.indexOf("Chrome");
		var nav = "";
		
		if (inicio == -1){
			inicio = agent.indexOf("Firefox");
			if (inicio == -1){
				inicio = agent.indexOf("Version/")+8;
				nav = "Safari/";
			}
		}
		if (agent.indexOf(" ",inicio) >= 0){
			var fim = agent.indexOf(" ",inicio);
			return nav + agent.substr(inicio,fim-inicio);
		} else {
			return nav + agent.substr(inicio);
		}
	} else if (navegador == "Opera"){
		if (agent.indexOf("Version/") > -1){
			var inicio = agent.indexOf("Version/")+8;
			return "Opera/"+agent.substr(inicio);
		} else {
			var inicio = agent.indexOf("Opera/")+6;
			var fim = agent.indexOf(" ",inicio);
			return "Opera/"+agent.substr(inicio,fim-inicio);
		}
	}
}
function getOS(){ // gets Operacional System
	var navegador = navigator.appName;
	var agent = navigator.userAgent;
	
	var inicio = agent.indexOf("(");
	var fim = agent.indexOf(")",inicio);
	var items = agent.substr(inicio,fim-inicio);
	items = items.replace("(","");
	items = items.split(";");

	if (navegador == "Microsoft Internet Explorer"){
		retorno = items[2];
	} else if (navegador == "Netscape"){
		retorno = items[2];
	} else if (navegador == "Opera"){
		retorno = items[0];
	}
	if (retorno.indexOf("Windows") >= 0){
		if (retorno.indexOf("NT 4") >= 0){
			retorno = "Windows NT 4";
		} else if (retorno.indexOf("NT 5") >= 0){
			retorno = "Windows 2000";
		} else if (retorno.indexOf("NT 5.1") >= 0){
			retorno = "Windows XP";
		} else if (retorno.indexOf("NT 5.2") >= 0){
			retorno = "Windows Server 2003";
		} else if (retorno.indexOf("NT 6.0") >= 0){
			retorno = "Windows Vista";
		} else if (retorno.indexOf("NT 6.1") >= 0){
			retorno = "Windows 7";
		} else {
			alert('Outro windows');
		}
		alert(retorno);
	}
	return retorno;
}
function recebeLink(id){
	var data = new Date();
	var agora = data.getFullYear()+"-"+data.getMonth()+"-"+data.getDay()+" "+data.getHours()+":"+data.getMinutes()+":"+data.getSeconds();
	
	document.getElementById("id").value = id;
	document.getElementById("data").value = agora;
	//document.getElementById("info").value = getNavigator();
	//document.getElementById("info2").value = getOS();
	
	document.getElementById("registro").submit();
}
function clicaBox(id){
	if (id == "nivel"){
		if (document.getElementById(id).value == "X"){
			document.getElementById("nivel").value = "";
		} else {
			document.getElementById("nivel").value = "X";
			document.getElementById("nivel2").value = "";
		}
	} else if (id == "nivel2"){
		if (document.getElementById(id).value == "X"){
			document.getElementById("nivel2").value = "";
		} else {
			document.getElementById("nivel2").value = "X";
			document.getElementById("nivel").value = "";
		}
	} else {
		if (document.getElementById(id).value == "X"){
			document.getElementById(id).value = "";
		} else {
			document.getElementById(id).value = "X";
		}
	}
}

function selecionaBox(e,id){
	var key = (e.which) ? e.which : e.keyCode;
	
	if (key == 9){
		return true;
	}
	
    if(key == 32) {
		if (id == "nivel"){
			if (document.getElementById(id).value == "X"){
				document.getElementById("nivel").value = "";
			} else {
				document.getElementById("nivel").value = "X";
				document.getElementById("nivel2").value = "";
			}
		} else if (id == "nivel2"){
			if (document.getElementById(id).value == "X"){
				document.getElementById("nivel2").value = "";
			} else {
				document.getElementById("nivel2").value = "X";
				document.getElementById("nivel").value = "";
			}
		} else {
			if (document.getElementById(id).value == "X"){
				document.getElementById(id).value = "";
			} else {
				document.getElementById(id).value = "X";
			}
		}
		return true;
	} else {
		return false;
	}
}
function trocaDiv(id_){
	if (id_ == 'pessoaFisica'){
		document.getElementById('pessoaFisica').style.display = 'block';
		document.getElementById('pessoaJuridica').style.display = 'none';
	} else {
		document.getElementById('pessoaJuridica').style.display = 'block';
		document.getElementById('pessoaFisica').style.display = 'none';
	}
}
function validaPF(Form){
	
	var conteudo = remover_espacos(Form.nome.value);
	
	if (conteudo.length == 0){
		document.getElementById("aviso").innerHTML = "Favor informar seu nome!";
		Form.nome.focus();
		return false;
	}
	
	conteudo = remover_espacos(Form.email.value);
	
	if (conteudo.length == 0){
		alert("Insira um email!");
		Form.email.focus();
		return false;
	} else {
		invalidCharsList = " #$!*()[]^<>{}\'\"";
		// define a list of invalid characters
		if (conteudo.indexOf('@',0)==-1 ||
			conteudo.indexOf('@',0)== 0 ||
			conteudo.indexOf('.',3)==-1 ||
			conteudo.lastIndexOf('.') > conteudo.length-3) {
			document.getElementById("aviso").innerHTML = "Formato de email inválido!";
			Form.email.focus();
			return false;
		}
	
		for (i = 0; i < invalidCharsList.length; i++) {
			errorChar = invalidCharsList.charAt(i);
			if (conteudo.indexOf(errorChar,0) != -1) {
				document.getElementById("aviso").innerHTML = "Caractere inválido!";
				Form.email.focus();
				return false;
			}
		}
	}
	Form.email.value = conteudo;
	
	conteudo = remover_espacos(Form.aniversario.value);
	
	if ((conteudo.length == 0) || (Form.aniversario.value == "dd/mm")){
		document.getElementById("aviso").innerHTML = "Favor informar sua data de aniversário!";
		Form.aniversario.focus();
		return false;
	}
	
	if (Form.estado.value == ""){
		document.getElementById("aviso").innerHTML = "Selecione um estado!";
		Form.estado.focus();
		return false;
	}
	
	conteudo = remover_espacos(Form.profissao.value);
	
	if (conteudo.length == 0){
		document.getElementById("aviso").innerHTML = "Favor informar sua profissão!";
		Form.profissao.focus();
		return false;
	}
	
	if ((Form.nivel.value == "") && (Form.nivel2.value == "")){
		document.getElementById("aviso").innerHTML = "Favor selecionar o nível de complexidade!";
		return false;
	}
	
	if (Form.privacidade.value == ""){
		document.getElementById("aviso").innerHTML = "O termo de privacidade deve ser aceito!";
		return false;
	}
	
	return true;
}

function validaPJ(Form){
	
	var conteudo = remover_espacos(Form.razao.value);
	
	if (conteudo.length == 0){
		document.getElementById("aviso2").innerHTML = "Favor informar a razão social!";
		Form.razao.focus();
		return false;
	}

	
	erro = validaCNPJ(Form.cnpj.value);
	
	if (erro != ""){
		document.getElementById("aviso2").innerHTML = erro;
		Form.cnpj.focus();
		return false;
	}
	
	conteudo = remover_espacos(Form.endereco.value);
	
	if (conteudo.length == 0){
		document.getElementById("aviso2").innerHTML = "Favor informar seu endereço!";
		Form.endereco.focus();
		return false;
	}
	
	var validChar = "0123456789-";
	conteudo = Form.cep.value;
	if (conteudo.length == 0){
		document.getElementById("aviso2").innerHTML = "Favor informar o CEP!";
		Form.cep.focus();
		return false;
	} else if (conteudo.length < 9){
		document.getElementById("aviso2").innerHTML = "Favor informar um CEP válido!";
		Form.cep.focus();
		return false;
	} else {
		for (i = 0; i < conteudo.length; i++){
			if (validChar.indexOf(conteudo.charAt(i)) < 0){
				document.getElementById("aviso2").innerHTML = "Caractere inválido no CEP!";
				Form.cep.focus();
				return false;
			}
		}
	}
	
	conteudo = remover_espacos(Form.cidade.value);
	
	if (conteudo.length == 0){
		document.getElementById("aviso2").innerHTML = "Favor informar sua cidade!";
		Form.cidade.focus();
		return false;
	}
	
	conteudo = remover_espacos(Form.estado.value);
	
	if (conteudo.length == 0){
		document.getElementById("aviso2").innerHTML = "Favor informar seu estado!";
		Form.estado.focus();
		return false;
	}
	
	conteudo = remover_espacos(Form.pais.value);
	
	if (conteudo.length == 0){
		document.getElementById("aviso2").innerHTML = "Favor informar seu país!";
		Form.pais.focus();
		return false;
	}
	
	conteudo = remover_espacos(Form.ddd.value);
	
	if (conteudo.length == 0){
		document.getElementById("aviso2").innerHTML = "Favor informar seu ddd!";
		Form.ddd.focus();
		return false;
	} else if(conteudo.length < 2){
		document.getElementById("aviso2").innerHTML = "Favor informar um ddd válido!";
		Form.ddd.focus();
		return false;
	} else {
		validChar = "0123456789";
		for (i = 0; i < conteudo.length; i++){
			if (validChar.indexOf(conteudo.charAt(i)) < 0){
				document.getElementById("aviso2").innerHTML = "Caractere inválido no ddd!";
				Form.ddd.focus();
				return false;
			}
		}
	}
	
	conteudo = remover_espacos(Form.telefone.value);
	
	if (conteudo.length == 0){
		document.getElementById("aviso2").innerHTML = "Favor informar seu telefone!";
		Form.telefone.focus();
		return false;
	} else if(conteudo.length < 9){
		document.getElementById("aviso2").innerHTML = "Favor informar um telefone válido!";
		Form.telefone.focus();
		return false;
	} else {
		validChar = "0123456789- ";
		for (i = 0; i < conteudo.length; i++){
			if (validChar.indexOf(conteudo.charAt(i)) < 0){
				document.getElementById("aviso2").innerHTML = "Caractere inválido no telefone!";
				Form.telefone.focus();
				return false;
			}
		}
	}
	
	conteudo = remover_espacos(Form.email.value);
	
	if (conteudo.length == 0){
		alert("Insira um email!");
		Form.email.focus();
		return false;
	} else {
		invalidCharsList = " #$!*()[]^<>{}\'\"";
		// define a list of invalid characters
		if (conteudo.indexOf('@',0)==-1 ||
			conteudo.indexOf('@',0)== 0 ||
			conteudo.indexOf('.',3)==-1 ||
			conteudo.lastIndexOf('.') > conteudo.length-3) {
			document.getElementById("aviso2").innerHTML = "Formato de email inválido!";
			Form.email.focus();
			return false;
		}
	
		for (i = 0; i < invalidCharsList.length; i++) {
			errorChar = invalidCharsList.charAt(i);
			if (conteudo.indexOf(errorChar,0) != -1) {
				document.getElementById("aviso2").innerHTML = "Caractere inválido!";
				Form.email.focus();
				return false;
			}
		}
	}
	Form.email.value = conteudo;
	
	if (Form.regulamento.value == ""){
		document.getElementById("aviso2").innerHTML = "O regulamento deve ser aceito!";
		return false;
	}
	if (Form.privacidade.value == ""){
		document.getElementById("aviso2").innerHTML = "O termo de privacidade deve ser aceito!";
		return false;
	}
	
	return true;
}

function validaContato(Form){
	
	var conteudo = remover_espacos(Form.nome.value);
	
	if (conteudo.length == 0){
		document.getElementById("aviso").innerHTML = "Favor informar seu nome!";
		Form.nome.focus();
		return false;
	}
	
	conteudo = remover_espacos(Form.ddd.value);
	
	if ((conteudo.length > 0) && (conteudo.length < 2)){
		document.getElementById("aviso").innerHTML = "Favor informar um ddd válido!";
		Form.ddd.focus();
		return false;
	} else {
		validChar = "0123456789";
		for (i = 0; i < conteudo.length; i++){
			if (validChar.indexOf(conteudo.charAt(i)) < 0){
				document.getElementById("aviso").innerHTML = "Caractere inválido no ddd!";
				Form.ddd.focus();
				return false;
			}
		}
	}
	
	conteudo = remover_espacos(Form.telefone.value);
	
	if ((conteudo.length > 0) && (conteudo.length < 9)){
		document.getElementById("aviso").innerHTML = "Favor informar um telefone válido!";
		Form.telefone.focus();
		return false;
	} else {
		validChar = "0123456789- ";
		for (i = 0; i < conteudo.length; i++){
			if (validChar.indexOf(conteudo.charAt(i)) < 0){
				document.getElementById("aviso").innerHTML = "Caractere inválido no telefone!";
				Form.telefone.focus();
				return false;
			}
		}
	}
	
	conteudo = remover_espacos(Form.email.value);
	
	if (conteudo.length == 0){
		alert("Insira um email!");
		Form.email.focus();
		return false;
	} else {
		invalidCharsList = " #$!*()[]^<>{}\'\"";
		// define a list of invalid characters
		if (conteudo.indexOf('@',0)==-1 ||
			conteudo.indexOf('@',0)== 0 ||
			conteudo.indexOf('.',3)==-1 ||
			conteudo.lastIndexOf('.') > conteudo.length-3) {
			document.getElementById("aviso").innerHTML = "Formato de email inválido!";
			Form.email.focus();
			return false;
		}
	
		for (i = 0; i < invalidCharsList.length; i++) {
			errorChar = invalidCharsList.charAt(i);
			if (conteudo.indexOf(errorChar,0) != -1) {
				document.getElementById("aviso").innerHTML = "Caractere inválido!";
				Form.email.focus();
				return false;
			}
		}
	}
	Form.email.value = conteudo;
	
	if (!Form.tipoContato[0].checked && !Form.tipoContato[1].checked){
		document.getElementById("aviso").innerHTML = "Favor selecionar uma categoria de pessoa!";
		Form.tipoContato[0].focus();
		return false;
	}
	
	conteudo = remover_espacos(Form.mensagem.value);
	
	if (conteudo.length == 0){
		document.getElementById("aviso").innerHTML = "Favor inserir uma mensagem!";
		Form.mensagem.focus();
		return false;
	}
	
	if (Form.privacidade.value == ""){
		document.getElementById("aviso").innerHTML = "O termo de privacidade deve ser aceito!";
		return false;
	}
	
	return true;
}
function ajaxInit(){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	} else {// code for IE6, IE5
	   return new ActiveXObject("Microsoft.XMLHTTP");
	}
}
function carregaRep(estado){
	
	textoTitulo = "Representantes <br>no estado de:<br><span>";
	switch (estado)
	{
	case 'am': 
	 textoTitulo += "Amazonas";
	  break;
	case 'ac':
	  textoTitulo += "Acre";
	  break;
	case 'sc':
	  textoTitulo += "Santa Catarina";
	  break;
	case 'rs':
	  textoTitulo += "Rio Grande do Sul";
	  break;
	case 'rj':
	  textoTitulo += "Rio de Janeiro";
	  break;
	case 'sp':
	  textoTitulo += "São Paulo";
	  break;
	case 'sc':
	  textoTitulo += "Santa Catarina";
	  break;
	case 'mg':
	  textoTitulo += "Minas Gerais";
	  break;
	case 'to':
	  textoTitulo += "Tocantins";
	  break;
	case 'rr':
	  textoTitulo += "Roraima";
	  break;
	case 'ro':
	  textoTitulo += "Rondônia";
	  break;
	case 'ap':
	  textoTitulo += "Amapá";
	  break;	  
	case 'df':
	  textoTitulo += "Distrito Federal";
	break;
	case 'go':
	  textoTitulo += "Goiás";
	  break;
	case 'pe':
	  textoTitulo += "Pernambuco";
	  break;
	case 'mt':
	  textoTitulo += "Mato Grosso";
	break;
	case 'ms':
	  textoTitulo += "Mato Grosso do Sul";
	  break;
	case 'pr':
	  textoTitulo += "Paraná";
	  break;
	case 'ma':
	  textoTitulo += "Maranhão";
	break;
	case 'pa':
	  textoTitulo += "Pará";
	  break;
	case 'es':
	  textoTitulo += "Espírito Santo";
	  break;
	case 'pi':
	  textoTitulo += "Piauí";
	break;
	case 'rn':
	  textoTitulo += "Rio Grande do Norte";
	  break;
	case 'pb':
	  textoTitulo += "Paraíba";
	  break;
	case 'al':
	  textoTitulo += "Alagoas";
	break;
	case 'ba':
	  textoTitulo += "Bahia";
	  break;
	case 'se':
	  textoTitulo += "Sergipe";
	  break;
	case 'ce':
	  textoTitulo += "Ceará";
	  break;
	default:
	  textoTitulo += "Santa Catarina";
	}
	
	textoTitulo += "</span>";
	
	document.getElementById('tituloEstado').innerHTML = textoTitulo; 	
	
	ajax = ajaxInit();
	
	url = "scripts/ajax.php?busca=representantes&estado="+estado;	
	ajax.open("GET",url,true);	
	
	ajax.onreadystatechange=function() {				
		if (ajax.readyState==4){
			document.getElementById('representantes2').innerHTML = ajax.responseText;					
			parent.document.getElementById('centro').style.height = document.getElementById('tabela').clientHeight +"px";
			parent.document.getElementById("fundoConteudo").style.height = document.getElementById('tabela').clientHeight+150+"px";
		}
	}	
	
	ajax.send(null);
	
}
function atualizaProduto(idCat){
	ajax = ajaxInit();
	
	url = "../scripts/ajax.php?busca=produtos&cat="+idCat;	
	ajax.open("GET",url,true);	
	
	ajax.onreadystatechange=function() {				
		if (ajax.readyState==4){
			document.getElementById('produto').innerHTML = ajax.responseText;
		}
	}
	ajax.send(null);
}

function loadintoIframe(iframeid, url){
if (document.getElementById)
document.getElementById(iframeid).src=url
}

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

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}