// ###         XMLHTTPRequest          ###
// ##  Exemplo de artigo publicado por  ##
// #  diego nunes - dnunes[em]gmail.com  #
// #######################################
// #      Conteúdo sob licença (CC)      #
// #   Mais info: ver final do arquivo   #
// #######################################
function gE(tI) { /* theID */
  if (document.getElementById) { return document.getElementById(tI); }
  else if (document.all) { return document.all[tI]; } else return false;
}
function cE(tN, tId, tCN, tIH) { /* tagName, id, className, innerHTML */ if (!document.createElement) return false;
  var nE, tER; nE=document.createElement(tN); if (valorValido(tId)) { nE.id=tId; }
  if (valorValido(tCN)) { nE.className=tCN; } if (valorValido(tIH)) { nE.innerHTML=tIH; } return nE;
}
function cTN(tV) { /* theValue */ return (tV && document.createTextNode) ? document.createTextNode(tV) : false; }
function rEs(tO) { var i, n; //removeElements. Recebe um objeto ou uma coleção deles, para remover do documento
  if (!tO) { return false; } if (!tO.nodeName) { if (tO.length) for (n=tO.length; n--;) rEs(tO[n]); }
  else tO.parentNode.removeChild(tO);
}
function adEvento(tO, tE, tF) { //Adaptado da função de Scott Andrew - scottandrew.com
  if (tO.addEventListener) { tO.addEventListener(tE, tF, true); return true; }
  else if (tO.attachEvent) { return tO.attachEvent('on'+tE, tF); }
  else { alert('Erro!'); return false; }
}
function remEvento(tO, tE, tF) { //Adaptado da função de Scott Andrew - scottandrew.com
  if (tO.removeEventListener) { tO.removeEventListener(tE, tF, false); return true; }
  else if (tO.detachEvent) { return tO.detachEvent("on"+tE, tF); }
  else { alert('Erro!'); return false; }
}
function getSrc(e) { /* event */ return (e.target) ? e.target : (window.event && event.srcElement) ? event.srcElement : false; }
function getKeyCode(e) { /* event */ return (e.which) ? e.which : (window.event && event.keyCode) ? event.keyCode : false; }
function valorValido(tV) { /* theValue */ var tER=/[a-z0-9]/gi; return tER.test(tV); }
function insertAfter(tN, nN) { /* tNode, newNode */ var tP=tN.parentNode;
  while ((tN=tN.nextSibling) && tN.nodeType != 3) { /* ... */ }
  if (tN) { tP.insertBefore(tN, nN); } else { tP.appenChild(nN); } return tP;
}
function firstOfType(tO, tT) { /* theObject, theTag */ var i, n, tCs;
  for (i=0, n=(tCs=tO.childNodes).length; i<n; i++) {
    if (tCs[i].nodeType==1 && tCs[i].nodeName.toLowerCase()==tT.toLowerCase()) return tCs[i];
  } return false;
}
function lastOfType(tO, tT) { /* theObject, theTag */ var i, tCs;
  for (i=(tCs=tO.childNodes).length; (i--)>0; ) {
    if (tCs[i].nodeType==1 && tCs[i].nodeName.toLowerCase()==tT.toLowerCase()) return tCs[i];
  } return false;
}
function nextOfType(tO, tT) { /* theObject, theTag */
  while (tO=tO.nextSibling) { if (tO.nodeType==1 && tO.nodeName.toLowerCase()==tT.toLowerCase()) return tO; }
  return false;
}
function previousOfType(tO, tT) { /* theObject, theTag */
  while (tO=tO.previousSibling) { if (tO.nodeType==1 && tO.nodeName.toLowerCase()==tT.toLowerCase()) return tO; }
  return false;
}
function sW(tS, sS) { /* [Bool] StartsWith: theString, SubString */
  return (tS && sS && tS.substring(0,sS.toString().length) == sS.toString()) ? true : false;
}
function getTok(tokList, tIndex, tDiv, tPattern) { /* tokList, theIndex, tDivisor, tPattern (Filtro [RegExp]) */
  if (!tPattern) { tPattern='.'; } var tER, tL, i, n, tMs=0; tER=new RegExp(tPattern); tL=tokList.split(tDiv);
  for (i=0, n=tL.length; i<n; i++) { if (tER.test(tL[i])) tMs++; if (tMs==tIndex) { return tL[i].toString(); } }
  return false;
}