<!-- 

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 = "" + nm;
      var gdr = nm.toLowerCase();
      gdr = gdr.substring(gdr.length-1,gdr.length);
      gdr = ( gdr == "a" || gdr == "e" )?"a":"o";
      if ( gdr == "s" ) {
        gdr = gdr.substring(gdr.length-2,gdr.length);
        gdr = ( gdr == "as" || gdr == "es" )?"as":"os";
      }
      if ( val.type == "select-one" || val.type == "select-multiple" ) {
        if ( val.options && val.selectedIndex <= 0 ) errors += "" + nm + " deve ser selecionad" + gdr + ".\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 + " deve conter um endereço eletrônico.\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 + " deve conter um número.\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 + " deve conter um número entre " + vmin + " e " + vmax + ".\n";
            }
          }
        } else if ( test.charAt(0) == "R" ) errors += "" + nm + " deve" + ((gdr.length>1)?"m":"") + " ser informad" + gdr + ".\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 AddLoadEvent(func) {
  var oldonload = window.onload;
  if ( typeof window.onload != "function" ) window.onload = func;
  else {
    window.onload = function() {
      if ( oldonload ) oldonload();
      func();
    }
  }
}

function GetAction(args) {
  if ( args[0] ) {
    if ( typeof(args[0]) == "object" ) {
      args[0].blur();
      if ( args[0].name != "" ) return args[0].name.toUpperCase();
      else return args[0].value.toUpperCase();
    } else return args[0];
  }
}

var currFocus = "";

function GetFocus(arg) {
  if ( typeof(arg) == "object" ) currFocus = arg.name;
  else currFocus = "";
}

function NumKeypad() {
  var args = NumKeypad.arguments;
  if ( args.length == 1 ) {
    var Keypad = "", n, s = 10; w = 20, h = 20, stl = "font-size:" + s + "px;width:" + w + "px;height:" + h + "px";
    Keypad += "<table border=0 cellspacing=0 cellpadding=0><tr>";
    for ( n = 7; n <= 9; n++ ) Keypad += "<td><input type=button value=" + n + " class=NumKeyPad style=\"" + stl + "\" onclick=\"NumKeypad('" + args[0] + "',this);\" /></td>";
    Keypad += "</tr><tr>";
    for ( n = 4; n <= 6; n++ ) Keypad += "<td><input type=button value=" + n + " class=NumKeyPad style=\"" + stl + "\" onclick=\"NumKeypad('" + args[0] + "',this);\" /></td>";
    Keypad += "</tr><tr>";
    for ( n = 1; n <= 3; n++ ) Keypad += "<td><input type=button value=" + n + " class=NumKeyPad style=\"" + stl + "\" onclick=\"NumKeypad('" + args[0] + "',this);\" /></td>";
    Keypad += "</tr><tr>";
    Keypad += "<td colspan=2><input type=button value=0 class=NumKeyPad style=\"" + stl.replace("width:" + w, "width:" + (2*w)) + "\" onclick=\"NumKeypad('" + args[0] + "',this);\" /></td>";
    Keypad += "<td><input type=button value=\« class=NumKeyPad style=\"" + stl + "\" onclick=\"NumKeypad('" + args[0] + "',this);\" /></td>";
    Keypad += "</tr></table>";
  document.write(Keypad);
  }
  if ( args.length == 2 ) {
    args[1].blur();
    if ( !args[0] && currFocus ) var f = FindObject(currFocus);
    else var f = FindObject(args[0]);
    if ( f ) {
      f.focus();
      if ( !f.readOnly ) {
        if ( isNaN(args[1].value) ) f.value = f.value.substring(0, f.value.length - 1);
        else if ( f.value.length < f.maxLength ) f.value += args[1].value;
      }
    }
  }
}

function HtmlEncode(s) {
  var el = document.createElement("div");
  el.innerText = el.textContent = s;
  s = el.innerHTML;
  delete el;
  return s;
}

function HtmlDecode(s) {
  var el = document.createElement("div");
  el.innerHTML = s;
  s = el.innerText;
  delete el;
  return s;
}

function removeHTMLTags(s) {
  var strInputCode = s;
  strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1) { return ( p1 == "lt" ) ? "<" : ">"; });
  var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
  strTagStrippedText = strTagStrippedText.replace("\n","","g");
  //strTagStrippedText = strTagStrippedText.replace(new RegExp( "\\n", "g" ), " ... ");
  return strTagStrippedText;
}

function Loading(f,b) {
  var df; if ( !f ) df = document.all;
  else if ( typeof(f) == "object" ) df = f;
  else if ( isNaN(f) ) df = document.forms(f);
  else df = document.forms[f];
  for ( var i = 0; i < df.elements.length; i++ ) df.elements[i].disabled = b;
  df = FindObject("Loading"); if ( df ) df.style.display = ( b )?"block":"none";
}

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;
      }
    }
  }
}

//-->

