//codificar parâmetros de url
function EnviaDadosAjax(url, parametros)
{
    xmlhttp.open("post", url, true);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    xmlhttp.setRequestHeader("Content-Length", parametros.length);
    xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    xmlhttp.setRequestHeader("Pragma", "no-cache");
    xmlhttp.send(parametros);
}

//definir componente ajax
try
{
    xmlhttp = new XMLHttpRequest();
}
catch (ee)
{
    try
    {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
        try
        {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (E)
        {
            xmlhttp = false;
        }
    }
}


// ************ Função de mouseover nas células
function mOvr(src,clrOver)
{
	if (!src.contains(event.fromElement))
	{
		src.style.cursor = 'default';
		src.bgColor = clrOver;
	}
}

function mOut(src,clrIn)
{
	if (!src.contains(event.toElement))
	{
		src.style.cursor = 'default';
		src.bgColor = clrIn;
	}
}

// ************ Função que abre pop-ups
function AbreJanela(theURL,winName,features)
{
	 window.open(theURL,winName,features);
}


// ************ Função de Formatação de campos
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++;
			}
		}
	}
	//alert(valorFinal)
	_RefObjeto.value = valorFinal 
}  
     

// ************ Função de fomulário de Login
function ValidaForm(theForm)
{

  if (theForm.login.value == "")
  {
    alert("Por favor, digite seu Nome de usuário.");
    theForm.login.focus();
    return (false);
  }

  if (theForm.senha.value == "")
  {
    alert("Por favor, digite sua Senha.");
    theForm.senha.focus();
    return (false);
  }
     
  return (true);
}

// ************ Função de abrir outro website
function AbreSite(url)
{
	if(url!="#")
	{
		MM_openBrWindow(url,'','toolbar=yes,location=yes,menubar=yes,scrollbars=yes,resizable=yes,status=yes')
	}
	else
	{
		return(false);
	}
}

// ************ Função
function Voltar()
{
	history.back();
}

// ************ Função
function Imprimir()
{
	window.print();
}

// ************ Funções que controlam a exibição de DIVs
function Mostrar(qual)
{
	objeto = 'document.getElementById("'+qual+'")';
	eval(objeto).style.display = 'block'
}

function Esconder(qual)
{
	objeto = 'document.getElementById("'+qual+'")';
	eval(objeto).style.display = 'none'
}



// ************ Função para enviar forms
function Enviar(nomedoform)
{
	eval(nomedoform).submit();
}


// ************ Função para cor de fundo dos forms
var highlightcolor="#FFFFEA"

var ns6=document.getElementById&&!document.all
var previous=''
var eventobj

//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA|SELECT|OPTION/

//Function to check whether element clicked is form element
function checkel(which)
{
	if (which.style&&intended.test(which.tagName))
	{
		if (ns6&&eventobj.nodeType==3)
		eventobj=eventobj.parentNode.parentNode
		return true
	}
	else
		return false
}

//Function to highlight form element
function highlight(e)
{
	eventobj=ns6? e.target : event.srcElement
	if (previous!='')
	{
		if (checkel(previous))
			previous.style.backgroundColor=''
			previous=eventobj
			if (checkel(eventobj))
				eventobj.style.backgroundColor=highlightcolor
	}
	else
	{
		if (checkel(eventobj))
		eventobj.style.backgroundColor=highlightcolor
		previous=eventobj
	}
}

function EscondeSelects(action)
{
	if (top.document.frames.length > 0)
	{
		if (action!='visible'){action='hidden';}
		if (navigator.appName.indexOf("MSIE"))
		{
			for (var S = 0; S < document.forms.length; S++)
			{
				for (var R = 0; R < document.forms[S].length; R++)
				{
					if (document.forms[S].elements[R].options)
					{
						document.forms[S].elements[R].style.visibility = action;
						window.focus()
					}
				}
			}
		}
	}
}


function ChecaData(field){
	var checkstr = "0123456789";
	var DateField = field;
	var Datevalue = "";
	var DateTemp = "";
	var seperator = "/";
	var day;
	var month;
	var year;
	var leap = 0;
	var err = 0;
	var i;
    err = 0;
    DateValue = DateField.value;

   /* Delete all chars except 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 = ""; seperator = "";
   }
   
   if(DateValue=="11111111"){
   	err=11111111;
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
      alert("Verifique o formato da data!");
      DateField.select();
      DateField.focus();
   }
}


function ChecaNumero(campo){
	var campo = campo;
	var valor = campo.value;
	valor = valor.replace(/\./g,"");
	valor = valor.replace(/\,/g,".");	
	
	if ((isNaN(valor))){
		alert('Campo deve ser preenchido somente com valor numérico!');
		campo.focus();
		return(false);
	}
}

function AtivaLinks(links){
	if(links.length > 0)
	{
		var arrLinks = links.split(",");
		for (i=0;i<arrLinks.length;i++)
		{
			objeto = 'document.getElementById("link_'+arrLinks[i]+'")';
			eval(objeto).className = eval(objeto).className + 'Over';
//			alert(objeto)
		}
	}
}