function get_id(ID) {
	return document.getElementById(ID);
}

function get_tag(tag) {
	return document.getElementsByTagName(tag);
}

function get_name(name) {
	return document.getElementsByName(name);
}

function sleep(milliseconds) {
	var start = new Date().getTime();
	for (var i = 0; i < 1e7; i++) {
		if ((new Date().getTime() - start) > milliseconds){
			break;
		}
	}
}

function load_url(url,alvo,msg) {
	document.getElementById('alerta').style.display = "block";
	document.getElementById('alerta').innerHTML = '&nbsp; / '+msg;
	window.location=url;
}

function abre_ajax() {
	var core;
	if (window.XMLHttpRequest) {
		core = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		core= new ActiveXObject("Msxml2.XMLHTTP");
		if (!core) {
			core = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else {
		alert("Seu Navegador não possui suporte a essa aplicação");
	}
	return core;
}

function Trim(ip) { 
	var str = ip;
	return str.replace(/^\s+|\s+$/g,"");
}

function show_hide(opt1,opt2){
	get_id(opt2).style.display = 'none';
	get_id(opt1).style.display = 'block';
}
function formata_data(campo,passo) {
	if (passo==1) {
		if (get_id(campo).value.length == 2) { get_id(campo).value += '/'; }
	}
	else {
		if (get_id(campo).value.length == 2) { get_id(campo).value += '/'; }
		if (get_id(campo).value.length == 5) { get_id(campo).value += '/'; }
	}}
function formata_hora(campo,passo) {
	if (passo==1) {
		if (get_id(campo).value.length == 2) { get_id(campo).value += ':'; }
	}
	else {
		if (get_id(campo).value.length == 2) { get_id(campo).value += ':'; }
		if (get_id(campo).value.length == 5) { get_id(campo).value += ':'; }
	}
}
function horizontal() { 

   var navItems = document.getElementById("barra").getElementsByTagName("li"); 
    
   for (var i=0; i< navItems.length; i++) { 
      if((navItems[i].className == "menuvertical") || (navItems[i].className == "submenu")) 
      { 
         if(navItems[i].getElementsByTagName('ul')[0] != null) 
         { 
            navItems[i].onmouseover=function() {this.getElementsByTagName('ul')[0].style.display="block";this.style.backgroundColor = "#e2e4ff";} 
            navItems[i].onmouseout=function() {this.getElementsByTagName('ul')[0].style.display="none";this.style.backgroundColor = "#e2e4ff";} 
         } 
      } 
   } 
} 


/* funcoes do alert window */
var lz_alert_html='<table id=\"lz_chat_alert_box\" cellspacing=\"4\" cellpadding=\"0\"><tr><td height=\"15\" valign=\"top\" id=\"lz_chat_alert_box_title\" colspan=\"2\">Alerta de evento</td></tr><tr><td width=\"50\" align=\"center\"><img src=\"imagens/icon_info.gif\" alt=\"\" width=\"32\" height=\"32\" border=\"0\" style=\"margin-left:8px;\"></td><td id=\"lz_chat_alert_box_text\"></td></tr><tr><td height=\"25\" valign=\"top\" align=\"center\" colspan=\"2\"><input type=\"button\" id=\"lz_chat_alert_button\" value=\"OK\"></td></tr></table>';
var lz_alert_window=null;

function lz_tracking_send_alert(_text)
{
	if(lz_alert_window != null) {
		document.body.removeChild(document.getElementById('lz_alert_window'));
	}
	lz_alert_window = new lz_livebox('lz_alert_window',500,110,lz_alert_html);
	lz_alert_window.lz_livebox_show();
	document.getElementById("lz_chat_alert_box").style.visibility = "visible";
	document.getElementById("lz_chat_alert_button").onclick = function(){if(lz_alert_window != null){document.body.removeChild(document.getElementById('lz_alert_window'));lz_alert_window=null;}};
	document.getElementById("lz_chat_alert_box_text").innerHTML = _text;
	window.focus();
}
function lz_livebox(_name,_width,_height,_template)
{
	this.lz_livebox_scroll_finished = false;
	this.lz_livebox_template = _template;
	this.lz_livebox_name = _name;
	this.lz_livebox_width = _width;
	this.lz_livebox_height = _height;
	this.lz_livebox_move = lz_livebox_move_box;
	this.lz_livebox_show = lz_livebox_show_box;
	this.lz_livebox_close = lz_livebox_close_box;
	
	
	function lz_livebox_close_box(uid)
	{
		if(!this.lz_livebox_scroll_finished)
			return;
		
		document.body.removeChild(this.MainDiv);
		lz_request_window = null;
	}
	
	function lz_livebox_show_box()
	{
		this.MainDiv = document.createElement('DIV');
		this.MainDiv.id = this.lz_livebox_name;
		this.MainDiv.style.height = this.lz_livebox_height+'px';
		this.MainDiv.style.width = this.lz_livebox_width+'px';
		this.MainDiv.style.position = 'absolute';
		this.MainDiv.style.left = -400+'px';
		this.MainDiv.style.top = -400+'px';
		this.MainDiv.style.zIndex = 100001;
		this.MainDiv.innerHTML = this.lz_livebox_template;
		document.body.appendChild(this.MainDiv);
		window.setTimeout("window['"+ this.lz_livebox_name +"'].lz_livebox_move()",1000);
	}

	function lz_livebox_move_box()
	{
		var current = parseInt(this.MainDiv.style.top.replace("px","").replace("pt",""));
		current+=15;

		this.MainDiv.style.top = current+'px';
		this.MainDiv.style.left = (lz_livebox_center_get_left()*0.8)+'px';

		if(current < (lz_livebox_center_get_top()-15))
			window.setTimeout("window['"+ this.lz_livebox_name +"'].lz_livebox_move()",15);
		else
			this.lz_livebox_scroll_finished = true;

		if(this.lz_livebox_scroll_finished && document.body.onresize == null)
		{
			window.onresize = 
			window.onscroll = lz_livebox_center_box;
		}
	}
}

function lz_livebox_center_box()
{
	if(document.getElementById("lz_request_window") != null)
	{
		document.getElementById("lz_request_window").style.top = lz_livebox_center_get_top()+'px';
		document.getElementById("lz_request_window").style.left = (lz_livebox_center_get_left()*0.8)+'px';
	}
	if(document.getElementById("lz_alert_window") != null)
	{
		document.getElementById("lz_alert_window").style.top = lz_livebox_center_get_top()+'px';
		document.getElementById("lz_alert_window").style.left = (lz_livebox_center_get_left()*0.8)+'px';
	}
}

function lz_livebox_center_get_left()
{
	var scrollleft = (document.documentElement) ? Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) : 50;
	var xc = (document.documentElement) ? 50 : window.pageXOffset;
	var xd = (document.documentElement) ? (document.documentElement.offsetWidth * 50 / 100) + scrollleft : (window.innerWidth * 50 / 100) + window.pageXOffset;
	var top;
	if (3 == 2) 
		top = xc + scrollleft;
	else if (3 == 3) 
		top = xd;
	else 
		top = 50;
	top -= (302 / 2);
	return top;
}

function lz_livebox_center_get_top()
{
	var scrolltop = (document.documentElement) ? Math.max(document.documentElement.scrollTop, document.body.scrollTop) : 50;
	var xc = (document.documentElement) ? 50 : window.pageYOffset;
	var xd = (document.documentElement) ? (document.documentElement.offsetHeight * 50 / 100) + scrolltop : (window.innerHeight * 50 / 100) + window.pageYOffset;

	if(window.pageYOffset != null)
		xd = (window.innerHeight * 50 / 100) + window.pageYOffset;
	
	var top;
	if (3 == 2) 
		top = xc + scrolltop;
	else if (3 == 3) 
		top = xd;
	else 
		top = 50;
	top -= (220 / 2);

	return top;
}

function add_ponto(id_cliente,lat,lngg) {
	data_post = 'id_cliente='+id_cliente;
	data_post += '&lat='+lat;
	data_post += '&long='+long;
	window.frames[0].tb_show("Adicionar Ponto","../cadastro_pontos_iframe.php?"+data_post+"TB_iframe=true&height=60&width=530","etc");
}
