/*
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
::: Validar Formulario com campos obrigatorios
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
// Modo de Usar: onSubmit="return ValForm(this);"

function ValForm( theForm )
{

	var msg_req  = 'Erro: Um ou mais campos são requeridos.\n- O campo ';
	var msg_req2 = ' é requerido!';
	var objetos = theForm.length;
	var retorno = true;

	for (var i=0; i<objetos; i++)
	{

		// tirar espacos do campo
		while(''+theForm.elements[i].value.charAt(theForm.elements[i].value.length-1)==' ')theForm.elements[i].value=theForm.elements[i].value.substring(0,theForm.elements[i].value.length-1);


		// obrigar campo texto
		if ((theForm.elements[i].type == 'text') && (theForm.elements[i].id == 'REQ') && (theForm.elements[i].disabled == false) && (theForm.elements[i].value.length == 0))
		{
				destReq(theForm, true);
				window.alert(msg_req + theForm.elements[i].name + msg_req2);
				theForm.elements[i].focus();
				destReq(theForm, false);
				return false;
		}

		// obrigar campo password
		if ((theForm.elements[i].type == 'password') && (theForm.elements[i].id == 'REQ') && (theForm.elements[i].disabled == false) && (theForm.elements[i].value.length == 0))
		{
				destReq(theForm, true);
				window.alert(msg_req + theForm.elements[i].name + msg_req2);
				theForm.elements[i].focus();
				destReq(theForm, false);
				return false;
		}

		// obrigar campo textarea
		else if ((retorno == true) && (theForm.elements[i].type == 'textarea') && (theForm.elements[i].id == 'REQ') && (theForm.elements[i].disabled == false) && (theForm.elements[i].value.length == 0))
		{
				destReq(theForm, true);
				window.alert(msg_req + theForm.elements[i].name + msg_req2);
				theForm.elements[i].focus();
				destReq(theForm, false);
				return false;
		}

		// obrigar campo hidden
		if ((theForm.elements[i].type == 'hidden') && (theForm.elements[i].id == 'REQ') && (theForm.elements[i].disabled == false) && (theForm.elements[i].value.length == 0))
		{
				destReq(theForm, true);
				window.alert(msg_req + theForm.elements[i].name + msg_req2);
				destReq(theForm, false);
				return false;
		}

		// obrigar campo combobox (listbox)
		else if ((retorno == true) && (theForm.elements[i].type == 'select-one') && (theForm.elements[i].id == 'REQ') && (theForm.elements[i].disabled == false) && (theForm.elements[i].selectedIndex == 0))
		{
				destReq(theForm, true);
				window.alert(msg_req + theForm.elements[i].name + msg_req2);
				theForm.elements[i].focus();
				destReq(theForm, false);
				return false;
		}

		// obrigar campo combobox multiple (listbox multiple)
		else if ((retorno == true) && (theForm.elements[i].type == 'select-multiple') && (theForm.elements[i].id == 'REQ') && (theForm.elements[i].disabled == false) && (theForm.elements[i].value.length == 0))
		{
				destReq(theForm, true);
				window.alert(msg_req + theForm.elements[i].name + msg_req2);
				theForm.elements[i].focus();
				destReq(theForm, false);
				return false;
		}

		// obrigar campo checkbox
		else if ((retorno == true) && (theForm.elements[i].type == 'checkbox') && (theForm.elements[i].id == 'REQ') && (theForm.elements[i].disabled == false) && (theForm.elements[i].checked == false))
		{
				destReq(theForm, true);
				window.alert(msg_req + theForm.elements[i].name + msg_req2);
				theForm.elements[i].focus();
				destReq(theForm, false);
				return false;
		}

		// obrigar campo radio
		else if ((retorno == true) && (theForm.elements[i].type == 'radio') && (theForm.elements[i].id == 'REQ') && (theForm.elements[i].disabled == false) && (theForm.elements[i].checked == false))
		{
				destReq(theForm, true);
				window.alert(msg_req + theForm.elements[i].name + msg_req2);
				theForm.elements[i].focus();
				destReq(theForm, false);
				return false;
		}

		// obrigar campo file
		if ((theForm.elements[i].type == 'file') && (theForm.elements[i].id == 'REQ') && (theForm.elements[i].disabled == false) && (theForm.elements[i].value.length == 0))
		{
				destReq(theForm, true);
				window.alert(msg_req + theForm.elements[i].name + msg_req2);
				theForm.elements[i].focus();
				destReq(theForm, false);
				return false;
		}

    else if ((theForm.elements[i].type == 'submit') && (retorno == true))
        {theForm.elements[i].disabled=true;}

	}
		return retorno;

}

/*
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
::: Destacar campos obrigatorios
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
// Modo de Usar: destReq(document.nome_form, true)
// true = destacar, false = normal

function destReq(theForm, dest)
{
	var objetos = theForm.length;

	for (var i=0; i<objetos; i++)
	{
		if (theForm.elements[i].id == 'REQ')
		{
			if (dest)
			{
				theForm.elements[i].style.background='#F0F0F0';
			}
			else
			{
				theForm.elements[i].style.background='';
			}
		}
	}
}

/*
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
::: Formatar Text com Mascaras
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
// Modo de Usar: onKeyPress="return txtBoxFormat(document.nomeform, 'NOMECAMPO', '99/99/9999', event);"

  function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

    if(document.all) { // Internet Explorer
      nTecla = evtKeyPress.keyCode; }
    else if(document.layers) { // Nestcape
      nTecla = evtKeyPress.which;
    }

    sValue = objForm[strField].value;

    // Limpa todos os caracteres de formatação que
    // já estiverem 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( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
      bolMask = bolMask || ((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 números...
        return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
      else { // qualquer caracter...
        return true;
      } }
    else {
      return true;
    }
  }

/*
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
::: Validar Campo Numérico com : (dois pontos)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
// Modo de Usar: OnBlur="ValNumero_DP(e, campo)"

  function ValNumero_DP(e, campo) {

	if (document.all) // Internet Explorer
	{
		var tecla = event.keyCode;
	}
	else if (document.layers) // Nestcape
	{
		var tecla = e.which;
	}

	if (campo.value.length == 2)
	{
		campo.value = campo.value + ':'; // adiciona : (dois pontos)
	}

	if (tecla > 47 && tecla < 58) // numeros de 0 a 9 e : (dois pontos)
	{
		return true;
	}
	else
	{
		if (tecla != 8) // backspace
		{
			return false;
		}
		else
		{
			return true;
		}
	}
  }

/*
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
::: Validar Campo Numérico com Virgula e Ponto
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
// Modo de Usar: onKeyPress="return ValNumero2(event, this);"

  function ValNumero2(e, campo) {

	if (document.all) // Internet Explorer
	{
		var tecla = event.keyCode;
	}
	else if (document.layers) // Nestcape
	{
		var tecla = e.which;
	}

	if ((tecla == 44) || (tecla >= 46) && (tecla < 58)) // numeros de 0 a 9, virgula (,) e ponto
	{
		return true;
	}
	else
	{
		if (tecla != 8) // backspace
		{
			return false;
		}
		else
		{
			return true;
		}
	}
  }

/*
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
::: Campo Hora
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
// Modo de Usar: OnBlur="txtHora(this)"

  function txtHora(campo_hora) { // funcao para validar hora/minuto

    if ((campo_hora.value.length != 5) && (campo_hora.value.length != 0))
    {
      window.alert('Campo Hora Incorreto. Digite Novamente.\nUtilize o formato hh:mm.');
      campo_hora.value = '';campo_hora.focus();
    }
    else
    {
      var hora		= campo_hora.value.substring(0, 2); // pegar hora
      var minuto	= campo_hora.value.substring(3, 5); // pegar minuto
      var erro = 0;

      if ( (campo_hora.value.substring(2, 3) != ':') && (campo_hora.value.length != 0) ) // dois pontos (invalido)
      {
        erro = 1;
      }

      if ((parseInt(hora) < 0) || (parseInt(hora) > 23)) // hora invalida
      {
        erro = 1;
      }

      if ((parseInt(minuto) < 0) || (parseInt(minuto) > 59)) // minuto invalido
      {
        erro = 1;
      }

      if (erro == 1)
      {
        window.alert('Campo Hora Incorreto. Digite Novamente.\nUtilize o formato hh:mm.');
	campo_hora.value = '';campo_hora.focus();
      }

    }

  }

/*
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
::: Comparar Horas
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
// Modo de Usar: "javascript:comparaHora(campo_hora1, campo_hora2)"

  function comparaHora(campo_hora1, campo_hora2) { // funcao para comparar 2 campos hora

    if ((campo_hora1.value.length != 0) && (campo_hora2.value.length != 0))
    {
      var hora1		= campo_hora1.value.substring(0, 2); // pegar hora1
      var minuto1	= campo_hora1.value.substring(3, 5); // pegar minuto1
      var hora2		= campo_hora2.value.substring(0, 2); // pegar hora2
      var minuto2	= campo_hora2.value.substring(3, 5); // pegar minuto2

      hora1 = hora1 + minuto1; //une hora com numero para formar um numero inteiro
      hora2 = hora2 + minuto2;

      if (hora2 <= hora1) //hora termino menos que hora inicio
      {
        window.alert('A Hora de Término não pode ser igual ou menor que a Hora de Início.');
		campo_hora2.value='';
		campo_hora2.focus();
      }

    }

  }

/*
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
:::Filtrando as extensões de arquivo no upload: (gif, jpg, png)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
// Modo de Usar: OnBlur="ChecaExtensaoArquivo( this )">

function ChecaExtensaoArquivo( field ){
   var extensoesOk = ",.gif,.jpg,.png,";
   var extensao    = "," + field.value.substr( field.value.length - 4 ).toLowerCase() + ",";
 if (field.value.length != 0) {
   if( extensoesOk.indexOf( extensao ) == -1 ){
       alert( field.value + "\nNão Possui uma Extensão Válida." );
	   field.value = '';
	   field.focus();
	   field.select();
       return false;
     }
 }
   return true;
 }

/*
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
::: Validar E-mail
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
// Modo de Usar: OnBlur="ValEmail(this)"

	 function ValEmail(field) { // validar campo email
	 if (field.value.length != 0)
	 {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(field.value)){
		return (true)
		}
		alert("O e-mail informado é inválido!")
		field.value = '';
		field.focus();
		field.select();
		return (false)
	 }
	}

/*
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
::: Preload Images
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
// Modo de Usar: preloadImages('http://www.site.com/img1.gif','http://www.site.com/img2.gif')

	function preloadImages() { //v3.0
  		var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    		var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}

/*
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
::: AutoTab
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
// Modo de Usar: onKeyup="autotab(this, document.nomedoform.nomedocampo)"

	function autotab(original,destino){
	  if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
	  destino.focus()
	}

/*
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
::: Janela Pop Up Centralizada
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
// Modo de Usar: javascript:winPopup('pagina', 'nome', largura, altura, centralizar, 'propriedades da janela')
//pagina = caminho da pagina ou site para abrir na popup
//nome = nome da janela
//largura = largura da janela em px | altura = altura da janela em px
//centralizar = 1 ou 2 (1 = centralizada | 2 = sem centralizar)
//propriedades da janela = scrollbars=yes, status=no, etc etc

    function winPopup(pag, nome, larg, alt, centralizar, opcoes) { // abrir janela popup

  	  if (centralizar = 1)
	  {
	    var winl = (screen.width - larg) / 2;
	    var wint = (screen.height - alt) / 2;
	  }
	  else
	  {
	    var winl = 0;
	    var wint = 0;
	  }

	  if (opcoes != '')
	  {
	    opcoes = ', ' + opcoes;
      }

	  newWindow = window.open('' + pag + '',''+nome+'','width=' + larg + ',height=' + alt + ',top='+wint+',left='+winl+'' + opcoes + '');
	  newWindow.focus();
    }


/*
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
::: Voltar Quantas Telas for Necessário
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
// Modo de Usar: OnBlur="GoBack(Número) onde Número é a quantidade de telas que deseja voltar o padrão é 1"

function GoBack(Qtde)
{
	if (Qtde==null)
		Qtde=1;
	if (Qtde>0)
		Qtde *= (-1);
	history.go(Qtde);
}


/*
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
::: Validar Data
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
// Modo de Usar: OnBlur="ValData(this)"

    function ValData(field) { // campo data (dd/mm/aaaa)

	var checkstr = "0123456789";
	var DateField = field;
	var Datevalue = "";
	var DateTemp = "";
	var separador = "/";
	var day; var month; var year;
	var leap = 0;
	var err = 0;
	var i;

	err = 0;
	DateValue = DateField.value;

	/* Deletar todos os caracteres que nao forem numeros (0-9) */
	for (i = 0; i < DateValue.length; i++) {
		if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
			DateTemp = DateTemp + DateValue.substr(i,1);
		}
	}

	DateValue = DateTemp;

	/* Always change date to 8 digits - string*/
	/* if year is entered as 2-digit / always assume 20xx */
	if (DateValue.length == 6) {
		DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
	if (DateValue.length != 8) {
		err = 19;}
	/* year is wrong if year = 0000 */
	year = DateValue.substr(4,4);
	if (year == 0) {
		err = 20;
	}

	/* Validation of month*/
	month = DateValue.substr(2,2);
	if ((month < 1) || (month > 12)) {
		err = 21;
	}

	/* Validation of day*/
	day = DateValue.substr(0,2);

	if (day < 1) {
		err = 22;
	}

	/* Validation leap-year / february / day */
	if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
		leap = 1;
	}
	if ((month == 2) && (leap == 1) && (day > 29)) {
		err = 23;
	}
	if ((month == 2) && (leap != 1) && (day > 28)) {
		err = 24;
	}

	/* Validation of other months */
	if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
		err = 25;
	}
	if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
		err = 26;
	}

	/* if 00 ist entered, no error, deleting the entry */
	if ((day == 0) && (month == 0) && (year == 00)) {
		err = 0; day = ""; month = ""; year = ""; separador = "";
	}
	/* if no error, write the completed date to Input-Field (e.g. 13/12/2001) */
	if (err == 0) {
		DateField.value = day + separador + month + separador + year;
	}
	/* Error-message if err != 0 */
	else {
		alert("Campo Data Incorreto! Digite Novamente.\nUtilize o formato dd/mm/aaaa.");
		DateField.value = '';
		DateField.select();
		DateField.focus();
	}
    }

/*
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
::: Jump Select
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
// Modo de Usar: <select onChange="MM_jumpMenu('self',this,0)">

  function MM_jumpMenu(targ,selObj,restore){ //v3.0
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
  }


/*
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
::: Title
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
// Modo de Usar: <a href="?" class="helpLink" onclick="showHelpTip(event, 'Texto do title', true); return false">link</a>

	function Title(e, sHtml, bHideSelects) {

		// find anchor element
		var el = e.target || e.srcElement;
		while (el.tagName != "A")
			el = el.parentNode;
		
		// is there already a tooltip? If so, remove it
		if (el._helpTip) {
			helpTipHandler.hideHelpTip(el);
		}
	
		helpTipHandler.hideSelects = Boolean(bHideSelects);
	
		// create element and insert last into the body
		helpTipHandler.createHelpTip(el, sHtml);
		
		// position tooltip
		helpTipHandler.positionToolTip(e);
	
		// add a listener to the blur event.
		// When blurred remove tooltip and restore anchor
		el.onblur = helpTipHandler.anchorBlur;
		el.onkeydown = helpTipHandler.anchorKeyDown;
	}
	
	var helpTipHandler = {
		hideSelects:	false,
		
		helpTip:		null,
		
		showSelects:	function (bVisible) {
			if (!this.hideSelects) return;
			// only IE actually do something in here
			var selects = [];
			if (document.all)
				selects = document.all.tags("SELECT");
			var l = selects.length;
			for	(var i = 0; i < l; i++)
				selects[i].runtimeStyle.visibility = bVisible ? "" : "hidden";	
		},
		
		create:	function () {
			var d = document.createElement("DIV");
			d.className = "help-tooltip";
			d.onmousedown = this.helpTipMouseDown;
			d.onmouseup = this.helpTipMouseUp;
			document.body.appendChild(d);		
			this.helpTip = d;
		},
		
		createHelpTip:	function (el, sHtml) {
			if (this.helpTip == null) {
				this.create();
			}
	
			var d = this.helpTip;
			d.innerHTML = sHtml;
			d._boundAnchor = el;
			el._helpTip = d;
			return d;
		},
		
		// Allow clicks on A elements inside tooltip
		helpTipMouseDown:	function (e) {
			var d = this;
			var el = d._boundAnchor;
			
			if (!e) e = event;
			var t = e.target || e.srcElement;
			while (t.tagName != "A" && t != d)
				t = t.parentNode;
			if (t == d) return;
			
			el._onblur = el.onblur;
			el.onblur = null;
		},
		
		helpTipMouseUp:	function () {
			var d = this;
			var el = d._boundAnchor;
			el.onblur = el._onblur;
			el._onblur = null;
			el.focus();
		},	
		
		anchorBlur:	function (e) {
			var el = this;
			helpTipHandler.hideHelpTip(el);
		},
		
		anchorKeyDown:	function (e) {
			if (!e) e = window.event
			if (e.keyCode == 27) {	// ESC
				helpTipHandler.hideHelpTip(this);
			}
		},
		
		removeHelpTip:	function (d) {
			d._boundAnchor = null;
			d.style.filter = "none";
			d.innerHTML = "";
			d.onmousedown = null;
			d.onmouseup = null;
			d.parentNode.removeChild(d);
			//d.style.display = "none";
		},
		
		hideHelpTip:	function (el) {
			var d = el._helpTip;
			d.style.visibility = "hidden";
			d.style.top = - el.offsetHeight - 100 + "px"
			d._boundAnchor = null;
	
			el.onblur = null;
			el._onblur = null;
			el._helpTip = null;
			el.onkeydown = null;
			
			this.showSelects(true);
		},
		
		positionToolTip:	function (e) {
			this.showSelects(false);		
			var scroll = this.getScroll();
			var d = this.helpTip;
			
			var dw = (window.innerWidth || document.documentElement.offsetWidth) - 25;
			
			if (d.offsetWidth >= dw)
				d.style.width = dw - 10 + "px";
			else
				d.style.width = "";
			
			if (e.clientX > dw - d.offsetWidth)
				d.style.left = dw - d.offsetWidth + scroll.x + "px";
			else
				d.style.left = e.clientX - 2 + scroll.x + "px";
			d.style.top = e.clientY + 18 + scroll.y + "px";
			
			d.style.visibility = "visible";
		},
		
		// returns the scroll left and top for the browser viewport.
		getScroll:	function () {
			if (document.all && typeof document.body.scrollTop != "undefined") {	// IE model
				var ieBox = document.compatMode != "CSS1Compat";
				var cont = ieBox ? document.body : document.documentElement;
				return {x : cont.scrollLeft, y : cont.scrollTop};
			}
			else {
				return {x : window.pageXOffset, y : window.pageYOffset};
			}
			
		}
	
	};


/*
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
::: CurrencyFormat
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
// Modo de Usar: onKeyPress="return(currencyFormat(this,'.',',',event, 9))
// Original:  Mario Costa (mariocosta@openlink.com.br)
// This script and many more are available free online at
// The JavaScript Source!! http://javascript.internet.com
// Ultimo Escopo define o tamanho máx de caracteres para valores

function currencyFormat(fld, milSep, decSep, e, maxchr) {
	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;
	if (whichCode == 13) return true;  // Enter
	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;
	if (len == 0) fld.value = '';
	if (len == 1) fld.value = '0'+ decSep + '0' + aux;
	if (len == 2) fld.value = '0'+ decSep + aux;
	if (len > 2 && len < (maxchr + 1)) {
	aux2 = '';
	for (j = 0, i = len - 3; 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 - 2, len);
	}
	return false;
}

