var isMovining;
/*
|----------------------------------------------------------------------------------------------------|
|           Função: fct_ajustaProdutos()                                                        |
|        Descrição: Ajusta o starindex.                                               |
|  ================================================================================================  |
|       Parâmetros: nenhum                                                                           |
|           Evento: onload
|  Tipo de Retorno: void                                                                          |
|  ================================================================================================  |
|           Criado: 01/11/2007 | Por: Rafael Une                                                  |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/
function fct_ajustaProdutos(){
   var oProduto = document.getElementById("lista_imagens_flickr");
   var qtdProduto = oProduto.getElementsByTagName("LI");
   //---## 275 é o tamanho um pouco maior da li ##---//
     tamanho_ul = qtdProduto.length * 275;
     oProduto.style.width = tamanho_ul + "px";
     startindex = fct_calcularStartIndex(tamanho_ul);
     oProduto.style.left = startindex + "px";
} 

function PorqueCPF(L_ROOT)
{
    //Configurando as dimensões da janela
	var inteWindowWidth		= 500;
	var inteWindowHeight	= 350;
	//Recuperando a resolução do clienye
	var inteWidth					= screen.width;
	var inteHeight				= screen.height;
	//Configurando a posição da janela
	var inteWindowTop			= ((inteHeight - inteWindowHeight)/2);
	var inteWindowLeft		= ((inteWidth - inteWindowWidth)/2);
	//Abrindo a janela com as configurações anteriores
	var oPopup	= window.open(L_ROOT + 'addons/PorqueCPF.aspx', 'PorqueCPF', 'top='+ inteWindowTop +', left='+ inteWindowLeft +', width='+ inteWindowWidth +', height='+ inteWindowHeight +', scrollbars=1');
	oPopup.focus();
	
	return false;
}

/*
|----------------------------------------------------------------------------------------------------|
|           Função: fct_calcularStartIndex()                                                        |
|        Descrição: Calcula a posição inicial  da onde serão exibidas as imagens.                                               |
|  ================================================================================================  |
|       Parâmetros: tamanho_ul                                                                           |
|           Evento: nenhum
|  Tipo de Retorno: numero                                                                          |
|  ================================================================================================  |
|           Criado: 01/11/2007 | Por: Rafael Une                                                  |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/
function fct_calcularStartIndex(tamanho_ul){
    qtd_itens_por_pagina = 6;

    var str_url = new String(window.location);
     
    indice_imagem = fct_lastIndex(str_url);
    
    indice_pagina = Math.floor(indice_imagem / qtd_itens_por_pagina);
    
    start_index = 0;
    
    for (i =0; i< indice_pagina; i++)
    { 
        start_index = start_index + tamanho_ul;
	}
    
    return start_index;
}

/*
|----------------------------------------------------------------------------------------------------|
|           Função: fct_lastIndex()                                                        |
|        Descrição: Resgata o indice da imagem na querystring.                                               |
|  ================================================================================================  |
|       Parâmetros: str_url                                                                           |
|           Evento: nenhum
|  Tipo de Retorno: string                                                                          |
|  ================================================================================================  |
|           Criado: 01/11/2007 | Por: Rafael Une                                                  |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/
function fct_lastIndex(str_url){
    var arra = str_url.split("=");
    lastindex = arra.length - 1; 

    return arra[lastindex];
}

/*
|----------------------------------------------------------------------------------------------------|
|           Função: fct_moveProduto()                                                        |
|        Descrição: Move as imagens para a próxima imagem.                                               |
|  ================================================================================================  |
|       Parâmetros: lado                                                                           |
|           Evento: click
|  Tipo de Retorno: void                                                                          |
|  ================================================================================================  |
|           Criado: 01/11/2007 | Por: Rafael Une                                                  |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/
function fct_moveProduto(lado){
   var oProduto = document.getElementById("lista_imagens_flickr");
   var oBotaoAvancar = document.getElementById("lnkProximoPopup");
   var oBotaoVoltar = document.getElementById("lnkAnteriorPopup");
   var produtoTam = parseInt(oProduto.offsetWidth, 10)-913;
   var lposition = oProduto.style.left;
   var position =  fct_calcularStartIndex(500);//recebe valor da função que calcula o startindex
   var modposition = -1*position;

   if(isMovining) return;
     if(lado == 1)
     {
       if(modposition > produtoTam)
       {
           return;
       }
       else
       {
            //---## 271 é o tamanho da li ##---// 
           var t1 = new Tween (oProduto.style,'left',Tween.regularEaseInOut,position,position-271,1,'px');
           t1.start();
       }
       t1.onMotionChanged = function()
       {
           isMovining = true;
       }
       t1.onMotionFinished = function()
       {
           isMovining = false;
       }
   }
   else
   {
       if(position == 0)
       {
           return;
       }
       else
       {
            //---## 271 é o tamanho da li ##---// 
           var t2 = new Tween (oProduto.style,'left',Tween.regularEaseInOut,position,position+271,1,'px');
           t2.start();
       }
       t2.onMotionChanged = function()
       {
           isMovining = true;
       }
       t2.onMotionFinished = function()
       {
           isMovining = false;
       }
   }
} 

/*
|----------------------------------------------------------------------------------------------------|
|           Função: fctMudaImage()                                                        |
|        Descrição: Muda a imagem da popup de fotos do Flickr.                                               |
|  ================================================================================================  |
|       Parâmetros: nenhum                                                                           |
|           Evento: onclick                                                                          |
|  Tipo de Retorno: void                                                                          |
|  ================================================================================================  |
|           Criado: 01/11/2007 | Por: Rafael Une                                                  |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/
function fctMudaImage(img_id,img_zoom)
{
    var oImgZoom = document.getElementById(img_zoom);
    var oImg = document.getElementById(img_id);
    path = oImg.src.replace(/_t/, ""); 
    oImgZoom.src = path;
    
    //return;
}

/*
|----------------------------------------------------------------------------------------------------|
|           Função: Request()                                                                        |
|        Descrição: Carrega a página solicitada utilizando o Ajax.                                   |
|  ================================================================================================  |
|       Parâmetros: nenhum                                                                           |
|           Evento: onclick                                                                          |
|  Tipo de Retorno: string                                                                           |
|  ================================================================================================  |
|           Criado: 01/11/2007 | Por: Rafael Une                                                     |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/
function Request(url_send)
{
    new Ajax(url_send, 
    {
		method: 'get',
		update: $('popup'),
		//evento realizado apos a resposta a solicitação
		onComplete: function() 
		{
			$('img_ajax').className = 'display_none'; 
			new Drag.Move('popup', {
			'handle': $('poptop')
			});
		},
		onFailure: function() 
		{
			$('img_ajax').className = 'display_none';
			alert('Houve um problema durante sua requisição! Contate o administrador da rede.');
			$('cortina').style.display = 'none';
			//$('html_id').style.overflow = 'auto';
		}
	}).request();
	//exibe a cortina
	DisplayMask();
	//exibe a imagem de carregando
	$('img_ajax').className = 'display_block';
}

/*
|----------------------------------------------------------------------------------------------------|
|           Função: RequestFlickr()                                                                        |
|        Descrição: Carrega a página solicitada utilizando o Ajax.                                   |
|  ================================================================================================  |
|       Parâmetros: nenhum                                                                           |
|           Evento: onclick                                                                          |
|  Tipo de Retorno: string                                                                           |
|  ================================================================================================  |
|           Criado: 01/11/2007 | Por: Rafael Une                                                     |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/
function RequestFlickr(url_send)
{
    new Ajax(url_send, {
		method: 'get',
		update: $('popup'),
		//evento realizado apos a resposta a solicitação
		onComplete: function() {
			$('img_ajax').className = 'display_none'; 
			new Drag.Move('popup', {
			'handle': $('poptop')
			});
			GeraListaFlickr();
		},
		onFailure: function() {
			$('img_ajax').className = 'display_none';
			alert('Houve um problema durante sua requisição! Contate o administrador da rede.');
			$('cortina').style.display = 'none';
			//$('html_id').style.overflow = 'auto';
		}
	}).request();
	//exibe a cortina
	DisplayMask();
	//exibe a imagem de carregando
	$('img_ajax').className = 'display_block';
}

/*
|----------------------------------------------------------------------------------------------------|
|           Função: RequestGaleria()                                                                        |
|        Descrição: Carrega a página solicitada utilizando o Ajax.                                   |
|  ================================================================================================  |
|       Parâmetros: nenhum                                                                           |
|           Evento: onclick                                                                          |
|  Tipo de Retorno: string                                                                           |
|  ================================================================================================  |
|           Criado: 01/11/2007 | Por: Rafael Une                                                     |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/
function RequestGaleria(url_send,qtde_imagens)
{
    new Ajax(url_send, {
		method: 'get',
		update: $('popup'),
		//evento realizado apos a resposta a solicitação
		onComplete: function() {
			$('img_ajax').className = 'display_none';
			new Drag.Move('popup', {
			'handle': $('poptop')
			});
			ImagemSelecionada(url_send, qtde_imagens);
		},
		onFailure: function() {
			$('img_ajax').className = 'display_none';
			alert('Houve um problema durante sua requisição! Contate o administrador da rede.');
			$('cortina').style.display = 'none';
			//$('html_id').style.overflow = 'auto';
		}
	}).request();
	//exibe a cortina
    DisplayMask();
	//exibe a imagem de carregando
	$('img_ajax').className = 'display_block';
}

//-----------------------------------------------//
// Script ValidarEnvioPagina - ParisFilmes            //
// Criado por: Rafael Une Data: 19/11/2007  //
// Modificado por:             Em: __/__/____    //
//-----------------------------------------------//
function ValidarEnvioPagina(client_id)
{
    if($(client_id + 'txtRemetente').value == "")
    {
        alert('Por favor, informe seu nome');
        $(client_id + 'txtRemetente').focus();
        return false;
    }
    
    if($(client_id + 'txtEmailRemetente').value == "")
    {
        alert('Por favor, informe seu e-mail');
        $(client_id + 'txtEmailRemetente').focus();
        return false;
    }
    else
    {
        if(!$(client_id + 'txtEmailRemetente').value.isValidEmail())
        {
            alert('Por favor, informe um e-mail válido');
            $(client_id + 'txtEmailRemetente').select();
            return false;
        }
    }
    
    
    if($(client_id + 'txtDestinatario1').value == "")
    {
        alert('Por favor, informe o nome do destinatário');
        $(client_id + 'txtDestinatario1').focus();
        return false;
    }
    
    if($(client_id + 'txtEmailDestinatario1').value == "")
    {
        alert('Por favor, informe o e-mail do destinatário');
        $(client_id + 'txtEmailDestinatario1').focus();
        return false;
    }
    else
    {
        if(!$(client_id + 'txtEmailDestinatario1').value.isValidEmail())
        {
            alert('Por favor, informe um e-mail válido');
            $(client_id + 'txtEmailDestinatario1').select();
            return false;
        }
    }
    
   
   if($(client_id + 'txtDestinatario2').value != "" && $(client_id + 'txtEmailDestinatario2').value=="")
    {
        alert('Por favor, informe o e-mail do segundo destinatário');
        $(client_id + 'txtEmailDestinatario2').focus();
        return false;
    }
    else
    {
        if($(client_id + 'txtDestinatario2').value == "" && $(client_id + 'txtEmailDestinatario2').value!="")
        {
            alert('Por favor, informe o nome do segundo destinatário');
            $(client_id + 'txtDestinatario2').focus();
            return false;
        }
        else
        {
             if($(client_id + 'txtDestinatario2').value != "" && $(client_id + 'txtEmailDestinatario2').value!="")
            {
                if(!$(client_id + 'txtEmailDestinatario2').value.isValidEmail())
                {
                    alert('Por favor, informe um e-mail válido');
                    $(client_id + 'txtEmailDestinatario2').select();
                    return false;
                }
            }
        }
    } 
   
 
  if($(client_id + 'txtDestinatario3').value != "" && $(client_id + 'txtEmailDestinatario3').value=="")
    {
        alert('Por favor, informe o e-mail do terceiro destinatário');
        $(client_id + 'txtEmailDestinatario3').focus();
        return false;
    }
    else
    {
        if($(client_id + 'txtDestinatario3').value == "" && $(client_id + 'txtEmailDestinatario3').value!="")
        {
            alert('Por favor, informe o nome do terceiro destinatário');
            $(client_id + 'txtDestinatario3').focus();
            return false;
        }
        else
        {
             if($(client_id + 'txtDestinatario3').value != "" && $(client_id + 'txtEmailDestinatario3').value!="")
            {
                
                if(!$(client_id + 'txtEmailDestinatario3').value.isValidEmail())
                {
                    alert('Por favor, informe um e-mail válido');
                    $(client_id + 'txtEmailDestinatario3').select();
                    return false;
                }
            }
        }
    } 
}


//-----------------------------------------------//
// Script CriaArray - ParisFilmes             //
// Criado por: Rafael Une - Data: 20/11/2007  //
// Modificado por:             Em: __/__/____    //
//-----------------------------------------------//
function CriaArray(n){
this.length=n;
for(var i=0;i<=n-1;i++){
  this[i]=null;
}
}

//-----------------------------------------------//
// Script show_map - ParisFilmes             //
// Criado por: RAFAEL UNE Data: 20/11/2007  //
// Modificado por:             Em: __/__/____    //
//-----------------------------------------------//
function show_map(latitude, longitude, titulo, texto_info, texto_endereco, url_imagem)
{          
     if (GBrowserIsCompatible()) 
     {
        var map = new GMap2($("contain_map"));
//        //Centraliza o mapa de acordo com essas coordenadas. Aproximadamente perto do Distrito Federal.
        map.setCenter(new GLatLng(-14.349548, -50.361328), 4);
        
        latitudes = latitude.split("[&%$]");
        longitudes = longitude.split("[&%$]");
        titulos = titulo.split("[&%$]");
        texto_infos = texto_info.split("[&%$]");
        texto_enderecos = texto_endereco.split("[&%$]");

        for(i=1; i< latitudes.length; i++)
        {    
			if(latitudes[i] != "" && longitudes[i] != "")
			{
				//Configuracao da latitude e longitude
				var point = new GLatLng(latitudes[i], longitudes[i], true);
	            
				//Texto que será exibido na aba de informações no balão de informacoes.
				var text_info = "<h3><strong>" + titulos[i] + "</strong></h3><br/>" + texto_infos[i].replace(/{br}/g,"<br/>");
	            
				//Texto que será exibido na aba de endereço do balão de informações
				var text_endereco = "<h3><strong>" + titulos[i] + "</strong></h3><br/>" + texto_enderecos[i].replace(/{br}/g,"<br/>");
	                        
				//Adiciona marcação do local.	
				function createMarker(point) 
				{
				    
						var tabs = new CriaArray(2);
						
						tabs[0] = new GInfoWindowTab("Informações",text_info);
						tabs[1] = new GInfoWindowTab("Endereço",text_endereco);
						//Configuracoes do icone
						 var blueIcon = new GIcon(G_DEFAULT_ICON);
  						 blueIcon.image = url_imagem;
  						 blueIcon.iconSize = new GSize(34, 34);
						 markerOptions = { icon:blueIcon };
	    		 
						 //Criando o icone.
						 var marker = new GMarker(point, markerOptions);
						 //Adicionando o evento clique.
						 GEvent.addListener
						 (
						    marker,"click", function() {map.openInfoWindowTabs(point,tabs);}
						 );
						return marker;
				}
	            
				//Adiciona o icone
				map.addOverlay(createMarker(point));
			}//fecha if2
        }//fecha for
        
        //Adiciona controles do mapa
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
      }//fechaif
}

//-----------------------------------------------//
// Script fctMudaImagem - ParisFilmes             //
// Criado por: RAFAEL UNE Data: 26/11/2007  //
// Modificado por:             Em: __/__/____    //
//-----------------------------------------------//
function fctMudaImagem(img_grande,link_imagem, img_selecionada,qtde_imagens)
{
   var imagens = new CriaArray(qtde_imagens);
   var links = new CriaArray(qtde_imagens);
   
   for(i=0; i< qtde_imagens; i++)
   {
        imagens[i] = "img_" + i;
        links[i] = 'lnk_' + i;
   }
   
   for(i=0; i< qtde_imagens; i++)
   {
        document.getElementById(imagens[i]).className = '';
        document.getElementById(links[i]).className = 'img_off';
   }
   
   var zoom = document.getElementById(img_grande);
   var normal = document.getElementById(img_selecionada);
   var link = document.getElementById(link_imagem);
   
   zoom.src = normal.src.replace(/_gi_thumb/,'');
   
   normal.className = 'img_selecionada'; 
   link.className = '';
}

//-----------------------------------------------//
// Script fctProximaImagem - ParisFilmes             //
// Criado por: RAFAEL UNE Data: 26/11/2007  //
// Modificado por:             Em: __/__/____    //
//-----------------------------------------------//
function fctProximaImagem(qtde_imagens,imagemzoom_id)
{
   var imagens = new CriaArray(qtde_imagens);
   var links = new CriaArray(qtde_imagens);
   
   for(i=0; i< qtde_imagens; i++)
   {
        imagens[i] = "img_" + i;
        links[i] = 'lnk_' + i;
   }
   
   for(i=0; i< qtde_imagens; i++)
   {
        if(document.getElementById(imagens[i]).className == 'img_selecionada')
        {
            validar_proxima = i + 1;
            if(validar_proxima < qtde_imagens)  
            {
                document.getElementById(imagemzoom_id).src = document.getElementById(imagens[validar_proxima]).src.replace(/_gi_thumb/,'');
                document.getElementById(imagens[validar_proxima]).className = 'img_selecionada';
                document.getElementById(links[validar_proxima]).className = ''; 
                document.getElementById(imagens[i]).className = ''; 
                document.getElementById(links[i]).className = 'img_off';  
               
                 i=i+qtde_imagens; 
            }  
        }
   }
}

//-----------------------------------------------//
// Script fctImagemAnterior - ParisFilmes             //
// Criado por: RAFAEL UNE Data: 26/11/2007  //
// Modificado por:             Em: __/__/____    //
//-----------------------------------------------//
function fctImagemAnterior(qtde_imagens,imagemzoom_id)
{
   var imagens = new CriaArray(qtde_imagens);
   var links = new CriaArray(qtde_imagens);
   for(i=0; i< qtde_imagens; i++)
   {
        imagens[i] = "img_" + i;
        links[i] = 'lnk_' + i;
   }
   
   for(i=0; i< qtde_imagens; i++)
   {
        if(document.getElementById(imagens[i]).className == 'img_selecionada')
        {
            validar_anterior = i - 1;
            if(validar_anterior >= 0)  
            {
                document.getElementById(imagemzoom_id).src = document.getElementById(imagens[validar_anterior]).src.replace(/_gi_thumb/,'');
                document.getElementById(imagens[validar_anterior]).className = 'img_selecionada';
                document.getElementById(links[validar_anterior]).className = '';
                document.getElementById(imagens[i]).className = ''; 
                document.getElementById(links[i]).className = 'img_off'; 
               
                 i=i+qtde_imagens; 
            }  
        }
   }
}

//-----------------------------------------------//
// Script ImagemSelecionada - ParisFilmes             //
// Criado por: RAFAEL UNE Data: 26/11/2007  //
// Modificado por:             Em: __/__/____    //
//-----------------------------------------------//
function ImagemSelecionada(url,qtde_imagens)
{
    start = url.lastIndexOf("=");
    indice_imagem = url.substring(start + 1,url.length);
    indice_imagem = indice_imagem -1; 
    document.getElementById('img_' + indice_imagem).className = 'img_selecionada';

    for(i=0; i< qtde_imagens; i++)
    {
        document.getElementById('lnk_' + i).className = 'img_off';
    } 
    
    document.getElementById('lnk_' + indice_imagem).className = '';
} 

//-----------------------------------------------//
// Script DisplayMask - ParisFilmes             //
// Criado por: Victor Leonardo Data: 5/12/2007  //
// Modificado por:             Em: __/__/____    //
//-----------------------------------------------//
function DisplayMask()
{
    $('cortina').style.height = getPageSize().pageHeight + "px";
    $('cortina').style.display = 'block';    
}

function getPageSize(){
    var xScroll, yScroll;

    if(window.innerHeight && window.scrollMaxY){
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    }else if(document.body.scrollHeight > document.body.offsetHeight){
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    }else{
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;

    if(self.innerHeight){
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    }else if(document.documentElement && document.documentElement.clientHeight){
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    }else if(document.body){
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }	

    if(yScroll < windowHeight)
        pageHeight = windowHeight;
    else
        pageHeight = yScroll;

    if(xScroll < windowWidth)
        pageWidth = windowWidth;
    else
        pageWidth = xScroll;

    arrayPageSize = {pageWidth:pageWidth,pageHeight:pageHeight,windowWidth:windowWidth,windowHeight:windowHeight};

    return arrayPageSize;
}

function getPageScroll(){
    var yScroll;
    if(self.pageYOffset)
        yScroll = self.pageYOffset;
    else if(document.documentElement && document.documentElement.scrollTop)
        yScroll = document.documentElement.scrollTop;
    else if(document.body)
        yScroll = document.body.scrollTop;
    
    arrayPageScroll = {yScroll:yScroll};
    return arrayPageScroll;
}

//-----------------------------------------------//
// Script TratarImagem - ParisFilmes             //
// Criado por: Aline Neves Data: 16/05/2008  //
// Modificado por:             Em: __/__/____    //
//-----------------------------------------------//

function TratarImagem()
{
    //var interval = window.setInterval(TratarImagem(),10);
    $$('.img_grande').removeClass('img_grande_width');
    var img_width_aux = $$('.img_grande').getStyle('width');
    var img_width = parseInt(img_width_aux);
    
   if(img_width== 'NaN' || img_width== NaN )
    $$('.img_grande').addClass('img_grande_width');
   
   if(img_width > 500)
       $$('.img_grande').addClass('img_grande_width');
    
}