// MENU
var classe = 'menu';
function mostra(submenu, menu) {
	classe = document.getElementById(menu).className;
	document.getElementById(menu).className="menu_sel";
	document.getElementById(submenu).style.display = 'block';
	}
function esconde(submenu, menu) {
	document.getElementById(submenu).style.display = 'none';
	document.getElementById(menu).className=classe;
	}

//Fechar avisos
var aberto = 0;
var y=1
function aviso_marc(i, id_aviso, delay){
	setTimeout(function() {
		if(aberto==0){				
			y = (y - .025).toFixed(3)
			if(y<.1)
				document.getElementById(id_aviso).style.display = 'none'
			else{
				if(navigator.appName == 'Microsoft Internet Explorer')
					document.getElementById(id_aviso).filters.alpha.opacity = y*100
				else
					document.getElementById(id_aviso).style.opacity = y
				}
			}
		}, (delay+(i*10)))
}

function fechar(id_aviso, delay){
	aberto = 0;
	y=1;
	for(i=0; i<40; i++){
		aviso_marc(i, id_aviso, delay);
		}
}

//Marcar a primeira data de aplicação através do aviso acima chamando o calendário
function marcar(t, d, m, a, cl){
	aberto = 1;
	if(t==""){//Se for a 1ª marcação
		document.getElementById('ins_tipo').value = 'insere'
		document.getElementById('data').innerHTML = 'Deseja marcar a data da<br>1&ordf; aplica&ccedil;&atilde;o em: '+d+'/'+m+'/'+a+'?'
		document.getElementById('btn_marcar').src = 'images/btn_marcar.jpg'
	}
	else if(t==1){//Se já tiver marcações e quiser uma msg diferente no aviso
		if(cl == 'td_cal_marcado'){//Se clicar numa data já marcada, apaga a mesma
			document.getElementById('ins_tipo').value = 'apaga'
			document.getElementById('data').innerHTML = 'Deseja apagar a aplica&ccedil;&atilde;o<br>de: '+d+'/'+m+'/'+a+'?'
			document.getElementById('btn_marcar').src = 'images/btn_apagar.jpg'
		}
		else{//Se clicar numa data sem marcação, marca a mesma
			document.getElementById('ins_tipo').value = 'insere'
			document.getElementById('data').innerHTML = 'Deseja marcar a data da<br>&uacute;ltima aplica&ccedil;&atilde;o para: '+d+'/'+m+'/'+a+'?'
			document.getElementById('btn_marcar').src = 'images/btn_marcar.jpg'
		}
	}
	y=1
	document.getElementById('ins_data').value = d+'/'+m+'/'+a

	mostra_aviso('aviso_marcar')
}

function mostra_aviso(id_aviso){
	y=1
	document.getElementById(id_aviso).style.display = 'block'
	if(navigator.appName == 'Microsoft Internet Explorer')
		document.getElementById(id_aviso).filters.alpha.opacity = 100
	else
		document.getElementById(id_aviso).style.opacity = 1
}


/*---------------AJAX Geral-----------------------*/

var id_elemento

var xmlHttp

function ajax(pagina, page, elemento)
{
if(elemento!='aviso_user')
document.getElementById(elemento).innerHTML='A carregar...'
id_elemento = elemento
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("O seu Browser não suporta pedidos HTTP.")
 return
 }
var url=pagina
if(url.indexOf('?')<0)
url=url+"?sid="+Math.random()
else
url=url+"&sid="+Math.random()
if(page)
url=url+"&PAGE="+page
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
 document.getElementById(id_elemento).innerHTML=xmlHttp.responseText
 } 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

