// LTrim(string) : Returns a copy of a string without leading spaces.
function ltrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

//RTrim(string) : Returns a copy of a string without trailing spaces.
function rtrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}

// Trim(string) : Returns a copy of a string without leading or trailing spaces
function trim(str) {
   return rtrim(ltrim(str));
}

function isEmpty(strConteudo) {
	blnRetorno = false;
	
	if (trim(strConteudo) == "") {blnRetorno = true;}
	
	return blnRetorno;
}

function isEmail(pStr, pFmt)
{
	var reEmail1 = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	var reEmail2 = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	var reEmail3 = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	
	if (pFmt == null) {pFmt = 3;}

	eval("reEmail = reEmail" + pFmt);
	
	if (reEmail.test(pStr)) {return true;} else {return false;}
}

/**
* Pops up a new window in the middle of the screen
*/
function popupWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

/***
*Função abrir div splash 
*/

function openSplash (sDiv)
	{
		if(document.getElementById(sDiv))
		{
			if(document.getElementById(sDiv).style.display != 'none'){
				document.getElementById(sDiv).style.display = 'none';
			}
		}
	}
		
function closeSplash (sDiv)
	{		
		if(document.getElementById(sDiv))
		{
			if(document.getElementById(sDiv).style.display != 'none'){
				document.getElementById(sDiv).style.display = 'none';
			}
		}
	}
	
//window.onload = openSplash('splash');

//Função para trocar estilos input
function trocaBackGround(pObject, pbgColor, pColor){
	pObject.style.backgroundColor = pbgColor;
	pObject.style.color = pColor;
}

function isValidFile(strArquivo, strFormato) {

		// Quebra os formatos pela vírgula e armazena no vetor
		var astrFormato = strFormato.split(",");
		
		// Busca a posição do último ponto no nome do arquivo
		var intPosicaoPonto = strArquivo.lastIndexOf(".");

		// Variável para retorno da função
		blnRetorno = false;

		// Variável para armazenamento da extensão do arquivo
		var strExtensao;

		// Encontrou o ponto que separa o nome do arquivo da extensão
		if (intPosicaoPonto > -1) {
			strExtensao = strArquivo.substr(intPosicaoPonto + 1);
			// Encontrou a extensão do arquivo dentro da string de formatos válidos
			if (strFormato.indexOf(strExtensao) > 0) {blnRetorno = true;}
		}
		
		return blnRetorno;
}