

// funcao basica para as operacoes em ajax .. nao me pergunte com funcionao pq eh assim eh pronto
function GetXmlObject(){
var xmlhttp=null;
try
  {  xmlhttp=new XMLHttpRequest();  }
catch (e)
  {
try
    {    xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");    }  
catch (e)
    {    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
  }
return xmlhttp;

}

function pag_size()
{
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}
      function ob_resolucao(idxx){ 
		if(document.getElementById("id_sts_oc"+idxx).value == '2')
		{
			if(document.getElementById("resolucao"+idxx).value == '')
			{
			alert("Para colocar o status resolvido, preencha a resolução !")
				return false;
			}
			else{
			return valida();}
		}else{
			return valida();}
		 
		 } 

function ef_black1()
{
	if ( typeof(black_div)=="undefined"  || black_div=="" || black_div == 'x'){
	document.getElementById('black').style.height = pag_size()[1]+"px"
	document.getElementById('black').style.width = pag_size()[0]+"px" 
	black_div="x"
	Effect.Appear('black', {duration:1.0 ,from: 0.0,to: 0.6}); return false;
	}else
{
	black_div="y";}
	}


// funcao basica em ajax para atualizar os checks box sem refresh
function pronto(id_id,url,nome_box,n_itens){

var conf=confirm("Voce tem certeza que deseja modificar esse item?")

if (conf==true){
//alert(conf)

var valor_box;

if(typeof(n_itens)!="undefined"){
uncheckAll(n_itens)
document.getElementById(nome_box).checked=true
}
if(document.getElementById(nome_box).checked==true){

valor_box="1";
}
else{
valor_box="0";

}
//alert(valor_box)
xmlhttp = GetXmlObject()
if (xmlhttp==null){
alert('Seu navegador não suporta Ajax');
return;
}

var url2=url+".asp";
url2 = url2+"?id_id="+id_id
url2 = url2+"&valor_box="+valor_box
url2 = url2+"&tm="+Math.random();
//xmlhttp.onreadystatechange=ajax_div;
//alert(url2)
xmlhttp.open("GET",url2,true);
xmlhttp.send(null);
}
else
{
	if(document.getElementById(nome_box).checked==true){
	document.getElementById(nome_box).checked=false	
	}else{document.getElementById(nome_box).checked=true}
}
}

//funcao para descelecionar todos os checks box de um form
function uncheckAll(n_itens) {
for (var j = 1; j <= n_itens; j++) {
box = document.p + j; 
if (box.checked == true) box.checked = false;
   }
//window.location.reload();

}
// funcao em ajax para atualizar automaticamente o conteudo de um caixa de selecao dependente de outra
function selecao(id_id,url,id_id2){
id_id2=document.getElementById(id_id2).value
//alert(id_id2)
xmlhttp = GetXmlObject()
if (xmlhttp==null){
alert('Seu navegador não suporta Ajax');
return;
}
id_id_fixo=id_id
var url2=url+"";
url2 = url2+"?id_id2="+id_id2
//url2 = url2+"&valor_box="+valor_box
url2 = url2+"&tm="+Math.random();
xmlhttp.onreadystatechange=ajax_id;
xmlhttp.open("GET",url2,true);
xmlhttp.send(null);

}


// funcao para tooltips, carrega uma div na posicao atual do mouse
function show_usuarios(event,id_perfil,url){
	
xmlhttp = GetXmlObject()
if (xmlhttp==null){
alert('Seu navegador não suporta Ajax');
return;
}
id_id_fixo=url
var url2=url+'.asp';
url2 = url2+"?id_perfil="+id_perfil
url2 = url2+"&tm="+Math.random();
xmlhttp.onreadystatechange=ajax_id;
xmlhttp.open("GET",url2,true);
xmlhttp.send(null);
tool_tip_div(event,id_id_fixo)}


// funcao para tooltips, carrega uma div na posicao atual do mouse
function show_tool_div_mouse(event,id,url,parametro,parametro1,parametro2,parametro3){
	
xmlhttp = GetXmlObject()
if (xmlhttp==null){
alert('Seu navegador não suporta Ajax');
return;
}
id_id_fixo=url
var url2=url+'.asp';
url2 = url2+"?id="+id
url2 = url2+"&parametro="+parametro
url2 = url2+"&parametro1="+parametro1
url2 = url2+"&parametro2="+parametro2
url2 = url2+"&parametro3="+parametro3
url2 = url2+"&tm="+Math.random();
xmlhttp.onreadystatechange=ajax_id;
xmlhttp.open("GET",url2,true);
xmlhttp.send(null);
tool_tip_div(event,id_id_fixo)}



// funcao q faz a atualizacao do target do ajax. ela tem consegue recarregar scripts dentro de scrips
function ajax_id(){if(xmlhttp.readyState==4){	
     if(xmlhttp.status == 200){
                var texto=xmlhttp.responseText;
                if(texto.indexOf(" ")<0) texto=texto.replace(/\+/g," ");
                //texto=unescape(texto); //descomente esta linha se tiver usado o urlencode no php ou asp
             
                extraiScript(texto);
            }

var switcher = document.getElementById(id_id_fixo);
switcher.innerHTML=xmlhttp.responseText;	

}

}

function ajax_aguarda(id_id_fixo2){
var switcher = document.getElementById(id_id_fixo2);	
alert(id_id_fixo2);


if(xmlhttp.readyState==4){
switcher.innerHTML=xmlhttp.responseText;	
//document.getElementById("menux").innerHTML=flash("menu-inst.swf","210","130")
var so = new SWFObject("../top.swf", "mymovie", "100%", "150", "7", "");
so.addParam("wmode", "transparent");
so.write(id_id_fixo2);
}
}


function ef_black2()
{
		black_div=""
new Effect.Appear('black', {duration:0.5, to: 0.0}); 
var xxxx = function testexx (){document.getElementById('black').style.display = "none";}
setTimeout(xxxx, 1000)
}


function mostra_id(id)
{
	if (document.getElementById(id).style.display == "none")
	{
		document.getElementById(id).style.display = "inline";
	}
	else
	{
		document.getElementById(id).style.display = "none";
	if (typeof(black_div)!="undefined"){	
	if (black_div=="x"){ef_black2()} else {black_div="x";} }
	
		if (typeof(white_div)!="undefined"){	
	
		if (white_div=="x"){geral_ef2()}}
	}	
}
// mostra ou oculta uma determinada tag pelo seu ID, e aplica o efeito de fade
function mostra_ef_id(id)
{
	if (document.getElementById(id).style.display == "none")
	{
		Effect.BlindDown(id);
		//document.getElementById(id).style.display = "inline";
	
	Effect.Fade('geral', {to: 0.3});
  //Effect.SwitchOff('geral');
		//document.getElementById("geral").switchOff();
		// document.getElementById("geral").style.display="inline-block";
		//document.getElementById("geral").onclick=alert('xxx');return false;
	}
	else
	{
		
		document.getElementById(id).style.display = "none";
		Effect.Appear('geral', {to: 1});
		//document.getElementById("geral").onclick=alert('xxx');return false;
	}	
}


// funcao para popup
function popExec( URLStr, w, h )
{
	var left = (screen.width / 2) - (w / 2);
	var top = (screen.height / 2) - (h / 2);
    window.open(URLStr, 'VARExe', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=no,width='+w+',height='+h+',left='+left+', top='+top+'');
}

// funcao para tooltips, carrega uma div na posicao atual do mouse
function show_div_mouse_fade(event,id_perfil,div,larg_div,posx_div,posy_div,urlx,parametro1){
xmlhttp = GetXmlObject()
if (xmlhttp==null){
alert('Seu navegador não suporta Ajax');
return;
}
id_id_fixo=div;
id_id_fixo2 = 'aguarda';

if (typeof(urlx)=="undefined"){url=div;}
else{
if (urlx==""){url=div}
else{
	url=urlx;
	}}
	
var url2=url+'.asp';
url2 = url2+"?id_perfil="+id_perfil
url2 = url2+"&parametro1="+parametro1
url2 = url2+"&tm="+Math.random();
xmlhttp.onreadystatechange=ajax_id_;
xmlhttp.open("GET",url2,true);
xmlhttp.send(null);
tool_tip_div_fade(event,div,larg_div,posx_div,posy_div)
ef_black1()
}

// funcao para tooltips, carrega uma div na posicao atual do mouse
function show_div_mouse_fade_fixo(event,id_perfil,div,larg_div,posx_div,posy_div,urlx,parametro1){
xmlhttp = GetXmlObject()
if (xmlhttp==null){
alert('Seu navegador não suporta Ajax');
return;
}
id_id_fixo=div;
id_id_fixo2 = 'aguarda';

if (typeof(urlx)=="undefined"){url=div;}
else{
if (urlx==""){url=div}
else{
	url=urlx;
	}}
	
var url2=url+'.asp';
url2 = url2+"?id_perfil="+id_perfil
url2 = url2+"&parametro1="+parametro1
url2 = url2+"&tm="+Math.random();
xmlhttp.onreadystatechange=ajax_id_;
xmlhttp.open("GET",url2,true);
xmlhttp.send(null);
tool_tip_div_fade_fixo(event,div,larg_div,posx_div,posy_div)
ef_black1()
}

function ajax_id_(){if(xmlhttp.readyState==4){	
     if(xmlhttp.status == 200){
                var texto=xmlhttp.responseText;
                if(texto.indexOf(" ")<0) texto=texto.replace(/\+/g," ");
                //texto=unescape(texto); //descomente esta linha se tiver usado o urlencode no php ou asp
             
                extraiScript(texto);
            }

var switcher = document.getElementById(id_id_fixo);
switcher.innerHTML=xmlhttp.responseText;	


}
}


// funcao para tooltips, carrega uma div na posicao atual do mouse
function show_div_mouse(event,id_perfil,url){
	
xmlhttp = GetXmlObject()
if (xmlhttp==null){
alert('Seu navegador não suporta Ajax');
return;
}
id_id_fixo=url
var url2=url+'.asp';
url2 = url2+"?id_perfil="+id_perfil
url2 = url2+"&tm="+Math.random();
xmlhttp.onreadystatechange=ajax_id;
xmlhttp.open("GET",url2,true);
xmlhttp.send(null);
tool_tip_div(event,id_id_fixo)}



// funcao para carregar popups, depende da popExec
function altera_pop(cd,urlx,xx,yy)
{	 
		var urlstr = urlx+'.asp?cd='+cd;
		popExec(urlstr,xx,yy);
}


function mostra_menu(){
	
	
	if (document.getElementById('td_menu').style.display=="none"){
	document.getElementById('td_menu').style.display="inline";
	document.getElementById('menu_show').innerHTML="(-) Menu";}
	else {
	document.getElementById('td_menu').style.display="none";
	document.getElementById('menu_show').innerHTML="(+) Menu";
}	}

function extraiScript(texto){
//Maravilhosa função feita pelo SkyWalker.TO do imasters/forum
//http://forum.imasters.com.br/index.php?showtopic=165277&
    // inicializa o inicio ><
    var ini = 0;
    // loop enquanto achar um script
    while (ini!=-1){
        // procura uma tag de script
        ini = texto.indexOf('<script', ini);
        // se encontrar
        if (ini >=0){
            // define o inicio para depois do fechamento dessa tag
            ini = texto.indexOf('>', ini) + 1;
            // procura o final do script
            var fim = texto.indexOf('</script>', ini);
            // extrai apenas o script
            codigo = texto.substring(ini,fim);
            // executa o script
            //eval(codigo);
            /**********************
            * Alterado por Micox - micoxjcg@yahoo.com.br
            * Alterei pois com o eval não executava funções.
            ***********************/
            novo = document.createElement("script")
            novo.text = codigo;
            document.body.appendChild(novo);
        }
    }
}



function tool_tip_div_fade(event,div_mov,larg_div,posx_div,posy_div){
	
	if (typeof(larg_div)=="undefined"){
		var ajuste=10
		}
		else{
		if (larg_div==""){var ajuste=10}
		else{
		var ajuste = (1*larg_div-250)*(-1)
		document.getElementById(div_mov).style.width = larg_div+'px';
		}
		}
	
mouse_xy(event)
_x=_x+parseInt(posx_div)
_y=_y+parseInt(posy_div)

document.getElementById(div_mov).style.top = _y+'px';
document.getElementById(div_mov).style.left = (_x+ajuste)+'px';
document.getElementById(div_mov).style.display="block";

}

function tool_tip_div_fade_fixo(event,div_mov,larg_div,posx_div,posy_div){
	
	if (typeof(larg_div)=="undefined"){
		var ajuste=10
		}
		else{
		if (larg_div==""){var ajuste=10}
		else{
		var ajuste = (1*larg_div-250)*(-1)
		document.getElementById(div_mov).style.width = larg_div+'px';
		}
		}
	
mouse_xy(event)

document.getElementById(div_mov).style.top = posy_div+'px';
document.getElementById(div_mov).style.left = posx_div+'px';
document.getElementById(div_mov).style.display="block";

}

function mouse_xy(event){
	
var marginX = 2; //distancia do mouse em x
var marginY = 2; //distancia do mouse em y
var opacity = 75; // 0 a 100
 _x = -1;
 _y = -1;
var padding = "2px 5px";
var position = "absolute";
var lar_janela = document.body.clientWidth || innerWidth

	if (document.all) {//IE
		_x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		_y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		_x += (window.event.clientX+marginX);
		_y += (window.event.clientY+marginY);
	} else {//Good Browsers
		_x = (event.pageX+marginX);
		_y = (event.pageY+marginY);
	}


}

function tool_tip_div(event,div_mov){
	
var marginX = 2; //distancia do mouse em x
var marginY = 2; //distancia do mouse em y
var opacity = 75; // 0 a 100
var padding = "2px 5px";
var position = "absolute";
var _x = -10;
var _y = -10;
var lar_janela = document.body.clientWidth || innerWidth

	if (document.all) {//IE
		_x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		_y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		_x += (window.event.clientX+marginX);
		_y += (window.event.clientY+marginY);
	} else {//Good Browsers
		_x = (event.pageX+marginX);
		_y = (event.pageY+marginY);
	}

document.getElementById(div_mov).style.top = _y+'px';

document.getElementById(div_mov).style.left = (_x+10)+'px';
document.getElementById(div_mov).style.display="block";

}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode;
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}

function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}

function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}
//  funcaoo ajax para transformar uma tag em input de edicao
function editar(id,url){
var elemento1 = document.getElementById("c_"+id);
//var elemento2 = document.getElementById("d_"+id);

alterador = "<input type=\"text\" value=\"" + elemento1.innerHTML + "\" id='"+id+"_c' style=\"width:auto;\" />&nbsp;&nbsp";
alterador = alterador + '<a href="javascript:editado(\''+id+'\',\''+url+'\')">Alterar</a>'
elemento1.innerHTML = alterador;
document.getElementById("click_"+id).onclick=null;
/*if (elemento2!=null){
alterador2 = "<input type=\"text\" value=\"" + elemento2.innerHTML + "\" id='"+id+"_d' style=\"width:39px;\" />&nbsp;&nbsp";
alterador2 = alterador2 + '<a href="javascript:editado(\''+id+'\',\''+url+'\')">Alterar</a>'
elemento2.innerHTML = alterador2;
 }
 */
}

//atualiza a base de dados com os dados do input gerado na funcao acima
function editado(id,url) {
var elemento1 = document.getElementById(id+'_c').value;
//var elemento2 = document.getElementById(id+'_d').value;

xmlhttp = GetXmlObject()
if (xmlhttp==null){
alert('Seu navegador não suporta Ajax');
return;
}

var url2=url+".asp";
url2 = url2+"?id="+id;
url2 = url2+"&elemento1="+elemento1;
//url2 = url2+"&elemento2="+elemento2;
url2 = url2+"&tm="+Math.random();
xmlhttp.open("GET",url2,true);
xmlhttp.send(null);
document.getElementById("c_"+id).innerHTML = elemento1; 
//document.getElementById("d_"+id).innerHTML = elemento2; 

}
