<!--
//#######################################################################//
//Fun?s utilizadas para inserir m?ara de data em um text e validar data
// Check browser version
var isNav4 = false, isNav5 = false, isIE4 = false
var strSeperator = "/";
// If you are using any Java validation on the back side you will want to use the / because
// Java date validations do not recognize the dash as a valid date separator.

var vDateType = 3; // Global value for type of date format
//                1 = mm/dd/yyyy
//                2 = yyyy/dd/mm  (Unable to do date check at this time)
//                3 = dd/mm/yyyy

var vYearType = 4; //Set to 2 or 4 for number of digits in the year for Netscape
var vYearLength = 2; // Set to 4 if you want to force the user to enter 4 digits for the year before validating.

var err = 0; // Set the error code to a default of zero


if(navigator.appName == "Netscape")
{
   if (navigator.appVersion < "5")
   {
      isNav4 = true;
      isNav5 = false;
	}
   else
   if (navigator.appVersion > "4")
   {
      isNav4 = false;
      isNav5 = true;
	}
}
else
{
   isIE4 = true;
}

function DateFormat(vDateName, vDateValue, e, dateCheck, dateType)  {

vDateType = dateType;

// vDateName = object name
// vDateValue = value in the field being checked
// e = event
// dateCheck
//       True  = Verify that the vDateValue is a valid date
//       False = Format values being entered into vDateValue only
// vDateType
//       1 = mm/dd/yyyy
//       2 = yyyy/mm/dd
//       3 = dd/mm/yyyy


   //Enter a tilde sign for the first number and you can check the variable information.
   if (vDateValue == "~")
   {
      alert("AppVersion = "+navigator.appVersion+" \nNav. 4 Version = "+isNav4+" \nNav. 5 Version = "+isNav5+" \nIE Version = "+isIE4+" \nYear Type = "+vYearType+" \nDate Type = "+vDateType+" \nSeparator = "+strSeperator);
      vDateName.value = "";
      vDateName.focus();
      return true;
   }

   var whichCode = (window.Event) ? e.which : e.keyCode;

   // Check to see if a seperator is already present.
   // bypass the date if a seperator is present and the length greater than 8
   if (vDateValue.length > 8 && isNav4)
   {
      if ((vDateValue.indexOf("-") >= 1) || (vDateValue.indexOf("/") >= 1))
         return true;
   }

   //Eliminate all the ASCII codes that are not valid
   var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/-";
   if (alphaCheck.indexOf(vDateValue) >= 1)
   {
      if (isNav4)
      {
         vDateName.value = "";
         vDateName.focus();
         vDateName.select();
         return false;
      }
      else
      {
         vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));
         return false;
      }
   }
   if (whichCode == 8) //Ignore the Netscape value for backspace. IE has no value
      return false;
   else
   {
      //Create numeric string values for 0123456789/
      //The codes provided include both keyboard and keypad values

      var strCheck = '47,48,49,50,51,52,53,54,55,56,57,58,59,95,96,97,98,99,100,101,102,103,104,105';
      if (strCheck.indexOf(whichCode) != -1)
      {
         if (isNav4)
         {
            if (((vDateValue.length < 6 && dateCheck) || (vDateValue.length == 7 && dateCheck)) && (vDateValue.length >=1))
            {
               alert("Data Inv?da. Redigite...");
               vDateName.value = "";
               vDateName.focus();
               vDateName.select();
               return false;
            }
            if (vDateValue.length == 6 && dateCheck)
            {
               var mDay = vDateName.value.substr(2,2);
               var mMonth = vDateName.value.substr(0,2);
               var mYear = vDateName.value.substr(4,4)

               //Turn a two digit year into a 4 digit year
               if (mYear.length == 2 && vYearType == 4)
               {
                  var mToday = new Date();

                  //If the year is greater than 30 years from now use 19, otherwise use 20
                  var checkYear = mToday.getFullYear() + 30;
                  var mCheckYear = '20' + mYear;
                  if (mCheckYear >= checkYear)
                     mYear = '19' + mYear;
                  else
                     mYear = '20' + mYear;
               }
               var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;

               if (!dateValid(vDateValueCheck))
               {
                  alert("Data Inv?da. Redigite...");
                  vDateName.value = "";
                  vDateName.focus();
                  vDateName.select();
                  return false;
		         }
               return true;

            }
            else
            {
               // Reformat the date for validation and set date type to a 1


               if (vDateValue.length >= 8  && dateCheck)
               {
                  if (vDateType == 1) // mmddyyyy
                  {
                     var mDay = vDateName.value.substr(2,2);
                     var mMonth = vDateName.value.substr(0,2);
                     var mYear = vDateName.value.substr(4,4)
                     vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;
                  }
                  if (vDateType == 2) // yyyymmdd
                  {
                     var mYear = vDateName.value.substr(0,4)
                     var mMonth = vDateName.value.substr(4,2);
                     var mDay = vDateName.value.substr(6,2);
                     vDateName.value = mYear+strSeperator+mMonth+strSeperator+mDay;
                  }
                  if (vDateType == 3) // ddmmyyyy
                  {
                     var mMonth = vDateName.value.substr(2,2);
                     var mDay = vDateName.value.substr(0,2);
                     var mYear = vDateName.value.substr(4,4)
                     vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
                  }

                  //Create a temporary variable for storing the DateType and change
                  //the DateType to a 1 for validation.

                  var vDateTypeTemp = vDateType;
                  vDateType = 1;
                  var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;

                  if (!dateValid(vDateValueCheck))
                  {
                     alert("Data Inv?da. Redigite...");
                     vDateType = vDateTypeTemp;
                     vDateName.value = "";
                     vDateName.focus();
                     vDateName.select();
                     return false;
		            }
                     vDateType = vDateTypeTemp;
                     return true;
	            }
               else
               {
                  if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1))
                  {
                     alert("Data Inv?da. Redigite...");
                     vDateName.value = "";
                     vDateName.focus();
                     vDateName.select();
                     return false;
                  }
               }
            }
         }
         else
         {
         // Non isNav Check
            if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1))
            {
               alert("Data Inv?da. Redigite...");
               vDateName.value = "";
               vDateName.focus();
               return true;
            }

            // Reformat date to format that can be validated. mm/dd/yyyy


            if (vDateValue.length >= 8 && dateCheck)
            {

               // Additional date formats can be entered here and parsed out to
               // a valid date format that the validation routine will recognize.

               if (vDateType == 1) // mm/dd/yyyy
               {
                  var mMonth = vDateName.value.substr(0,2);
                  var mDay = vDateName.value.substr(3,2);
                  var mYear = vDateName.value.substr(6,4)
               }
               if (vDateType == 2) // yyyy/mm/dd
               {
                  var mYear = vDateName.value.substr(0,4)
                  var mMonth = vDateName.value.substr(5,2);
                  var mDay = vDateName.value.substr(8,2);
               }
               if (vDateType == 3) // dd/mm/yyyy
               {
                  var mDay = vDateName.value.substr(0,2);
                  var mMonth = vDateName.value.substr(3,2);
                  var mYear = vDateName.value.substr(6,4)
               }
               if (vYearLength == 4)
               {
                  if (mYear.length < 4)
                  {
                     alert("Data Inv?da. Redigite...");
                     vDateName.value = "";
                     vDateName.focus();
                     return true;
                  }
               }

               // Create temp. variable for storing the current vDateType
               var vDateTypeTemp = vDateType;

               // Change vDateType to a 1 for standard date format for validation
               // Type will be changed back when validation is completed.
               vDateType = 1;

               // Store reformatted date to new variable for validation.
               var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;

               if (mYear.length == 2 && vYearType == 4 && dateCheck)
               {

                  //Turn a two digit year into a 4 digit year
                  var mToday = new Date();

                  //If the year is greater than 30 years from now use 19, otherwise use 20
                  var checkYear = mToday.getFullYear() + 30;
                  var mCheckYear = '20' + mYear;
                  if (mCheckYear >= checkYear)
                     mYear = '19' + mYear;
                  else
                     mYear = '20' + mYear;
                  vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;

                  // Store the new value back to the field.  This function will
                  // not work with date type of 2 since the year is entered first.

                  if (vDateTypeTemp == 1) // mm/dd/yyyy
                     vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;
                  if (vDateTypeTemp == 3) // dd/mm/yyyy
                     vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;

               }


               if (!dateValid(vDateValueCheck))
               {
                  alert("Data Inv?da. Redigite...");
                  vDateType = vDateTypeTemp;
                  vDateName.value = "";
                  vDateName.focus();
                  return true;
		         }
               vDateType = vDateTypeTemp;
               return true;

            }
            else
            {

               if (vDateType == 1)
               {
                  if (vDateValue.length == 2)
                  {
                     vDateName.value = vDateValue+strSeperator;
                  }
                  if (vDateValue.length == 5)
                  {
                     vDateName.value = vDateValue+strSeperator;
                  }
               }
               if (vDateType == 2)
               {
                  if (vDateValue.length == 4)
                  {
                     vDateName.value = vDateValue+strSeperator;
                  }
                  if (vDateValue.length == 7)
                  {
                     vDateName.value = vDateValue+strSeperator;
                  }
               }
               if (vDateType == 3)
               {
                  if (vDateValue.length == 2)
                  {
                     vDateName.value = vDateValue+strSeperator;
                  }
                  if (vDateValue.length == 5)
                  {
                     vDateName.value = vDateValue+strSeperator;
                  }
               }
               return true;
            }
         }
         if (vDateValue.length == 10   && dateCheck)
         {
            if (!dateValid(vDateName))
            {
// Un-comment the next line of code for debugging the dateValid() function error messages
//               alert(err);
               alert("Data Inv?da. Redigite...");
               vDateName.focus();
               vDateName.select();
	         }
         }
         return false;
      }
      else
      {
         // If the value is not in the string return the string minus the last
         // key entered.
         if (isNav4)
         {
            vDateName.value = "";
            vDateName.focus();
            vDateName.select();
            return false;
         }
         else
         {
            vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));
            return false;
         }
		}
	}
}


   function dateValid(objName) {
      var strDate;
      var strDateArray;
      var strDay;
      var strMonth;
      var strYear;
      var intday;
      var intMonth;
      var intYear;
      var booFound = false;
      var datefield = objName;
      var strSeparatorArray = new Array("-"," ","/",".");
      var intElementNr;
      // var err = 0;
      var strMonthArray = new Array(12);
      strMonthArray[0] = "Jan";
      strMonthArray[1] = "Fev";
      strMonthArray[2] = "Mar";
      strMonthArray[3] = "Abr";
      strMonthArray[4] = "Mai";
      strMonthArray[5] = "Jun";
      strMonthArray[6] = "Jul";
      strMonthArray[7] = "Ago";
      strMonthArray[8] = "Set";
      strMonthArray[9] = "Out";
      strMonthArray[10] = "Nov";
      strMonthArray[11] = "Dez";

      //strDate = datefield.value;
      strDate = objName;

      if (strDate.length < 1) {
         return true;
      }
      for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
         if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1)
         {
            strDateArray = strDate.split(strSeparatorArray[intElementNr]);
            if (strDateArray.length != 3)
            {
               err = 1;
               return false;
            }
            else
            {
               strDay = strDateArray[0];
               strMonth = strDateArray[1];
               strYear = strDateArray[2];
            }
            booFound = true;
         }
      }
      if (booFound == false) {
         if (strDate.length>5) {
            strDay = strDate.substr(0, 2);
            strMonth = strDate.substr(2, 2);
            strYear = strDate.substr(4);
         }
      }
      //Adjustment for short years entered
      if (strYear.length == 2) {
         strYear = '20' + strYear;
      }
      strTemp = strDay;
      strDay = strMonth;
      strMonth = strTemp;
      intday = parseInt(strDay, 10);
      if (isNaN(intday)) {
         err = 2;
         return false;
      }

      intMonth = parseInt(strMonth, 10);
      if (isNaN(intMonth)) {
         for (i = 0;i<12;i++) {
            if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
               intMonth = i+1;
               strMonth = strMonthArray[i];
               i = 12;
            }
         }
         if (isNaN(intMonth)) {
            err = 3;
            return false;
         }
      }
      intYear = parseInt(strYear, 10);
      if (isNaN(intYear)) {
         err = 4;
         return false;
      }
      if (intMonth>12 || intMonth<1) {
         err = 5;
         return false;
      }
      if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
         err = 6;
         return false;
      }
      if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
         err = 7;
         return false;
      }
      if (intMonth == 2) {
         if (intday < 1) {
            err = 8;
            return false;
         }
         if (LeapYear(intYear) == true) {
            if (intday > 29) {
               err = 9;
               return false;
            }
         }
         else {
            if (intday > 28) {
               err = 10;
               return false;
            }
         }
      }
         return true;
      }

   function LeapYear(intYear) {
      if (intYear % 100 == 0) {
         if (intYear % 400 == 0) { return true; }
      }
      else {
         if ((intYear % 4) == 0) { return true; }
      }
         return false;
      }
//#############################################################
// Outras Funcoes
//#############################################################
function JanelaGrafico(URLPrinc,Imagem,Legenda){
  var HTML = "<link rel='stylesheet' href='"+URLPrinc+"tige.css' type='text/css'>" +
    "<SCRIPT LANGUAGE='JavaScript' src='" + URLPrinc + "tige.js'></SCRIPT>" +
    "<img src='" + Imagem + "'><br><br><center>";
  if (!Legenda == "") {
    HTML = HTML + "<input type='button' value='Legenda' class='botao' onClick=\"" +
      "JavaScript:JanelaDetalhe('" + URLPrinc + "','" + Legenda + "')\">" +
      "&nbsp&nbsp&nbsp";
  }
  HTML = HTML + "<input type='button' value='Fechar' class='botao' onClick='" +
         "JavaScript:window.close()'></center>";
  popup = window.open(URLPrinc + "grafico.html","popDialog","width=520,height=570,scrollbars=no");
  popup.document.write(HTML);
  popup.document.close;
}

function OcultarAguarde() {
  if (navigator.appName == "Netscape") {
    document.getElementById('alerta').style.visibility="hidden";
  }
  else {
    alerta.style.visibility = "hidden";
  }
}

function MostrarAguarde() {
  if (navigator.appName == "Netscape") {
    document.getElementById('alerta').style.visibility="visible";
  }
  else {
    alerta.style.visibility = "visible";
  }
}


function LimpaUsuario() {
  document.fUserBd.UsuarioBD.selectedIndex = 0;
}






function EscRelatorio() {
	Retorno = "";
	if (document.fPermissoes.ckRelatorio.length > 0) {
		for (var i = 0; i < document.fPermissoes.ckRelatorio.length; i++) {
			if (document.fPermissoes.ckRelatorio[i].checked == true) {
				if (Retorno != "") {Retorno += ",";}
				Retorno += document.fPermissoes.ckRelatorio[i].value;
			}
		}
	}
	else if (document.fPermissoes.ckRelatorio.checked == true) {
		Retorno = document.fPermissoes.ckRelatorio.value;
	}
	document.fPermissoes.listaRelatorio.value = Retorno;
	document.fPermissoes.submit();
}

function EscGrupo() {
	Retorno = "";
	if (document.fPermissoes.ckGrupo.length > 0) {
		for (var i = 0; i < document.fPermissoes.ckGrupo.length; i++) {
			if (document.fPermissoes.ckGrupo[i].checked == true) {
				if (Retorno != "") {Retorno += ",";}
				Retorno += document.fPermissoes.ckGrupo[i].value;
			}
		}
	}
	else if (document.fPermissoes.ckGrupo.checked == true) {
		Retorno = document.fPermissoes.ckGrupo.value;
	}
	document.fPermissoes.listaGrupo.value = Retorno;
	document.fPermissoes.submit();
}

function MoveItem (intDir, strSel){
  var c = 0
  var frm = document.frmOrdem
  var iSel
  // check for items in select box
  if (document.frm[strSel].options.length<1){return false}
    // check that they only selected one item
    for (x = 0; x<document.frm[strSel].options.length; x++){
      if (document.frm[strSel].options(x).selected){
        c++
      }
    }
    if (c==0){return false}
    if (c>1){
    alert ('Please select 1 item at a time.')
    return false;
  }

  // Get the selected item
  for (x = 0; x<document.frm[strSel].options.length; x++){
    if (document.frm[strSel].options(x).selected ==  true){
      iSel = x
    }
  }

  // check for a selected item
  if (iSel<0){return false}

  // Check to make sure it is not the last
  if (iSel == document.frm[strSel].options.length-1 && intDir == 1){return false}

  // Check to make sure it is not the first
  if (iSel == 0 && intDir == -1){return false}

  /*
  Now see which way to move
  Move it down a spot if there are more options below it
  Make a temp variable to hold it
  */

  var strTempText = document.frm[strSel].options(iSel).text
  var strTempValue = document.frm[strSel].options(iSel).value
  // Move the one next to it into it's place
  document.frm[strSel].options(iSel).text =
  document.frm[strSel].options(iSel+intDir).text
  document.frm[strSel].options(iSel).value =
  document.frm[strSel].options(iSel+intDir).value
  // Now set the new position to have the save values
  document.frm[strSel].options(iSel+intDir).value = strTempValue
  document.frm[strSel].options(iSel+intDir).text = strTempText
  for (x = 0; x<document.frm[strSel].options.length; x++){
    document.frm[strSel].options(x).selected = false
  }
  document.frm[strSel].options(iSel+intDir).selected = true
}

function MoveContent (objSel){
  var frm = document.forms['frmOrdem']
  var z = document.frm.Campo.options.length-1
  for (x = 0;x<=z;x++){
    if (document.frm.Campo.options(x).selected){
      var oOption = document.createElement('OPTION')
      oOption.text = document.frm.Campo.options(x).text
      oOption.value = document.frm.Campo.options(x).value
      document.frm[objSel].add(oOption)
    }
  }
  for (x=z; x>=0;x--){
    if (document.frm.Campo.options(x).selected){
      document.frm.Campo.remove(x)
    }
  }
}

function RemoveContent (objSel){
  var frm = document.forms['frmOrdem']
  var z = document.frm[objSel].options.length-1

  for (x = 0;x<=z;x++){
    if (document.frm[objSel].options(x).selected){
      var oOption = document.document.createElement('OPTION')
      oOption.text = document.frm[objSel].options(x).text
      oOption.value = document.frm[objSel].options(x).value
      document.frm.Campo.add(oOption)
    }
  }
  for (x=z; x>=0;x--){
    if (document.frm[objSel].options(x).selected){
      document.frm[objSel].remove(x)
    }
  }
}

function checkForm(frm, selName){
  var sel = frm.elements[selName]
  var x = sel.options.length-1;
  for (y=0;y<=x;y++){
    sel.options[y].selected = true;
  }
}
 
function Aguarde() {
  if (navigator.appName == "Netscape") {
    document.getElementById('alerta').style.visibility="visible";
  }
  else {
    alerta.style.visibility = "visible";
  }
}

function OcultarAguarde() {
  if (navigator.appName == "Netscape") {
    document.getElementById('alerta').style.visibility="hidden";
  }
  else {
    alerta.style.visibility = "hidden";
  }
}
   
function EscCampo() {
	Retorno = "";
	if (document.fPermissoes.ckCampo.length > 0) {
		for (var i = 0; i < document.fPermissoes.ckCampo.length; i++) {
			if (document.fPermissoes.ckCampo[i].checked == true) {
				if (Retorno != "") {Retorno += ",";}
				Retorno += document.fPermissoes.ckCampo[i].value;
			}
		}
	}
	document.fPermissoes.listaCampo.value = Retorno;
	document.fPermissoes.submit();
}

function EscTabela() {
	Retorno = "";
	if (document.fPermissoes.ckTabela.length > 0) {
		for (var i = 0; i < document.fPermissoes.ckTabela.length; i++) {
			if (document.fPermissoes.ckTabela[i].checked == true) {
				if (Retorno != "") {Retorno += ",";}
				Retorno += document.fPermissoes.ckTabela[i].value;
			}
		}
	}
	document.fPermissoes.listaTabela.value = Retorno;
	document.fPermissoes.submit();
}
   
function MoveAcimaAbaixo(f,bDir,sName) {
  var el = f.elements[sName]
  var idx = el.selectedIndex
  if (idx==-1)
    alert("?necess?o selecionar apenas um item.")
  else {
    if (el[idx].value == "") {return;}
    var nxidx = idx+( bDir? -1 : 1)
    if (nxidx<0) nxidx=el.length-1
    if (nxidx>=el.length) nxidx=0
    if (el[nxidx].value == "") {return;}
    var oldVal = el[idx].value
    var oldText = el[idx].text
    el[idx].value = el[nxidx].value
    el[idx].text = el[nxidx].text
    el[nxidx].value = oldVal
    el[nxidx].text = oldText
    el.selectedIndex = nxidx
  }
}
   
//####################################################################//
//Outras Fun?s
//####################################################################//
function CampoVazio(Campo){
	if (Campo.value == "") {
		alert("Campo vazio!");
		Campo.focus();
		return false;
	}
	else
		return true;
}

function Consistir(Campo,Vazio){
	if (Campo.value == Vazio) {
		alert("Campo obrigatrio. Favor preench?o!");
		Campo.focus();
		return false;
	}
	else
		return true;
}

function VisuaReq(Link){
	popup = window.open(Link,"popDialog","height=200,width=400,top=100,left=300,scrollbars=no,toolbar=no,resizable=no");
}

function CampoPsq(Link){
	popup = window.open(Link,"popDialog","height=200,width=400,scrollbars=no,toolbar=no,resizable=no");
}

function AbreJanela(Link){
	popup = window.open(Link,"popDialog","width=600,height=400,top=100,left=100,scrollbars=yes,status=yes,toolbar=no,menubar=no,resizable=yes");
}

function SubmitLink(Link){
	document.formpsq.action = Link;
	document.formpsq.submit();
}

function AbreJanelaLinha(Link){
	popup = window.open(Link,"popDialog","width=600,height=400,top=100,left=100,scrollbars=yes,status=yes,toolbar=no,menubar=no,resizable=yes");
}


function JanelaDetalhe(Detalhe){
        var HTML = "<TITLE></TITLE>" +
          "<BODY BGCOLOR='ffffff'><CENTER>" +
          Detalhe +
          "<FORM><INPUT TYPE='BUTTON' VALUE='Fechar' onClick='self.close()'></FORM>" +
          "</CENTER></BODY>"
        popup = window.open("","popDialog","height=150,width=450,scrollbars=yes")
        popup.document.write(HTML)
        popup.document.close()
}


function fechar () {
		if (confirm("Tem certeza que deseja fechar esta janela?")) {
			self.close();
		}
}

function ConfirmaRemocao(Link) {
	if (confirm("Confirma a remoção deste cadastro?"))
		SubmitLink(Link);
}
         
function ConfirmaDesvinculacao(Link) {
	if (confirm("Tem certeza que deseja confirmar a desvinculação desse Cartão"))
		SubmitLink(Link);
}

function ConfirmaVinculacao(Link) {
	if (confirm("Tem certeza que deseja confirmar a vinculação desse Cartão"))
		SubmitLink(Link);
}

function ConfirmaLiberacao(Link) {
	if (confirm("Confirma a Disponibilização desse Cartão"))
		SubmitLink(Link);
}

function ConfirmaAssociacao(Link) {
	if (confirm("Confirma a Vinculação desse Cartão"))
		SubmitLink(Link);
}

function ConfirmaBloquear(Link) {
	if (confirm("Tem certeza que deseja bloquear esse Cartão"))
		SubmitLink(Link);
}

function ConfirmaEnviar(Link) {
	if (confirm("Confirma o envio dessa Requisição?"))
		SubmitLink(Link);
}

function ConfirmaSolicita2via(Link) {
	if (confirm("Confirma a solicitação de 2ª Via de Cartão(ões)?"))
		SubmitLink(Link);
}

function ConfirmaSolicitaEntrega(Link) {
	if (confirm("Confirma a solicitação de Entrega de 1ª Via de Cartão(ões)"))
		SubmitLink(Link);
}

function ConfirmaExcluirReq(Link) {
	if (confirm("Tem certeza que deseja excluir essa Requisição?"))
		SubmitLink(Link);
}

function ConfirmaExcluirDadosEscolares(Link) {
	if (confirm("Tem certeza que deseja excluir esses Dados Escolares?"))
		SubmitLink(Link);
}

function ConfirmaCancelarCredito(Link) {
	if (confirm("Tem certeza que deseja suspender os créditos dessa requisição, esta operação é irreversível?"))
		SubmitLink(Link);
}

function ConfirmaTransferirCredito(Link) {
	if (confirm("Tem certeza que deseja transferir essa requisição de crédito para outro Cartão"))
		SubmitLink(Link);
}

function ConfirmaTransferirCredito2(Link, NomeAtual,Quantidade,NovoNome) {
	Nome1 = NomeAtual;
  Nome2 = NovoNome;
  Quant = Quantidade;
	
  if (confirm("Confirma a Transferência da Requisição de " + Quant + " créditos do cartão " + Nome1 + " para o cartão " + Nome2 + " ?"))
		SubmitLink(Link);
}

function ConfirmaImprimirFale(Link) {
	if (confirm("Tem certeza que deseja imprimir essa mensagem?")) 
		SubmitLink(Link);
}

function ConfirmaFinalizarFale(Link) {
	if (confirm("Tem certeza que deseja Finalizar essa mensagem?")) 
		SubmitLink(Link);
}

function ConfirmaTransferencia(Link, EmpresaAtual,NovaEmpresa) {
	Empresa1 = EmpresaAtual;
  Empresa2 = NovaEmpresa;
	
  if (confirm("Confirma a Transferência desse Usuario da Empresa " + EmpresaAtual + " para a Empresa " + NovaEmpresa))
		SubmitLink(Link);
}

function AtualizaEmpresa(Link) {
		SubmitLink(Link);
}

// Ajuda: Teclas de Atalho
Ajuda_A = "Localizar = Alt+A";
Ajuda_P = "Pesquisar = Alt+P";
Ajuda_L = "Listar = Alt+L";
Ajuda_I = "Inserir = Alt+I";
Ajuda_R = "Remover = Alt+R";
Ajuda_S = "Salvar = Alt+S";
Ajuda_C = "Cancelar = Alt+C";
Ajuda_M = "Imprimir = Alt+M";
Ajuda_T = "Exportar TXT = Alt+T";
Ajuda_F = "Exportar PDF = Alt+F";
Ajuda_H = "Visualizar HTML = Alt + H";
Ajuda_N = "Nova = Alt+N";


function Ajuda(CampoAjuda,Botao) {
	CampoAjuda.value = eval("Ajuda_"+Botao);
}

function ConverteMaiuscula(Campo) {
	Campo.value = Campo.value.toUpperCase();
}

function LimpaCampo(Campo) {
	Campo.value = "";

}

function autoTab(input, e)  { 
  var ind = 0;
  var isNN = (navigator.appName.indexOf("Netscape")!=-1);
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var nKeyCode = e.keyCode; 
  if(keyCode == 13){ 
    if (!isNN) {window.event.keyCode = 0;} // evitar o beep
    ind = getIndex(input);
    if (input.form[ind].type == 'textarea') {
      return;
    }
    ind++;
    input.form[ind].focus(); 
    if (input.form[ind].type == 'text') {
      input.form[ind].select(); 
    }
  } 

  function getIndex(input) { 
    var index = -1, i = 0, found = false; 
    while (i < input.form.length && index == -1) 
      if (input.form[i] == input) {
        index = i;
       	if (i < (input.form.length -1)) {
      	  if (input.form[i+1].type == 'hidden') {
	    index++; 
	  }
	  if (input.form[i+1].type == 'button' && input.form[i+1].id == 'tabstopfalse') {
	    index++; 
	  }
	}
      }
      else 
	i++; 
    return index; 
  }
} 

function editMask(objForm, strField, sMask, evtKeyPress) {
  var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla, nTeclaDel;

  if(navigator.appName == "Netscape") { // Netscape
    nTecla = evtKeyPress.which;
    nTeclaDel = evtKeyPress.keyCode;
  }
  else {//if(document.layers) { // Internet Explorer
    nTecla = evtKeyPress.keyCode; 
  }

  if (nTecla == 13) return true;
  if (nTecla == 8) return true;
  if (nTeclaDel == 46) return true;
  
  sValue = objForm[strField].value;
  
  if (sValue.length == sMask.length) {return;}

  // Limpa todos os caracteres de formata? que
  // j?stiverem no campo.
  sValue = sValue.toString().replace( "-", "" );
  sValue = sValue.toString().replace( "-", "" );
  sValue = sValue.toString().replace( ".", "" );
  sValue = sValue.toString().replace( ".", "" );
  sValue = sValue.toString().replace( "/", "" );
  sValue = sValue.toString().replace( "/", "" );
  sValue = sValue.toString().replace( "(", "" );
  sValue = sValue.toString().replace( "(", "" );
  sValue = sValue.toString().replace( ")", "" );
  sValue = sValue.toString().replace( ")", "" );
  sValue = sValue.toString().replace( " ", "" );
  sValue = sValue.toString().replace( " ", "" );
  sValue = sValue.toString().replace( ":", "" );
  sValue = sValue.toString().replace( ":", "" );
  fldLen = sValue.length;
  mskLen = sMask.length;

  i = 0;
  nCount = 0;
  sCod = "";
  mskLen = fldLen;

  // Incluindo os caracteres da m?ara no valor digitado
  while (i <= mskLen) {
    bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
    bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
 
    if (bolMask) {
      sCod += sMask.charAt(i);
      mskLen++;
    }
    else {
      sCod += sValue.charAt(nCount);
      nCount++;
    }
    i++;
  }

  objForm[strField].value = sCod;

  if (nTecla != 8) { // backspace
    if (sMask.charAt(i-1) == "9") { // apenas nmeros...
      return ((nTecla > 47) && (nTecla < 58)); } // nmeros de 0 a 9
    else { // qualquer caracter...
      return true;
    }
  }
  else {
    return true;
  }
}

function zero(tam, dec) {
  var x = 0;
  var retorno = '';
  for (x = tam; x < dec; x++) {
    retorno += '0';
  }
  return retorno;
}

function editDecMask(fld, milSep, decSep, mask, e) {
  var dec = 0;
  var mskLen = 0;
  var sep = 0;
  var key = '';
  var i = j = 0;
  var len = len2 = 0;
  var strCheck = '0123456789';
  var aux = aux2 = '';
  var whichCode = (window.Event) ? e.which : e.keyCode;
  var whichCodeDel = (window.Event) ? e.keyCode : e.keyCode;
  if (whichCode == 13) return true; // Enter
  if (whichCode == 8) return true; // BackSpace
  if (whichCodeDel == 46) return true; // Delete
  key = String.fromCharCode(whichCode); // Get key value from key code
  if (strCheck.indexOf(key) == -1) return false; // Not a valid key
  len = fld.value.length;
  for(i = 0; i < len; i++)
    if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
  aux = '';
  for(; i < len; i++)
    if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
  aux += key;
  len = aux.length;
  mskLen = mask.length;

  for (i = mskLen; i > 0; i--) {
    if (mask.charAt(i-1) == "." || mask.charAt(i-1) == ",") {break;}
    else {dec++;}
  }
    
  if (len == 0) fld.value = '';
  if (len < dec) fld.value = '0' + decSep + zero(len,dec) + aux;
  if (len == dec) fld.value = '0'+ decSep + aux;
  if (len > dec) {
    aux2 = '';
    for (j = 0, i = len - (dec + 1); i >= 0; i--) {
      if (j == 3) {
        aux2 += milSep;
        j = 0;
      }
      aux2 += aux.charAt(i);
      j++;
    }
    fld.value = '';
    len2 = aux2.length;
    for (i = len2 - 1; i >= 0; i--)
      fld.value += aux2.charAt(i);
    fld.value += decSep + aux.substr(len - dec, len);
  }
  return false;
}

function AbreHelp(Link){
  popup = window.open(Link,"popDialog","width=600,height=400,top=100,left=100,scrollbars=yes,status=yes,toolbar=no,menubar=no,resizable=yes");
}


/*************************** 
  Abas
 ***************************/
function Aba(menu,conteudo)	{
	this.menu = menu;
	this.conteudo = conteudo;
}
function AtivarAba(arrayAbas,menu,conteudo) {
	for (i=0;i<arrayAbas.length;i++)	{
		m = document.getElementById(arrayAbas[i].menu);
		m.className = 'abamenu';
		c = document.getElementById(arrayAbas[i].conteudo)
		c.style.display = 'none';
	}
	m = document.getElementById(menu)
	m.className = 'abamenu-sel';
	c = document.getElementById(conteudo)
	c.style.display = '';
}
//Cria efeito de cor fundo amarelo nos campo INPUT
//function setColorOnEnter(comp) {comp.style.backgroundColor = "#FFFFCC";}
//function setColorOnExit(comp) {comp.style.backgroundColor = "#FFFFFF";}

/* Funcao cria um efeito de rolagem nas tabelas */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;
    var marked_row = new Array;
    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }
    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5
    return true;
} // end of the 'setPointer()' function

function setColorOnEnter(comp) {comp.style.backgroundColor = "#FFFFCC";}
function setColorOnExit(comp) {comp.style.backgroundColor = "#FFFFFF";}


function FormataCPF(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 < 7)
			Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
		if (tam >= 7 && tam <10)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
		if (tam >= 10 && tam < 12)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
		}
}


//####################################################################//
// Funcoes abaixo sao usadas para controle de SELLOOKUPCOMBO/TEXTLOOKUP
//####################################################################//
var req = null;
var isIE;
var atualizado = true;
var lookupcomp, textcomp;
var XMLTEXTLOOKUP = "textlookup";
var XMLSELLOOKUPCOMBO = "sellookupcombo";
function RefreshLookup(link, idfield, typecomp) {
	var isTEXTLOOKUP = typecomp == XMLTEXTLOOKUP;
	var isSELLOOKUPCOMBO = typecomp == XMLSELLOOKUPCOMBO;
	if (isTEXTLOOKUP || !atualizado) {
		lookupcomp = document.getElementById(idfield);
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			isIE = false;
			link += "&isIE=0";
		}
		else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
			isIE = true;
			link += "&isIE=1";
		}
		if (isSELLOOKUPCOMBO || lookupcomp.value != "") {
			if (isTEXTLOOKUP)
				link += "&codtextlookup=" + lookupcomp.value;
//alert(link);				
			req.open("GET", link, true);
			if (isSELLOOKUPCOMBO)
				req.onreadystatechange = CallbackLookup;
			else {
				textcomp = document.getElementById("desc"+idfield);
				req.onreadystatechange = CallbackTextLookup;
			}
			req.send(null);
		}
		else if (isTEXTLOOKUP) {
			textcomp = document.getElementById("desc"+idfield);
			textcomp.innerHTML = "";
		}
	}
}   
function CallbackTextLookup() {
	if (req == null)
		return;
	if (req.readyState == 4) {
		if (req.status == 200) {
			textcomp.innerHTML = "&nbsp;" + req.responseXML.getElementsByTagName("desc")[0].childNodes[0].nodeValue + "&nbsp;";
			req = null;
		} 
		else {
			alert("Problema no retorno de dados XML do servidor: " + req.statusText);
			req = null;
		}
	}
}
function CallbackLookup() {
	if (req == null)
		return;
	if (req.readyState == 4) {
		if (req.status == 200) {
			ClearLookup();
			BuildLookup();
			req = null;
		} 
		else {
			alert("Problema no retorno de dados XML do servidor: " + req.statusText);
			req = null;
		}
	}
}
function ClearLookup() {
	while (lookupcomp.length > 0) {
		lookupcomp.remove(0);
	}
}
function BuildLookup() {
	var i = 0, j = 0, k;
	var s, cod, desc;
	var message = req.responseXML.getElementsByTagName("option")[0].childNodes[0].nodeValue;
  AppendLookup(lookupcomp, -1, document.createTextNode("-----"));
	while (message != "") {
		j = message.indexOf(";");
		s = message.substring(0,j);
		if (j == message.length)
			message = "";
		else
			message = message.substring(j+1);
		k = s.indexOf("-");
		desc = s.substring(0,k);
		cod = s.substring(k+1,s.length);
  	AppendLookup(lookupcomp, cod, document.createTextNode(desc));
	}
	atualizado = true;
}
function AppendLookup(select, value, content) {
    var opt;
    opt = document.createElement("option");
    opt.value = value;
    opt.appendChild(content);
    select.appendChild(opt);
}              

/*************************** 
  Abas
 ***************************/
function Aba(menu,conteudo)	{
	this.menu = menu;
	this.conteudo = conteudo;
}


function RefreshLembrete(link, idfield) {
    
    if (!atualizado) {        
        field = document.getElementById(idfield);        
        if (window.XMLHttpRequest) {            
            req = new XMLHttpRequest();            
            isIE = false;            
            link += "&isIE=0";            
        }
        
        else if (window.ActiveXObject) {            
            req = new ActiveXObject("Microsoft.XMLHTTP");            
            isIE = true;           
            link += "&isIE=1";            
        }
        
        link += "&CPF=" + field.value;        
        req.open("GET", link, true);        
        textcomp = document.getElementById("pergunta");        
        req.onreadystatechange = CallbackLembrete;        
        atualizado = true;        
        req.send(null);
        
    }
    
}

function CallbackLembrete() {
    
    if (req == null)
        return;
    if (req.readyState == 4) {        
        if (req.status == 200) {            
            textcomp.innerHTML = "" + req.responseXML.getElementsByTagName("CPF")[0].childNodes[0].nodeValue + "&nbsp;";            
            req = null;            
        }        
        else {            
            alert("Problema no retorno de dados XML do servidor: " + req.statusText);            
            req = null;            
        }        
    }    
}

function RefreshCodigo(link, idfield) {
    
    if (!atualizado) {        
        field = document.getElementById(idfield);        
        if (window.XMLHttpRequest) {            
            req = new XMLHttpRequest();            
            isIE = false;            
            link += "&isIE=0";            
        }
        
        else if (window.ActiveXObject) {            
            req = new ActiveXObject("Microsoft.XMLHTTP");            
            isIE = true;           
            link += "&isIE=1";            
        }
        
        link += "&CODIGO=" + field.value;    
        req.open("GET", link, true);        
        textcomp = document.getElementById("pergunta2"); 
        req.onreadystatechange = CallbackCodigo;        
        atualizado = true;        
        req.send(null);
        
    }
    
}

function CallbackCodigo() {
    
    if (req == null)
        return;
    if (req.readyState == 4) {        
        if (req.status == 200) {            
            textcomp.innerHTML = "" + req.responseXML.getElementsByTagName("CODIGO")[0].childNodes[0].nodeValue + "&nbsp;";            
            req = null;            
        }        
        else {            
            alert("Problema no retorno de dados XML do servidor: " + req.statusText);            
            req = null;            
        }        
    }    
}

function RefreshVendaComum(link, idfield) {
    
    if (!atualizado) {        
        field = document.getElementById(idfield);        
        if (window.XMLHttpRequest) {            
            req = new XMLHttpRequest();            
            isIE = false;            
            link += "&isIE=0";            
        }
        
        else if (window.ActiveXObject) {            
            req = new ActiveXObject("Microsoft.XMLHTTP");            
            isIE = true;           
            link += "&isIE=1";            
        }
        
        link += "&CPF=" + field.value;        
        req.open("GET", link, true);        
        textcomp = document.getElementById("pergunta");        
        req.onreadystatechange = CallbackVendaComum;        
        atualizado = true;        
        req.send(null);
        
    }
    
}

function CallbackVendaComum() {
    
    if (req == null)
        return;
    if (req.readyState == 4) {        
        if (req.status == 200) {            
            textcomp.innerHTML = "" + req.responseXML.getElementsByTagName("CPF")[0].childNodes[0].nodeValue + "&nbsp;";            
            req = null;            
        }        
        else {            
            alert("Problema no retorno de dados XML  212121212asa do servidor: " + req.statusText);
            req = null;            
        }        
    }    
}

function AtivarAba(arrayAbas,menu,conteudo) {
	for (i=0;i<arrayAbas.length;i++)	{
		m = document.getElementById(arrayAbas[i].menu);
		m.className = 'abamenu';
		c = document.getElementById(arrayAbas[i].conteudo)
		c.style.display = 'none';
	}
	m = document.getElementById(menu)
	m.className = 'abamenu-sel';
	c = document.getElementById(conteudo)
	c.style.display = '';
}
/***************************/
function TrocaFigura(btn, img) {
  var button = document.getElementById(btn);
  button.src = img;
}


-->
