﻿/*
CSS Browser Selector v0.3.4 (Sep 29, 2009)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

function showmenu(elmnt){document.getElementById(elmnt).style.display="block";}
function hidemenu(elmnt){document.getElementById(elmnt).style.display="none";}
var fadeInterval="";
var xxx=0;
function fadeOut(id, time) {
    clearInterval(fadeInterval);
    fadeInterval="";
    target = document.getElementById(id);
    alpha = 100;
    timer = time;
      if(xxx>0){
              alpha = xxx;
        fadeInterval = setInterval(
              function() {
                    if (alpha <= 0){
                        clearInterval(fadeInterval);
                        fadeInterval="";
                        target.style.display="none";
                   }else
                        setAlpha(id, alpha);

                    alpha -= 10;
              }, timer);
    }
    else
       fadeInterval = setInterval(
          function() {
          xxx = alpha;
                if (alpha <= 0){
                    clearInterval(fadeInterval);
                    fadeInterval="";
                    target.style.display="none";
                }else
                    setAlpha(id, alpha);
                alpha -= 10;
          }, timer);
}

function fadeIn(id, time) {
      clearInterval(fadeInterval);
      fadeInterval="";
      target = document.getElementById(id);
      target.style.display="block";
      alpha = 0;
      timer = time;
      setAlpha(id,0);
     if(xxx>0){
        xxx=0;
         alpha=0;
         zeraFade();
         fadeIn(id, time)
    }
    else
     if(fadeInterval==""){
            fadeInterval = setInterval(
                  function() {
                   xxx = alpha;
                        if (alpha >= 100){
                             clearInterval(fadeInterval);
                             fadeInterval=="";
                        }else
                            setAlpha(id, alpha);
                        alpha += 10;
                  }, timer);
      }else
      {
       //     checkFadeOut(id,time);
       //     checkFadeIn(id,time);
      }
}
function checkFadeIn(id,time){
    var xx = setInterval(function() {
        if(fadeInterval==""){
            clearInterval(xx);
            xx="";
            fadeIn(id, time);
        }
    }, 1);
}
function checkFadeOut(id,time){
    var xx = setInterval(function() {
        if(fadeInterval==""){
            clearInterval(xx);
            xx="";
            fadeOut(id, time);
        }
    }, 1);
}
function keepFade(id){
    clearInterval(fadeInterval);
    target = document.getElementById(id);
    target.style.display="block";
    setAlpha(id,100);
}
function zeraFade(){
    for(var i=1;i<=7;i++){
        setAlpha('s'+i,0);
        if(document.getElementById('s'+i)!=null)
        document.getElementById('s'+i).style.display="none";
    }
}
function setAlpha(id, alpha) {
if(document.getElementById(id)!=null){
      target = document.getElementById(id);     
      target.style.filter = "alpha(opacity="+ alpha +")";
      target.style.opacity = alpha/100;
      }
}





//MAPA

 function initialize() {
      if (GBrowserIsCompatible()) {
        map2 = new GMap2(document.getElementById("map_canvas2"));
        map2.setUIToDefault();
        geocoder = new GClientGeocoder();
		showAddress('Av. Ipiranga, 1267 , São Paulo - SP - Brasil',map2);
		 
        map = new GMap2(document.getElementById("map_canvas"));
        map.setUIToDefault();        
        geocoder = new GClientGeocoder();
		showAddress('Rua Cristiano Viana, 91, São Paulo - SP - Brasil',map);   
      }
     
    }
	
	function showAddress(address,obj) {
      if (geocoder) {
        geocoder.getLatLng(address,function(point) {
													if (!point) {
														alert(address + " not found");
													} else {
														obj.setCenter(point, 15);
														
														var mark = new GMarker(point);
														obj.openInfoWindow(obj.getCenter(),
                 document.innerHTML="<img src='/../images/conteudo/backgrounds/CBL.jpg'>");
														//GEvent.addListener(mark, "load", function() {
                                                        //    mark.openInfoWindowHtml('Minha Casa');
                                                        //});
														
														obj.addOverlay(mark);
													}
													}
							);	
					}
		}


//$('.div').Drags({
 //  handler: '.handler',
//   onMove: function(e) {
//     $('.content').html('Div Position:(Left:' + e.pageX + ' ,Top:' + e.pageY + ')');
//   },
//   onDrop:function(e){
//     $('.content').html('dropped!');
//   }
//});

//     FUNÇÃO PARA GALERIA DE IMAGENS       //
 
var galeriaPosition=0;
var posicaoFinal=0;
var divGaleriaHidden = null;
function moveGaleria(){
    if(divGaleriaHidden.style.left!="0px")
        galeriaPosition+=20;
    divGaleriaHidden.style.left=galeriaPosition + 'px';
}
function moveGaleriaAnterior(){
    if(galeriaPosition>=-posicaoFinal)
        galeriaPosition-=20;
    divGaleriaHidden.style.left=galeriaPosition + 'px';
 }
var loopGaleria = null;
function loopGaleriaInterval(f){
    if(f=="direito")
        loopGaleria = setInterval(moveGaleria,100);
    else
        loopGaleria = setInterval(moveGaleriaAnterior,100);
}
function clearloopGaleria(){
    clearInterval(loopGaleria);
    loopGaleria=null;
}
function posGaleriaLoad(v){
    GaleriaPosition = v;
    divGaleriaHidden.style.left= v +'px';
}
function init(){
    divGaleriaHidden = document.getElementById("divGaleriaHidden");
}

//      FINAL DA FUNÇÃO GALERIA DE IMAGENS       //

function checkboxCampoHidden(campo,div){
    if(campo.checked)
        document.getElementById(div).style.display = "block";
    else
        document.getElementById(div).style.display = "none";    
}
function valObraColaboradorTipo(source, args)
    {
    if(document.getElementById('ctl00_ContentPlaceHolder1_chkObraColaboradoresTraduzido').checked || document.getElementById('ctl00_ContentPlaceHolder1_chkObraColaboradoresIlustracao').checked)
        args.IsValid = true;
        else
        args.IsValid=false;

}   
function valPublico(source, args)
    {
    chkPublicoGeral=document.getElementById('ctl00_ContentPlaceHolder1_chkPublicoGeral').checked;
    chkPublicoInfantil=document.getElementById('ctl00_ContentPlaceHolder1_chkPublicoInfantil').checked;
    chkPublicoJuvenil=document.getElementById('ctl00_ContentPlaceHolder1_chkPublicoJuvenil').checked;
    chkPublico1Grau=document.getElementById('ctl00_ContentPlaceHolder1_chkPublico1Grau').checked;
    chkPublico2Grau=document.getElementById('ctl00_ContentPlaceHolder1_chkPublico2Grau').checked;
    chkPublicoUniversitario=document.getElementById('ctl00_ContentPlaceHolder1_chkPublicoUniversitario').checked;
    chkPublicoOutro=document.getElementById('ctl00_ContentPlaceHolder1_chkPublicoOutro').checked;
    if(chkPublicoGeral || chkPublicoInfantil || chkPublicoJuvenil || chkPublico1Grau || chkPublico2Grau || chkPublicoUniversitario || chkPublicoOutro)
        args.IsValid = true;
        else
        args.IsValid=false;

}   
function valCaracteristica(source, args)
    {
    chkCaracteristicaFiccao=document.getElementById('ctl00_ContentPlaceHolder1_chkCaracteristicaFiccao').checked;
    chkCaracteristicaPoesia=document.getElementById('ctl00_ContentPlaceHolder1_chkCaracteristicaPoesia').checked;
    chkCaracteristicaDissetacao=document.getElementById('ctl00_ContentPlaceHolder1_chkCaracteristicaDissetacao').checked;
    chkCaracteristicaContos=document.getElementById('ctl00_ContentPlaceHolder1_chkCaracteristicaContos').checked;
    chkCaracteristicaTeatro=document.getElementById('ctl00_ContentPlaceHolder1_chkCaracteristicaTeatro').checked;
    chkCaracteristicaBibliografia=document.getElementById('ctl00_ContentPlaceHolder1_chkCaracteristicaBibliografia').checked;
    chkCaracteristicaCronicas=document.getElementById('ctl00_ContentPlaceHolder1_chkCaracteristicaCronicas').checked;
    chkCaracteristicaCriticas=document.getElementById('ctl00_ContentPlaceHolder1_chkCaracteristicaCriticas').checked;
    chkCaracteristicaOutro=document.getElementById('ctl00_ContentPlaceHolder1_chkCaracteristicaOutro').checked;
    if(chkCaracteristicaFiccao || chkCaracteristicaPoesia || chkCaracteristicaDissetacao || chkCaracteristicaContos || chkCaracteristicaTeatro || chkCaracteristicaBibliografia || chkCaracteristicaCronicas || chkCaracteristicaCriticas || chkCaracteristicaOutro)
        args.IsValid = true;
        else
        args.IsValid=false;
}   
function valIsbn(source, args){
    campo=document.getElementById('ctl00_ContentPlaceHolder1_txtObraPublicacaoISBN');
    if(Trim(campo.value)!="978-85-" && Trim(campo.value)!="")
        args.IsValid = true;
    else
        args.IsValid=false;

}

function abreNovaJanela(t){
document.getElementById("aspnetForm").target=t;
}
function habilita_campos()
{
    document.getElementById('autores').style.display = "block";
    document.getElementById('nascimento').style.display = "block";
    document.getElementById('nacionalidade').style.display = "block";    
}  
function onlynumber(myfield, e,tolerado)
{
	if (myfield.length ==0)
		myfield.value=0;  
	
	var key;
	var keychar;
	
	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
	
	keychar = String.fromCharCode(key);
	
	if ((key==null) || (key==0) || (key==8) || (key==9)|| (key==13)|| (key==27) )
		return true;
	else if ((("0123456789"+tolerado).indexOf(keychar) > -1)){
		if (((myfield.value).indexOf(tolerado) > -1)&&(keychar==tolerado))
			return false;
		else if ((myfield.value.length==0)&&(keychar==tolerado))
		{
			myfield.value = "0";
			return true;	
		}
		else
			return true;
	}
	else
		return false;	
}    
// Formatando o CPF        
function Formato_CPF(input, e){
    var keyCode; /*= (isNN) ? e.which : e.keyCode;*/

	 if (keyCode != 8){
		if(input.value.length == 3){
			input.value = input.value+'.';
		}
		if(input.value.length == 7){
			input.value = input.value+'.';
		}
		else if(input.value.length == 11){
			input.value = input.value+'-';
		}
	}
}

// Formatando o CNPJ
function Formato_CNPJ(input, e)
{
    var keyCode;
    
	if (window.event)
		keyCode = window.event.keyCode;
	else if (e)
		keyCode = e.which;
	
    if (keyCode != 8)
	{ 
		if(input.value.length == 2 || input.value.length == 6)
			input.value = input.value+'.';
	
	    if (input.value.length == 10)
	        input.value = input.value+'/';
	        
	    if (input.value.length == 15)
	        input.value = input.value+'-';
	}
}
        
// Formatando o CEP
function Formato_CEP(input, e)
{
    var keyCode;
    
	if (window.event)
		keyCode = window.event.keyCode;
	else if (e)
		keyCode = e.which;
	
    if (keyCode != 8)
	{ 
		if(input.value.length == 5)
			input.value = input.value+'-';
	}
}

// Formatando o Fone
function Formato_Fone(input, e)
{
    var keyCode;
    
	if (window.event)
		keyCode = window.event.keyCode;
	else if (e)
		keyCode = e.which;
	
    if (keyCode != 8)
	{ 
		if(input.value.length == 4)
			input.value = input.value+'-';
	}
}

function Formato_Fone2(input, e)
{
    var keyCode;
    
	if (window.event)
		keyCode = window.event.keyCode;
	else if (e)
		keyCode = e.which;
	
    if (keyCode != 8)
	{ 
	    if(input.value.length == 1)
			input.value = '('+input.value;
		
		if(input.value.length == 3)
			input.value = input.value+')';
	    
		if(input.value.length == 8)
			input.value = input.value+'-';
	}
}

// Formatando o Data
function Formato_Data(input, e)
{
    var keyCode;
    
	if (window.event)
		keyCode = window.event.keyCode;
	else if (e)
		keyCode = e.which;
	
    if (keyCode != 8)
	{ 
		if(input.value.length == 2 || input.value.length == 5)
			input.value = input.value+'/';
	}
}

// Formatando o Hora
function Formato_Hora(input, e)
{
    var keyCode;
    
	if (window.event)
		keyCode = window.event.keyCode;
	else if (e)
		keyCode = e.which;
	
    if (keyCode != 8)
	{ 
		if(input.value.length == 2)
			input.value = input.value+':';
	}
}
var objAssociado = null;
function showAssociado(elmnt)
{
    hideAssociado();
    
    objAssociado = document.getElementById(elmnt);
    //objAssociado.style.top = document.scrollY;
    //objAssociado.style.left = document.scrollX;
    objAssociado.style.display="block";
}
        
function hideAssociado()
{
    if(objAssociado != null)
    {
        objAssociado.style.display="none";
    }     	
}
function addFav(title){
    
    var url = window.location;    
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all){window.external.AddFavorite(url, title);}
}
function postTwitter(url){
window.open("http://twitter.com/home?status="+url,'','');
}
var tituloTwitter;
var TweetThisLink = { 
    shorten : function(e) { 
        // this stops the click, which will later be handled in the  response method 
        e.preventDefault(); 
        // find the link starting at the second 'http://' 
        var url = this.href.substr(this.href.indexOf('http:',5)); 
        BitlyClient.shorten(url, 'TweetThisLink.response'); 
    }, 
     
    response : function(data) { 
        var bitly_link = null; 
        for (var r in data.results) { 
            bitly_link = data.results[r]['shortUrl'];  
            break; 
        } 
       window.location.href="http://twitter.com/home?status=" + encodeURIComponent(tituloTwitter + ' - ' + bitly_link); 
    } 
}

// Início do código de Aumentar/ Diminuir a letra  
	var tagAlvo = new Array('p','a','em','div','span','li','strong','b','i','u','h1','h2','h3','h4'); 
	//pega todas as tags p//  
	// Especificando os possíveis tamanhos de fontes, poderia ser: x-small, small...
	var tamanhos = new Array( '9px','10px','11px','12px','13px','14px','15px' );
	var tamanhoInicial = 2;
	function mudaTamanho( idAlvo,acao ){
	if (!document.getElementById) 
	return   
	var selecionados = null,tamanho = tamanhoInicial,i,j,tagsAlvo;
	tamanho += acao; 
	
	if ( tamanho < 0 )
		tamanho = 0;   
	if ( tamanho > 6 )
			tamanho = 6;
			tamanhoInicial = tamanho;

	if ( !( selecionados = document.getElementById( idAlvo ) ) )
		selecionados = document.getElementsByTagName( idAlvo )[ 0 ];
		selecionados.style.fontSize = tamanhos[ tamanho ];

	for ( i = 0; i < tagAlvo.length; i++ )
	{    
		tagsAlvo = selecionados.getElementsByTagName( tagAlvo[ i ] );
		for ( j = 0; j < tagsAlvo.length; j++ ) tagsAlvo[ j ].style.fontSize = tamanhos[ tamanho ];
	} 
	} 
	// Fim do código de Aumentar/ Diminuir a letra 
	
	function clickButton(e, buttonid){ 

      var evt = e ? e : window.event;

      var bt = document.getElementById(buttonid);

      if (bt){ 

          if (evt.keyCode == 13){ 

                bt.click(); 

                return false; 

          } 
      } 
}