var map = null;
var map2 = null;
var geocoder = null;
var geocoder2 = null;
var pacotes = null;
function load() {
     
  if (GBrowserIsCompatible()) {
       //map = null; // limpa mapa para novos pontos
	map = new GMap2(document.getElementById('travelmapa'));
		//Localizacao de abertura e zoom
	map.setCenter(new GLatLng(-18.729501999072138, -52.646484375), 3)
	//##############Habilitar Controles no Mapa ##################
	//map.enableDoubleClickZoom();
   	map.enableScrollWheelZoom();
   	//map.addControl(new GMapTypeControl());
    map.addControl(new GSmallMapControl());
	//############################################################
	//map.addMapType(G_PHYSICAL_MAP); 
	map.setMapType(G_NORMAL_MAP);
	
		
      }
    }
	//Adiciona ponto digitado no textfield, joga texto para dentro do balão e div    
function showAddress(addressTitular, textoInfo, textoMapa, destaque,endereco,quantidade,zoom) {	 
	  
	  geocoder = new GClientGeocoder();
	  var enderecoMapa = addressTitular.split(';');
	  var ultimo = enderecoMapa[enderecoMapa.length - 1];
	  // o ultimo eh a busca do usuario
	  for(var i = 0;i<enderecoMapa.length;i++) {
	  if (enderecoMapa[i] != ''){
		 if (ultimo != enderecoMapa[i] || i == (enderecoMapa.length - 1)) { // pega o ultimo ponto para centralizar pela busca
	
			if (geocoder) {
	    		geocoder.getLatLng(enderecoMapa[i] ,function(point) {

															 if (!map){
																load();
															 }
															 if (point) {
	    		                                                
															     map.setCenter(point, zoom);
														  	     var marker = new GMarker(point);
											              	     map.addOverlay(marker);
											              	    
											              	 }
      		    									});
	 		 }
		 }
	  }
     }
	  //document.getElementById("pacoteTravel").innerHTML = destaque;
	  //document.getElementById("pacoteTravel2").innerHTML = textoInfo;
	  document.getElementById("teste").href='#'+ addressTitular + '#';
	  document.getElementById("teste").cidade = textoMapa;

 }
		//funcao passa coordenadas

function pop(mypage,myname,w,h,scroll,redim,menubar){
	var win = null;
	if(!redim) redim = "no";
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+redim
	if(menubar=="yes") settings+=",menubar=yes"
	win = window.open(mypage,myname,settings);
}

function popupVisualarNavioEx(endereco) {
	var w = 600, h = 480
	var x = (screen.width / 2 - w / 2)
	var y = (screen.height / 2 - h / 2)
	window.open(endereco,'_blank',
	 'scrollbars=no,status=no,menubar=no,resizable=no,toolbar=no,location=yes,left=' + x + ',top=' + y + ',height=' + h + ',width=' + w);
}
function popupIndica(endereco) {
	var w = 400, h = 370
	var x = (screen.width / 2 - w / 2)
	var y = (screen.height / 2 - h / 2)
	window.open(endereco,'_blank',
	 'scrollbars=no,status=no,menubar=no,resizable=no,toolbar=no,location=no,left=' + x + ',top=' + y + ',height=' + h + ',width=' + w);
}

function autopost(elem) {
	elem.form.submit();
}

function linksubmit(idform) {
	document.getElementById(idform).submit();
	return false;
}

function submit_news() {
	var janela;
	var nome = document.form_news.nome.value;
	var email = document.form_news.email.value;
	w = 500;
	h = 480;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	janela = window.open('../../../cadastro_news.asp?nome='+nome+'&email='+email+'', 'Cadastrar', 'left='+LeftPosition+',top='+TopPosition+',width='+w+', height='+h+'');
	document.form_news.reset();
}

function horario_mundial(w, h, msg){
	var janela_fuso;
	var len_query = document.form_fuso.query.value.length;
	if (len_query < 3){
		alert(msg);
		document.form_fuso.query.focus();
		return false;
	}
	var query = document.form_fuso.query.value;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	janela_fuso = window.open('redirect.asp?url=http://www.timeanddate.com/worldclock/results.html?query='+query+'', 'Fuso', 'left='+LeftPosition+',top='+TopPosition+',width='+w+', height='+h+'');
	document.form_fuso.reset();
}

//utilitários de formulários
function vaiParaProximoCampo(e) {
	var evento = (window.event ? window.event : e);
	if(evento.keyCode >= 48 && evento.keyCode <= 105) {
		var elemDe = (window.event ? evento.srcElement : evento.target);
		if(elemDe.value.length == elemDe.maxLength) {
			var frm = elemDe.form;
			for(var i = 0;i<frm.length;i++) {
				if(frm[i]==elemDe && i < frm.length - 1) {
					frm[i+1].focus();
					break;
				}
			}
		}
	}
}

//formatar valores
function formatNumber(valor, mask) {
	var re = /(222)([\.,]?)(111)([\.,]?)(0+)?/;
	return mask.replace(re, 
		function($0, $1, $2, $3, $4, $5) {
			var resto = parseInt(valor);
			var parte = (resto % 1000);
			resto = parseInt(resto / 1000);
			if(resto > 0)
				fmt = "" + resto + $2 + "000".substring(0, 3 - parte.toString().length) + parte;
			else
				fmt = "" + parte;
			if($5 && $5.length > 0) {
				var cent = parseInt((valor - parseInt(valor)) * Math.pow(10, $5.length));
				fmt += $4 + $5.substring(0, $5.length - cent.toString().length) + cent;
			}
			return fmt;
		}
	);
}

// Cookies
function setCookie(c_name, value, expiredays){
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}

function ShowPopup(pagina,largura,altura) {
    w = screen.width;
    h = screen.height;

    meio_w = w/2;
    meio_h = h/2;

    altura2 = altura/2;
    largura2 = largura/2;
    meio1 = meio_h-altura2;
    meio2 = meio_w-largura2;

    window.open(pagina,'','height=' + altura + ', width=' + largura + ', top='+meio1+', left='+meio2+''); 
}

