﻿var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function SetUniqueRadioButton(nameregex, current)
{
   re = new RegExp(nameregex);
   for(i = 0; i < document.forms[0].elements.length; i++)
   {
      elm = document.forms[0].elements[i]
      if (elm.type == 'radio')
      {
     // alert(elm.name)
         if (re.test(elm.name))
         {
            elm.checked = false;
         }
      }
   }
   current.checked = true;
}


//alert(navigator.appName.indexOf("Netscape"));
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
var strPonto = ".";
var strBarra = "/";
var strTraco = "-";

function showhide(elmnt)
{
    if(document.getElementById(elmnt).style.display == "block")
        document.getElementById(elmnt).style.display = "none";
    else
        document.getElementById(elmnt).style.display = "block";
}

function showmenu(elmnt)
{
    document.getElementById(elmnt).style.display = "block";
}
        
function hidemenu(elmnt)
{
    document.getElementById(elmnt).style.display = "none";     	
}
        
function abre_menu(elmnt)
{
    document.getElementById(elmnt).style.display = "block";
    document.getElementById('lnk_'+elmnt).className = "menu_on"; 		
}
        
function esconde_menu(elmnt)
{
    document.getElementById(elmnt).style.display = "none";
    document.getElementById('lnk_'+elmnt).className = "menu_off";	
}      
        
function habilita_campos()
{
    document.getElementById('autores').style.display = "block";
    document.getElementById('nascimento').style.display = "block";
    document.getElementById('nacionalidade').style.display = "block";    
}          
        
/*
CSS Browser Selector v0.2.7
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',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')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' '+s+' chrome':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);


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";
    }     	
}

// Formatando o RG        
function Formato_RG(input, e){
	var keyCode = (isNN) ? e.which : e.keyCode;

	 if (keyCode != 8){
		if(input.value.length == 2){
			input.value = input.value+'.';
		}
		if(input.value.length == 6){
			input.value = input.value+'.';
		}
		else if(input.value.length == 10){
			input.value = input.value+'-';
		}
	}
}

// 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+'-';
	}
}

// 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+':';
	}
}

// Somente numeros
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;	
}        


function EnviarBuzz(BuzzCloud_Id){
    // paramentros para o método //
    var pArea = "Atualiza_Qtde_Buzzcloud";
    var pUrl = "/ajax/conteudo.aspx?Area="+pArea+"&pBuzzCloud_Id="+BuzzCloud_Id;
    var pDivResultado = document.getElementById("DivResultado");
   
    // método para recuperar o retorno ;
    ajax_conteudo(getRequestXml(),pUrl,pDivResultado);
    
}

function getRequestXml()
{
    if (window.XMLHttpRequest){
        http_request = new XMLHttpRequest();
        
        if (http_request.overrideMimeType) 
            http_request.overrideMimeType('text/xml');
        
    }else if (window.ActiveXObject){
        try{
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e){
            // Faz nada
        }
        
        if(!http_request){
            try{
                http_request= new ActiveXObject("Microsoft.XMLHTTP");
            }catch (e){// Faz nada 
            }
        }
    }
   
    if (!http_request)
        alert('Sem suporte há esta funcionalidade');
    else
        return http_request;
      
}

// Conteudo //
function ajax_conteudo(xmlHttp,url,div_resultado)
{       
    xmlHttp.onreadystatechange = function() {ajax_conteudo_ready(xmlHttp,div_resultado);}
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function ajax_conteudo_ready(xmlHttp,div_resultado){
    if (xmlHttp.readyState == 4){ 
        if (xmlHttp.status == 200){
            retorno = xmlHttp.responseText;
            
            if(retorno != ""){
                div_resultado.innerHTML = "";
                div_resultado.innerHTML = retorno;
            }else{ 
                div_resultado.style.display = "none";
                div_resultado.innerHTML = "";
            }
        }
    }
}

function Formatar_Numero(Valor)
{
	Valor = Valor.toString();	

	if(Valor.indexOf(",",0) >= 0 && Valor.indexOf(".",0) >= 0)
		Valor = Valor.replace(".","").replace(",",".");
	else if(Valor.indexOf(",",0) >= 0)
		Valor = Valor.replace(",",".");

	var Numero = parseFloat(Valor);

	
	
	if(Numero)
	{
		var Formatado = Math.round(Numero * 100).toString();
		var Qtd = Formatado.length - 2;
		
		if(Qtd == -1)
			Formatado = "0,0" + Formatado
		else
			Formatado = Formatado.substring(0,Qtd) + "," + Formatado.substring(Qtd,Formatado.length)
		
		if(Qtd > 3)
		{
			Final = Formatado.substring(Qtd,Qtd + 3)
			
			for(var i=3; i < Qtd ; i=i+3)
				Final = "." + Formatado.substring(Qtd - i,(Qtd - i) + 3) + Final
			
			Final = Formatado.substring(0,Qtd - (i-3)) + Final;
		}
		else if(Qtd == 0)
			Final = "0" + Formatado;
		else
			Final = Formatado;

		return Final;
	}
	else
		return "0,00"
}

function AbrirVideo(video)
{
    var player;
    
    if (player != null)
    {
        player.close();
    }
	
	player = window.open("/upload/conteudo/videos/Player.aspx?Video_Id="+video,"","scrollbars=no,location=no,directories=no,status=no,menubar=no,resizable=no,toolbar=no,top="+(screen.height-280)/2+",left="+(screen.width-320)/2+",width=320,height=280");
}

function Upper(Campo)
{
	if(Campo.value.length != -1)
	{
		if (window.event)
		{
			var key = window.event.keyCode;
			
			if((key > 96 && key < 123) || (key > 223 && key < 254))
			{
				key = key - 32;
				window.event.keyCode = key;
			}	
		}
	}
}

function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}

function autoTab(input,len,e) {

var keyCode = (isNN) ? e.which : e.keyCode;
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
}


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; 

          } 
      } 
}
function mudaTipo(div,tipo){
    if(div=="divFisico"){
        document.getElementById("lblNomeFisico").innerHTML="Nome do autor<span style='color: Red;'>*</span>:"; 
        document.getElementById("lblCpfCnpj").innerHTML="CPF"; 
        if(tipo==1){
        try{
            document.getElementById("ctl00_ContentPlaceHolder1_txtNomeFisico").value="";        
            document.getElementById("ctl00_ContentPlaceHolder1_txtCnpj").value="";        
            }catch(e){
            document.getElementById("txtNomeFisico").value="";        
            document.getElementById("txtCnpj").value="";        
            }
        }
    }
    else{
         document.getElementById("lblNomeFisico").innerHTML="Nome da empresa<span style='color: Red;'>*</span>:"; 
         document.getElementById("lblCpfCnpj").innerHTML="CNPJ";        
        if(tipo==1){
            try{
            document.getElementById("txtNomeFisico").value="";        
            document.getElementById("txtCnpj").value=""; 
            }catch(e){
            
            }       
        }
    }
}
function Trim(str){return str.replace(/^\s+|\s+$/g,"");}
function verificaCampo(campo,valor,comparacao){
    if(valor==comparacao){
        document.getElementById(campo).value="";
    }else if(Trim(valor)==""){
        document.getElementById(campo).value=comparacao;
    }
}

function formataDecimal(input){
    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+',';
	}
}

function fechar_floater(){
	document.getElementById('Floater').style.display = 'none';
	document.getElementById('Floater_fechar').style.display = 'none';
    }
   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 showmenu(elmnt)
{
    document.getElementById(elmnt).style.display = "block";
}

function hidemenu(elmnt)
{
    document.getElementById(elmnt).style.display = "none";     	
}
