//      basico 1.2.8 - 2008-01-03 (descontinuada)
//      prefira o uso da biblioteca "basico2"
//
//      por diego nunes - dn[em]dnunes.com
//  (cc) Conteúdo sob licença Creative Commons
//http://creativecommons.org/licenses/by-sa/3.0/

function gE(tI, tDoc) { var d=tDoc || document, r=[], n, i;
  if (tI instanceof Array) { for (n=tI.length, i=0; i<n; i++) { r[r.length]=gE(tI[i]); } return r; }
  else { return (d.getElementById && d.getElementById(tI)) || (d.all && d.all[tI]); }
}
function makeArray(collection, forceNumeric) { var i=0, v, r=[];
  for (var v in collection) { if (forceNumeric && (v=='length' || v=='item' || v=='namedItem')) { continue; }
    r[((forceNumeric)?i++:v)]=collection[v];
  } return r;
}
function gFETN(tTn, tFs, isER, rE, justChilds) {
  //getFilteredElements[by]TagName: <str TagName> [, str/arr theFilters [, bool isERFilter [, object rootElement]]]
  //Se o quarto parâmetro for enviado, a função só retornará elementos descendentes de _rootElement_.
  //O quinto parâmetro, _justChilds_, faz a função só retornar filhos diretos do elemento estabelecido em _rootElement_.
  var tEs, i, n, ii, nn, passed, tF, tER, tR=new Array();
  if (rE && justChilds) { tEs=childsOfType(rE, tTn); } else { tEs=(rE || document).getElementsByTagName(tTn); }
  if (!tFs) { return tEs.length ? makeArray(tEs, 1) : false; } if (typeof(tFs) == 'string') { tFs=[tFs]; }
  for (n=tEs.length, i=0; i<n; i++) { passed=1;
    for (nn=tFs.length, ii=0; ii<nn; ii++) { tF=tFs[ii].split('=');
      if (isER) { tER=new RegExp(tF[1], 'g'); if (!tER.test(tEs[i][tF[0]])) { passed=0; } }
      else { if (tEs[i][tF[0]] != tF[1]) passed=0; }
    } if (passed) { tR[tR.length]=tEs[i]; /* compatÃ­vel com IE5.1 */ }
  }
  return tR.length ? tR : false;
}
var createNamedElement=function (){}; //Cria elemento com "name" -- cross-browser
(function () {
  try {
    var el=document.createElement('<div name="foo">'); //IE nasty way of creating named elements
    if (el.tagName != 'DIV' || el.name != 'foo') { throw 'create element error'; }
    /* else... */
    createNamedElement = function (tag, name) {
      return document.createElement('<'+ tag +' name="'+ name +'"></'+ tag +'>');
    };
  } catch (e) { //Good ol' compliants way
    createNamedElement = function (tag, name) {
      var el = document.createElement(tag); el.name = name; return el;
    }
  }
})();
function cE(tN, tPs, tC) { // createElement 3.3 -- <str tagName> [, str/arr tProperties] [, str/obj conteúdo]
  //Essa função, se chamada com 2 parâmetros, os assumirá como "tN" e "tC", e não "tN" e "tPs".
  if (!document.createElement) { return false; } var nE, tER, i, n, tP; nE=document.createElement(tN);
  if (arguments.length > 1) { if (arguments.length == 2) { tC=tPs; tPs=[]; } if (typeof(tPs) == 'string') { tPs=[tPs]; }
    if (tPs && tPs.length != 0) { //Caso tenha propriedades, procurar por "name".
      var tNA=0; for (n=tPs.length, i=0; i<n; i++) { tP=tPs[i].split('=');
        if (tP.shift().toLowerCase() == 'name') { tNA=tP.join('='); tPs.splice(i--, 1); n--; }
      } //Para criar um elemento com "name" é preciso um tratamento devido a um bug no IE
      if (tNA) { nE=createNamedElement(tN, tNA); } //Ver "createNamedElement".
    }
    for (n=tPs.length, i=0; i<n; i++) { tP=tPs[i].split('='); //O atributo "class" tem diferenças de interpretação, então
      if (tP[0] == 'class' || tP[0] == 'className') { tP.shift(); nE.className=tP.join('='); } //uso a propriedade "className"
      else { nE.setAttribute(tP.shift(), tP.join('=')); } //Todos os outros são definidos com o "setAttribute" do DOM.
    }
    if (tC) { i=0;
      if (tC instanceof Array) { for (n=tC.length; i<n; i++) {
        nE.appendChild( (typeof(tC[i])=='string') ? cTN(tC[i]) : tC[i] );
      } } else { nE.appendChild( (typeof(tC)=='string') ? cTN(tC) : tC ); }
    }
  } return nE;
}
function cTN(tV) { return (tV && document.createTextNode && document.createTextNode(tV)); }
function rEs(tO) { var i, n; if (!tO) { return false; } //RemoveElements
  if (!tO.nodeName) { if (!tO.length) { return false; }
    for (n=tO.length; n--;) { if (!rEs(tO[n])) { return false; } } return true;
  } else { tO.parentNode.removeChild(tO); return true; }
}

Function.prototype.bind=function(obj, args) { var metodo=this; return function() { return metodo.apply(obj, args); } }
Function.prototype.bindAsEventListener=function(obj) { var metodo=this; return function(e) { return metodo.call(obj, e); } }
//adEvento 3.2 - <str/arr tObj(s)>, <str/arr tEvent(s)>, <func tFunction> [, arr tParams [, bool captureEvents]]
function adEvento(tO, tE, tF, tPs, eCpt) { var n, nn, tnF; if (!tO) { return false; }
  if (tO instanceof Array || tE instanceof Array) { if (!(tO instanceof Array)) tO=[tO]; if (!(tE instanceof Array)) tE=[tE]; }
  if (tO instanceof Array) { for (n=tO.length; (n--)>0; n) { for (nn=tE.length; (nn--)>0; ) {
      if (!adEvento(tO[n], tE[nn], tF, tPs)) { return false; }
  } } return true; }
  tnF=(tPs) ? function(e) { tF.apply(tO, Array(e).concat(tPs)); } : tF;
  /* Iniciar arrays, caso não existam */ if (!tO.eventos) { tO.eventos=[]; } if (!tO.eventos[tE]) { tO.eventos[tE]=[]; }
  tO.eventos[tE][tO.eventos[tE].length]={tE: tE,   tnF: tnF};
  if (tO.addEventListener) { tO.addEventListener(tE, tnF, (eCpt == 'nocapture')?false:true); return true; }
  else if (tO.attachEvent) { tO.attachEvent('on'+tE, tnF); return true; }
  else { tO['on'+ tE]=tnF; }
  /* alert('Erro!'); */ return false;
}
function remEventos(tO, tE, tF, tPs, eCpt) {
  //Recebendo apenas objeto e nome do evento
  if (arguments.length == 2) { if (!tO.eventos) { return false; }
    var tCEv; if (!(tE instanceof Array)) tE=[tE];
    for (n=tE.length, i=0; i<n; i++) { tCEv=tE[i]; tCEvs=tO.eventos[tCEv];
      if (!tCEvs) { continue; } //Evento inexistente
      for (nn=tCEvs.length, ii=0; ii<nn; ii++) {
        remEventos(tO, tCEvs[ii]['tE'], tCEvs[ii]['tnF']);
      } tO.eventos[tCEv]=[];
    } return true;
  }
  //Recebendo informações sobre o evento
  var tnF=(tPs) ? function(e) { tF.apply(tO, Array(e).concat(tPs)); } : tF;
  if (tO.removeEventListener) { tO.removeEventListener(tE, tnF, (eCpt == 'nocapture')?false:true); }
  else if (document.detachEvent) { tO.detachEvent('on'+ tE, tnF); }
  else { tO["on"+ tE] = null; } return true;
}
function getSrc(e) { /* event */ return e.target || (window.event && event.srcElement); }
function getKeyCode(e) { /* event */ var ev=e || event; return ev.which || ev.keyCode || false; }
function getMouseButton(e) { if (!e) e = window.event; var z=0, keymap=Array();
  if (e.which != undefined) { z=e.which; keymap[1]='left'; keymap[2]='middle'; keymap[3]='right'; }
  else if (e.button != undefined) { z=e.button; keymap[1]='left'; keymap[4]='middle'; keymap[2]='right'; }
  else { return false; } return keymap[z];
}
function poin(e) { try { e.preventDefault(); } catch(e) { try { event.returnValue=false; } catch(e) { } } return false; }
function valorValido(tV) { /* theValue */ return new RegExp('[a-z0-9]','gi').test(tV); }
function RETest(tER, tV, tFs) { /* tRegExp, tValue, tFlags */ return new RegExp(tER, tFs || '').test(tV); }
function insertBefore(tN, nN) { /* tNode, newNode */ return tN.parentNode.insertBefore(nN, tN); }
function insertAfter(tN, nN) { /* tNode, newNode */ var tP=tN.parentNode;
  while ((tN=tN.nextSibling) && tN.nodeType != 1) { /* dã! */ }
  if (tN) { tP.insertBefore(nN, tN); } else { tP.appendChild(nN); } return tP.childNodes.length;
}
function childsOfType(tO, tT) { /* tParentObject, <string/arr tTag(s)> */ var i, n, tCs, tR=[];
  tT=new RegExp( (tT instanceof Array) ? tT.join('|') : tT , 'i');
  for (i=0, n=(tCs=tO.childNodes).length; i<n; i++) {
    if (tCs[i].nodeType==1 && tT.test(tCs[i].nodeName.toLowerCase())) tR[tR.length]=tCs[i];
  } return tR.length ? tR : false;
}
function firstParentOfType(tO, tT) { /* <node tObject>, <string/arr tTag(s)> */
  tT=new RegExp( (tT instanceof Array) ? tT.join('|') : tT , 'i');
  while (tO && (tO.nodeType != 1 || !tT.test(tO.nodeName.toLowerCase()))) { tO=tO.parentNode; }
  return tO || false;
}
function isDescendantOf(tO, tT) { while ((tO=tO.parentNode)) { if (tO == tT) { return true; } } return false; }

function sW(tS, sS) { /* (Bool) startsWith: theString, subString */
  return (tS && sS && tS.substring(0,sS.toString().length) == sS.toString()) ? true : false;
}
function addTok(tokList, tTok, tDiv, duplicate) { tDiv=tDiv || ' ';
  if (hasTok(tokList, tTok, tDiv) && !duplicate) { return tokList; }
  return ((tokList) ? (tokList + tDiv) : '') + tTok;
}
function hasTok(tokList, tTok, tDiv) { var n, i, tToks=tokList.split(tDiv || ' ');
  for (n=tToks.length; n--; ) { if (tToks[n] == tTok) { return true; } } return false;
}
function remTok(tokList, tTok, tDiv) { if (!tokList) return ''; var n, i, tRs=[]; tDiv=tDiv || ' ';
  var tToks=tokList.split(tDiv);
  for (n=tToks.length, i=0; i<n; i++) { if (tToks[i] != tTok) { tRs[tRs.length] = tToks[i]; } }
  return tRs.length ? tRs.join(tDiv) : '';
}
function getStyle(tO, tS) { /* tObject, tStylename */
  if (window.getComputedStyle) { return window.getComputedStyle(tO, null).getPropertyValue(tS); }
  else if (tO.currentStyle) { var tER=new RegExp('^([^\-]+)\-([a-z])(.*)$');
    tS=tS.replace(tER, '$1') + tS.replace(tER, '$2').toUpperCase() + tS.replace(tER, '$3');
    return tO.currentStyle[tS];
  }
  return false;
}
function round(tN, n) { tP=Math.pow(10, n); return Math.round(tN * tP) /tP; }
function getElementPos(tE) { var tR={x: 0, y: 0};
  do { tR['x']+=tE.offsetLeft; tR['y']+=tE.offsetTop; tE=tE.offsetParent; }
  while (tE && tE.nodeName.toLowerCase() != 'body'); return tR;
}
function getScrollPos(tW) { var ret=Array(); if (!tW) { tW=window; }
  if (tW.pageYOffset) { ret['x']=tW.pageXOffset; ret['y']=tW.pageYOffset; } //all except Explorer
  else if (tW.document.documentElement && tW.document.documentElement.scrollTop) { // Explorer 6 Strict
	  ret['x']=tW.document.documentElement.scrollLeft; ret['y']=tW.document.documentElement.scrollTop; }
  else if (tW.document.body) { ret['x']=tW.document.body.scrollLeft; ret['y']=tW.document.body.scrollTop; } //all other Explorers
  return ret;
}
function setScrollPos(pos, tE) { if (!tE) tE=document;
  if (tE.documentElement && tE.documentElement.scrollTop) { tE=tE.documentElement; }
  else if (tE.body) { tE=tE.body; } else if (!tE.offsetLeft) { tE=0; }
  if (tE) {
    if (typeof(pos['x']) != 'undefined') { tE.scrollLeft=pos['x']; }
    if (typeof(pos['y']) != 'undefined') { tE.scrollTop=pos['y']; }
    return true;
  } else { return false; }
}
function getPageSize() { var size1=document.body.scrollHeight; var size2=document.body.offsetHeight;
  if (size1 > size2) { return {'x': document.body.scrollWidth, 'y': document.body.scrollHeight}; /* all but Explorer Mac */ }
  else { return {'x': document.body.offsetWidth, 'y': document.body.offsetHeight}; /* Explorer Mac */ }
}
function getViewportSize(tW) { var ret=Array(); tW=tW || window;
  if (tW.innerWidth) { return {'x': tW.innerWidth, 'y': tW.innerHeight}; }
  else if (tW.document.documentElement && tW.document.documentElement.clientWidth) {
    return {'x': tW.document.documentElement.clientWidth, 'y': tW.document.documentElement.clientHeight};
  }
  else if (tW.document.body) { return {'x': tW.document.body.clientWidth, 'y': tW.document.body.clientHeight}; }
  else { return false; }
}
function getEventXY(e) { // Retornar a posição X/Y da ocorrência de um evento
  if (e.pageX && e.pageY) { return {'x': e.pageX, 'y': e.pageY }; }
  else if (e.clientX && e.clientY)  {
    var pox=e.clientX +document.body.scrollLeft +document.documentElement.scrollLeft;
    var posy=e.clientY +document.body.scrollTop  +document.documentElement.scrollTop;
    return {'x': posx, 'y': posy };
  } return false;
}

function XMLHTTPRequest() { //Criação de objeto XMLHTTPRequest cross-browser
  if (window.XMLHttpRequest) { return new XMLHttpRequest(); } //Objeto nativo (FF/Safari/Opera7.6+)
  else {
    var ts=['Microsoft.XMLHTTP', 'MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
    for (var n=ts.length, i=0; i<n; i++) {
      try { return new ActiveXObject(ts[i]); } catch(e) { }
    }
    return undefined;
  }
}
//void makeXHRCall : makes a XMLHTTPRequest and configure the callback function with optional parameters
//  object t(XHR)Object, string tURL, string tMethod ("POST" | "GET")
//  [, string tContents(ToSend) [, array tHeaders (array of arrays in pair format: "['name', 'value']")
//  [, function t(Callback)Function [, boolean tReturn(Type) [, array t(aditional)Params(ToCallBack) ]]] ]]
//    - tHeaders: an array containing other arrays with two indexes: 0) Header Name, and 1) Header Value
//    - tReturn(Type): 0 = responseText. 1 = responseXML.
function makeXHRCall(tO, tU, tM, tC, tHs, tF, tR, tPs) { if (!tO || !tU) { return false; } if (!tHs) tHs=[]; var i, n;
  if (tF) tO.onreadystatechange=XHRStateChanged.bind(tO, [tF, tPs]);
  tO.open((tM || 'GET'), tU, true);
  for (i=0, n=tHs.length; i<n; i++) { tO.setRequestHeader(tHs[i][0], tHs[i][1]); }
  tO.send(tC || null);
  return void(null);
}
function XHRStateChanged(tF, tPs, tRT) { //function tFunction [, array Params [, boolean tReturnType]]
  if (this.readyState == 4) { if (this.status == 200) {
    //Definir retorno do XHR como primeiro parâmetro da chamada da função callBack
    tPs=tPs || Array(); tPs.unshift( (this[(tRT) ? 'responseHTML' : 'responseText' ]) ); tF.apply(window, tPs);
  } else { return false; } }
  return true;
}