document.onmousemove = function(){
   window.status = "";
}
function gbid(e){
	return document.getElementById(e);
}
function al_f(obj, msg){
	alert(msg);
	gbid(obj).focus();
}
function element_exist(element){
	if(gbid(element) != null)
		return 1;
   else
		return 0;
}
function returnPosElement(obj, angle){
	var objRef = gbid(obj);
   var refX   = objRef.offsetLeft;
   var refY   = objRef.offsetTop;
   aux        = objRef.offsetParent;
   while(aux){
      refX += aux.offsetLeft;
      refY += aux.offsetTop;
      aux   = aux.offsetParent;
   }
   return angle=='x'?refX:refY;
}
function mascaraCNPJ(Campo, teclapres){
   var tecla = teclapres.keyCode;
   var vr = new String(Campo.value);
   vr = vr.replace(".", "");
   vr = vr.replace(".", "");
   vr = vr.replace("/", "");
   vr = vr.replace("-", "");
   tam = vr.length + 1 ;
   if(tecla != 9 && tecla != 8){
      if(tam > 2 && tam < 6)
         Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
      if(tam >= 6 && tam < 9)
         Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(5,tam-5);
      if(tam >= 9 && tam < 13)
         Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(5, 3) + '/' + vr.substr(8, tam - 8);
      if(tam >= 13 && tam < 20)
         Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(5, 3) + '/' + vr.substr(8, 4)+ '-' + vr.substr(12, 2);
   }
}
function mascaraCPF(Campo, teclapres){
   var tecla = teclapres.keyCode;
   var vr = new String(Campo.value);
   vr = vr.replace(".", "");
   vr = vr.replace(".", "");
   vr = vr.replace("-", "");
   tam = vr.length + 1;
   if(tecla != 9 && tecla != 8){
      if(tam > 3 && tam < 6)
         Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
      if(tam >= 7 && tam < 8)
         Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, 3) + '.' + vr.substr(6, tam - 6);
      if(tam >= 10 && tam < 16)
         Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, 3) + '.' + vr.substr(6, 3) + '-' + vr.substr(9, 2);
   }
}
function mascaraCEP(Campo, teclapres){
   var tecla = teclapres.keyCode;
   var vr = new String(Campo.value);
   vr = vr.replace("-", "");
   tam = vr.length + 1 ;
   if(tecla != 9 && tecla != 8)
      if(tam > 5)
         Campo.value = vr.substr(0, 5) + '-' + vr.substr(5, 3);
}
function mascaraTel(Campo, teclapres){
   var tecla = teclapres.keyCode;
   var vr = new String(Campo.value);
   vr = vr.replace("-", "");
   tam = vr.length + 1 ;
   if(tecla != 9 && tecla != 8)
      if(tam > 4)
         Campo.value = vr.substr(0, 4) + '-' + vr.substr(4, 4);
}
function mascaraDATA(Campo, teclapres){
   var tecla = teclapres.keyCode;
   var vr = new String(Campo.value);
   vr = vr.replace("/", "");
   vr = vr.replace("/", "");
   tam = vr.length + 1 ;
   if(tecla != 9 && tecla != 8){
      if(tam > 2 && tam < 4)
         Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);
      if(tam >= 5 && tam < 10)
         Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2) + '/' + vr.substr(4, 4);
   }
}
function mascaraHORA(Campo, teclapres){
   var tecla = teclapres.keyCode;
   var vr = new String(Campo.value);
   vr = vr.replace("/", "");
   vr = vr.replace("/", "");
   tam = vr.length + 1 ;
   if(tecla != 9 && tecla != 8)
      if(tam > 2 && tam < 4)
         Campo.value = vr.substr(0, 2) + 'h' + vr.substr(2, tam);
}
function virgulaPonto(value, campo){
   gbid(campo).value = value.replace(",", ".");
}
function formataValor(campo, tammax, teclapres){
   var tecla = teclapres.keyCode;
   var vr = campo.value;
   vr = vr.replace("/", "");
   vr = vr.replace("/", "");
   vr = vr.replace(",", "");
   vr = vr.replace(".", "");
   vr = vr.replace(".", "");
   vr = vr.replace(".", "");
   vr = vr.replace(".", "");
   tam = vr.length;
   if(tam < tammax && tecla != 8)
      tam = vr.length + 1;
   if(tecla == 8 )
      tam = tam - 1;
   if(tecla == 8 || (tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105)){
      if(tam <= 2 )
         campo.value = vr;
      tam = tam - 1;
      if((tam > 2) && (tam <= 5))
         campo.value = vr.substr(0, tam - 2) + ',' + vr.substr(tam - 2, tam);
      if((tam >= 6) && (tam <= 8))
         campo.value = vr.substr(0, tam - 5) + '.' + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam);
      if((tam >= 9) && (tam <= 11))
         campo.value = vr.substr(0, tam - 8) + '.' + vr.substr(tam - 8, 3) + '.' + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam);
      if((tam >= 12) && (tam <= 14))
         campo.value = vr.substr(0, tam - 11) + '.' + vr.substr(tam - 11, 3) + '.' + vr.substr(tam - 8, 3) + '.' + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam);
      if((tam >= 15) && (tam <= 17))
         campo.value = vr.substr(0, tam - 14) + '.' + vr.substr(tam - 14, 3) + '.' + vr.substr(tam - 11, 3) + '.' + vr.substr(tam - 8, 3) + '.' + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam);
   }
}
function formataKg(campo, tammax,teclapres){
   var tecla = teclapres.keyCode;
   var vr = campo.value;
   vr = vr.replace("/", "");
   vr = vr.replace("/", "");
   vr = vr.replace(",", "");
   vr = vr.replace(".", "");
   vr = vr.replace(".", "");
   vr = vr.replace(".", "");
   vr = vr.replace(".", "");
   tam = vr.length;
   if(tam < tammax && tecla != 8)
      tam = vr.length + 1;
   if(tecla == 8)
      tam = tam - 1;
   if(tecla == 8 || (tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105)){
      if(tam <= 3 )
      campo.value = vr;
      tam = tam - 1;
      if((tam > 3) && (tam <= 6))
         campo.value = vr.substr(0, tam - 3) + ',' + vr.substr(tam - 3, tam);
      if((tam >= 7) && (tam <= 9))
         campo.value = vr.substr(0, tam - 6) + '.' + vr.substr(tam - 6, 3) + ',' + vr.substr(tam - 3, tam);
      if((tam >= 10) && (tam <= 12))
         campo.value = vr.substr(0, tam - 9) + '.' + vr.substr(tam - 9, 3) + '.' + vr.substr(tam - 3, 3) + ',' + vr.substr(tam - 3, tam);
      if((tam >= 13) && (tam <= 15))
         campo.value = vr.substr(0, tam - 12) + '.' + vr.substr(tam - 12, 3) + '.' + vr.substr(tam - 9, 3) + '.' + vr.substr(tam - 6, 3) + ',' + vr.substr(tam - 3, tam);
      if((tam >= 16) && (tam <= 18))
         campo.value = vr.substr(0, tam - 15) + '.' + vr.substr(tam - 15, 3) + '.' + vr.substr(tam - 12, 3) + '.' + vr.substr(tam - 9, 3) + '.' + vr.substr(tam - 6, 3) + ',' + vr.substr(tam - 3, tam);
   }
}
function formataReais(valor){
   sign = (valor == (valor = Math.abs(valor)));
   valor = Math.floor(valor * 100 + 0.50000000001);
   cents = valor % 100;
   valor = Math.floor(valor / 100).toString();
   if(cents<10)
      cents = "0" + cents;
   for(var i = 0; i < Math.floor((valor.length - (1 + i)) / 3); i++)
      valor = valor.substring(0, valor.length - (4 * i + 3)) + '.' + valor.substring(valor.length - (4 * i + 3));
   valor = ((sign?'':'-') + valor + ',' + cents);
   return valor;
}
function validaCPF(valor){
   valor = valor.replace(".", "");
   valor = valor.replace(".", "");
   valor = valor.replace("-", "");
   cpf = valor;
   erro = new String;
   if(cpf.length < 11)
      return 0;
	if(cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
      return 0;
   var a = [];
   var b = new Number;
   var c = 11;
   for (i=0; i<11; i++){
      a[i] = cpf.charAt(i);
      if(i < 9)
         b += (a[i] * --c);
   }
   if((x = b % 11) < 2)
      a[9] = 0;
   else
      a[9] = 11-x;
   b = 0;
   c = 11;
   for(y=0; y<10; y++)
      b += (a[y] * c--); 
   if((x = b % 11) < 2)
      a[10] = 0;
   else
      a[10] = 11-x;
   if((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10]))
		return 0;
   else
      return 1;
}
function validaCNPJ(valor){
   var CNPJ = valor;
   erro = new String;
   if(CNPJ.length < 18)
      return 0;
   if((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-"))
      if(erro.length == 0)
         return 0;
   if(document.layers && parseInt(navigator.appVersion) == 4){
      x = CNPJ.substring(0,2);
      x += CNPJ.substring(3,6);
      x += CNPJ.substring(7,10);
      x += CNPJ.substring(11,15);
      x += CNPJ.substring(16,18);
      CNPJ = x; 
   }
   else{
      CNPJ = CNPJ.replace(".","");
      CNPJ = CNPJ.replace(".","");
      CNPJ = CNPJ.replace("-","");
      CNPJ = CNPJ.replace("/","");
   }
   var a = [];
   var b = new Number;
   var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
   for (i=0; i<12; i++){
      a[i] = CNPJ.charAt(i);
      b += a[i] * c[i+1];
   }
   if((x = b % 11) < 2)
      a[12] = 0;
   else
      a[12] = 11-x;
   b = 0;
   for (y=0; y<13; y++){
      b += (a[y] * c[y]); 
   }
   if((x = b % 11) < 2)
      a[13] = 0;
   else
      a[13] = 11-x;
   if((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13]))
		return 0;
   else
      return 1;
}
function show_campos(){
   if(gbid("TIPO_PESSOA").value == "F")
      hide_o("dados_j");
   if(gbid("TIPO_PESSOA").value == "J")
      show_o("dados_j");
   if(gbid("TIPO_PESSOA").value == "")
      hide_o("dados_j");
}
function scrolTop(){
   window.parent.scrollTo(0, 0);
}
function textCounter(field, countfield, maxlimit){
   if(field.value.length > maxlimit)
      field.value = field.value.substring(0, maxlimit);
   else 
      countfield.value = maxlimit - field.value.length;
}
function somenteNumeros(input){
   if((event.keyCode < 48)||(event.keyCode > 57))
      event.returnValue = false;
}
function imputUser(){
	var Acentos = "áàãââÁÀÃÂéêÉÊíÍóõôÓÔÕúüÚÜçÇ ´";
	var Traducao ="aaaaaaaaaeeeeiioooooouuuucc__";
	var Posic, Carac;
	var TempLog = "";
   var Campo = gbid("USUARIO").value;
	
	for(x=0; x<Campo.length; x++){
		Carac = Campo.charAt(x);
		Posic = Acentos.indexOf(Carac);
		if(Posic > -1)
			TempLog += Traducao.charAt(Posic);
		else
			TempLog += Campo.charAt(x);
	}
   gbid("USUARIO").value = TempLog.toLowerCase();
}
function show_o(obj){
	obj = gbid(obj);
   obj.style.visibility = "visible";
   obj.style.display    = "inline";
}
function show_o2(obj){
	obj = gbid(obj);
   obj.style.visibility = "visible";
}
function hide_o(obj){
	obj = gbid(obj);
   obj.style.visibility = "hidden";
   obj.style.display    = "none";
}
function hide_o2(obj){
	obj = gbid(obj);
   obj.style.visibility = "hidden";
}
function span_muda(element){
   document.all[element].style.color = "#FF0000";
}
function span_retorna(element){
   document.all[element].style.color = "";
}
function adjustLay(matrix, ajustar, add){
   objeto = document.all[ajustar];
   var objRef = gbid(matrix);
   var refX = objRef.offsetLeft;        
   aux = objRef.offsetParent;
   while(aux){
      refX += aux.offsetLeft;        
      aux = aux.offsetParent;
   }
   objeto.style.left = refX + add;
}
function select_cidades(estado, dir){
	ajax = new ajax_engine;
   if(ajax){
		gbid("CIDADE").options.length = 1;
      ajax.open("POST", dir + "includes/ajax_process.php", true);
      ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      ajax.onreadystatechange = function(){
         if(ajax.readyState == 4)
            if(ajax.responseXML)
               proces_cidade(ajax.responseXML);
      }
      var params = "acao=cidade_select&estado=" + estado;
      ajax.send(params);
   }
}
function proces_cidade(obj){
   var dataArray = obj.getElementsByTagName("cidades");
   if(dataArray.length > 0){
      for(i=0; i<dataArray.length; i++){
         var item  = dataArray[i];
         var value = item.getElementsByTagName("value")[0].firstChild.nodeValue;
         var text  = item.getElementsByTagName("text")[0].firstChild.nodeValue;
         var novo  = document.createElement("option");
         novo.setAttribute("id", "opcoes");
         novo.value = value;
         novo.text  = text;
         gbid("CIDADE").options.add(novo);
      }
   }
}
function dataAtual(){
	Hoje = new Date();
	Data = Hoje.getDate();
	Dia = Hoje.getDay();
	Mes = Hoje.getMonth();
	Ano = Hoje.getFullYear();
	if(Data < 10) 
		Data = "0" + Data;
	NomeDia = new Array(7)
	NomeDia[0] = "domingo"
	NomeDia[1] = "segunda-feira"
	NomeDia[2] = "terça-feira"
	NomeDia[3] = "quarta-feira"
	NomeDia[4] = "quinta-feira"
	NomeDia[5] = "sexta-feira"
	NomeDia[6] = "sábado"
	NomeMes = new Array(12)
	NomeMes[0] = "Janeiro"
	NomeMes[1] = "Fevereiro"
	NomeMes[2] = "Marco"
	NomeMes[3] = "Abril"
	NomeMes[4] = "Maio"
	NomeMes[5] = "Junho"
	NomeMes[6] = "Julho"
	NomeMes[7] = "Agosto"
	NomeMes[8] = "Setembro"
	NomeMes[9] = "Outubro"
	NomeMes[10] = "Novembro"
	NomeMes[11] = "Dezembro"
	document.write("Ribeirao Preto, "+ Data + " de " + NomeMes[Mes] + " de " + Ano);
}
//--- verifica senha
function testa_senha(valor){
   var erespeciais = /[@!#$%&*+=?|-]/;
   var ermaiuscula = /[A-Z]/;
   var erminuscula = /[a-z]/;
   var ernumeros = /[0-9]/;
   var cont = 0;
   if(erespeciais.test(valor))
      cont++;
   if(ermaiuscula.test(valor))
      cont++;
   if(erminuscula.test(valor))
      cont++;
   if(ernumeros.test(valor))
      cont++;
   if(valor.replace("_", "_"))
      cont++;
   return cont;
}
function recebe_senha(valor, return_in){
   var r = gbid(return_in);
   var c = testa_senha(valor);
   var t = valor.length;
   if(t == "")
      r.innerHTML = "";
   else{
      if(t > 7 && c >= 3)
         r.innerHTML = "<font color='green'>ALTA</font>";
      else{
         if(t > 7 && c >= 2 || t > 4 && c >= 3)
            r.innerHTML = "<font color='orange'>MEDIA</font>";
         else
            r.innerHTML = "<font color='red'>BAIXA</font>";
      }
   }
}
//--- ajax
function ajax_engine(){
   try{
      return new ActiveXObject("Microsoft.XMLHTTP");
   }
   catch(e){
      try{
         return new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch(ex){
         try{
            return new XMLHttpRequest();
         }
         catch(exc){
            alert("Esse browser não tem recursos para uso do AJAX");
            return false;
         }
      }
   }
}
//--- flash
if(Browser == undefined){
   var Browser = {
      isIE: function(){
         return(window.ActiveXObject && document.all && navigator.userAgent.toLowerCase().indexOf("msie") > -1  && navigator.userAgent.toLowerCase().indexOf("opera") == -1)?true:false;
      }
   }
}
var Flash = function(movie, id, width, height, initParams){
   this.html = "";
   this.attributes = this.params = this.variables = null;
   this.variables = new Array();
   this.attributes = {
   "classid": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
   "codebase": "http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab#version=8,0,22,0",
   "type": "application/x-shockwave-flash"
   }
   this.params = { "pluginurl": "http://www.macromedia.com/go/getflashplayer_br" };
      if(movie){
         this.addAttribute("data", movie);
         this.addParameter("movie", movie);
      }
      if(id && id != null)
          this.addAttribute("id", id);
      if(width)
          this.addAttribute("width", width);
      if(height)
          this.addAttribute("height", height);
      if(initParams != undefined){
         for(var i in initParams){
            this.addParameter(i.toString(), initParams[i]);
         }
      }
   }
   Flash.version = "1.2b";
   Flash.getObjectByExceptions = function(obj, excep){
   var tempObj = {};
   for(var i in obj){
      var inclui = true;
      for(var j=0; j<excep.length; j++)
         if(excep[j] == i.toString()){
              inclui = false;
              break;
           };
         if(inclui)
              tempObj[i] = obj[i];
      }
      return tempObj;
   }
   Flash.prototype.addAttribute = function(prop, val){ this.attributes[prop] = val; }
   Flash.prototype.addParameter = function(prop, val){ this.params[prop] = val; }
   Flash.prototype.addVariable = function(prop, val){ this.variables.push([prop, val]); }
   Flash.prototype.getFlashVars = function(){
   var tempString = new Array();
   for(var i=0; i<this.variables.length; i++)
      tempString.push(this.variables[i].join("="));
   return tempString.join("&");
}
Flash.prototype.toString = function(){
   this.params.flashVars = this.getFlashVars();
   if(Browser.isIE()){
      //IE
      this.html = "<object";
      var attr = Flash.getObjectByExceptions(this.attributes, ["type", "data"]);
      for(var i in attr)
         if(i.toString() != "extend")
             this.html += " " + i.toString() + " = \"" + attr[i] + "\"";
      this.html += "> ";
      var params = Flash.getObjectByExceptions(this.params, ["pluginurl", "extend"]);
      for(var i in params) if(i.toString() != "extend")
         this.html += "<param name=\"" + i.toString() + "\" value=\"" + params[i] + "\" /> ";
      this.html += " </object>";
   }
   else{
      //non-IE
      this.html = "<object";
      var attr = Flash.getObjectByExceptions(this.attributes, ["classid", "codebase"]);
      for(var i in attr)
          if(i.toString() != "extend")
              this.html += " " + i.toString() + " = \"" + attr[i] + "\"";
      this.html += "> ";
      var params = Flash.getObjectByExceptions(this.params, ["extend"]);
      for(var i in params)
          if(i.toString() != "extend")
              this.html += "<param name=\"" + i.toString() + "\" value=\"" + params[i] + "\" /> ";
      this.html += " </object>";
      }
      return this.html;
   }
   Flash.prototype.write = Flash.prototype.outIn = Flash.prototype.writeIn = function(w){
   if(typeof w == "string" && document.getElementById)
      var w = document.getElementById(w);
   if(w != undefined && w)
      w.innerHTML = this.toString();
   else
       document.write(this.toString());
}

