var ie = /msie/i.test(navigator.userAgent);
var versao = navigator.appVersion;
var versaoIE = null;

var paisId;
var primeiroClique = true;
var timerTesteProcesso = -1;
var xmlTextos;
var contTempo;
var maxTempoEspera = 120;
var http_request = false;

var arrProdutos;
//nome|cod

var arrProdutosL = new Array();
arrProdutosL[0] = new Object();
arrProdutosL[0].cod = "01";
arrProdutosL[0].nome = "VoxMetria";

arrProdutosL[1] = new Object();
arrProdutosL[1].cod = "02";
arrProdutosL[1].nome = "Avalie";

arrProdutosL[2] = new Object();
arrProdutosL[2].cod = "04";
arrProdutosL[2].nome = "VoiceReport";

arrProdutosL[3] = new Object();
arrProdutosL[3].cod = "05";
arrProdutosL[3].nome = "FonoTools";

arrProdutosL[4] = new Object();
arrProdutosL[4].cod = "06";
arrProdutosL[4].nome = "VoxGames";

arrProdutosL[5] = new Object();
arrProdutosL[5].cod = "07";
arrProdutosL[5].nome = "FonoFlex";

arrProdutosL[6] = new Object();
arrProdutosL[6].cod = "08";
arrProdutosL[6].nome = "FonoView";

arrProdutosL[7] = new Object();
arrProdutosL[7].cod = "09";
arrProdutosL[7].nome = "Desafio dos Fonemas";

arrProdutosL[8] = new Object();
arrProdutosL[8].cod = "11";
arrProdutosL[8].nome = "Pedro na Casa Mal-Assombrada";

arrProdutosL[9] = new Object();
arrProdutosL[9].cod = "12";
arrProdutosL[9].nome = "AudiReport";

arrProdutosL[10] = new Object();
arrProdutosL[10].cod = "14";
arrProdutosL[10].nome = "FisiMetrix";

arrProdutosL[11] = new Object();
arrProdutosL[11].cod = "16";
arrProdutosL[11].nome = "FonoSpeak";

arrProdutosL[12] = new Object();
arrProdutosL[12].cod = "20";
arrProdutosL[12].nome = "EarMix";

arrProdutosL[13] = new Object();
arrProdutosL[13].cod = "21";
arrProdutosL[13].nome = "Pedro no Parque de Divers&otilde;es";

arrProdutosL[14] = new Object();
arrProdutosL[14].cod = "22";
arrProdutosL[14].nome = "Vocalgrama";

arrProdutosL[15] = new Object();
arrProdutosL[15].cod = "23";
arrProdutosL[15].nome = "Motrisis";

var timerInicio = -1;

//txtOperacao.value = -99 = reiniciar;

function carregarControleL() {
	timerInicio = setTimeout(testarInicioControleL, 100);
}

function testarInicioControleL() {
	try {
		if(arrProd!=null && arrProd.length>0) {
			marcarCheckCompra("chkF");
			montaComboProdutosControleL(0, "txtProduto", onCmbProdChange, onCmbProdKeyUp);	
			document.getElementById("tdProduto").className = "compFormContainer";
			document.getElementById("tdErroProduto").className = "tdAsteriscoOk";
			document.getElementById("trBotoes").className = "tabInvisivel";				
		} else {
			timerInicio = setTimeout(testarInicioControleL, 100);
		}
	} catch(e) {}
}

function carregarAjudaControleL() {
	if(document.getElementById("trAjuda").className=="tabInvisivel") {
		document.getElementById("trAjuda").className = "trVisivel";
		if(document.getElementById("trFormRequisicoes").className=="trVisivel") {
			document.getElementById("trFormRequisicoes").className = "invisivel";
		} else {
			document.getElementById("trFormRequisicoes").className = "tabInvisivel";
		}
	} else {
		esconderAjudaControleL();
	}
}

function esconderAjudaControleL() {
	topoPagina();
	document.getElementById("trAjuda").className = "tabInvisivel";
	if(document.getElementById("trFormRequisicoes").className=="invisivel") {
		document.getElementById("trFormRequisicoes").className = "trVisivel";
	}
}

function carregarRequisicaoCS() {	
	document.getElementById("tituloFormCL").innerHTML = "Obter Contrassenha";
	document.getElementById("txtOperacao").value = 0;
	
	document.getElementById("txtCodProduto").value = "";
	document.getElementById("txtCodProduto").onkeypress = onkeypressR;
	
	document.getElementById("trTipoCompra").className = "trVisivel";
	if(document.getElementById("txtCompra").value==0) {
		marcarCheckCompra("chkF");						  
	} else {
		marcarCheckCompra("chkJ");
	}
	configurarInstrucoes();
	
	if(document.getElementById("trAjuda").className!="tabInvisivel") {
		document.getElementById("trAjuda").className = "tabInvisivel";
	}
	document.getElementById("lblCodigo").innerHTML = "C&oacute;digo:";
	document.getElementById("trFormRequisicoes").className = "trVisivel";
}

function onkeypressR(event) {
    return mascara(event, this, "###############");
}

function carregarRemocaoSenha() {
	document.getElementById("tituloFormCL").innerHTML = "Enviar Senha de Remo&ccedil;&atilde;o";	
	document.getElementById("txtOperacao").value = 2;
	document.getElementById("trCodigo").className = "trVisivel";
	
	document.getElementById("txtCodProduto").value = "";
	document.getElementById("txtCodProduto").onkeypress = null;
	
	document.getElementById("trTipoCompra").className = "tabInvisivel";	

	configurarInstrucoes();

	if(document.getElementById("trAjuda").className!="tabInvisivel") {
		document.getElementById("trAjuda").className = "tabInvisivel";
	}
	document.getElementById("lblCodigo").innerHTML = "Senha de Remo&ccedil;&atilde;o:";
	document.getElementById("trFormRequisicoes").className = "trVisivel";			
}

function configurarInstrucoes() {
	document.getElementById("trInstrGerais").className = "tabInvisivel";
	document.getElementById("trInstrSenhaCTS").className = "tabInvisivel";
	document.getElementById("trInstrSenhaRev").className = "tabInvisivel";
	document.getElementById("trInstrSenhaRem").className = "tabInvisivel";
	
	if(document.getElementById("txtOperacao").value==0) {
		if(document.getElementById("txtCompra").value==0) {
			document.getElementById("trInstrSenhaCTS").className = "trVisivel";		  
		} else {
			document.getElementById("trInstrSenhaRev").className = "trVisivel";
		}
	} else if(document.getElementById("txtOperacao").value==2) {
		document.getElementById("trInstrSenhaRem").className = "trVisivel";
	}
	
	document.getElementById("trInstrGerais").className = "trVisivel";
}

function onCmbProdChange() {
	if(document.getElementById("txtProduto").value>0) {
		document.getElementById("tdProduto").className = "compFormContainer";
		document.getElementById("tdErroProduto").className = "tdAsteriscoOk";
	} else {
		document.getElementById("tdProduto").className = "compFormContainerErro";
		document.getElementById("tdErroProduto").className = "tdAsteriscoErro";		
	}
}

function onCmbProdKeyUp() {
	if(document.getElementById("txtProduto").value>0) {
		document.getElementById("tdProduto").className = "compFormContainer";
		document.getElementById("tdErroProduto").className = "tdAsteriscoOk";
	} else {
		document.getElementById("tdProduto").className = "compFormContainerErro";
		document.getElementById("tdErroProduto").className = "tdAsteriscoErro";		
	}
}

function getFormSenha(obj, idLocal) {
	var poststr = "pais=" + encodeURI(document.getElementById("campoPais").value);
	poststr += "&cliente=" + encodeURI(document.getElementById("campoCliente").value);
	poststr += "&email=" + encodeURI(document.getElementById("campoEmail").value);
	poststr += "&revenda=" + encodeURI(document.getElementById("campoRevenda").value);
	poststr += "&senha=" + encodeURI(document.getElementById("campoSenha").value);
	poststr += "&codProduto=" + encodeURI(document.getElementById("campoCodProduto").value);
	poststr += "&produto=" + encodeURI(document.getElementById("campoProduto").value);
	poststr += "&nomeProduto=" + encodeURI(document.getElementById("campoNomeProduto").value);
	poststr += "&op=" + encodeURI(document.getElementById("campoOperacao").value);

	if(document.getElementById("campoOperacao").value=="0") {
		makePOSTRequest('http://www.ctsinformatica.com.br/liberacao/enviaEmailReqSenha.php', idLocal, poststr);
	} else if(document.getElementById("campoOperacao").value=="2") {
		makePOSTRequest('http://www.ctsinformatica.com.br/liberacao/enviaEmailReqSenha.php', idLocal, poststr);
	} else  if(document.getElementById("campoCliente").value=="reqStatus") {
		 makePOSTRequest('http://www.ctsinformatica.com.br/liberacao/enviaReqStatus.php', idLocal, poststr);  
	}
	/*
	if(document.getElementById("campoCliente").value=="reqStatus") {
	 makePOSTRequest('http://www.ctsinformatica.com.br/liberacao/enviaReqStatus.php', idLocal, poststr);  
	} else if(document.getElementById("campoCodProduto").value=="senhaRemocao") {
	  
	} else {
	 makePOSTRequest('http://www.ctsinformatica.com.br/liberacao/enviaEmailReqSenha.php', idLocal, poststr);
	}
	*/
	document.getElementById("divGeral2").innerHTML = "&nbsp;";
}

function abrirURL(url) {
	window.open(url);
}

function trocaCSS(cod, classe) {
	if(document.getElementById(cod)!=null) {
		document.getElementById(cod).className = classe;
	}
}

function validaFormReqStatus(idBtnEnviar) {
	
	var jaAvisado = false;
	var ok = true;

	pais = document.getElementById("txtPais").value;
	cliente = document.getElementById("txtCliente").value;

	if(idBtnEnviar!=null) {
		trocaCSS(idBtnEnviar, 'botaoTdSobre');
	}

	ok = ok * validaCampo("CodProduto");
	if(!ok) { 
		if(!jaAvisado) {
			alert(getTexto("CODPRODINVALIDO"));	
			jaAvisado = true;
		}
	}

	if(idBtnEnviar==null) {
		if(ok) {
			setClasseCSS(document.getElementById("trOpcoesAcao"), "tabInvisivel");
			enviaFormReqSenha();
			topoPagina();
		} else if(!jaAvisado) {			
			alert(getTexto("AVISOFORMERRO"));
		}
	}
}

function mostrarErro(msgErro) {
	document.getElementById("tdErro").innerHTML = msgErro;	
	alert(document.getElementById("tdErro").innerHTML);
}

function esconderErro() {
}

function retirarOQueNaoEhNumero(str) {
	var strAux = "0123456789";
	var txtCodValue = str;
	var codValue = "";
	for(var iChar=0;iChar<txtCodValue.length;iChar++) {
		if(strAux.indexOf(String(txtCodValue.charAt(iChar)))>-1) {
			codValue += String(txtCodValue.charAt(iChar));
		}
	}
	return codValue;
}

function validaFormSenha(idBtnEnviar) {

	var jaAvisado = false;
	var ok = true;
	
	if(document.getElementById("txtOperacao").value==0) {
		document.getElementById("txtCodProduto").value = retirarOQueNaoEhNumero(document.getElementById("txtCodProduto").value);
	}
	pais = document.getElementById("txtPais").value;

	if(idBtnEnviar!=null) {
		trocaCSS(idBtnEnviar, 'botaoTdSobre');
	}

	ok = ok * validaSenha("Senha", 11);
	if(!ok) { 
		if(!jaAvisado) {
			mostrarErro(getTexto("SENHAINVALIDA"));
			//alert(getTexto("SENHAINVALIDA"));
			jaAvisado = true;
		}
	}
	ok = ok * validaCampo("Revenda");
	if(pais=="br") {
		var tempAviso = validaCampoCpfCnpj("Revenda");
		switch(tempAviso) {
			case -1: { //cpf inválido
				ok = ok * false;
				if(!jaAvisado) {
					mostrarErro(getTexto("CPFINVALIDO"));				
					jaAvisado = true;
				}
				break;
			}
			case -2: { //cnpj inválido
				ok = ok * false;
				if(!jaAvisado) {
					mostrarErro(getTexto("CNPJINVALIDO"));				
					jaAvisado = true;
				}
				break;
			}			
			case false: { //cpf ou cnpj inválido
				ok = ok * false;
				if(!jaAvisado) {
					mostrarErro(getTexto("CPFCNPJINVALIDO"));				
					jaAvisado = true;
				}
				break;				
			}
			case true: {//cpf ou cnpj válido
				ok = ok * true;
				break;				
			}
			default: {
				ok = ok * false;
				if(!jaAvisado) {
					mostrarErro(getTexto("CPFINVALIDO"));				
					jaAvisado = true;
				}
				break;	
			}
		}	
		/*
		if(!ok) { 
			if(!jaAvisado) {
				mostrarErro(getTexto("CPFINVALIDO"));				
				jaAvisado = true;
			}
		}
		*/
	} else {
		if(!ok) { 
			if(!jaAvisado) {
				mostrarErro(getTexto("REVENDAINVALIDA"));				
				jaAvisado = true;
			}
		}			
	}
	if(document.getElementById("txtOperacao").value==0) {
		if(document.getElementById("txtCompra").value>0) {
			ok = ok * validaCampo("CodProduto");
			if(!ok) { 
				if(!jaAvisado) {
					mostrarErro(getTexto("CODPRODINVALIDO"));	
					jaAvisado = true;
				}
			}
		}
	} else {
		ok = ok * validaSenhaR("CodProduto", 10);
		if(!ok) { 
			if(!jaAvisado) {
				mostrarErro(getTexto("SENHARINVALIDA"));
				//alert(getTexto("SENHAINVALIDA"));
				jaAvisado = true;
			}
		}
	}
	ok = ok * validaEmail("Email");
	if(!ok) { 
		if(!jaAvisado) {
			mostrarErro(getTexto("EMAILINVALIDO"));	
			jaAvisado = true;
		}
	}
	ok = ok * validaCombo("Produto");
	if(!ok) { 
		if(!jaAvisado) {
			mostrarErro(getTexto("PRODUTOINVALIDO"));	
			jaAvisado = true;
		}
	}
	ok = ok * validaCampo("Cliente");
	if(!ok) { 
		if(!jaAvisado) {
			mostrarErro(getTexto("CLIENTEINVALIDO"));	
			jaAvisado = true;
		}
	}

	if(idBtnEnviar==null) {
		if(ok) {
			setClasseCSS(document.getElementById("trOpcoesAcao"), "tabInvisivel");
			topoPagina();
			enviaFormSenha();
			esconderErro();
		} else if(!jaAvisado) {			
			mostrarErro(getTexto("AVISOFORMERRO"));
		}
	} else if(ok) {
		esconderErro();
	}
}

function validaCampo(nomeValor) {
	if(document.getElementById("txt" + nomeValor)!=null) {
		if(retirarEspacos(document.getElementById("txt" + nomeValor).value)=="") {
			document.getElementById("td" + nomeValor).className = "compFormContainerErro";
			document.getElementById("tdErro" + nomeValor).className = "tdAsteriscoErro";
			return false;
		} else {
			tirarCaracteresInvalidos(document.getElementById("txt" + nomeValor));
			document.getElementById("td" + nomeValor).className = "compFormContainer";
			document.getElementById("tdErro" + nomeValor).className = "tdAsteriscoOk";
			return true;
		}	
	}
}

function validaCampoCpfCnpj(nomeValor) {
	if(document.getElementById("txt" + nomeValor)!=null) {
		if(retirarEspacos(document.getElementById("txt" + nomeValor).value)=="") {
			document.getElementById("td" + nomeValor).className = "compFormContainerErro";
			document.getElementById("tdErro" + nomeValor).className = "tdAsteriscoErro";
			return false;
		} else {
			tirarCaracteresInvalidos(document.getElementById("txt" + nomeValor));
			document.getElementById("txt" + nomeValor).value = retirarEspacos(document.getElementById("txt" + nomeValor).value);

			strNum = "";
			valorCampo = document.getElementById("txt" + nomeValor).value;
			for(i=0;i<valorCampo.length;i++) {
				caracter = valorCampo.substring(i,i+1)
				if((caracter >= '0') && (caracter <= '9')) {
				   strNum = strNum + caracter;
				}
			};

			if(strNum.length<12) {
				if(validaCPF(strNum)) {			
					document.getElementById("td" + nomeValor).className = "compFormContainer";
					document.getElementById("tdErro" + nomeValor).className = "tdAsteriscoOk";
					return true;
				} else {
					document.getElementById("td" + nomeValor).className = "compFormContainerErro";
					document.getElementById("tdErro" + nomeValor).className = "tdAsteriscoErro";
					return -1; //cpf inválido
				}
			} else {
				if(validaCNPJ(strNum)) {			
					document.getElementById("td" + nomeValor).className = "compFormContainer";
					document.getElementById("tdErro" + nomeValor).className = "tdAsteriscoOk";
					return true;
				} else {
					document.getElementById("td" + nomeValor).className = "compFormContainerErro";
					document.getElementById("tdErro" + nomeValor).className = "tdAsteriscoErro";
					return -2; //cnpj inválido
				}
			}			
		}	
	}
}

function validaCombo(nomeValor) {
	if(document.getElementById("txt" + nomeValor)!=null) {
		if(document.getElementById("txtProduto").selectedIndex>0) {
			document.getElementById("td" + nomeValor).className = "compFormContainer";
			document.getElementById("tdErro" + nomeValor).className = "tdAsteriscoOk";
			return true;
		} else {
			document.getElementById("td" + nomeValor).className = "compFormContainerErro";
			document.getElementById("tdErro" + nomeValor).className = "tdAsteriscoErro";
			return false;			
		}	
	}
}

function validaCPF(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;
	}
	
	strNum = "";
	for (i = 0; i < cpf.length; i++) {
        caracter = cpf.substring(i,i+1)
        if ((caracter >= '0') && (caracter <= '9')) {
        	strNum = strNum + caracter;
		}
  	}
	cpf = strNum;

	add = 0;
	for(i=0; i < 9; i ++) {
		add += parseInt(cpf.charAt(i)) * (10 - i);
	}
	rev = 11 - (add % 11);
	if(rev == 10 || rev == 11) {
		rev = 0;
	}
	if(rev != parseInt(cpf.charAt(9)))
		return false;
	add = 0;
	for(i = 0; i < 10; i ++) {
		add += parseInt(cpf.charAt(i)) * (11 - i);
	}
	rev = 11 - (add % 11);
	if(rev == 10 || rev == 11) {
		rev = 0;
	}
	if(rev != parseInt(cpf.charAt(10))) {
		return false;
	}
	return true;
}

//014.029.260-81
//02.092.758/0001-22
function validaCNPJ(cnpj) {

	var i = 0;
	var l = 0;
	var strNum = "";
	var strMul = "6543298765432";
	var character = "";
	var iValido = 1;
	var iSoma = 0;
	var strNum_base = "";
	var iLenNum_base = 0;
	var iLenMul = 0;
	var iSoma = 0;
	var strNum_base = 0;
	var iLenNum_base = 0;

	if(cnpj == "") {
		return false;
	}

	l = cnpj.length;
  	for(i = 0; i < l; i++) {
        caracter = cnpj.substring(i,i+1)
        if((caracter >= '0') && (caracter <= '9')) {
           strNum = strNum + caracter;
		}
  	};

  	if(strNum.length != 14) {
        return false;
	}

	strNum_base = strNum.substring(0,12);
	iLenNum_base = strNum_base.length - 1;
	iLenMul = strMul.length - 1;
	for(i = 0;i < 12; i++) {
    	iSoma = iSoma + parseInt(strNum_base.substring((iLenNum_base-i),(iLenNum_base-i)+1),10) *
                        parseInt(strMul.substring((iLenMul-i),(iLenMul-i)+1),10);
		iSoma = 11 - (iSoma - Math.floor(iSoma/11) * 11);
	}
	if(iSoma == 11 || iSoma == 10) {
		iSoma = 0;
	}

	strNum_base = strNum_base + iSoma;
	iSoma = 0;
	iLenNum_base = strNum_base.length - 1
	for(i = 0; i < 13; i++) {
       	iSoma = iSoma + parseInt(strNum_base.substring((iLenNum_base-i),(iLenNum_base-i)+1),10) *
                      	parseInt(strMul.substring((iLenMul-i),(iLenMul-i)+1),10);
	}
 	iSoma = 11 - (iSoma - Math.floor(iSoma/11) * 11);
  	if(iSoma == 11 || iSoma == 10) {
    	iSoma = 0;
	}
  	strNum_base = strNum_base + iSoma;
  	if(strNum != strNum_base) {
        return false;
	}
	return true;
}

function pertenceAoConjunto(char, validChars) {
	return validChars.indexOf(char)>-1;
}

function validaFormatoSenha(senha) {
	var mask = "";
	if(pertenceAoConjunto(senha.charAt(0), "0123456789")) {
		mask = "NLLNNLNLNLL";
	} else {
		mask = "LNLNLNNLNLL";
	}
	var senhaOk = true;
	for(i=1;i<senha.length;i++) {
		if(mask.charAt(i)=="L" && !pertenceAoConjunto(senha.charAt(i), "0123456789")) {
			senhaOk = true;
		} else if(mask.charAt(i)=="N" && pertenceAoConjunto(senha.charAt(i), "0123456789")) {
			senhaOk = true;
		} else {
			senhaOk = false;
			break;
		}
	}
	return senhaOk;
}

function validaFormatoSenhaR(senha) {
	var mask = "LNNNNLNLLL";
	var senhaOk = true;
	for(i=1;i<senha.length;i++) {
		if(mask.charAt(i)=="L" && !pertenceAoConjunto(senha.charAt(i), "0123456789")) {
			senhaOk = true;
		} else if(mask.charAt(i)=="N" && pertenceAoConjunto(senha.charAt(i), "0123456789")) {
			senhaOk = true;
		} else {
			senhaOk = false;
			break;
		}
	}
	return senhaOk;
}

function validaSenha(nomeValor, nroCaracteres) {
	if(document.getElementById("txt" + nomeValor)!=null) {

		document.getElementById("txt" + nomeValor).value = retirarEspacos(document.getElementById("txt" + nomeValor).value);
		var senhaFromForm = document.getElementById("txt" + nomeValor).value;

		if(senhaFromForm.length==nroCaracteres) {			
			senhaOk = validaFormatoSenha(senhaFromForm);
			if(senhaOk) {		
				document.getElementById("td" + nomeValor).className = "compFormContainer";
				document.getElementById("tdErro" + nomeValor).className = "tdAsteriscoOk";
				return true;
			} else {
				document.getElementById("td" + nomeValor).className = "compFormContainerErro";
				document.getElementById("tdErro" + nomeValor).className = "tdAsteriscoErro";
				return false;
			}
		} else {
			document.getElementById("td" + nomeValor).className = "compFormContainerErro";
			document.getElementById("tdErro" + nomeValor).className = "tdAsteriscoErro";
			return false;
		}
	}
}

function validaSenhaR(nomeValor, nroCaracteres) {
	if(document.getElementById("txt" + nomeValor)!=null) {

		document.getElementById("txt" + nomeValor).value = retirarEspacos(document.getElementById("txt" + nomeValor).value);
		var senhaFromForm = document.getElementById("txt" + nomeValor).value;

		if(senhaFromForm.length==nroCaracteres) {			
			senhaOk = validaFormatoSenhaR(senhaFromForm);
			if(senhaOk) {		
				document.getElementById("td" + nomeValor).className = "compFormContainer";
				document.getElementById("tdErro" + nomeValor).className = "tdAsteriscoOk";
				return true;
			} else {
				document.getElementById("td" + nomeValor).className = "compFormContainerErro";
				document.getElementById("tdErro" + nomeValor).className = "tdAsteriscoErro";
				return false;
			}
		} else {
			document.getElementById("td" + nomeValor).className = "compFormContainerErro";
			document.getElementById("tdErro" + nomeValor).className = "tdAsteriscoErro";
			return false;
		}
	}
}

function tirarCaracteresInvalidos(objeto) {
	objeto.value = objeto.value.replace(/&/gi, "e");
}

function retirarEspacos(texto) {
	texto = texto.replace(/ /gi, "");	
	return texto;
}

function validaEmail(nomeEmail) {
	if(document.getElementById("txt" + nomeEmail)!=null) {
		document.getElementById("txt" + nomeEmail).value = retirarEspacos(document.getElementById("txt" + nomeEmail).value);
		var email = document.getElementById("txt" + nomeEmail).value;
		
		if(email=="" || email.indexOf("@.")!=-1 || email.substring(email.lastIndexOf(".")+1, email.length)<1) {
			ok = false;
		} else {		
			if(email.indexOf("@")!=-1 && email.indexOf("@")==email.lastIndexOf("@")) {
				if(email.lastIndexOf("@")<email.lastIndexOf(".")-1) {
					if(email.substring(0, email.lastIndexOf("@")).length>0) {
						ok = true;
					} else {
						ok = false;	
					}
				} else {
					ok = false;
				}
			} else {
				ok = false;
			}
		}
		if(ok) {
			document.getElementById("td" + nomeEmail).className = "compFormContainer";
			document.getElementById("tdErro" + nomeEmail).className = "tdAsteriscoOk";
			return true;
		} else {
			document.getElementById("td" + nomeEmail).className = "compFormContainerErro";
			document.getElementById("tdErro" + nomeEmail).className = "tdAsteriscoErro";
			return false;
		}
	}
}

function enviaFormReqSenha() {
	if(primeiroClique) {

		/*
		pais = document.getElementById("txtPais").value;
		paisId = pais;
		cliente = document.getElementById("txtCliente").value;
		email = document.getElementById("txtEmail").value;
		revenda = document.getElementById("txtRevenda").value;
		
		if(pais=="br") {
			strNum = "";
			for(i=0;i<revenda.length;i++) {
				caracter = revenda.substring(i,i+1)
				if((caracter>='0') && (caracter<='9')) {
					strNum = strNum + caracter;
				}
			}
			revenda = strNum;
		}
		
		codProduto = document.getElementById("txtCodProduto").value;
		senha = document.getElementById("txtSenha").value;
		produto = document.getElementById("txtProduto").value;
		nomeProduto = document.getElementById("txtProduto").text;
		*/
		
		pais = document.getElementById("txtPais").value;
		paisId = pais;
		cliente = document.getElementById("txtCliente").value;
		email = document.getElementById("txtEmail").value;
		revenda = document.getElementById("txtRevenda").value;
		if(pais=="br") {
			strNum = "";
			for(i=0;i<revenda.length;i++) {
				caracter = revenda.substring(i,i+1)
				if((caracter>='0') && (caracter<='9')) {
					strNum = strNum + caracter;
				}
			}
			revenda = strNum;
		}
		if(document.getElementById("txtOperacao").value==0) {
			if(document.getElementById("txtCompra").value==0) {		
				//document.getElementById("trCodigo").value = "";
				document.getElementById("txtCodProduto").value = "";
			}
		}
		codProduto = document.getElementById("txtCodProduto").selected.value;
		senha = document.getElementById("txtSenha").value;
		produto = getIdProduto(document.getElementById("txtProduto").options[document.getElementById("txtProduto").selectedIndex].innerHTML);
		nomeProduto = document.getElementById("txtProduto").options[document.getElementById("txtProduto").selectedIndex].innerHTML;	
		
		operacao = document.getElementById("txtOperacao").value;
		
		//document.getElementById("corpo").className = "tabInvisivel";
		document.getElementById("trForm").className = "tabInvisivel";
		document.getElementById("trBotoes").className = "tabInvisivel";
		document.getElementById("trAvisos").className = "trVisivel";
	
		htmlHead = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\"/><title>CTS Informática</title></head><body>";

		html1Form = "<form id=\"formSenha\" name=\"formSenha\" method=\"post\" action=\"javascript:getFormSenha(document.getElementById('formSenha'), 'tdForm');\" target=\"_parent\">";

		html2Form = "</form></body></html>";	

		htmlPais = "<input id=\"campoPais\" type=\"hidden\" name=\"pais\" value=\"" + pais + "\"/>";	
		htmlCliente = "<input id=\"campoCliente\" type=\"hidden\" name=\"cliente\" value=\"" + cliente + "\"/>";	
		htmlEmail  = "<input id=\"campoEmail\" type=\"hidden\" name=\"email\" value=\"" + email + "\"/>";	
		htmlRevenda = "<input id=\"campoRevenda\" type=\"hidden\" name=\"endereco\" value=\"" + revenda + "\"/>";
		htmlSenha = "<input id=\"campoSenha\" type=\"hidden\" name=\"senha\" value=\"" + senha + "\"/>";					
		htmlCodProduto = "<input id=\"campoCodProduto\" type=\"hidden\" name=\"codProduto\" value=\"" + codProduto + "\"/>";
		htmlProduto = "<input id=\"campoProduto\" type=\"hidden\" name=\"produto\" value=\"" + produto + "\"/>";
		htmlNomeProduto = "<input id=\"campoNomeProduto\" type=\"hidden\" name=\"nomeProduto\" value=\"" + nomeProduto + "\"/>";
		htmlOperacao = "<input id=\"campoOperacao\" type=\"hidden\" name=\"operacao\" value=\"" + operacao + "\"/>";

		htmlPronto = htmlHead + html1Form + htmlPais + htmlCliente + htmlEmail + htmlProduto + htmlNomeProduto + htmlRevenda + htmlSenha + htmlCodProduto + htmlOperacao + html2Form;	

		document.getElementById("divGeral2").innerHTML = htmlPronto;	

		document.getElementById("divGeral2").className = "tabInvisivel";

		document.formSenha.submit();
		primeiroClique = false;

		mostrarAviso(getTexto("ENVIANDO") + "...", "tdAvisos");

		timerTesteProcesso = setInterval(testarFimProcessoHistorico, 1000);				
		//document.getElementById("corpo").className = "tabInvisivel";
	}
}

function testarFimProcessoHistorico() {
	if(document.getElementById("tabFormSuporte").innerHTML.substring(0, 14)=="#235453322517#") {
		document.getElementById("corpo").className = "";
		clearInterval(timerTesteProcesso);

		var arrDados =document.getElementById("tabFormSuporte").innerHTML.split(";");
		
		/*
			0 - cabecalho
			1 - op
			2 - produto
			3 - senha
			4 - cpf/revenda
		*/
				
		//window.location = "http://www.ctsinformatica.com.br/liberacao/historyResult.php?cod=" + paisId + "&codprod=" + arrDados[2] + "&senha=" + arrDados[3] + "&revenda=" + arrDados[4] + "&sucesso=1";
		
		makePOSTRequest("http://www.ctsinformatica.com.br/liberacao/historyResult.php?cod=" + paisId + "&codprod=" + arrDados[2] + "&senha=" + arrDados[3] + "&revenda=" + arrDados[4] + "&sucesso=1", "tabFormSuporte");  
		
	} else if(document.getElementById("tabFormSuporte").innerHTML=="#000000000000#") {
		document.getElementById("corpo").className = "";
		clearInterval(timerTesteProcesso);
		//window.location = "http://www.ctsinformatica.com.br/liberacao/historyResult.php?cod=" + paisId + "&codprod=" + arrDados[2] + "&senha=" + arrDados[3] + "&revenda=" + arrDados[4] + "&sucesso=0";
		makePOSTRequest("http://www.ctsinformatica.com.br/liberacao/historyResult.php?cod=" + paisId + "&codprod=" + arrDados[2] + "&senha=" + arrDados[3] + "&revenda=" + arrDados[4] + "&sucesso=0", "tabFormSuporte"); 
	} else {
		//document.getElementById("corpo").className = "tabInvisivel";		
	}
}


function enviaFormSenha() {
	
	if(primeiroClique) {

		pais = document.getElementById("txtPais").value;
		paisId = pais;
		cliente = document.getElementById("txtCliente").value;
		email = document.getElementById("txtEmail").value;
		revenda = document.getElementById("txtRevenda").value;
		if(pais=="br") {
			strNum = "";
			for(i=0;i<revenda.length;i++) {
				caracter = revenda.substring(i,i+1)
				if((caracter>='0') && (caracter<='9')) {
					strNum = strNum + caracter;
				}
			}
			revenda = strNum;
		}
		if(document.getElementById("txtOperacao").value==0) {
			if(document.getElementById("txtCompra").value==0) {		
				//document.getElementById("trCodigo").value = "";
				document.getElementById("txtCodProduto").value = "";
			}
		}
		codProduto = document.getElementById("txtCodProduto").value;
		senha = document.getElementById("txtSenha").value;		
		produto = getIdProduto(document.getElementById("txtProduto").options[document.getElementById("txtProduto").selectedIndex].innerHTML);
		nomeProduto = document.getElementById("txtProduto").options[document.getElementById("txtProduto").selectedIndex].innerHTML;	

		operacao = document.getElementById("txtOperacao").value;

		//document.getElementById("corpo").className = "tabInvisivel";
		document.getElementById("trForm").className = "tabInvisivel";
		document.getElementById("trBotoes").className = "tabInvisivel";
		document.getElementById("trAvisos").className = "trVisivel";
	
		htmlHead = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\"/><title>CTS Informática</title></head><body>";

		html1Form = "<form id=\"formSenha\" name=\"formSenha\" method=\"post\" action=\"javascript:getFormSenha(document.getElementById('formSenha'), 'tdForm');\" target=\"_parent\">";

		html2Form = "</form></body></html>";	

		htmlPais = "<input id=\"campoPais\" type=\"hidden\" name=\"pais\" value=\"" + pais + "\"/>";	
		htmlCliente = "<input id=\"campoCliente\" type=\"hidden\" name=\"cliente\" value=\"" + cliente + "\"/>";	
		htmlEmail  = "<input id=\"campoEmail\" type=\"hidden\" name=\"email\" value=\"" + email + "\"/>";	
		htmlRevenda = "<input id=\"campoRevenda\" type=\"hidden\" name=\"endereco\" value=\"" + revenda + "\"/>";
		htmlSenha = "<input id=\"campoSenha\" type=\"hidden\" name=\"senha\" value=\"" + senha + "\"/>";					
		htmlCodProduto = "<input id=\"campoCodProduto\" type=\"hidden\" name=\"codProduto\" value=\"" + codProduto + "\"/>";
		htmlProduto = "<input id=\"campoProduto\" type=\"hidden\" name=\"produto\" value=\"" + produto + "\"/>";
		htmlNomeProduto = "<input id=\"campoNomeProduto\" type=\"hidden\" name=\"nomeProduto\" value=\"" + nomeProduto + "\"/>";
		htmlOperacao = "<input id=\"campoOperacao\" type=\"hidden\" name=\"operacao\" value=\"" + operacao + "\"/>";

		htmlPronto = htmlHead + html1Form + htmlPais + htmlCliente + htmlEmail + htmlProduto + htmlNomeProduto + htmlRevenda + htmlSenha + htmlCodProduto + htmlOperacao + html2Form;	

		document.getElementById("divGeral2").innerHTML = htmlPronto;	

		document.getElementById("divGeral2").className = "tabInvisivel";

		document.formSenha.submit();
		primeiroClique = false;

		mostrarAviso(getTexto("ENVIANDO") + "...", "tdAvisos");

		timerTesteProcesso = setInterval(testarFimProcesso, 1000);
		//document.getElementById("corpo").className = "tabInvisivel";
	}
}

function testarFimProcesso() {
	if(document.getElementById("tdForm").innerHTML.substring(0, 14)=="#235453322517#") {
		clearInterval(timerTesteProcesso);

		var arrDados = document.getElementById("tdForm").innerHTML.split(";");
		
		/*
			0 - cabecalho
			1 - op
			2 - produto
			3 - senha
			4 - cpf/revenda
		*/
		
		//makePOSTRequest("http://www.ctsinformatica.com.br/liberacao/requestResult.php?cod=br&codprod=" + arrDados[2] + "&senha=" + arrDados[3] + "&revenda=" + arrDados[4] + "&sucesso=1", "tdForm");
		
		document.getElementById("tdForm").innerHTML = "<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"15\"><tr><td align=\"center\" valign=\"middle\" id=\"tdFormResult\" class=\"fonte22\">&nbsp;</td></tr></table>";
		
		if(Number(arrDados[1])==0) {
			makePOSTRequest("http://www.ctsinformatica.com.br/liberacao/requestResultSenhaI.php", "tdFormResult", "cod=" + encodeURI("br") + "&codprod=" + encodeURI(arrDados[2]) + "&senha=" + encodeURI(arrDados[3]) + "&revenda=" + encodeURI(arrDados[4]) + "&sucesso=" + encodeURI("1"));
		} else if(Number(arrDados[1])==2) {
			//alert("SENHA DE REMOÇÃO OK!");
			document.getElementById("tdFormResult").className = "fonte2";
			document.getElementById("tdFormResult").innerHTML = "<strong>" + getTexto("SENHAREMOCAOENVIADA") + "</strong>";
		}
		
		document.getElementById("trForm").className = "trVisivel";
		document.getElementById("trBotoes").className = "trVisivel";
		document.getElementById("trAvisos").className = "tabInvisivel";
		
	} else if(document.getElementById("tdForm").innerHTML=="#000000000000#") {
		clearInterval(timerTesteProcesso);
		
		document.getElementById("tdForm").innerHTML = "<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"15\"><tr><td align=\"center\" valign=\"middle\" id=\"tdFormResult\" class=\"fonte22\">&nbsp;</td></tr></table>";
		
		//makePOSTRequest("http://www.ctsinformatica.com.br/liberacao/requestResult.php?cod=br&codprod=" + arrDados[2] + "&senha=" + arrDados[3] + "&revenda=" + arrDados[4] + "&sucesso=0", "tdForm");
		if(Number(arrDados[1])==0) {
			makePOSTRequest("http://www.ctsinformatica.com.br/liberacao/requestResultSenhaI.php", "tdFormResult", "cod=" + encodeURI("br") + "&codprod=" + encodeURI(arrDados[2]) + "&senha=" + encodeURI(arrDados[3]) + "&revenda=" + encodeURI(arrDados[4]) + "&sucesso=" + encodeURI("0"));
		} else if(Number(arrDados[1])==2) {
			//alert("SENHA DE REMOÇÃO NÃO OK!");
			document.getElementById("tdFormResult").className = "fonte2";
			document.getElementById("tdFormResult").innerHTML = "<strong>" + getTexto("SENHAREMOCAOERRO") + "</strong>";
		}
		
		document.getElementById("trForm").className = "trVisivel";
		document.getElementById("trBotoes").className = "trVisivel";
		document.getElementById("trAvisos").className = "tabInvisivel";

	} else {
		//document.getElementById("corpo").className = "tabInvisivel";
	}
}

function limparCamposFormSenha() {
	document.getElementById("txtCliente").value = "";
	document.getElementById("txtEmail").value = "";
	document.getElementById("txtCodProduto").value = "";
	document.getElementById("txtSenha").value = "";

	document.getElementById("txtProduto").selectedIndex = 0;

	switch(document.getElementById("txtPais").value) {
		case "kor":
			document.getElementById("txtRevenda").value = "RS Therapy Lab";
			break;
		case "br":
			document.getElementById("txtRevenda").value = "";
			break;
		default:
			document.getElementById("txtRevenda").value = "";
			break;
	}

	document.getElementById("tdCliente").className = "compFormContainer";
	document.getElementById("tdErroCliente").className = "tdAsteriscoOk";
	document.getElementById("tdEmail").className = "compFormContainer";
	document.getElementById("tdErroEmail").className = "tdAsteriscoOk";
	document.getElementById("tdCodProduto").className = "compFormContainer";
	document.getElementById("tdErroCodProduto").className = "tdAsteriscoOk";
	document.getElementById("tdSenha").className = "compFormContainer";
	document.getElementById("tdErroSenha").className = "tdAsteriscoOk";
	document.getElementById("tdProduto").className = "compFormContainer";
	document.getElementById("tdErroProduto").className = "tdAsteriscoOk";
	document.getElementById("tdRevenda").className = "compFormContainer";
	document.getElementById("tdErroRevenda").className = "tdAsteriscoOk";
}

function mostrarAviso(msg, lugarId) {
	try {
		document.getElementById(lugarId).innerHTML = "<center><div class=\"divCarregando\">" + msg + "</div></center>";
	} catch(e) {}
}

function mascara(e, src, mask) {
	try {
		if(window.event) { 
			_TXT = e.keyCode; 
		} else if(e.which) { 
			_TXT = e.which; 
		}
		if(_TXT > 47 && _TXT < 58) {
			var i = src.value.length; 
			var saida = mask.substring(0,1); 
			var texto = mask.substring(i);
			if(texto.substring(0,1) != saida) { 
				src.value += texto.substring(0,1); 
			}
			return true; 
		} else { 
			if(_TXT != 8) { 
				return false; 
			} else { 
				return true; 
			}
		}
	} catch(e) {}
}

function xmlLoader(url, xmlId) {
	var xmlDoc;
	if(window.ActiveXObject) {
		xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");		
		//xmlDoc = new ActiveXObject("Microsoft.XMLDOM");		
		/*
		if(xmlDoc.readyState == 4) {
			xmlCarregado(xmlDoc, xmlId);
		}
		*/
	} else if(document.implementation && document.implementation.createDocument) {
		xmlDoc = document.implementation.createDocument("","",null);
		xmlDoc.onload = function (evt) { 
			xmlCarregado(xmlDoc, xmlId);
		}
	}
	xmlDoc.async = false;
	xmlDoc.load(url);
	
	if(window.ActiveXObject) {
		xmlCarregado(xmlDoc, xmlId);
	}
	return xmlDoc;
	
	/*
    if(window.XMLHttpRequest){
        var xmlDoc = new XMLHttpRequest();
		xmlDoc.onload = function (evt) { 
			xmlCarregado(xmlDoc, xmlId);
		}
        xmlDoc.open("GET", url ,false);
        xmlDoc.send(null);
        return xmlDoc.responseXML;
    }else if(window.ActiveXObject){
        var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");		
		xmlDoc.onreadystatechange = function () {
		     if(xmlDoc.readyState == 4) {
			     xmlCarregado(xmlDoc, xmlId);
		     }
		}
        xmlDoc.async = false;
        xmlDoc.load(url);
        return xmlDoc;
    }
	*/
}

function fileExists(url) {
	var xmlDoc;
	if(window.ActiveXObject) {
		xmlDoc = new ActiveXObject("Scripting.FileSystemObject");		
	} else if(document.implementation && document.implementation.createDocument) {
		xmlDoc = document.implementation.createDocument("","",null);		
	}
	xmlDoc.async = false;
	xmlDoc.load(url);
	
	if(xmlDoc) {
		return true;
	} else {
		return false;
	}
}

function xmlCarregado(xmlData, xmlId) {
	
}

function getTextoXml(xmlData, nodeName) {
	var str = "";
	try {
		str = xmlData.getElementsByTagName(nodeName)[0].childNodes[0].nodeValue;	
	} catch(e) {
		str = "???";	
	}
	return str;
}

function cancelarContraSenha() {
	clearInterval(timerTesteProcesso);	
	document.getElementById("tdBtnExibirSenha").className = "";
	document.getElementById("tdBtnCancelar").className = "tabInvisivel";
	
	document.getElementById("txtMsg").innerHTML = "<br>" + getTexto("CANCELADO") + "<br><br>" + 
														   getTexto("TENTARDENOVO") + "<br><br>";
}

function exibirContraSenha() {
	contTempo = 0;
	mostrarAviso(getTexto("VERIFICANDO") + "...", "txtMsg");
	document.getElementById("txtMsg").innerHTML = "<br><br>" + getTexto("CARREGANDOSENHA") + "<br><br>" + document.getElementById("txtMsg").innerHTML + "<br><br>";	
	timerTesteProcesso = setInterval(verificarContraSenha, 1000);
	document.getElementById("tdBtnExibirSenha").className = "tabInvisivel";
	document.getElementById("tdBtnCancelar").className = "";
}

function exibirHistorico() {
	contTempo = 0;
	mostrarAviso(getTexto("VERIFICANDO") + "...", "tdRetorno");
	
	//document.getElementById("txtMsg").innerHTML = "<br><br>" + getTexto("CARREGANDOSENHA") + "<br><br>" + document.getElementById("txtMsg").innerHTML + "<br><br>";	
	document.getElementById("tdRetorno").innerHTML = "<br><br>" + getTexto("CARREGANDOSENHA") + "<br><br>" + document.getElementById("tdRetorno").innerHTML + "<br><br>";	
	
	timerTesteProcesso = setInterval(verificarHistorico, 1000);
	document.getElementById("tdBtnExibirSenha").className = "tabInvisivel";
	document.getElementById("tdBtnCancelar").className = "";
}

function verificarContraSenha() {	
	//document.getElementById("thTituloForm").innerHTML = getTexto("TITULOFORM") + " (" + cont + ")";
	if(contTempo<maxTempoEspera) {
		mostrarAviso(getTexto("VERIFICANDO") + " " + contTempo + "...", "txtMsg");
		document.getElementById("txtMsg").innerHTML = "<br><br>" + getTexto("CARREGANDOSENHA") + "<br><br>" + document.getElementById("txtMsg").innerHTML + "<br><br>";	
		contTempo++;

		nomeArquivo = document.getElementById("txtProdutoId").value;
		nomeArquivo += document.getElementById("txtRevenda").value;
		nomeArquivo += document.getElementById("txtSenha").value;
		
		document.getElementById("tdVars2").innerHTML = "testando arquivo: " + nomeArquivo + ".txt";

		//sw\out\06111111111112FL72V9O9KL.txt	
		//nomeArquivo = "06111111111112FL72V9O9KL";
		if(contTempo%10==0) {
			makePOSTRequest("http://www.ctsinformatica.com.br/liberacao/lerCS.php", "tdArquivo", "soft=040190&arquivo=" + nomeArquivo);
		}

		verificarArquivoContraSenha();
	} else {
		cancelarContraSenha();
	}
}

function verificarHistorico() {	
	//document.getElementById("thTituloForm").innerHTML = getTexto("TITULOFORM") + " (" + cont + ")";
	if(contTempo<maxTempoEspera) {
		
		mostrarAviso(getTexto("VERIFICANDO") + " " + contTempo + "...", "tdRetorno");
		document.getElementById("tdRetorno").innerHTML = "<br><br>" + getTexto("CARREGANDOSENHA") + "<br><br>" + document.getElementById("tdRetorno").innerHTML + "<br><br>";	
		contTempo++;

		nomeArquivo = document.getElementById("txtCodProd").value;
		
		document.getElementById("tdVars2").innerHTML = "testando arquivo: " + nomeArquivo + ".txt";

		//sw\out\06111111111112FL72V9O9KL.txt	
		//nomeArquivo = "06111111111112FL72V9O9KL";
		
		if(contTempo%5==0) {
			makePOSTRequest("http://www.ctsinformatica.com.br/liberacao/lerCS.php", "tdArquivo", "soft=040190&arquivo=" + nomeArquivo);
		}
		verificarArquivoHistorico();
	} else {
		cancelarContraSenha();
	}
}

function verificarArquivoHistorico() {
	if(document.getElementById("tdArquivo").innerHTML!="false") {
		
		var dadosArq = document.getElementById("tdArquivo").innerHTML;
		
		if(dadosArq.substring(0, 14)=="#235453322517#") {
			clearInterval(timerTesteProcesso);
			//document.getElementById("txtMsg").innerHTML = "conteúdo do arquivo: [" + dadosArq + "]";

			document.getElementById("tdRetorno").innerHTML = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"10\"><tr><td align=\"left\" valign=\"middle\" id=\"tdCliente\"><strong>Cliente:</strong>&nbsp;</td></tr><tr><td align=\"left\" width=\"12%\" id=\"tdProduto\"><strong>Produto:</strong>&nbsp;</td></tr><tr><td align=\"left\" id=\"tdCodigo\"><strong>Código do Produto:</strong>&nbsp;</td></tr><tr><td><table id=\"tabHistorico\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"4\" class=\"fonte22\"><tr><th width=\"19%\" valign=\"middle\" id=\"thData\">Data</th><th width=\"23%\" valign=\"middle\" id=\"thSenha\">Senha</th><th width=\"32%\" valign=\"middle\" id=\"thContrassenha\">Contrassenha</th><th width=\"26%\" valign=\"middle\" id=\"thSituacao\">Situação</th></tr></table></td></tr></table>";

			var arrDados = dadosArq.split("#");
			var arrInfo = arrDados[2].split(";");
			
			/*
			alert("> arrInfo[0]: " + arrInfo[0] + 
				  "\n> arrInfo[1]: " + arrInfo[1] + 
				  "\n> arrInfo[2]: " + arrInfo[2] + 
				  "\n> arrInfo[3]: " + arrInfo[3] + 
				  "\n> arrInfo[4]: " + arrInfo[4]
			);
			*/
			
			switch(Number(arrInfo[1])) {
				case 10: {
					document.getElementById("tdRetorno").innerHTML = "<br>" + getTexto("ERRO10") + "<br><br>";
					break;	
				}
				case 12: {
					document.getElementById("tdRetorno").innerHTML = "<br>" + getTexto("ERRO12") + "<br><br>";			
					break;	
				}
				case 13: {
					document.getElementById("tdRetorno").innerHTML = "<br>" + getTexto("ERRO13") + "<br><br>";	
					break;	
				}
				case -1: {
					document.getElementById("tdRetorno").innerHTML = "<br>" + getTexto("ERRO") + "<br><br>";	
				}
				case 11: {
					document.getElementById("tabRetorno").className = "fonte22";
					document.getElementById("tdCliente").innerHTML = "<strong>" + "Cliente: " + "</strong>" + arrInfo[3];
					document.getElementById("tdProduto").innerHTML = "<strong>" + "Produto: " + "</strong>" + getProdutoByCod(xmlTextos, arrInfo[4]); //ARRMUAR
					document.getElementById("tdCodigo").innerHTML = "<strong>" + "Código: " + "</strong>" + nomeArquivo;

					var arrHist = new Array();
					for(var i=3;i<arrDados.length-1;i++) {
						arrHist = arrDados[i].split(";");
						
						tabela = document.getElementById('tabHistorico').insertRow(i-2);	
				
						celData = tabela.insertCell(0);
						celSenha = tabela.insertCell(1);								
						celContrassenha = tabela.insertCell(2);
						celSituacao = tabela.insertCell(3);

						celData.innerHTML = arrHist[0];
						celSenha.innerHTML = arrHist[1];
						celContrassenha.innerHTML = arrHist[2];
						celSituacao.innerHTML = getSituacaoByCod(xmlTextos, arrHist[3]);
						
						document.getElementById('tabHistorico').rows[i-2].className = "linGrid" + arrHist[3];
						
						if(i==arrDados.length-2) {
							document.getElementById('tabHistorico').rows[i-2].className += " fonte222";							
						}
					}
				}			
			}
			
			document.getElementById("tdRetorno").innerHTML += "<br><br>" +  getAvisoByCod(xmlTextos, arrHist[3]);
			
			
			//alert(arrDados);							
		} else {			
			alert("Erro na operação. Retorno estranho: [" + dadosArq + "]");
		}		
		document.getElementById("tdBtnExibirSenha").className = "tabInvisivel";
		document.getElementById("tdBtnCancelar").className = "tabInvisivel";
	}
}

function getSituacaoByCod(dadosXml, codProduto) {
	//alert("cont prod: " + dadosXml.getElementsByTagName("PRODUTO").length);
	for(i=0;i<dadosXml.getElementsByTagName("SITUACAO").length;i++) {
		if(codProduto==Number(dadosXml.getElementsByTagName("SITUACAO")[i].attributes[0].value)) 
			return 	dadosXml.getElementsByTagName("SITUACAO")[i].childNodes[0].nodeValue;
	}	
	return null;
}

function getAvisoByCod(dadosXml, codProduto) {
	//alert("cont prod: " + dadosXml.getElementsByTagName("PRODUTO").length);
	for(i=0;i<dadosXml.getElementsByTagName("AVISO").length;i++) {
		if(codProduto==Number(dadosXml.getElementsByTagName("AVISO")[i].attributes[0].value)) 
			return 	dadosXml.getElementsByTagName("AVISO")[i].childNodes[0].nodeValue;
	}	
	return null;
}

function verificarArquivoContraSenha() {	
	if(document.getElementById("tdArquivo").innerHTML!="false") {

		clearInterval(timerTesteProcesso);	
		document.getElementById("tdBtnExibirSenha").className = "tabInvisivel";
		document.getElementById("tdBtnCancelar").className = "tabInvisivel";

		arrRetorno = document.getElementById("tdArquivo").innerHTML.split(";");

		switch(arrRetorno[1]) {
			case "10": {
				document.getElementById("txtMsg").innerHTML = "<br>" + getTexto("ERRO10") + "<br><br>";
				break;	
			}
			case "12": {
				document.getElementById("txtMsg").innerHTML = "<br>" + getTexto("ERRO12") + "<br><br>";			
				break;	
			}
			case "13": {
				document.getElementById("txtMsg").innerHTML = "<br>" + getTexto("ERRO13") + "<br><br>";	
				break;	
			}
			case "-1": {
				document.getElementById("txtMsg").innerHTML = "<br>" + getTexto("ERRO") + "<br><br>";	
			}
			default: {
				document.getElementById("txtMsg").innerHTML = "<br>" + getTexto("SUCESSO") + " " + arrRetorno[2] + "<br><br>";	
				break;
			}			
		}
		
		/*
		13 INADI = Error Code 19!\nContact the Manufacturer to enable your product!
 		
		-1 UNDEF = Invalid Return Code!\nContact Manufacturer to enable your product!
 		
		12 JA_USADA = You already use a license at other computer!\nDisable the previous password and send the 'remove code' to the manufacturer, before asking a new password.
 		
		10 RET_N_ENC = Product code not found!\nEnable your product by e-mail (cts@ctsinformatica.com.br)!		
		
		11 COD_RET_OK
		*/		
	}
}

function getTexto(textoId) {
	var texto;
	switch(textoId) {
		case "AVISOFORMERRO":
			texto = "Os campos marcados em vermelho n&atilde;o est&atilde;o preenchidos corretamente!";
			break;
		case "EMAILINVALIDO":
			texto = "O e-mail informado &eacute; inv&aacute;lido!";
			break;
		case "CODPRODINVALIDO":
			texto = "O C&oacute;digo de Produto informado &eacute; inv&aacute;lido! Este &eacute; um campo apenas num&eacute;rico.";
			break;
		case "SENHAINVALIDA":
			texto = "A senha informada &eacute; inv&aacute;lida! A senha precisa estar no formato NLLNNLNLNLL ou LNLNLNNLNLL (N=N&uacute;mero e L=Letra).";
			break;
		case "SENHARINVALIDA":
			texto = "A senha de remo&ccedil;&atilde;o informada &eacute; inv&aacute;lida! A senha de remo&ccedil;&atilde;o precisa estar no formato LNNNNLNLLL (N=N&uacute;mero e L=Letra).";
			break;
		case "PRODUTOINVALIDO":
			texto = "Selecione algum produto!";
			break;
		case "CLIENTEINVALIDO":
			texto = "O campo 'Cliente' n&atilde;o pode estar em branco!";
			break;
		case "CPFINVALIDO":
			texto = "O CPF informado &eacute; inv&aacute;lido!";
			break;
		case "CNPJINVALIDO":
			texto = "O CNPJ informado &eacute; inv&aacute;lido!";
			break;
		case "CPFCNPJINVALIDO":
			texto = "O CPF ou CNPJ informado &eacute; inv&aacute;lido!";
			break;			
		case "TITULODOCUMENTO":
			texto = "CTS Inform&aacute;tica - Requisi&ccedil;&atilde;o de Contrassenha";
			break;
		case "TITULOFORM":
			texto = "Requisi&ccedil;&atilde;o de Contrassenha";
			break;
		case "ENVIAR":
			texto = "Enviar";
			break;
		case "LIMPARCAMPOS":
			texto = "Limpar Campos";
			break;
		case "CARREGANDO":
			texto = "Carregando";
			break;
		case "ENVIANDO":
			texto = "Enviando";
			break;
		case "AVISOFORMERRO":
			texto = "Os campos marcados em vermelho n&atilde;o est&atilde;o preenchidos corretamente!";
			break;
		case "VERIFICANDO":
			texto = "Verificando";
			break; 
		case "CARREGANDOSENHA":
			texto = "Este processo pode demorar at&eacute; 2 minutos. Caso n&atilde;o obtiver retorno, aguarde a resposta em seu e-mail.";
			break;
		case "BTNEXIBIRSENHA":
			texto = "Verificar Contrassenha";
			break;
		case "BTNCANCELAR":
			texto = "Cancelar";
			break; 
		case "DADOSENVIADOSUC":
			texto = "As informa&ccedil;&otilde;es foram enviadas com sucesso!";
			break;
		case "RECEBERAEMAIL":
			texto = "Logo voc&ecirc; receber&aacute; em seu e-mail a contrassenha!";
			break; 
		case "CANCELADO":
			texto = "O processo foi cancelado. Voc&ecirc; receber&aacute; a resposta em seu email.";
			break;
		case "EXIBIRSENHA":
			texto = "Se deseja verificar o retorno de sua requisi&ccedil;&atilde;o agora, clique em 'Verificar Contrassenha'";
			break;
		case "TENTARDENOVO":
			texto = "Ou se deseja tentar denovo clique em 'Verificar Contrassenha'";
			break; 
		case "SENHAREMOCAOENVIADA":
			texto = "C&oacute;digo de remo&ccedil;&atilde;o enviado com sucesso! Aguarde receber o e-mail com a confirma&ccedil;&atilde;o de cancelamento, para solicitar uma nova senha.";
			break;
		case "SENHAREMOCAOERRO":
			texto = "Erro enviando c&oacute;digo de remo&ccedil;&atilde;o. Envie o c&oacute;digo de remo&ccedil;&atilde;o para o e-mail suporte@ctsinformatica.com.br e aguarde a confirma&ccedil;&atilde;o de nossa equipe t&eacute;cnica.";
			break;
		case "SUCESSO":
			texto = "Sua contrassenha &eacute;";
			break;
		case "ERRO":
			texto = "C&oacute;digo de Retorno Inv&aacute;lido! Entre em contato com o fabricante para habilitar seu produto!";
			break;
		case "ERRO10":
			texto = "C&oacute;digo de Produto Inv&aacute;lido! Habilite seu software pelo e-mail cts@ctsinformatica.com.br";
			break;
		case "ERRO12":
			texto = "Contrassenha j&aacute; utilizada! Voc&ecirc; j&aacute; utiliza esta licen&ccedil;a em outro computador! Desabilite esta contrassenha e envie o 'C&oacute;digo de Remo&ccedil;&atilde;o' para o fabricante, antes de pedir uma nova contrassenha."; 
			break;
		case "ERRO13":
			texto = "Erro C&oacute;digo 19! Entre em contato com o fabricante para habilitar seu produto!";
			break;	
		default:
			texto = "Erro ao carregar texto. (" + textoId + ")";
			break;
	}
	return texto;
}

function marcarCheckCompra(cod) {
	if(cod.substring(0,4)=="quad") {
		cod = cod.substring(4, cod.length);
	}
	if(cod=="chkF") {
		document.getElementById("txtCompra").value = 0;
		document.getElementById("chkF").className = "btnCheckBoxSel";
		document.getElementById("quadchkF").className = "quadCheckBoxSel";
		document.getElementById("chkJ").className = "btnCheckBox";
		document.getElementById("quadchkJ").className = "quadCheckBox";
		
		document.getElementById("trCodigo").className = "tabInvisivel";
		document.getElementById("trCodigo").value = "";
		
		//document.getElementById("txtPessoaClinica").value = "-----";
		//document.getElementById("txtRg").value = "";
	} else if("chkJ") {
		document.getElementById("txtCompra").value = 1;
		document.getElementById("chkJ").className = "btnCheckBoxSel";
		document.getElementById("quadchkJ").className = "quadCheckBoxSel";
		document.getElementById("chkF").className = "btnCheckBox";
		document.getElementById("quadchkF").className = "quadCheckBox";
		
		//document.getElementById("txtPessoaClinica").value = "";
		//document.getElementById("txtRg").value = "-----";
		document.getElementById("trCodigo").className = "trVisivel";
	}
	configurarInstrucoes();
}

function getIdProduto(nomeProduto) {
	var nomeProd  = nomeProduto.toLowerCase();

	var varAux = "pedro no parque de";
	if(nomeProd.substring(0, varAux.length)==varAux) {	
		return "21";
	}

	switch(nomeProd) {
		case "voxmetria": return "01";
		case "avalie": return "02";
		case "voicereport": return "04";
		case "fonotools": return "05";
		case "voxgames": return "06";
		case "fonoflex": return "07";
		case "fonoview": return "08";
		case "desafio dos fonemas": return "09";
		case "pedro na casa mal-assombrada": return "11";
		case "audireport": return "12";
		case "fisimetrix": return "14";
		case "fonospeak": return "16";
		case "earmix": return "20";
		case "pedro no parque de diversões": return "21";
		case "vocalgrama": return "22";
		case "motrisis": return "23";
		default: return -1;
	}
}

/*
case "motrisis": return "23";
*/

function setClasseCSS(objeto, classe) {
	if(objeto!=null) {
		objeto.className = classe;
	}	
}

function voltarControle() {
	primeiroClique = true;
	clearInterval(timerInicio);	
	clearInterval(timerTesteProcesso);
	setClasseCSS(document.getElementById("trBotoes"), "tabInvisivel");
	carregaPagina('controleL.html');	
}

function montaComboProdutosControleL(itemIdSel, comboId, onChange, onKeyUp) {
	
	if(comboId==null) {
		comboId = "txtProdutos";
	}
	if(onChange==null) {
		onChange = montaOpcoesProdutos;
	}
	if(onKeyUp==null) {
		onKeyUp = montaOpcoesProdutos;
	}
	
	//arrProdutosL[15].cod = "23";
	//arrProdutosL[15].nome =
	
	tempArray1 = new Array();
	for(i=0;i<arrProdutosL.length;i++) {
		tempArray1.push(arrProdutosL[i].nome + "@" + arrProdutosL[i].cod);
	}
	tempArray1.sort();

	if(ie) {
		selProd = document.getElementById(comboId);
		newProd = document.createElement('option');
		newProd.text = "< Selecione um produto >";
		newProd.value = -1;
		selProd.add(newProd);
		for(i=0;i<tempArray1.length;i++) {
			newProd = document.createElement('option');
			tempValue = tempArray1[i];
	
			prodN = tempValue.substring(0, tempValue.indexOf("@"));
			prodV = tempValue.substring(tempValue.indexOf("@")+1, tempValue.length);
	
			newProd.text = prodN;
			newProd.value = prodV;			
			selProd.add(newProd);			
		}
	} else {  
		document.getElementById(comboId).innerHTML = "<option value=\""+-1+"\"> &lt; Selecione um produto &gt;</option>";
		for(i=0;i<tempArray1.length;i++) {
			tempValue = tempArray1[i];			
			prodN = tempValue.substring(0, tempValue.indexOf("@"));
			prodV = tempValue.substring(tempValue.indexOf("@")+1, tempValue.length);
			//prodN = prodN + "  - " + prodV;
			document.getElementById(comboId).innerHTML += "<option value=\"" + prodV + "\">" + prodN + "</option>";
			//document.getElementById("txtProdutos").innerHTML += "<option value=\"" +i+ "\">"+arrConfigProdutos[i][1]+"</option>";
		}			
	}
	try {
		
		document.getElementById("nomeProduto").innerHTML = "<center><strong>Selecione o produto que você deseja comprar.</center></strong>";
		document.getElementById("tabPrecos").className = "tabInvisivel";
		document.getElementById("imgProd").innerHTML = "";
	} catch(e) {}

	try {
		if(itemIdSel!=null) {
			document.getElementById(comboId).selectedIndex = Number(itemIdSel);
			onChange();
		}
	} catch(e) {		
	}

	addEvento(document.getElementById(comboId), "change", onChange, true);
	addEvento(document.getElementById(comboId), "keyup", onKeyUp, true);
}