﻿//tiago
function historyChange(newLocation,historyData) 
{   
    if(newLocation != null && newLocation != '') 
    {
        var nav = GetNavegador();
        
        var Menu = QueryString('menuId');
        Menu = (Menu == null || Menu == '')? 116 : Menu;
        var ShowFlash = (location.hash.indexOf("TrocaMenu") >= 0)
      
        if(Menu != '')
        {
            if (EnumNavegador.IE6 != nav)
                MontaMenu(Menu,!ShowFlash);
        }

        if(newLocation.indexOf('pchave')>= 0)         
        {
            SetElements();

            if (EnumNavegador.IE == nav || EnumNavegador.IE6 == nav)
                document.getElementById('ctl00_pesquisa_campo').value = QueryString('pchave');
            
            if(EnumNavegador.SAFARI == nav)
            {
                var newPchave = QueryStringInUrl(newLocation,'pchave');
                newLocation = newLocation.replace('pchave','_p');
                newLocation = newLocation + '&pchave=' + newPchave;

                EnviarPedido(hashValue, TratarDados, '', 'GET', true);  
            }
            
            OcultarDivsGerenciar();
            ExibirDivMenu('PainelCarregando');       
            EnviarPedido(newLocation, TratarDados, '', 'GET',true);
        }  
    }
    else
    {
        location.reload(true);
    }
}

function KeyBusca(evt)
{
    var tecla;
    
      if (document.all)
            tecla = event.keyCode;
      else
            var tecla = evt.keyCode;

      if (tecla == 13)
      {
            document.getElementById('NumeroTotalFotos').innerHTML = '';
            document.getElementById('NumeroTotalFotosBottom').innerHTML = '';
          
          pagina = 1;
          ZerarClarificador();
          
          pesquisa_opcoes('none', '0');
          BuscarDados('new');
          return false;
      }
}

function Key(evt, src)
{	
    var tecla;
    
	if (document.all)
		tecla = event.keyCode;
	else
		var tecla = evt.keyCode;

	if (tecla == 13)
	    SelectPagina(src);
}

function ampliaBR(id, codigo, idBlocoPaiFoto)
{
    var proddc = document.getElementById('ampdc').value;
    var prodrf = document.getElementById('amprf').value;
    var numfotos = document.getElementById('NumeroTotalFotos').innerHTML;
    var url = paginaBusca;
    var ehPesqCodigo = '';

    var auxCacheKeyArray = document.getElementById('ctl00_ArrayCacheKey').value.split(',');
    var auxCacheKey = auxCacheKeyArray[idBlocoPaiFoto];
    if (auxCacheKey.length == 0)
        auxCacheKey = document.getElementById('cachekey').value;
    
    var link = '../dotnet/amplia.aspx?controleImgGrande=1&id=' + id + '&cacheKeyNavegacao=' + auxCacheKey + '&barra='+ parent.document.body.scrollTop + '&numerodefotos2=' + numfotos + '&ehPesqCodigo='+ ehPesqCodigo;
    link += '&' + url.substring(url.indexOf("pchave",0),url.length);
    
    var strId = new String(id);
    strId = strId.replace('-','0');
    
    top.janela = window.open(link, strId,'width=1020,height=610,top=0,left=0,alwaysRaised=yes,status=yes,resizable=yes,scrollbars=yes,toolbar=0,directories=0,menubar=0,location=0,copyhistory=0');
}

function ampliaBRPanther(codigo, preview, license, category, author, maxsize, keywords, pos)
{
//    var proddc = document.getElementById('ampdc').value;
//    var prodrf = document.getElementById('amprf').value;
//    var numfotos = document.getElementById('NumeroTotalFotos').innerHTML;
    var url = paginaBusca;
//    var ehPesqCodigo = '';

//    var auxCacheKeyArray = document.getElementById('ctl00_ArrayCacheKey').value.split(',');
//    var auxCacheKey = auxCacheKeyArray[idBlocoPaiFoto];
//    if (auxCacheKey.length == 0)
//        auxCacheKey = document.getElementById('cachekey').value; + '&descritores='+ descritores
    
    var link = '../dotnet/ampliapanther.aspx?codigo=' + codigo  + '&preview=' + preview + '&license=' + license + '&category=' + category + '&author=' + author + '&maxsize=' + maxsize + '&keywords=' + keywords + '&pos=' + pos;
    link += '&' + url.substring(url.indexOf("pchave",0),url.length);
    
//    var strId = new String(id);
//    strId = strId.replace('-','0');
    
    top.janela = window.open(link, 'Panther','width=1020,height=610,top=0,left=0,alwaysRaised=yes,status=yes,resizable=yes,scrollbars=yes,toolbar=0,directories=0,menubar=0,location=0,copyhistory=0');
}

function AmpliaVideoBR(idVideo,fornecedor)
{
	var url = paginaBusca;
	var link = '../dotnet/AmpliaVideo.aspx?fornecedor=' + fornecedor + '&id=' + idVideo;
    link += '&' + url.substring(url.indexOf("pchave",0),url.length);
	top.janela = window.open(link,idVideo,'width=720,height=720,top=0,left=0,alwaysRaised=yes,status=yes,resizable=yes,scrollbars=yes,toolbar=0,directories=0,menubar=0,location=0,copyhistory=0');
}

function amplia(id, codigo)
{
    var proddc = this.document.formulario.ampdc.value;
    var prodrf = this.document.formulario.amprf.value;
    var numfotos = this.document.getElementById('numerodefotos2').value;
    var url = new String(this.document.getElementById('urlb').value);
    var ehPesqCodigo= this.document.getElementById('ehPesqCodigo').value;
    var link = 'amplia.aspx?controleImgGrande=1&id=' + id + '&cacheKeyNavegacao=' + this.document.getElementById('cachekey').value + '&barra='+ this.parent.document.body.scrollTop + '&numerodefotos2=' + numfotos + '&ehPesqCodigo='+ ehPesqCodigo;
    link += '&' + url.substring(url.indexOf("pchave",0),url.length);
    var strId = new String(id);
    strId = strId.replace('-','0');
    top.janela = window.open(link, strId,'width=960,height=600,top=0,left=0,alwaysRaised=yes,status=yes,resizable=yes,scrollbars=yes,toolbar=0,directories=0,menubar=0,location=0,copyhistory=0');
}
function KeyPagina(control,evt)
{
    var tecla;
    
	if (document.all)
		tecla = event.keyCode;
	else
		var tecla = evt.keyCode;

	if (tecla == 13)
	{		
	    GoPage(control.value);
	    return false;
	}
}

function GoPage(PageNumber)
{  
    var TotalDePaginas = parseInt(document.getElementById('PaginaFinal').innerHTML);
    var PaginaAtual = document.getElementById('PaginaAtual').innerHTML;
      if (PageNumber == null || PageNumber.length == 0 || PageNumber == 0)
      {
          PageNumber = parseInt(PaginaAtual) + 1;
      }
      if(TotalDePaginas >= PageNumber || TotalDePaginas ==  0)
      { 
          pagina = parseInt(PageNumber);
            //BuscarDados(); 
            var Pag = parseInt(UltimaUrl.substr(UltimaUrl.indexOf('__pagina=') +9,PaginaAtual.length).replace('&',''));//Pega o número da página pesquisada
        if(Pag > 0)
        {  
              if(MenuId != EnumMenu.Panther)
              {
                  if(document.all)
                    UltimaUrl = UrlDecode(UltimaUrl);    
            
                    var NovaUrl = UltimaUrl.replace('__pagina=' + Pag + '&','__pagina=' + PageNumber + '&');      
                    LimpaTabela();          
                    EnviarPedido(NovaUrl, TratarDados, parametros, 'GET'); 
              }
              else
              {
                   if(document.all)
                    UltimaUrl = UrlDecode(UltimaUrl);    
            
                    var NovaUrl = UltimaUrl.replace('__pagina=' + Pag + '&','__pagina=' + PageNumber + '&');      
                    LimpaTabela();          
                    EnviarPedido(NovaUrl, TratarDadosPanther, parametros, 'GET'); 
              }           
        }
            
            
    }
      else  
      {
          pagina = PaginaAtual;
          alert('Pagina requisitada não está disponível');            
      }
      return false;
}

function IncrementPage()
{
    ++pagina;
}

function SelectPagina(src)
{
    var p = parseInt(document.getElementById(src).value);
    
    // Se o usuário tentar pular para a página atual, não faz a busca
    if(pagina == p)
        return;
    
    pagina = p;
    BuscarDados();
}
