function criaXMLHTTP(){
 var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0",
 "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
 "Microsoft.XMLHTTP"];
 var retorno = false;
 try{
  return new XMLHttpRequest();
 }catch(ee){
  try{
   for (var i=0; !retorno && i < arrSignatures.length; i++) {
    try {
     retorno = new ActiveXObject(arrSignatures[i]);
    } catch (oError) {
     retorno = false;
    }
   }
  }catch(e){
   return false;
  }
 }
 return retorno;
}
 
function criptCAF(ck, fn){
    xmlhttp = criaXMLHTTP();
 
    //Abre a conexão
    xw = new String(location).split('/')[2];
    xmlhttp.open('GET','http://'+xw+'/functions/criptcaf.php?u='+ck);
 xmlhttp.setRequestHeader("Cache-Control", "no-cache");
 xmlhttp.setRequestHeader("Pragma", "no-cache");
 
    // para solicitacoes utilizando o metodo post deve ser acrescentado 
    // oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 
    //Função para tratamento do retorno
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4){
   conteudo = xmlhttp.responseText;
            //Mostra o HTML recebido
   // return conteudo;
   if(fn!=''){ // deve chamar função, passando conteudo
    eval(fn);
   }
        }
    }
    //Executa
    xmlhttp.send(null);
}
function tiraespacos(tmpStr) {
  var tmpStr, atChar;
  if (tmpStr.length > 0) atChar = tmpStr.charAt(0);
  while (isSpace(atChar)) 
  {
		tmpStr = tmpStr.substring(1, tmpStr.length);
	atChar = tmpStr.charAt(0);
  }
  if (tmpStr.length > 0) 
		  atChar = tmpStr.charAt(tmpStr.length-1);
  while (isSpace(atChar)) 
  {
	tmpStr = tmpStr.substring(0,(tmpStr.length-1));
	atChar = tmpStr.charAt(tmpStr.length-1);
  }
  return tmpStr;
}

function isSpace(inChar) {
  return (inChar == ' ' || inChar == '\t' || inChar == '\n');
}

function abreAjuda(){
	if(getCookie('AutenticOk') && tiraespacos(getCookie('AutenticOk'))!=''){
		criptCAF(getCookie('AutenticOk'),'abreCAF(conteudo)');		
	}else{
		alert('Para utilizar esse recurso você precisa realizar o seu login!');
	}
}
 
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
  begin = dc.indexOf(prefix);
  if (begin != 0) return null;
  } else
  begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
  end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
 
function abreCAF(cript){
  largura = 800;
  altura = 600;
  centroTop = screen.height/2 - altura/2;
  centroLeft = screen.width/2 - largura/2;
  window.open('http://www.fiscosoft.com.br/caf/comex.php?u='+cript, 'janNotFoundCaf', 'status=0, resizable=0, location=0, toolbar=0, scrollbars=1, width='+largura+', height='+altura+', directories=0, menubar=0, titlebar=0, top='+centroTop+',left='+centroLeft);
}