// JavaScript Document





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 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 ajax_id(){
var switcher = document.getElementById(id_id_fixo);
if(xmlhttp.readyState<=3){
switcher.innerHTML = "<table cellspacing='5' cellpadding='9' border='0' bgcolor='black' class='tab1_div'><tr><td valign='middle' align='left'>Carregando... <center><img src='../imagens/load.gif' width='25px'></center></table>"
}
if(xmlhttp.readyState==4){	
var x = xmlhttp.responseText;
extraiScript(x);
switcher.innerHTML=x;
}
}


function switch_(){
	
var switcher = document.getElementById(id_id_fixo);
		if(xmlhttp.readyState<=3){
		switcher.innerHTML = "...carregando"
		}
		
		if(xmlhttp.readyState==4){			
		var x = xmlhttp.responseText;
		extraiScript(x);
		switcher.innerHTML=x;
		
}
	}

function mostra_ef_id(id)
{
	if (document.getElementById(id).style.display == "none")
	{document.getElementById(id).style.display = "inline";
	Effect.Fade('geral', {to: 0.3}); return false;
		
	}
	else
	{
		document.getElementById(id).style.display = "none";
		Effect.Appear('geral', {to: 1}); return false;
	}	
}



function tool_tip_div(event,div_mov,larg_div){
	
	if (typeof(larg_div)=="undefined"){
		var ajuste=10
		}
		else{
		if (larg_div==""){var ajuste=10}
		else{
		var ajuste = (1*larg_div+30)*(-1)
		document.getElementById(div_mov).style.width = larg_div+'px';
		}
		}
	
mouse_xy(event)
_x=_x-0
_y=_y-0
//alert(_x+"dsdsds"+_y)
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 at_td_sel (id_id,div_pop,n_par,url) {
	
	
	if (typeof(n_par)!="undefined"){
	n_par = n_par.split(',');
	//alert(n_par.length)
	var url3=""
	for (i=0; i<n_par.length-1;i++)
	{
	valor_box=document.getElementById(n_par[i]).value	
	url3 = url3+"&"+ n_par[i] +"="+document.getElementById(n_par[i]).value
	//alert(url3)
	document.getElementById("td_"+n_par[i]).innerHTML=document.getElementById(n_par[i]).value
	}
}
	

	xmlhttp = GetXmlObject()
	var url2=url+".asp";
url2 = url2+"?id_id="+id_id+url3

url2 = url2+"&tm="+Math.random();
//xmlhttp.onreadystatechange=ajax_div;
//alert(url2)
//alert(url2)
xmlhttp.open("GET",url2,true);
xmlhttp.send(null);
mostra_id(div_pop)

}




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}
}
}


function mouse_xy(event){
	
var marginX = 0; //distancia do mouse em x
var marginY = 0; //distancia do mouse em y

 _x = 0;
 _y = 0;


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);
		
	if (typeof(event.pageX)=="undefined"){
	_x = 400
	_y = 600
	}	
	}


}

function tool_tip_div(event,div_mov,larg_div){
	
	if (typeof(larg_div)=="undefined"){
		var ajuste=10
		}
		else{
		if (larg_div==""){var ajuste=10}
		else{
		var ajuste = (1*larg_div+30)*(-1)
		document.getElementById(div_mov).style.width = larg_div+'px';
		}
		}
	
mouse_xy(event)
_x=_x-9
_y=_y-9

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 box_new(event,valor,id_campo,div_url,url_op){

	if (valor=="0")
	{
		show_usuarios(event,id_campo,div_url,'',url_op);
		
	}
	else 
	
	{
		
		
		
			}
		
		}
	

function show_usuarios(event,id_perfil,div,larg_div,urlx){
	
xmlhttp = GetXmlObject()
if (xmlhttp==null){
alert('Seu navegador não suporta Ajax');
return;
}
id_id_fixo=div

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+"&tm="+Math.random();
xmlhttp.onreadystatechange=ajax_id;
xmlhttp.open("GET",url2,true);
xmlhttp.send(null);
tool_tip_div(event,id_id_fixo,larg_div)
//ef_black1()
}

function atualiza_div(div,urlx){

xmlhttp = GetXmlObject()
if (xmlhttp==null){
alert('Seu navegador não suporta Ajax');
return;
}
id_id_fixo=div
	

var url2=urlx
//url2 = url2+"?id_perfil="+id_perfil
url2 = url2+"&tm="+Math.random();

xmlhttp.onreadystatechange=ajax_id;
xmlhttp.open("GET",url2,true);
xmlhttp.send(null);

}

function check_msg(urlx,n_msg,url_funcao,div_funcao){

xmlhttp = GetXmlObject()
if (xmlhttp==null){
alert('Seu navegador não suporta Ajax');
return;
}

var url2=urlx
url_funcaox=url_funcao
div_funcaox=div_funcao
n_msgx=n_msg


url2 = url2+"&tm="+Math.random();

xmlhttp.onreadystatechange=ajax_idxxx;
xmlhttp.open("GET",url2,true);
xmlhttp.send(null);

}




function ajax_idxxx(){

if(xmlhttp.readyState==4){	
var x = xmlhttp.responseText;
if (x!=n_msgx){
//alert(url_funcaox)
//document.getElementById('n_msg').value=x
atualiza_div(div_funcaox,url_funcaox)
}
}
}

function ef_black1()
{
	if ( typeof(black_div)=="undefined"  || black_div==""){
	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";}
	}

	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 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 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()}}
	}	
}


function pronto_geral(url,div,array_campo,div_at,url_at)
{

	n_par = array_campo;
	n_par = n_par.split(',');
	var url3=""
	url3 = url;
	url3 = url3 + ".asp?xxx=1"
	
	for (i=0; i<n_par.length;i++){	
	url3 = url3+"&"+ n_par[i] + "="+document.getElementById(n_par[i]).value;	 	
	}
	
	xmlhttp = GetXmlObject()
url3 = url3+"&tm="+Math.random();

//xmlhttp.onreadystatechange=ajax_div;
//alert(url2)

xmlhttp.open("GET",url3,true);
xmlhttp.send(null);

xmlhttp = GetXmlObject()

	id_id_fixo=div_at
		var url2=url_at+".asp";

url2 = url2+"?xxx=1"
//alert(url2)
url2 = url2+"&tm="+Math.random();
xmlhttp.onreadystatechange=ajax_id;
//alert(url2)
xmlhttp.open("GET",url2,true);
xmlhttp.send(null);

mostra_id(div);

}

