var BPSMostrando = '';
var BPSMostrando2 = '';

function BPSShow(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	(BPSMostrando != mostra) {
			document.getElementById(mostra).style.display = '';
			BPSMostrando = mostra;
		}
		else {
			document.getElementById(mostra).style.display = 'none';
			BPSMostrando = '';
		}
	}
}
function BPSShowTel(mostra) {
	document.getElementById('div_telefone').style.display = 'none';
	if (String(mostra)!='') {
		if	(BPSMostrando2 != mostra) {
			document.getElementById(mostra).style.display = '';
			BPSMostrando2 = mostra;
		}
		else {
			document.getElementById(mostra).style.display = 'none';
			BPSMostrando2 = '';
		}
	}
}

function BPSShowFoto(foto) {
	document.getElementById('bpsfotoholder').src = foto;
}
function BPSPrint() {
	
}
function BPSSendBusca(sNewFormAction) {
	document.forms[0].method = 'get';
	document.forms[0].action = sNewFormAction;
	document.forms[0].__VIEWSTATE.value = '';
	document.forms[0].__VIEWSTATE.name = 'bps';
	document.forms[0].submit();
}
function BPSSendBuscaKeypress(e) {
	var kc = e.which||e.keyCode;
	if (kc==13) { BPSSendBusca('/busca.aspx'); }
	return kc;
}
function Preview_Foto() {
	document.getElementById("imagem1").src = "/userfiles/sistema_pacotes/pacotes/cache/" + String(document.getElementById("foto").value);
	document.getElementById("imagem2").src = "/userfiles/sistema_pacotes/pacotes/cache/" + String(document.getElementById("foto2").value);
	document.getElementById("imagem3").src = "/userfiles/sistema_pacotes/pacotes/cache/" + String(document.getElementById("foto3").value);
	document.getElementById("imagem4").src = "/userfiles/sistema_pacotes/pacotes/cache/" + String(document.getElementById("foto4").value);
}
function Preview_Foto_Hotel() {
	document.getElementById("imagem1").src = "/userfiles/sistema_pacotes/hoteis/" + String(document.getElementById("foto").value);
}
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 MM_openBrWindow(theURL,winName,features) { //v2.0
  if(window.screen){
    var myLeft = (screen.width-550)/2;
    var myTop = (screen.height-420)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  newwindow=window.open(theURL,winName,features);
  if (window.focus) {newwindow.focus()}
}
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' precisa conter um endereço válido de e-mail.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' precisa conter um número.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' precisa conter um número entre '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' é necessário.\n'; }
  } if (errors) alert('Os seguintes erros ocorreram:\n'+errors);
  document.MM_returnValue = (errors == '');
}
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

function Posicionamento() {
	var posicaoy = findPosY(document.getElementById('Local_Precos'));
	//alert(String(posicaoy));
	window.scrollTo(0,posicaoy);
}
function imgOn(imgName) {
	if (document.images) {
		document[imgName].src = eval(imgName + "up.src");
	}
}

function imgOff(imgName) {
	if (document.images) {
		document[imgName].src = eval(imgName + "over.src");
	}
}

function HandleError(message,url,line) {
	var str="An error has occurred:"+"\n\n"+"Line: "+line+"\nError: "+message;
	alert(str);
	return true;
}

function Remote(URL,popW,popH,res,scroll,wname){
	if (wname==null) {
		var wname='remote';
	}
	remote=null;w=480;h=340;
	if (document.all || document.layers) {
		w=screen.availWidth;h=screen.availHeight-30;
	}
	leftPos=(w-popW)/2;topPos=(h-popH)/2;
	remote=window.open(URL,wname,'toolbar=0,location=0,status=0,scrollbars='+scroll+',resizable='+res+',menubar=0,width='+popW+',height='+popH+', left='+leftPos+', top='+topPos+',directories=no');
	if (remote!=null) {
		remote.location.href=URL;
	}
	if (remote.opener==null) {
		remote.opener=self;
	}
	if (!remote.opener) {
		remote.opener=this.window;
	}
}

function setPointer(theRow, thePointerColor){
	if (typeof(theRow.style)=='undefined'||typeof(theRow.cells)=='undefined') {
		return false;
	}
	var row_cells_cnt=theRow.cells.length;
	for (var c=0;c<row_cells_cnt;c++) {
		theRow.cells[c].bgColor=thePointerColor;
	}
	return true;
}

function ReloadOpener(){
	opener.location.reload();
}

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 ConfirmDelete(action,waction) {
	var message='Confirma a exclusão?';
	if (confirm(message)) {
		if (waction==null) {
			var actwindow='tmvmain';
		} else {
			var actwindow=waction;
		}
		window.open(action,actwindow);
	}
}

function Get_Cookie(name) {
	var start = document.cookie.indexOf(name+'=');
	var len = start+name.length+1;
	if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
	if (start == -1) return null;
	var end = document.cookie.indexOf(';',len);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(cookie_name, cookie_value, cookie_expire, cookie_path, cookie_domain, cookie_secure) {

	// Begin the cookie parameter string
	var cookie_string = cookie_name + "=" + cookie_value

	// Add the expiration date, if it was specified
	if (cookie_expire) {
		var expire_date = new Date()
		var ms_from_now = cookie_expire * 24 * 60 * 60 * 1000
		Expire_date.setTime(expire_date.getTime() + ms_from_now)
		var expire_string = expire_date.toGMTString()
		cookie_string += "; expires=" + expire_string
	}

	// Add the path, if it was specified
	if (cookie_path) {
		cookie_string += "; path=" + cookie_path
	}

	// Add the domain, if it was specified
	if (cookie_domain) {
		cookie_string += "; domain=" + cookie_domain
	}

	// Add the secure Boolean, if it's true
	if (cookie_secure) {
		cookie_string += "; true"
	}

	// Set the cookie
	document.cookie = cookie_string
}

function isNum(caractere) {
	var strValidos="0123456789"
	if ( strValidos.indexOf(caractere)==-1) {
		return false;
	}
	return true;
}
function validaTecla(campo,event) {
	var BACKSPACE=8;
	var key;
	var tecla;
	CheckTAB=true;
	if(navigator.appName.indexOf("Netscape")!= -1) {
		tecla= event.which;
	} else {
		tecla= event.keyCode;
	}
	key=String.fromCharCode(tecla);
	//alert( 'key: ' + tecla + '  -> campo: ' + campo.value);
	if (tecla==13) {
		return false;
	}
	if (tecla==BACKSPACE) {
		return true;
	}
	return (isNum(key));
}
function FormataCNPJ(el) {
	vr=el.value;
	tam=vr.length;
	if ( vr.indexOf(".") == -1 ) {
		if ( tam <= 2 ) el.value = vr;
		if ( (tam > 2) && (tam <= 6) ) el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, tam );
		if ( (tam >= 7) && (tam <= 10) ) el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/';
		if ( (tam >= 11) && (tam <= 18) ) el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/' + vr.substr( 8, 4 ) + '-' + vr.substr( 12, 2 ) ;
	}
	return true;
}

function status_rotate(text) {
	rotate++;
	rotate%=text.length;
	window.status=text[rotate];
	setTimeout("status_rotate(text)",5000);
}

function blinkIt() {
	if (!document.all) {
		return;
	} else {
		for(i=0;i<document.all.tags('blink').length;i++){
			s=document.all.tags('blink')[i];
			s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
		}
	}
}

// get value of querystring param
function getQueryParamValue(param) {
	var q = document.location.search;
	var detectIndex = q.indexOf(param);
	var endIndex = (q.indexOf("&", detectIndex) != -1) ? q.indexOf("&", detectIndex) : q.length;
	if(q.length > 1 && detectIndex != -1) {
		return q.substring(q.indexOf("=", detectIndex)+1, endIndex);
	} else {
		return "";
	}
}

/* add Array.push if needed */
if(Array.prototype.push == null){
	Array.prototype.push = function(item){
		this[this.length] = item;
		return this.length;
	}
}

//ToolTip
function bs_isNull(theVar) {
	if (typeof(theVar) == 'undefined') return true;
	if (theVar == null) return true;
	return false;
}
function Position(x, y) {
	this.x = x;this.y = y;
}
function getAbsolutePos(el, stopIfAbsolute) {
	if (bs_isNull(el)) {
		var res = new Position(0, 0);return res;
	}
	var res = new Position(el.offsetLeft, el.offsetTop);
	if (el.offsetParent) {
		if ((stopIfAbsolute != true ) || ((el.offsetParent.currentStyle.position != 'absolute') && (el.offsetParent.currentStyle.position != 'relative') && (el.offsetParent.currentStyle.overflow != 'auto') && (el.offsetParent.currentStyle.overflow != 'scroll'))) {
			var tmp = getAbsolutePos(el.offsetParent, stopIfAbsolute);res.x += tmp.x;res.y += tmp.y;
		}
	}
	return res;
}
function ChilliToolTip(el) {
	try {
		var ct=document.getElementById('CHILLITOOLTIP');
	} catch (e) {
		alert(e.message);
	}
	var pos = getAbsolutePos(el);
	var elHeight = el.offsetHeight;
	ct.style.left=pos.x + el.offsetWidth;
	ct.style.top=parseInt(pos.y) + parseInt(elHeight) +0;
	if (ct.style.display=='block') {
		//ct.style.visibility='visible';
		el.title=ct.innerHTML;
		ct.style.display='none';
	} else {
		//ct.style.visibility='hidden';
		ct.title=el.title;
		el.title='';
		ct.innerHTML=ct.title;
		ct.style.display='block';
	}
}

/***
* 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;
	}
}

function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag)  {
	// the highlightStartTag and highlightEndTag parameters are optional
	if ((!highlightStartTag) || (!highlightEndTag)) {
		highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
		highlightEndTag = "</font>";
	}

	// find all occurences of the search term in the given text,
	// and add some "highlight" tags to them (we're not using a
	// regular expression search, because we want to filter out
	// matches that occur within HTML tags and script blocks, so
	// we have to do a little extra validation)
	var newText = "";
	var i = -1;
	var lcSearchTerm = searchTerm.toLowerCase();
	var lcBodyText = bodyText.toLowerCase();

	while (bodyText.length > 0) {
		i = lcBodyText.indexOf(lcSearchTerm, i+1);
		if (i < 0) {
			newText += bodyText;
			bodyText = "";
		} else {
			// skip anything inside an HTML tag
			if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
				// skip anything inside a <script> block
				if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
					newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
					bodyText = bodyText.substr(i + searchTerm.length);
					lcBodyText = bodyText.toLowerCase();
					i = -1;
				}
			}
		}
	}
	return newText;
}

function printOut(recid) {
	window.open('printout.php?recid='+recid+'&referer='+window.location.href);
	return false;
}
function recommend(recid) {
	Remote('recommend.php?recid='+recid,'310','360','yes');
	return false
}

//IE FLASH FIX
theObjects = document.getElementsByTagName("object"); 
for (var i = 0; i < theObjects.length; i++) { 
theObjects[i].outerHTML = theObjects[i].outerHTML; 
}
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

function Posicionamento() {
	var posicaoy = findPosY(document.getElementById('Local_Precos'));
	//alert(String(posicaoy));
	window.scrollTo(0,posicaoy);
}
