// JavaScript Document


function auto_tab(ini,len,itemx){
	
if (ini.value.length==len){document.getElementById(itemx).focus()}
}

function IsDate(day, month, year) {
	//IsDate(29, 2, 2005)
	//IsDate(29, 2, 2004)
	var date = new Date();
	var blnRet = false;
	var blnDay;
	var blnMonth;
	var blnYear;

	date.setFullYear(year, month -1, day);

	blnDay   = (date.getDate()      == day);
	blnMonth = (date.getMonth()     == month -1);
	blnYear  = (date.getFullYear()  == year);

	if (blnDay && blnMonth && blnYear)
	blnRet = true;

	return blnRet;
}


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 GetXmlObject2(){
var xmlhttp2=null;
try
  {  xmlhttp2=new XMLHttpRequest();  }
catch (e)
  {
try
    {    xmlhttp2=new ActiveXObject("Msxml2.XMLHTTP");    }  
catch (e)
    {    xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP"); }
  }
return xmlhttp2;

}

function ajax_id(){
var switcher = document.getElementById(id_id_fixo);
if(xmlhttp.readyState<=3){
switcher.innerHTML = "<table cellspacing='5' cellpadding='9' border='0'  class='tab1_div' width='100%'><tr><td valign='middle' align='center'><b>Carregando... </b><br><br><img src='../imagens/loading.gif' width='30px'></center></table>"
}
if(xmlhttp.readyState==4){	
var x = xmlhttp.responseText;
extraiScript(x);
switcher.innerHTML=x;
}
}

function ajax_id2(){
var switcher2 = document.getElementById(id_id_fixo2);
if(xmlhttp2.readyState<=3){
switcher2.innerHTML = "<table cellspacing='5' cellpadding='9' border='0'  class='tab1_div' width='100%'><tr><td valign='middle' align='center'><b>Carregando... </b><br><br><img src='../imagens/loading.gif' width='30px'></center></table>"
}
if(xmlhttp2.readyState==4){	
var x = xmlhttp2.responseText;
extraiScript(x);
switcher2.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){

//var conf=confirm("Voce tem certeza que deseja modificar esse item?")
var conf=true
if (conf==true){
//alert(conf)

var valor_box;
//alert(document.getElementById(nome_box).checked)
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(eventx){
	
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 = (eventx.pageX+marginX);
		_y = (eventx.pageY+marginY);
		
	if (typeof(eventx.pageX)=="undefined"){
	_x = 300
	_y = 200
	}	
	}
	
}

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 atualiza_div2(div,urlx){

xmlhttp2 = GetXmlObject2()
if (xmlhttp2==null){
alert('Seu navegador não suporta Ajax');
return;
}
id_id_fixo2=div
	

var url2=urlx
//url2 = url2+"?id_perfil="+id_perfil
url2 = url2+"&tm="+Math.random();

xmlhttp2.onreadystatechange=ajax_id2;
xmlhttp2.open("GET",url2,true);
xmlhttp2.send(null);

}

function atualiza_div_ef(div,urlx){
Effect.Appear(div, {to: 1});
atualiza_div(div,urlx)
//ef_black1()
}

function atualiza_div_ef2(div,urlx,event){
Effect.Appear(div, {to: 1});
atualiza_div(div,urlx)
mouse_xy(event)
_x=_x-9
_y=_y-150

document.getElementById(div).style.top = _y+'px';

}

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).innerHTML=""
		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);

}



function monta_campos(id){ 

  //alert(document.getElementById("campo_array").value)
   n_par=document.getElementById("campo_array"+id).value
   t_par=document.getElementById("tipo_array"+id).value
  	n_par = n_par.split(',');
		t_par = t_par.split(',');
	
	var url3="campo_array="+document.getElementById("campo_array"+id).value+"&tipo_array="+document.getElementById("tipo_array"+id).value
	for (i=1; i<n_par.length-0;i++)
	{
		//alert(t_par[i]+id)
		//alert(document.getElementById(n_par[i]).value)
	//valor_box=document.getElementById(n_par[i]).value	
	if (t_par[i]!="d"){
		if (t_par[i]=="t"){
	url3 = url3+"&"+ n_par[i] +id+"="+escape(document.getElementById(n_par[i]+id).value)}
	else{
		url3 = url3+"&"+ n_par[i] +id+"="+document.getElementById(n_par[i]+id).value
	}
	}
	else{
		url3 = url3+"&d"+ n_par[i] +id+"="+document.getElementById("d"+n_par[i]+id).value
		url3 = url3+"&m"+ n_par[i] +id+"="+document.getElementById("m"+n_par[i]+id).value
		url3 = url3+"&y"+ n_par[i] +id+"="+document.getElementById("y"+n_par[i]+id).value
	}
	//alert(url3)
	//document.getElementById("td_"+n_par[i]).innerHTML=document.getElementById(n_par[i]).value
	}
	return(url3)
	
  }
  
  function atualiza_div_post(div,urlx,para){

xmlhttp = GetXmlObject()
id_id_fixo=div
	

var url2=urlx
//url2 = url2+"?id_perfil="+id_perfil
url2 = url2+"?tm="+Math.random();

xmlhttp.onreadystatechange=ajax_id;
xmlhttp.open("POST",url2,true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xmlhttp.setRequestHeader("Content-length", para.length);
      xmlhttp.setRequestHeader("Connection", "close");

xmlhttp.send(para);

}

function show_data(sinal,div_data)

{
if (document.getElementById(div_data).style.display != "inline"){
document.getElementById(div_data).style.display = "inline"
sinal.innerHTML ="-"
}
else {
document.getElementById(div_data).style.display = "none"
sinal.innerHTML ="+"
}
}
function pronto_basico(url){


//alert(valor_box)
xmlhttp = GetXmlObject()
if (xmlhttp==null){
alert('Seu navegador não suporta Ajax');
return;
}

var url2=url;
url2 = url2+"&tm="+Math.random();
//xmlhttp.onreadystatechange=ajax_div;
//alert(url2)
xmlhttp.open("GET",url2,true);
xmlhttp.send(null);
}

		// Drag and drop
		  var objSelecionado = null;
		  var mouseOffset = null;

document.onmousemove = function(ev) {
//alert(" sdsds")
var ev = ev || window.event;
var mousePos = mouseCoords(ev);
if (objSelecionado) {
	
  document.getElementById(objSelecionado).style.left = mousePos.x - mouseOffset.x + 'px';
  document.getElementById(objSelecionado).style.top = mousePos.y - mouseOffset.y + 'px';
  document.getElementById(objSelecionado).style.margin = '0px';
  return false;
}
}

  function dragdrop2(caixa_movida, ev) {

  objSelecionado = caixa_movida;
  mouseOffset = getPosition(caixa_movida, ev);

}

function getPosition(e, ev){
e = document.getElementById(e);
var left = 0;
var top  = 0;
var coords = mouseCoords(ev);
while (e.offsetParent){
  left += e.offsetLeft;
  top  += e.offsetTop;
  e     = e.offsetParent;
}
left += e.offsetLeft;
top  += e.offsetTop;
return {x: coords.x - left, y: coords.y - top};
}
document.onmouseup = function() {
objSelecionado = null;
}

  function dragdrop2(caixa_movida, ev) {

  objSelecionado = caixa_movida;
  mouseOffset = getPosition(caixa_movida, ev);

}

function mouseCoords(ev){
if(ev.pageX || ev.pageY){
  return {x:ev.pageX, y:ev.pageY};
}
return {
  x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
  y:ev.clientY + document.body.scrollTop  - document.body.clientTop
};
}

function mostra_menu(){
	
	
	if (document.getElementById('td_menu').style.display=="none"){
		//document.getElementById('td_menu2').style.width = 160+'px';
	document.getElementById('td_menu').style.display="inline";
	document.getElementById('menu_show').innerHTML="(-) Ocultar Menu";}
	else {
		//document.getElementById('td_menu2').style.width = 1+'px';
	document.getElementById('td_menu').style.display="none";
	document.getElementById('menu_show').innerHTML="(+) Mostrar Menu";
}	}

function atualiza_ordem_geral(id_pagina,tabela, campo) {
 ordem = document.getElementById('ordem'+id_pagina).value;

if(!isNaN(ordem))
 {
xmlhttp = GetXmlObject()
 url2="atualiza_ordem.asp?id_pagina=" + id_pagina +"&ordem="+ ordem + "&tabela=" + tabela + "&campo=" + campo +"&tm="+Math.random();
xmlhttp.open("GET",url2,true);
xmlhttp.send(null);
 }
 else
 {
	alert("Digite somente Números!");
	return false;
 }
   

   
}
