///////////////////////////////////////////////////////////
// Arquivo de Funções padrão em js
// 18/05/2010 - LAA - GA
//
// Datas
// function makeArray(n)
// function isNonnegativeInteger(s)
// function isSignedInteger(s)
// function isInteger(s)
// function isDigit(c)
// function isEmpty(s)
// function isIntegerInRange (s, a, b)
// function isYear (s)
// function isMonth (s)
// function isDay (s)
// function isDateJS (year, month, day)
// function daysInFebruary (year)
// function GM_Verifica_Data(vAno, vMes, vDia)
// function onBlurData(campo_obj_data)
// function biSexto(data_valor, nome_campo)
// function Dia(Data_DDMMYYYY)
// function Mes(Data_DDMMYYYY)
// function Ano(Data_DDMMYYYY)
// function GM_Compara_Data(dt_inicio,dt_fim)
//
// Auxiliares
// function gotoPage
// function trim(str)
// function ltrim(str) 
// function rtrim(str)
// function replace(string, text, by) 
// function GM_Random()
// function flash(largura, altura, arquivo, parametro)
//
// Mascaras
// function criaMascara(_RefObjeto, _Modelo)
// function GM_AplicaMascara_Moeda(vElement)
// function GM_AplicaMascara_Peso(vElement)
//
// Validacoes
// function GM_ValidaCNPJ(CNPJ, ID_Campo)
// function GM_CNPJ_Validacao(NroCNPJ) 
// function GM_ValidaCPF(cpf, campo)
// function GM_CPF_Validacao(CPF)
// function GM_ValidaEmailRegExp(vEmail) 
// function GM_ValidaURL(url)
// function GM_SOH_Numeros(e)
//
// Ajax
// function getHTTPObject()
// function getMetodo()
//
///////////////////////////////////////////////////////////

//Data
var now = new Date();

year = now.getFullYear();
var monthName = now.getMonth() + 1;
var dayName = now.getDay() + 1;

var dayNumber = now.getDate();

if (dayName == 1) Day = "Domingo";
if (dayName == 2) Day = "Segunda-feira";
if (dayName == 3) Day = "Ter&ccedil;a-feira";
if (dayName == 4) Day = "Quarta-feira";
if (dayName == 5) Day = "Quinta-feira";
if (dayName == 6) Day = "Sexta-feira";
if (dayName == 7) Day = "S&aacute;bado";

if (monthName == 1) Month = "janeiro";
if (monthName == 2) Month = "fevereiro";
if (monthName == 3) Month = 'mar&ccedil;o';
if (monthName == 4) Month = "abril";
if (monthName == 5) Month = "maio";
if (monthName == 6) Month = "junho";
if (monthName == 7) Month = "julho";
if (monthName == 8) Month = "agosto";
if (monthName == 9) Month = "setembro";
if (monthName == 10) Month = "outubro";
if (monthName == 11) Month = "novembro";
if (monthName == 12) Month = "dezembro";

function makeArray(n) {
//*** BUG: If I put this line in, I get two error messages:
//(1) Window.length can't be set by assignment
//(2) daysInMonth has no property indexed by 4
//If I leave it out, the code works fine.
//   this.length = n;
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}



var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

var defaultEmptyOK = false

function isNonnegativeInteger(s) {
  var secondArg = defaultEmptyOK;

  if (isNonnegativeInteger.arguments.length > 1)
    secondArg = isNonnegativeInteger.arguments[1];

  // The next line is a bit byzantine.  What it means is:
  // a) s must be a signed integer, AND
  // b) one of the following must be true:
  //    i)  s is empty and we are supposed to return true for
  //        empty strings
  //    ii) this is a number >= 0

  return (isSignedInteger(s, secondArg)
         && ((isEmpty(s) && secondArg) || (parseInt(s) >= 0)));
}






// isSignedInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if all characters are numbers; 
// first character is allowed to be + or - as well.
//
// Does not accept floating point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// EXAMPLE FUNCTION CALL:          RESULT:
// isSignedInteger ("5")           true 
// isSignedInteger ("")            defaultEmptyOK
// isSignedInteger ("-5")          true
// isSignedInteger ("+5")          true
// isSignedInteger ("", false)     false
// isSignedInteger ("", true)      true

function isSignedInteger(s) {
  if (isEmpty(s))
    if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
  else return (isSignedInteger.arguments[1] == true);

  else {
    var startPos = 0;
    var secondArg = defaultEmptyOK;

    if (isSignedInteger.arguments.length > 1)
      secondArg = isSignedInteger.arguments[1];

    // skip leading + or -
    if ((s.charAt(0) == "-") || (s.charAt(0) == "+"))
      startPos = 1;
    return (isInteger(s.substring(startPos, s.length), secondArg))
  }
}



// isInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating 
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// By default, returns defaultEmptyOK if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
//      the default behavior which is specified globally by
//      defaultEmptyOK.
// If emptyOK is false (or any value other than true), 
//      the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//
// EXAMPLE FUNCTION CALL:     RESULT:
// isInteger ("5")            true 
// isInteger ("")             defaultEmptyOK
// isInteger ("-5")           false
// isInteger ("", true)       true
// isInteger ("", false)      false
// isInteger ("5", false)     true

function isInteger(s) {
  var i;

  if (isEmpty(s))
    if (isInteger.arguments.length == 1) return defaultEmptyOK;
  else return (isInteger.arguments[1] == true);

  // Search through string's characters one by one
  // until we find a non-numeric character.
  // When we do, return false; if we don't, return true.

  for (i = 0; i < s.length; i++) {
    // Check that current character is number.
    var c = s.charAt(i);

    if (!isDigit(c)) return false;
  }

  // All characters are numbers.
  return true;
}



// Returns true if character c is a digit 
// (0 .. 9).

function isDigit(c) {
  return ((c >= "0") && (c <= "9"))
}


function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
// 
// isIntegerInRange returns true if string s is an integer 
// within the range of integer arguments a and b, inclusive.
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.


function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);

    // Catch non-integer strings to avoid creating a NaN below,
    // which isn't available on JavaScript 1.0 for Windows.
    if (!isInteger(s, false)) return false;

    // Now, explicitly change the type to integer via parseInt
    // so that the comparison code below will work both on 
    // JavaScript 1.2 (which typechecks in equality comparisons)
    // and JavaScript 1.1 and before (which doesn't).
    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}


// isYear (STRING s [, BOOLEAN emptyOK])
// 
// isYear returns true if string s is a valid 
// Year number.  Must be 2 or 4 digits only.
// 
// For Year 2000 compliance, you are advised
// to use 4-digit year numbers everywhere.
//
// And yes, this function is not Year 10000 compliant, but 
// because I am giving you 8003 years of advance notice,
// I don't feel very guilty about this ...
//
// For B.C. compliance, write your own function. ;->
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isYear (s)
{   if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}

// isMonth (STRING s [, BOOLEAN emptyOK])
// 
// isMonth returns true if string s is a valid 
// month number between 1 and 12.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isMonth (s)
{   if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}



// isDay (STRING s [, BOOLEAN emptyOK])
// 
// isDay returns true if string s is a valid 
// day number between 1 and 31.
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}

function isDateJS (year, month, day)
{   // catch invalid years (not 2- or 4-digit) and invalid months and days.
    //alert(year)
    //alert(month)
    //alert(day)
	if(parseInt(month.substring(0,1))==0)
	{
		month = parseInt(month.substring(1,2))
	}
	if(parseInt(day.substring(0,1))==0)
	{
		day = parseInt(day.substring(1,2))
	}
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;
    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

// daysInFebruary (INTEGER year)
// 
// Given integer argument year,
// returns number of days in February of that year.

function daysInFebruary (year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

function GM_Verifica_Data(vAno, vMes, vDia)
  {
	  vOk = false;
	  //Cria uma data
		vData = new Date(vAno, vMes-1, vDia);
		//Verifica se a data criada é a mesma que foi digitada
		vDia1 = vData.getDate();
		if(vDia1<10)
		{
		vDia1 = '0'+vDia1
		}
		
		vMes1 = vData.getMonth();
		vAno1 = vData.getFullYear();  
		//alert(vDia + ' - ' + vDia1) 
		//alert(vMes-1 + ' - ' + vMes1)
		//alert(vAno + ' - ' + vAno1)
    vOk = isDateJS(vAno,vMes,vDia) && (vDia == vDia1) && ((vMes -1) == vMes1) && (vAno == vAno1);	
    return vOk;
  }
function onBlurData(campo_obj_data)
{
	var erro = 0;
	var Data = campo_obj_data.value;
	var ArrayData = Data.split("/");
	if(Data != '')
	{
	vAnoOriginal = ArrayData[2]
		if(vAnoOriginal<1900)
		{
			erro = erro + 1;
		}
		if(Data.length!=10) // Valida o len do campo
		{
			erro = erro + 1;
		}
		if(ArrayData.length!=3) // valida o tamanho do array de barras (/) DD/MM/YYYY
		{
			erro = erro + 1;
		}
		else
		{
			biSexto(Data,campo_obj_data);
		}
		if(erro>0)
		{
			campo_obj_data.value = '';
			alert('Data inválida')	
			return false;
		}
	}
}

function biSexto(data_valor, nome_campo)
{
var sData = data_valor.split("/");
var entrou;
	sDia = sData[0];
	sMes = sData[1];
	sAno=(sData[2]%4);
	sAnoOriginal=sData[2];
	entrou = 0;
	
	if((sData[1] == 2) && (sData[0] > 27))
	{
		if(sAno==0)
		{//ano bisexto (Fev tem 29 dias)
			if(sDia>29)
			{
				alert('O mês de Fevereiro ocorre variação em ano bisexto.\nVocê escolheu uma data de ano bisexto. \nEstamos corrigindo a data.');
				nome_campo.value = '29'+'/'+sData[1]+'/'+sData[2];
				entrou = 1;
			}
		}
		else
		{//nao eh ano bisexto, fev tem 28 dias
			if(sDia>28)
			{
				alert('O mês de Fevereiro ocorre variação em ano bisexto.\n A Data escolhida não é valida. \nEstamos corrigindo a data.');
				nome_campo.value = '28'+'/'+sData[1]+'/'+sData[2];
				entrou = 1;
			}
		}
	}
	if(entrou == 0)
	{
		if(GM_Verifica_Data(sAnoOriginal, sMes, sDia)==false)
		{
			nome_campo.value = '';
		}
	}
}


                function Dia(Data_DDMMYYYY)
		{
			string_data = Data_DDMMYYYY.toString();
			posicao_barra = string_data.indexOf("/");
			if (posicao_barra!= -1)
			{
				dia = string_data.substring(0,posicao_barra);
				return dia;
			}
			else
			{
				return false;
			}
		}
		
		function Mes(Data_DDMMYYYY)
		{
			string_data = Data_DDMMYYYY.toString();
			posicao_barra = string_data.indexOf("/");
			if (posicao_barra!= -1)
			{
				dia = string_data.substring(0,posicao_barra);
				string_mes = string_data.substring(posicao_barra+1,string_data.length);
				posicao_barra = string_mes.indexOf("/");
				if (posicao_barra!= -1)
				{
					mes = string_mes.substring(0,posicao_barra);
					mes = Math.floor(mes);
					return mes;
				}
				else
				{
					return false;
				}
				
			}
			else
			{
				return false;
			}
		}
		
		function Ano(Data_DDMMYYYY)
		{
			string_data = Data_DDMMYYYY.toString();
			posicao_barra = string_data.indexOf("/");
			if (posicao_barra!= -1)
			{
				dia = string_data.substring(0,posicao_barra);
				string_mes = string_data.substring(posicao_barra+1,string_data.length);
				posicao_barra = string_mes.indexOf("/");
				if (posicao_barra!= -1)
				{
					mes = string_mes.substring(0,posicao_barra);
					mes = Math.floor(mes);
					ano = string_mes.substring(posicao_barra+1,string_mes.length);
					return ano;
				}
				else
				{
					return false;
				}
			}
			else
			{
				return false;
			}
		}
		//verifica se a data inicial e menor que a final
		function GM_Compara_Data(dt_inicio,dt_fim)
		{
			Var_Dia1=Dia(dt_fim);
			Var_Mes1=Mes(dt_fim);
			Var_Mes1=Math.floor(Var_Mes1)-1;
			Var_Ano1=Ano(dt_fim);
			var data1 = new Date(Var_Ano1,Var_Mes1,Var_Dia1);
			
			Var_Dia2=Dia(dt_inicio);
			Var_Mes2=Mes(dt_inicio);
			Var_Mes2=Math.floor(Var_Mes2)-1;
			Var_Ano2=Ano(dt_inicio);
			var data2 = new Date(Var_Ano2,Var_Mes2,Var_Dia2);
			
			var diferenca = data1.getTime() - data2.getTime();
			var diferenca = Math.floor(diferenca / (1000 * 60 * 60 * 24));
			return diferenca;
			//
			//---| EXEMPLO |---------------------
			//var vValidacaoPeriodo = GM_compara_data(txt_Data_Inicio.value, txt_Data_Final.value);
			//if (vValidacaoPeriodo < 1) {
			//  vErros += ' A data Inicial do período é maior que a data Final';
			//}
		}

// Auxiliares

function gotoPage(pag)
{
  document.form_gotopage.pagina.value = pag;
  document.form_gotopage.submit();
}

 //trim completo
 function trim(str) {
 	return str.replace(/^\s+|\s+$/g,"");
 }

 //left trim
 function ltrim(str) {
  	return str.replace(/^\s+/,"");
 }

 //right trim
 function rtrim(str) {
 	return str.replace(/\s+$/,"");
 }

function replace(string, text, by) {
  // Replaces text with by in string
  var strLength = string.length, txtLength = text.length;
  if ((strLength == 0) || (txtLength == 0)) return string;

  var i = string.indexOf(text);

  if ((!i) && (text != string.substring(0, txtLength))) return string;
  if (i == -1) return string;

  var newstr = string.substring(0, i) + by;

  if (i + txtLength < strLength)
    newstr += replace(string.substring(i + txtLength, strLength), text, by);

  return newstr;
}

function GM_Random() 
{
	today = new Date();
	num= Math.abs(Math.sin(today.getTime()));
	return num;  
}

// JavaScript para exibir o flash
function flash(largura, altura, arquivo, parametro){
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+largura+'" height="'+altura+'" id="teste" align="middle">');
    document.write('<param name="allowScriptAccess" value="sameDomain" /><param name="wmode" value="transparent" />');
    document.write('<PARAM NAME=FlashVars VALUE="'+parametro+'" />');
    document.write('<param name="movie" value="'+arquivo+'" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><embed src="'+arquivo+'" flashvars="'+parametro+'" wmode="transparent" quality="best" width="'+largura+'" height="'+altura+'" name="teste" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</object>');
}




// Mascaras

function criaMascara(_RefObjeto, _Modelo){

var valorAtual = _RefObjeto.value;
var valorNumerico = '';
var nIndexModelo = 0;
var nIndexString = 0;
var valorFinal = '';
var adicionarValor = true;
 

// limpa a string valor atual para verificar
// se todos os caracteres são números
for (i=0;i<_Modelo.length;i++){
  if (_Modelo.substr(i,1) != '#'){
    valorAtual = valorAtual.replace(_Modelo.substr(i,1),'');
}}
 
// verifica se todos os caracteres são números
for (i=0;i<valorAtual.length;i++){
  if (!isNaN(parseFloat(valorAtual.substr(i,1)))){
    valorNumerico = valorNumerico + valorAtual.substr(i,1);
}}
 
// aplica a máscara ao campo informado usando
// o modelo de máscara informado no script
for (i=0;i<_Modelo.length;i++){
 
  if (_Modelo.substr(i,1) == '#'){
    if (valorNumerico.substr(nIndexModelo,1) != ''){
      valorFinal = valorFinal + valorNumerico.substr(nIndexModelo,1);
      nIndexModelo++;nIndexString++;
    }
      else {
        adicionarValor = false;
  }}
 
    else {
      if (adicionarValor && valorNumerico.substr(nIndexModelo,1) != ''){
      valorFinal = valorFinal + _Modelo.substr(nIndexString,1)
      nIndexString++;
    }}
}
 
_RefObjeto.value = valorFinal
 
}
// modelo input: onfocus="criaMascara(this,'##.###.###/####-##');" onkeypress="criaMascara(this,'##.###.###/####-##');" onkeyup="criaMascara(this,'##.###.###/####-##');" onblur="criaMascara(this,'##.###.###/####-##');"

function GM_AplicaMascara_Moeda(vElement){  
    var vAplicaMascara = vElement.value;
    vAplicaMascara = vAplicaMascara.replace(/\D/g,"")  //permite digitar apenas números
    vAplicaMascara = vAplicaMascara.replace(/[0-9]{13}/,"inválido")   //limita pra máximo 999.999.999,99
    vAplicaMascara = vAplicaMascara.replace(/(\d{1})(\d{8})$/,"$1.$2")  //coloca ponto antes dos últimos 8 digitos
    vAplicaMascara = vAplicaMascara.replace(/(\d{1})(\d{5})$/,"$1.$2")  //coloca ponto antes dos últimos 5 digitos
    vAplicaMascara = vAplicaMascara.replace(/(\d{1})(\d{1,2})$/,"$1,$2")    //coloca virgula antes dos últimos 2 digitos
    vElement.value = vAplicaMascara;

    // CAMPO COM:  MaxLength="12"
}



function GM_AplicaMascara_Peso(vElement){  
    var vAplicaMascara = vElement.value;
    vAplicaMascara = vAplicaMascara.replace(/\D/g,"")  //permite digitar apenas números
    vAplicaMascara = vAplicaMascara.replace(/[0-9]{13}/,"inválido")   //limita pra máximo 99,999
    vAplicaMascara = vAplicaMascara.replace(/(\d{1})(\d{8})$/,"$1.$2")  //coloca ponto antes dos últimos 8 digitos
    vAplicaMascara = vAplicaMascara.replace(/(\d{1})(\d{6})$/,"$1.$2")  //coloca ponto antes dos últimos 5 digitos
    vAplicaMascara = vAplicaMascara.replace(/(\d{1})(\d{2,3})$/,"$1,$2")    //coloca virgula antes dos últimos 3 digitos
    vElement.value = vAplicaMascara;

    // CAMPO COM: MaxLength="5"
}

// Validacoes

function GM_ValidaCNPJ(CNPJ, ID_Campo) {
  if (CNPJ != '') {
    var vCNPJ = GM_CNPJ_Validacao(CNPJ);
    if (vCNPJ == false) {
      document.getElementById(ID_Campo).value = "";
      alert('CNPJ inválido')
    }
  }
}

function GM_CNPJ_Validacao(NroCNPJ) {
  if ((NroCNPJ.length != 18)) {
    return false;
  }

  NroCNPJ = replace(NroCNPJ, "/", "");
  NroCNPJ = replace(NroCNPJ, ".", "");
  NroCNPJ = replace(NroCNPJ, "-", "");

  if (NroCNPJ < 1) {
    return false;
  }

  var dig1 = 0;
  var dig2 = 0;
  var x;
  var Mult1 = '543298765432';
  var Mult2 = '6543298765432';

  for (x = 0; x <= 11; x++) {
    dig1 = dig1 + (parseInt(NroCNPJ.slice(x, x + 1)) * parseInt(Mult1.slice(x, x + 1)));
  }
  for (x = 0; x <= 12; x++) {
    dig2 = dig2 + (parseInt(NroCNPJ.slice(x, x + 1)) * parseInt(Mult2.slice(x, x + 1)));
  }


  dig1 = (dig1 * 10) % 11;
  dig2 = (dig2 * 10) % 11;

  if (dig1 == 10) { dig1 = 0; }
  if (dig2 == 10) { dig2 = 0; }

  if (dig1 != parseInt(NroCNPJ.slice(12, 13))) {
    return false;
  }
  else {
    if (dig2 != parseInt(NroCNPJ.slice(13, 14))) {
      return false;
    }
    else {
      return true;
    }
  }
}


function GM_ValidaCPF(cpf, campo) {
  if (cpf != '') {
    var vRetorno = GM_CPF_Validacao(replace(cpf, ".", ""));
    if (vRetorno == false) {
      document.getElementById(campo).value = '';
      alert('CPF inválido')
    }
  }
}

function GM_CPF_Validacao(CPF) {
  dig_1 = 0;
  dig_2 = 0;
  controle_1 = 10;
  controle_2 = 11;
  lsucesso = 1;
  numero = CPF;
  if (
         numero == "000000000-00" ||
         numero == "111111111-11" ||
         numero == "222222222-22" ||
         numero == "333333333-33" ||
         numero == "444444444-44" ||
         numero == "555555555-55" ||
         numero == "666666666-66" ||
         numero == "777777777-77" ||
         numero == "888888888-88" ||
         numero == "999999999-99"
        ) {
    return false;
  }
  if ((numero.length != 12) || (numero.substring(9, 10) != "-")) {
    return false;
  }
  else {
    for (i = 0; i < 9; i++) {
      dig_1 = dig_1 + parseInt(numero.substring(i, i + 1) * controle_1);
      controle_1 = controle_1 - 1;
    }
    resto = dig_1 % 11;
    dig_1 = 11 - resto;
    if ((resto == 0) || (resto == 1))
      dig_1 = 0;
    for (i = 0; i < 9; i++) {
      dig_2 = dig_2 + parseInt(numero.substring(i, i + 1) * controle_2);
      controle_2 = controle_2 - 1;
    }
    dig_2 = dig_2 + 2 * dig_1;
    resto = dig_2 % 11;
    dig_2 = 11 - resto;

    if ((resto == 0) || (resto == 1))
      dig_2 = 0;

    dig_ver = (dig_1 * 10) + dig_2;

    if (dig_ver != parseFloat(numero.substring(numero.length - 2, numero.length))) {
      return false;
    }
  }
  return true;
}


function GM_ValidaEmailRegExp(vEmail) {
  var RegExp = /^(([\w]+:)?\/\/)?(([a-zA-Z0-9_\.\-\+])+([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
  if (RegExp.test(vEmail)) {
    return true;
  }
  else {
    return false;
  }
}
function GM_ValidaURL(url){
    var RegExp = /^(((ht|f)tp(s?))\:\/\/)([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?$/;
    if(RegExp.test(url)){
        return true;
    }else{
        return false;
    }
}




function GM_SOH_Numeros(e) {
  var tecla;
  var caracter;
  var expressao;
  if (window.event) { // IE
    tecla = e.keyCode;
  }
  else if (e.which) { // Netscape/Firefox/Opera
    tecla = e.which;
  }
  if (tecla != 8) { // backspace   
    //event.keyCode = 0;   
    caracter = String.fromCharCode(tecla); //converte o numero da tecla para caracter
    expressao = /\d/; // expressao regular so para numeros
    return expressao.test(caracter); //este return depende do resultado do teste da expressao 
  }
  else {
    return true;
  }
}

// Ajax
function getHTTPObject() {
    var xmlhttp;
    // Mozilla, Firefox, Safari, e Netscape
    if (window.XMLHttpRequest) {
      try {
        xmlhttp = new XMLHttpRequest();
      } catch (e) {
        xmlhttp = false;
      }
      return xmlhttp;
    }

    // Internet Explorer
    if (window.ActiveXObject) {
      try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
      } catch (e) {
        try {
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
        } catch (e) {
          try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
            try {
              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
              xmlhttp = false;

            }
          }
        }
      }

      return xmlhttp;
    }
    alert("Objeto XMLHTTP nao e suportado pelo navegador.");
}




function getMetodo() {
  var metoto;
  // Mozilla, Firefox, Safari, e Netscape
  if (window.XMLHttpRequest) {
    try {
      metodo = "GET";
    } catch (e) {
      xmlhttp = false;
    }
    return metodo;
  }

  // Internet Explorer
  if (window.ActiveXObject) {
    try {
      metodo = "POST";
    } catch (e) {
      try {
        metodo = "POST";
      } catch (e) {
        try {
          metodo = "POST";
        } catch (e) {
          try {
            metodo = "POST";
          } catch (e) {
            metodo = false;
          }
        }
      }
    }

    return metodo;
  }
  alert("Objeto XMLHTTP nao e suportado pelo navegador.");
}


































