// Botoes de formulario

var btFirstClick = true;

function mkBtRunOnce(nome, action){
  action = action.replace(/.submit\(\)/gi,".submit(),btFirstClick=false");
  action = action.replace(/history.back\(\)/gi,"btFirstClick=false,history.back()");
  action = action.replace(/history.go\(/gi,"btFirstClick=false,history.go(");
  action = action.replace(/enviar\(/gi,"btFirstClick=false,enviar(");
  str='<table border=0 cellspacing=0 cellpadding=0><tr><td><img src="/b2c/img/bt_esq.gif" width=7 height=16></td><td class="bt-bg"><a href="javascript:'+action+'" onclick="return btFirstClick;" class="link-bt" onmouseover="window.status=\'www.tam.com.br\';return true"><b>'+nome+'</b></a></td><td><img src="/b2c/img/bt_dir.gif" width=7 height=16></td></tr></table>';
  document.write(str);
}

function mkBtImgRunOnce(nome, idioma, action){
  action = action.replace(/.submit\(\)/gi,".submit(),btFirstClick=false");
  action = action.replace(/history.back\(\)/gi,"btFirstClick=false,history.back()");
  action = action.replace(/history.go\(/gi,"btFirstClick=false,history.go(");
  action = action.replace(/enviar\(/gi,"btFirstClick=false,enviar(");
  str ='<table id='+nome+' border=0 cellspacing=0 cellpadding=0><tr><td><a href="javascript:'+action+'" onclick="return btFirstClick;" class="link-bt" onmouseover="window.status=\'www.tam.com.br\';return true"><img src="/b2c/vgn/img/nb_botao/' + idioma + '_' + nome + '.gif" border="0"></a></td></tr></table>';
  document.write(str);
}

function mkBtImgRunOnceWithPath(nome, idioma, action, path){
  action = action.replace(/.submit\(\)/gi,".submit(),btFirstClick=false");
  action = action.replace(/history.back\(\)/gi,"btFirstClick=false,history.back()");
  action = action.replace(/history.go\(/gi,"btFirstClick=false,history.go(");
  action = action.replace(/enviar\(/gi,"btFirstClick=false,enviar(");
  var append = '';
  if(idioma != '') append = '_';
    str ='<table id='+nome+' border=0 cellspacing=0 cellpadding=0><tr><td><a href="javascript:'+action+'" onclick="return btFirstClick;" class="link-bt" onmouseover="window.status=\'www.tam.com.br\';return true"><img src="' + path + idioma + append + nome + '.gif" border="0"></a></td></tr></table>';
     
 // str='<table border=0 cellspacing=0 cellpadding=0><tr><td><img src="/b2c/img/bt_esq.gif" width=7 height=16></td><td class="bt-bg"><a href="javascript:'+action+'" onclick="return btFirstClick;" class="link-bt" onmouseover="window.status=\'www.tam.com.br\';return true"><b>'+nome+'</b></a></td><td><img src="/b2c/img/bt_dir.gif" width=7 height=16></td></tr></table>';
  document.write(str);
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
  }

  function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
    if(arr[index] == ele)
    found = true;
    else
    index++;
    return found;
  }

  function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input)index = i;
    else i++;
    return index;
  }
  return true;
}

//[FAR 13/08/2009] - REQ46 - Fábrica Accenture - Fim
function mkBtImgRunOnceClass(nome, idioma, action, className){
  action = action.replace(/.submit\(\)/gi,".submit(),btFirstClick=false");
  action = action.replace(/history.back\(\)/gi,"btFirstClick=false,history.back()");
  action = action.replace(/history.go\(/gi,"btFirstClick=false,history.go(");
  action = action.replace(/enviar\(/gi,"btFirstClick=false,enviar(");
  str ='<a href="javascript:'+action+'" onclick="return btFirstClick;" class="' + className + '" onmouseover="window.status=\'www.tam.com.br\';return true"><img src="/b2c/vgn/img/nb_botao/' + idioma + '_' + nome + '.gif" border="0" style="display:block"></a>';
  document.write(str);
}
//[FAR 13/08/2009] - REQ46 - Fábrica Accenture - Fim