// JavaScript Document

$op = new Objeto('');
$tipo   = 1;
$PAGINA = 1;
onload(function(){ F5();
var $pesquisa = new Objeto('pesquisar_');		
	$pesquisa.mask_value('Digite aqui o nome de sua pesquisa');

});


function Escolha($conf){
	try{ $pais       = get('pais').value;      }catch(e){ $pais       = ''; }
	try{ $estado     = get('estado').value;    }catch(e){ $estado     = ''; }
	try{ $cidade     = get('cidade').value;    }catch(e){ $cidade     = ''; }
	try{ $diacomo    = get('diacomo').value    }catch(e){ $diacomo    = ''; }
	try{ $cooperador = get('cooperador').value }catch(e){ $cooperador = ''; }
	try{ $tsda       = get('tsda').value       }catch(e){ $tsda       = ''; }
	try{ $dias       = get('dias').value       }catch(e){ $dias       = ''; }

    //       0          1           2            3            4            5         6          7       
	$com = $pais+'/'+$estado+'/'+$cidade+'/'+$diacomo+'/'+$cooperador+'/'+$tsda+'/'+$dias+'/'+$PAGINA;
if($conf == 1){	 $com = $pais.value;  }	
	var $local = window.location.href.split('#');
	$tipo = 1;
	window.location.href = $local[0]+'#'+$com;
	
	}
$_URL = window.location.href;
window.setInterval(function(){
							
				if($_URL != window.location.href){
			    console('Aguarde carregando...');
				$_URL = window.location.href;
				var $_URL2 = 'relatorio_busca.php?dados='+$com+'&tipo='+$tipo;
				$op.Ajax($_URL2,function($rsp){
				get('_local').innerHTML = $rsp; 
				close_alert();
				});
				
				}
							
							},100);	


function F5(){
	var $url = window.location.href;
	if($url.indexOf('#') != -1){
	var $go = true;
	var tmp = $url.split('#'); 
	if(tmp[1].indexOf('_Cidades') != -1){ $tipo = 2; }	
	if(tmp[1].indexOf('_Tsda')    != -1){ $tipo = 3; }	
	if(tmp[1].indexOf('Pesquisa') != -1){ $tipo = 4; var $imp = tmp[1].replace('Pesquisa/','');  get('pesquisar_').value=$imp; Pesquisar(); $go = false;}	
	if($go == true){
	$com  = tmp[1];	
	}
	$_URL = 'go';
	}
	
}


function cidades(){
	    var $local = window.location.href.split('#');
		window.location.href = $local[0]+'#_Cidades\\';
		$tipo = 2;
		$com = '#_Cidades\\';
		zeraPG();
		
}
function Tsda(){
	    var $local = window.location.href.split('#');
		window.location.href = $local[0]+'#_Tsda\\';
		$tipo = 3;
		$com = '#_Tsda\\';
		zeraPG();
		window.location.reload();
}
function avancada(){
	    var $local = window.location.href.split('#');
		window.location.href = $local[0];
}

/////
function Paginacao($GOpg){
var $esco = 's';
$PAGINA = $GOpg;

var $local = window.location.href.split('#');
//  window.location.href = $local[0]+'#_Tsda\\';
		
if(window.location.href.indexOf('#_Tsda') != -1){  
$esco = 'n'; 
$com = $local[0]+'#_Tsda\\0/1/2/3/'+$GOpg; 
$tipo = 3;
window.location.href = $com ;  

}
if(window.location.href.indexOf('#_Cidades') != -1){  
$esco = 'n'; 
$com = $local[0]+'#_Cidades\\0/1/2/3/'+$GOpg; 
$tipo = 2;
window.location.href = $com ;  

}


if($esco == 's'){
Escolha();
}
	
}

function zeraPG(){
	$PAGINA = 1;
}

function Pesquisar(){
	var $txt  = get('pesquisar_').value;
	if($txt == 'Digite aqui o nome de sua pesquisa'){ $txt = ''; }
	zeraPG();
	$tipo = 4;
    var $local = window.location.href.split('#');	
	$com = $local[0]+'#Pesquisa/'+$txt;
	window.location.href = $com ;
	
	
}