var BGMostrando = ''
function BGShow(mostra) {
	document.getElementById('div_informacoes').style.display = 'none';
	document.getElementById('div_relatos').style.display = 'none';
	document.getElementById('div_dicas').style.display = 'none';
	document.getElementById('div_mapas').style.display = 'none';
	//alert(mostra);
	if (String(mostra)!='') {
		if	(BGMostrando != mostra) {
			document.getElementById(mostra).style.display = '';
			BGMostrando = mostra;
		}
		else {
			document.getElementById(mostra).style.display = 'none';
			BGMostrando = '';
		}
	}
}
function BGShowFoto(foto) {
	document.getElementById('BGfotoholder').src = foto;
}
function BGSendBusca(sNewFormAction) {
	document.forms[0].method = 'get';
	document.forms[0].action = sNewFormAction;
	document.forms[0].__VIEWSTATE.value = '';
	document.forms[0].__VIEWSTATE.name = 'BG';
	document.forms[0].submit();
}
function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "Erro";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";
	
	tmpNumStr = tmpNumStr.replace(".","x")
	tmpNumStr = tmpNumStr.replace(",",".")
	tmpNumStr = tmpNumStr.replace(",",".")
	tmpNumStr = tmpNumStr.replace(",",".")
	tmpNumStr = tmpNumStr.replace(",",".")
	tmpNumStr = tmpNumStr.replace(",",".")
	tmpNumStr = tmpNumStr.replace(",",".")
	tmpNumStr = tmpNumStr.replace(",",".")
	tmpNumStr = tmpNumStr.replace(",",".")
	tmpNumStr = tmpNumStr.replace("x",",")

	var tmpNumStr2 = tmpNumStr.replace(".","")
	var posicao_ponto = tmpNumStr2.search(",")
	
	if (posicao_ponto < 0) {
		tmpNumStr = tmpNumStr + ",00"
	}//End if
	
	var tamanho_string = tmpNumStr2.length
	if ((posicao_ponto == (tamanho_string - 2)) && (tamanho_string > 1)) {
		tmpNumStr = tmpNumStr + "0"
	}//End if
	
	return tmpNumStr;		// Return our formatted string!
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_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=MM_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];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function Resize(popW,popH){
	w=480;h=340;
	if (document.all||document.layers) {
		w=screen.availWidth;h=screen.availHeight;
	}
	leftPos=(w-popW)/2;topPos=(h-popH)/2;
	window.moveTo(leftPos,topPos);window.resizeTo(popW,popH);
}

function isNum(caractere) {
	var strValidos="0123456789"
	if ( strValidos.indexOf(caractere)==-1) {
		return false;
	}
	return true;
}
/***
* Descrição.: formata um campo do formulário de
* acordo com a máscara informada...
* Parâmetros: - objForm (o Objeto Form)
* - strField (string contendo o nome
* do textbox)
* - sMask (mascara que define o
* formato que o dado será apresentado,
* usando o algarismo "9" para
* definir números e o símbolo "!" para
* qualquer caracter...
* - evtKeyPress (evento)
* Uso.......: <input type="textbox"
* name="xxx".....
* onkeypress="return inputMask(this,'99999-999', event);">
* Observação: As máscaras podem ser representadas como os exemplos abaixo:
* CEP -> 99.999-999
* CPF -> 999.999.999-99
* CNPJ -> 99.999.999/9999-99
* Data -> 99/99/9999
* Tel Resid -> (99) 999-9999
* Tel Cel -> (99) 9999-9999
* Processo -> 99.999999999/999-99
* C/C -> 999999-!
* E por aí vai...
***/

function inputMask(objForm,sMask,evtKeyPress) {
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
	var nTecla = (evtKeyPress.keyCode) ? evtKeyPress.keyCode : evtKeyPress.which;
	if (!nTecla) return true;
	if (nTecla==8 || nTecla==37)  return true;

	//alert(nTecla);
	objForm.maxLength=sMask.length;
	sValue = objForm.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( " ", "" );
	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) == " "))

		if (bolMask) {
			sCod += sMask.charAt(i);
			mskLen++;
		} else {
			sCod += sValue.charAt(nCount);
			nCount++;
		}

		i++;
	}

	objForm.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;
	}
}

