<!--

function FindObject(n, d) {
  var p, i, x; if ( !d ) d = document;
  if ( ( p = n.indexOf("?") ) > 0 && parent.frames.length ) {
    d = parent.frames[n.substring(p+1)].document; 
    n = n.substring(0, p);
  }
  if ( !( x = d[n] ) && d.all ) x = d.all[n];
  for ( i = 0; !x && i < d.forms.length; i++ ) x = d.forms[i][n];
  for ( i = 0; !x && d.layers && i < d.layers.length; i++ ) x = FindObject(n, d.layers[i].document);
  if ( !x && d.getElementById ) x = d.getElementById(n);
  return x;
}

function ValidateForm() {
  var k = 0, i, p, q, nm, test, val, num, vmin, vmax, errors = "", args = ValidateForm.arguments;
  for ( i = 0; i < ( args.length - 2 ); i += 3 ) {
    test = args[i+2]; val = FindObject(args[i]);
    if ( val ) {
      nm = ( args[i+1] != "" )?args[i+1]:val.name; nm = "" + VldFIELD + " " + nm;
      if ( val.type == "select-one" || val.type == "select-multiple" ) {
        if ( val.options && val.selectedIndex <= 0 ) errors += "- " + nm + " " + VldSELECTED + ".\n";
      } else {
        //if ( trim(( val = val.value ), " ") != "" ) {
        val = val.value;
        if ( trim(val, " ") != "" ) {
          if ( test.indexOf("isEmail") != -1 ) {
            p = val.indexOf("@"); if ( p < 1 || p == ( val.length - 1 ) ) errors += "- " + nm + " " + VldEMAIL + ".\n";
          } else if ( test != "R" ) {
            p = val.indexOf(","); if ( p != -1 ) val = val.substring(0, p) + "." + val.substring(p + 1);
            num = parseFloat(val); if ( val != "" + num && val.indexOf(".") == -1 ) errors += "- " + nm + " " + VldNUMBER + ".\n";
            if ( test.indexOf("inRange") != -1 ) {
              p = test.indexOf(":"); vmin = parseFloat(test.substring(8,p)); vmax=parseFloat(test.substring(p+1));
              if ( num < vmin || vmax < num ) errors += "- " + nm + " " + VldNUMBER + " " + VldBETWEEN + " " + vmin + " " + VldAND + " " + vmax + ".\n";
            }
          }
        } else if ( test.charAt(0) == "R" ) errors += "- " + nm + " " + VldREQUIRED + ".\n";
      }
    }
  }
  return errors;
}

function trim(str, chars) {
  return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
  chars = chars || "\\s";
  return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
  chars = chars || "\\s";
  return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function cnum(str) {
  p = str.indexOf(","); if ( p != -1 ) str = str.substring(0, p) + "." + str.substring(p + 1);
  return str;
}

function ReloadWindow() {
  window.location.reload();
}

function ReloadImage(n) {
  var img = FindObject(n);
  if ( img ) {
    var src = img.src;
    var i = src.indexOf("?");
    if ( i >= 0 ) src = src.substring(0, i);
    img.src = src + "?" + Math.random();
  }
}

function getPositionTop(element) {
  var offset = 0; 
  while ( element ) { 
    offset += element["offsetTop"]; 
    element = element.offsetParent; 
  } 
  return offset; 
} 
 
function isElementVisible(eltId) {
  var elt = document.getElementById(eltId); 
  if ( !elt ) return false; 
  var posTop = getPositionTop(elt); 
  var posBottom = posTop + elt.offsetHeight; 
  var visibleTop = document.body.scrollTop; 
  var visibleBottom = visibleTop + document.documentElement.offsetHeight; 
  return ( ( posBottom >= visibleTop ) && ( posTop <= visibleBottom ) ); 
}

function DataAction() {
  var args = DataAction.arguments, actn = "", errors = "";
  if ( args[0] ) {
    if ( typeof(args[0]) == "object" ) {
      args[0].blur();
      if ( args[0].name != "" ) actn = args[0].name.toUpperCase();
      else actn = args[0].value.toUpperCase();
    } else actn = args[0];
  }
  switch ( actn ) {
    case "COTACAO":
      var codprod = args[1];
      var codcat = args[2];
      var frm = FindObject("produto"); if ( frm ) {
        frm.action = "fale_conosco.asp";
        addproduto2(codprod, codcat);
      }
      return void(0);
      break;
    case "DOCS":
    case "DRIVERS":
    case "FAQ":
    case "DESCRICAO":
      if ( args[2] == "1" ) alert(VldRESTRICTED);
      else {
        var DIV = FindObject("DIV_DESCRICAO"); if ( DIV ) DIV.style.display = "none";
        DIV = FindObject("DIV_DOCS"); if ( DIV ) DIV.style.display = "none";
        DIV = FindObject("DIV_DRIVERS"); if ( DIV ) DIV.style.display = "none";
        DIV = FindObject("DIV_FAQ"); if ( DIV ) DIV.style.display = "none";
        DIV = FindObject("DIV_"+actn); if ( DIV ) DIV.style.display = "";
        if ( DIV ) { if ( !isElementVisible("DIV_"+actn) ) window.location.hash = actn; }
        //window.location.href = "produtos_descricao.asp?codigo_produto=" + args[1] + "&extra=" + actn + "#" + actn;
      }
      return void(0);
      break;
    case "SHOW":
      var DD = FindObject(args[1]); if ( DD ) DD.style.display = ( DD.style.display != "" ) ? "" : "none";
      return void(0);
      break;
    case "ZZZ":
      //errors += ValidateForm("Email","","RisEmail");
      //if ( !errors && !confirm(VldCONFIRM) ) return false;
      break;
    default:
      return void(0);
      break;
  }
  if ( errors ) {
    alert("" + VldALERT + ":\n\n" + errors);
    return false;
  } else {
    var frm = FindObject("FormData");
    if ( frm ) frm.submit();
  }
}

var ajaxRequest;

function ajaxFunction() {
  try {
    ajaxRequest = new XMLHttpRequest();
    ajaxRequest.overrideMimeType('text/html');
    return true;
  } catch (e) {
    try {
      ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
      return true;
    } catch (e) {
      try {
        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
        return true;
      } catch (e) {
        alert("O navegador Internet não suporta AJAX.");
        return false;
      }
    }
  }
}

//-->

