Mascaras = {
IsIE: navigator.appName.toLowerCase().indexOf('microsoft')!=-1,
AZ: /[A-Z]/i,
Acentos: /[À-ÿ]/i,
Num: /[0-9]/,
carregar: function(parte){
 var Tags = ['input','textarea'];
 if (typeof parte == "undefined") parte = document;
 for(var z=0;z<Tags.length;z++){
 Inputs=parte.getElementsByTagName(Tags[z]);
 for(var i=0;i<Inputs.length;i++)
  if(('button,image,hidden,submit,reset').indexOf(Inputs[i].type.toLowerCase())==-1)
   this.aplicar(Inputs[i]);
 }
},
aplicar: function(campo){
 tipo = campo.getAttribute('tipo');
 if (!tipo || campo.type == "select-one") return;
 orientacao = campo.getAttribute('orientacao');
 mascara = campo.getAttribute('mascara');
 if (tipo.toLowerCase() == "decimal"){
 orientacao = "esquerda";
 casasdecimais = campo.getAttribute('casasdecimais');
 tamanho = campo.getAttribute('maxLength');
 if (!tamanho || tamanho > 50)
  tamanho = 10;
 if (!casasdecimais)
  casasdecimais = 2;
 campo.setAttribute("mascara", this.geraMascaraDecimal(tamanho,
casasdecimais));
 campo.setAttribute("tipo", "numerico");
 campo.setAttribute("orientacao", orientacao);
 }
 if (orientacao && orientacao.toLowerCase() == "esquerda")
campo.style.textAlign = "right";
 if (mascara) campo.setAttribute("maxLength", mascara.length);
 if (tipo){
 campo.onkeypress = function(e){ return Mascaras.onkeypress(e?e:event); };
 campo.onkeyup = function(e){ Mascaras.onkeyup(e?e:event, campo) };
 }
 campo.setAttribute("snegativo", ((campo.value).substr(0,1) == "-" ?
"s" : "n"));
},
onkeypress: function(e){
 KeyCode = this.IsIE ? event.keyCode : e.which;
 campo =  this.IsIE ? event.srcElement : e.target;
 readonly = campo.getAttribute('readonly');
 if (readonly) return;
 maxlength = campo.getAttribute('maxlength');
 pt = campo.getAttribute('pt');
 selecao = this.selecao(campo);
 if (selecao.length > 0 && KeyCode != 0){
 campo.value = ""; return true;
 }
 if (KeyCode == 0) return true;
 Char = String.fromCharCode(KeyCode);
 valor = campo.value;
 mascara = campo.getAttribute('mascara');
 if (KeyCode != 8){
 tipo = campo.getAttribute('tipo').toLowerCase();
 negativo = campo.getAttribute('negativo');
 if(negativo && KeyCode == 45){
  snegativo = campo.getAttribute('snegativo');
  snegativo = (snegativo == "s" ? "n" : "s");
  campo.setAttribute("snegativo", snegativo);
 }else{
  valor += Char
  if (tipo == "numerico" && Char.search(this.Num) == -1) return false;
  if (KeyCode != 32 && tipo == "caracter" && Char.search(this.AZ) ==
-1 && Char.search(this.Acentos) == -1) return false;
 }
 }
 if (mascara){
 this.aplicarMascara(campo, valor);
 return false;
 }
 return true;
},
onkeyup: function(e, campo){
 KeyCode = this.IsIE ? event.keyCode : e.which;
 if (KeyCode != 9 && KeyCode != 16 && KeyCode != 109){
 valor = campo.value;
 if (KeyCode == 8 && !this.IsIE) valor = valor.substr(0,valor.length-1);
 this.aplicarMascara(campo, valor);
 }
},
aplicarMascara: function(campo, valor){
 mascara = campo.getAttribute('mascara');
 if (!mascara) return;
 negativo = campo.getAttribute('negativo');
 snegativo = campo.getAttribute('snegativo');
 if (negativo && valor.substr(0,1) == "-")
 valor = valor.substr(1,valor.length-1);
 orientacao = campo.getAttribute('orientacao');
 var i = 0;
 for(i=0;i<mascara.length;i++){
 caracter = mascara.substr(i,1);
 if (caracter != "#") valor = valor.replace(caracter, "");
 }
 retorno = "";
 if (orientacao != "esquerda"){
 contador = 0;
 for(i=0;i<mascara.length;i++){
  caracter = mascara.substr(i,1);
  if (caracter == "#"){
   retorno += valor.substr(contador,1);
   contador++;
  }else
   retorno += caracter;
  if(contador >= valor.length) break;
 }
 }else{
 contador = valor.length-1;
 for(i=mascara.length-1;i>=0;i--){
  if(contador < 0) break;
  caracter = mascara.substr(i,1);
  if (caracter == "#"){
   retorno = valor.substr(contador,1) + retorno;
   contador--;
  }else
   retorno = caracter + retorno;
 }
 }
 if (negativo && snegativo == "s")
 retorno = "-" + retorno;
 campo.value = retorno;
},
geraMascaraDecimal: function(tam, decimais){
 var retorno = ""; var contador = 0; var i = 0;
 decimais = parseInt(decimais);
 for (i=0;i<(tam-(decimais+1));i++){
 retorno = "#" + retorno;
 contador++;
 if (contador == 3){
  retorno = "." + retorno;
  contador=0;
 }
 }
 retorno = retorno + ",";
 for (i=0;i<decimais;i++) retorno += "#";
 return retorno;
},
selecao: function(campo){
 if (this.IsIE)
 return document.selection.createRange().text;
 else
 return (campo.value).substr(campo.selectionStart,
(campo.selectionEnd - campo.selectionStart));
},
formataValor: function (valor, decimais){
 valor = valor.split('.');
 if (valor.length == 1) valor[1] = "";
 for(var i=valor[1].length;i<decimais;i++)
 valor[1] += "0";
 valor[1] = valor[1].substr(0,2);
 return (valor[0] + "." + valor[1]);
}
};

// ---------------------------------------------------------
// ---------------------------------------------------------
tbl1 = '<table bgcolor="#ffffff" cellspacing=2 width=400 height=252 cellpadding=0><tr><td nowrap style="background: url(images/loadp.gif) no-repeat center center">';
tbl2 = '</td></tr></table>';
tbl1a = '<table bgcolor="#ffffff" cellspacing=2 class="trans70" cellpadding=0 style="border:#fff 1px solid"><tr><td nowrap align="center">';
tbl2a = '</td></tr></table>';
document.offsetx = -220; document.offsety = 21; var x = 0; var y = 0; var snow = 0; var sw = 0; var cnt = 0; var dir = 1; var tr = 1; var ns4, ie4, ie5, ns6, over;
function iniciar_layer(){ns4 = (document.layers)? true:false; ie4 = (document.all)? true:false; ns6 = (!document.all && document.getElementById)? true:false; if(ie4){if(navigator.userAgent.indexOf('MSIE 5')>0 || navigator.userAgent.indexOf('MSIE 6')>0){ie5 = true;}else{ie5 = false;}}else{ie5 = false;} if (ns4) over = document.overDiv; if (ie4) over = overDiv.style; if (ns6) over = document.getElementById('overDiv').style; document.onmousemove = mouseMove; if (ns4) document.captureEvents(Event.MOUSEMOVE);}
function nd(){if(cnt >= 1){sw = 0}; if(sw == 0){snow = 0; hideObject(over);}else{cnt++;}}
function dif(exibir){layerWrite(exibir); disp();}
function disp(){if(snow == 0){if(dir == 2){moveTo(over,x+document.offsetx-(width/2),y+document.offsety);}if(dir == 1){moveTo(over,x+document.offsetx,y+document.offsety);} if (dir == 0){moveTo(over,x-document.offsetx-width,y+document.offsety);} showObject(over); snow = 1;}}
function mouseMove(e){if(ns4){x=e.pageX; y=e.pageY;} if(ie4){x=event.x; y=event.y;} if(ie5){x=event.x+document.body.scrollLeft; y=event.y+document.body.scrollTop;} if(ns6){x=e.pageX+10; y=e.pageY;} if(snow){if(dir == 2){moveTo(over,x+document.offsetx-(width/2),y+document.offsety);} if(dir == 1){moveTo(over,x+document.offsetx,y+document.offsety);} if(dir == 0){moveTo(over,x-document.offsetx-width,y+document.offsety);}}}
function layerWrite(txt){if(ns4){var lyr = document.overDiv.document; lyr.write(txt); lyr.close();}else if (ie4){document.all["overDiv"].innerHTML = txt;}	else if (ns6){document.getElementById("overDiv").innerHTML = txt}}
function showObject(obj){if (ns4) obj.visibility = "show"; else if (ie4) obj.visibility = "visible"; else if (ns6) obj.visibility = "visible";}
function hideObject(obj){if (ns4) obj.visibility = "hide"; else if (ie4) obj.visibility = "hidden"; else if (ns6) obj.visibility = "hidden";}
function moveTo(obj,xL,yL){obj.left = xL; obj.top = yL;}
function def(x,y){ document.offsetx = x; document.offsety = y; }
// ---------------------------------------------------------
// ---------------------------------------------------------

function confirma() {
  if (confirm("ATENÇÃO! Faça o login primeiro.\nDeseja fazer o login agora?")){
     location.href='?pagina=login';
  }
}

// -----

function conecta(ref){
req = null;
url = "verp.php?ref="+ref+"&";
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChangeBusca;
req.open("GET",url,true);
req.send(null);
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChangeBusca;
req.open("GET",url,true);
req.send();
}
} else {
function getHTTPObject() {
var req;
try {
 if (window.XMLHttpRequest) {
  req = new XMLHttpRequest();
  if (req.readyState == null) {
   req.readyState = 1;
   req.addEventListener("load", function () {
   req.readyState = 4;
   if (typeof req.onReadyStateChange == "function")
    req.onReadyStateChange();
   }, false);
  }
  return req;
 }

 if (window.ActiveXObject) {
  var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
  for (var i = 0; i < prefixes.length; i++) {
   try {
    req = new ActiveXObject(prefixes[i] + ".XmlHttp");
    return req;
   } catch (ex) {};
  }
 }
} catch (ex) {}
alert("XmlHttp Objects not supported by client browser");
}
req.onreadystatechange = processReqChangeBusca;
req.open("GET",url,true);
req.send();
}
}
function processReqChangeBusca(){
obj = document.getElementById("trp");
if (req.readyState == 4) {
if (req.status ==200) {
if(req.responseText==""){
//obj.innerHTML = "<BR><BR><BR><font color=\"red\"><i><b>Nenhuma informação cadastrada</b></i></font><BR><BR><BR><BR>";
} else {
obj.innerHTML = req.responseText;
}
} else {
obj.innerHTML = "<BR><BR>Houve um problema ao obter os dados: <BR> " + req.statusText;
}
}
}




function adiciona(ref,tp){
req = null;
window.tp = tp;
url = "add.php?ref="+ref+"&tp="+tp;
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChangeAdd;
req.open("GET",url,true);
req.send(null);
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChangeAdd;
req.open("GET",url,true);
req.send();
}
} else {
function getHTTPObject() {
var req;
try {
 if (window.XMLHttpRequest) {
  req = new XMLHttpRequest();
  if (req.readyState == null) {
   req.readyState = 1;
   req.addEventListener("load", function () {
   req.readyState = 4;
   if (typeof req.onReadyStateChange == "function")
    req.onReadyStateChange();
   }, false);
  }
  return req;
 }

 if (window.ActiveXObject) {
  var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
  for (var i = 0; i < prefixes.length; i++) {
   try {
    req = new ActiveXObject(prefixes[i] + ".XmlHttp");
    return req;
   } catch (ex) {};
  }
 }
} catch (ex) {}
alert("XmlHttp Objects not supported by client browser");
}
req.onreadystatechange = processReqChangeAdd;
req.open("GET",url,true);
req.send();
}
}
function processReqChangeAdd(){
if(window.tp=="2") { obj = document.getElementById("divcarrinho"); } else { obj = document.getElementById("divcarrinho2"); }
if (req.readyState == 4) {
if (req.status ==200) {
if(req.responseText==""){
obj.innerHTML = "";
} else {

obj.innerHTML = req.responseText;
updt();
}
} else {
obj.innerHTML = "Houve um problema ao obter os dados: " + req.statusText;
}
}
}

function updt(){ req = null; url = "updt.php";
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChangeUpdt;
req.open("GET",url,true); req.send(null);
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) { req.onreadystatechange = processReqChangeUpdt;
req.open("GET",url,true);
req.send();
}  } else {
function getHTTPObject() {  var req;
try {
 if (window.XMLHttpRequest) {
  req = new XMLHttpRequest();
  if (req.readyState == null) {
   req.readyState = 1;
   req.UpdtEventListener("load", function () {
   req.readyState = 4;
   if (typeof req.onReadyStateChange == "function")
    req.onReadyStateChange();
   }, false);
  }
  return req;
 }

 if (window.ActiveXObject) {
  var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
  for (var i = 0; i < prefixes.length; i++) {
   try {
    req = new ActiveXObject(prefixes[i] + ".XmlHttp");
    return req;
   } catch (ex) {};
  }
 }
} catch (ex) {}
alert("XmlHttp Objects not supported by client browser");
}
req.onreadystatechange = processReqChangeUpdt;
req.open("GET",url,true);
req.send();
}
}
function processReqChangeUpdt(){
obj = document.getElementById("sqtde");
if (req.readyState == 4) {
if (req.status ==200) {
if(req.responseText==""){
obj.innerHTML = "";
} else {
obj.innerHTML = req.responseText;
}
} else {
obj.innerHTML = "Houve um problema ao obter os dados: " + req.statusText;
}
}
}

// -----------
function d(v){
    var cc = document.getElementById(v);
    cc.style.display = '';
}
function f(v){
    var cc = document.getElementById(v);
    cc.style.display = 'none';
}
