var search='/srv/search',random='/srv/random',fetch='/srv/fetch/',anagrama='/srv/anagram',uHist='/?w=',uHistFetId='/?id=',uHistFetW='/?fw=',uHistRan='/?random=ran',uHistAn='&anagram=anag',key='id',tanag='anagram',tran='random',wd,CATACTRAND='RANDOM',CATACTANAG='ANAGRAM',CATEXTE='EXTERNO',CATSEAR='SEARCH',CATFETC='FETCH',CATNOTFOUND='NOT FOUND',ACTSESCA='ESCALONADA',ACTSEXAC='EXACTA',ACTSTERM='TERMINA EN',ACTFNAVE='NAVEG',ACTFLISANA='LISTA ANAGR',ACTFLISDES='LISTA DESAMB',ACTFLISAPR='LISTA APROX',ACTFLISTER='LISTA TERMINA EN',ACTFCONJUGW='CONJUG WEB',BUSESC='form',BUSTER='32',BUSEXA='30',lisEnt='Lista de entradas',urlDle='http://dle.rae.es',sep=' - ',pdEr='<a href="?id=NWQcxLK">llover</a>',merror='El servicio de consulta del diccionario no está disponible en estos momentos. Inténtelo de nuevo pasados unos segundos.',cont=0,txtTitle='Diccionario de la lengua española - Edición del Tricentenario',txtTitleShare='Diccionario de la lengua española - Entrada: ';maxSizeTweet=85;feedBoxFb='https://www.facebook.com/dialog/feed?app_id=1654531804795469&display=popup',redDirFb='&redirect_uri=http://www.facebook.com',shareTw='https://twitter.com/share?url=',shareTwPar='&via=RAEinforma&related=twitterapi%2Ctwitter&hashtags=RAE%2CASALE&text=',shareGoogle='https://plus.google.com/share?url=',bodyMailI='Real Academia Española, Asociación de Academias de la Lengua Española. Diccionario de la lengua española, 23.ª ed., Edición del Tricentenario, [en línea]. Madrid: Espasa, 2014. [Consulta:',bodyMailF=']. ISBN: 978-84-670-4189-7. Disponible en: ',ua=window.navigator.userAgent,msie=ua.indexOf("MSIE "),ie9=false,gaDat=null,gaDLE=function(evGa){ga('send','event',evGa[0],evGa[1],evGa[2]);},tipoActModo=function(f){var act;if(f===BUSESC)
act=ACTSESCA;else if(f===BUSEXA)
act=ACTSEXAC;else if(f===BUSTER)
act=ACTSTERM;return act;},doResp=function(datos,u,uH,p,actHis,evGa,inicio){var hash,$resultados=$('#resultados'),$select=$('#formList'),$header,ids,natr='id',error=false,nCat=null,term='',cabecera='',isConj=false,isdocs=false,isArticle=false,focus=true;$redesSociales=$('#redesSociales'),$div=$('<div>').html(datos),$res=$div.find('#a0');if($res.length==0){$res=$div.find('#l0, #l1, #l2, #l3');if($res.length==0){$res=$div.find('#f0');if($res.length==0){$res=$div.find('#h0');if($res.length==0){if(datos.indexOf('The requested URL was rejected')!==-1)
$res=datos;else
$res=merror;error=true;$redesSociales.css('visibility','hidden');}else{if(u.indexOf('#')!=-1){hash=u.substring(u.indexOf('#')+1,u.length);natr='name';}
term=(u.indexOf('ayuda.html')!==-1?'Guía de consulta':'Preliminares');}}else
nCat=CATNOTFOUND;}else{var id=$res.attr('id');if(id=='l1')
nCat=CATNOTFOUND;term=lisEnt;$ul=$res.find('ul');$ul.html($ul.html().replace(/\./g,''));}}else{$header=$res.find('header');$encabezamiento=$res.find('header.f, header a.f');$encabezamiento.each(function(){var $this=$(this);quitarPunto($this);cabecera=cabecera+formateaTag($this.html())+'; ';marcarGuionAcentuado($this);});$res.html(marcarAbrAcep($res.html()));term=$header.text();cabecera=cabecera.substring(0,cabecera.length-2);if(term=='')term=cabecera;if($header.find('a').length==0){term=($header.length>1)?lisEnt:term;isArticle=true;$ae2=$res.find('a.e2');if($ae2.length>0){cambiaBoton($ae2,term);$ae1=$res.find('a.e1');if($ae1.length>0)cambiaBoton($ae1,term);}}else
term='Conjugación de '+term;isConj=true;hash=$res.attr('hash');if(hash===undefined&&p!=null&&p.id!=null){var ident=p.id;if(ident.indexOf('#')!=-1)
hash=ident.substring(ident.indexOf('#')+1,ident.length);}}
$resultados.html($res);if(!error){$wq=$('#wq');$resultados.find('article').each(function(){var $this=$(this);procesarFormasComplejas($this);procesarParentesis($this);procesarNumeroAcep();});$resultados.html(transformUrlFecht($resultados.html()));if(evGa!=null){var cat=evGa[0],act=evGa[1],valor=evGa[2];if(nCat!=null&&nCat==CATNOTFOUND)
if(act==ACTSESCA||act==ACTSEXAC)
cat=nCat;gaDat=[cat,act,valor];gaDLE(gaDat);}
if(hash===undefined){if(ie9==true)
document.querySelector('body').scrollIntoView();else{if(window.matchMedia('(max-width: 600px)').matches&&inicio!=true){document.querySelector('#patrocinio').scrollIntoView();focus=false;}else
document.querySelector('body').scrollIntoView();}}else{var $anchor=document.querySelector("["+natr+"='"+hash+"']");if($anchor!==null)
$anchor.scrollIntoView();else
document.querySelector('body').scrollIntoView();}
if(actHis){if(isArticle&&(inicio==false)){if(uH.indexOf('?id=')<0){var $arts=$('article'),ids='';$arts.each(function(){ids+=$(this).attr('id')+'|';});ids=ids.substring(0,ids.length-1);u=fetch;uH=uHistFetId+ids;p={'id':ids};}
var pos=uH.indexOf('#');if(pos>=0)
uH=uH.substring(0,pos);}else if(isdocs==false&&isConj==false)
uH='/';history.pushState({u:u,uH:uH,p:p},document.title,uH);}
document.title=(inicio==true)?txtTitle:"DLE: "+term+sep+txtTitle;wd=term;if(isArticle==true){var shareTitle=txtTitleShare+cabecera+' | ';uH=urlDle+uH.replace('&o=h','');addthis.update('share','url',uH);if(shareTitle.indexOf(';')>=0){if(shareTitle.length>=maxSizeTweet)
shareTitle=shareTitle.replace(' - Entrada:',':');else
shareTitle=shareTitle.replace('Entrada:','Entradas:');shareTitle=shareTitle.replace(/;/g,' -');}
addthis.update('share','title',shareTitle);$redesSociales.css('visibility','visible');}else
$redesSociales.css('visibility','hidden');$wq.val('');if($select.val()===tran){$select.val(BUSESC);$wq.prop('disabled',false);$('#keyfilter').css('visibility','visible');}
if(focus&&hash===undefined)
$wq.focus();if(!focus)document.activeElement.blur();var $refer=$('mark, #resultados a');$refer.hover(resaltarEnlace);$('mark').on('click',consultarMark);$('#a0 a, #l0 a, #l1 a, #l2 a, #l3 a, #f0 a').on('click',consultarA);$('#h0 a').on('click',consultarText);popup();}},consultar=function(u,uH,p,actHis,evGa,inicio){var request=$.ajax({url:u,type:'GET',data:p,dataType:'html'});request.done(function(datos){if(datos.indexOf('challenge()')!==-1){var iframe=document.getElementById('fc'),doc=iframe.contentWindow.document;iframe.name=u+'|'+uH+'|'+JSON.stringify(p)+'|'+actHis+'|'+JSON.stringify(evGa);doc.open('text/html');doc.write(datos);doc.close();}else{doResp(datos,u,uH,p,actHis,evGa,inicio);}});request.fail(function(jqXHR,textStatus){console.log('Solicitud fallida: '+textStatus);$('#resultados').html(merror);$('#redesSociales').css('visibility','hidden');});},consultarA=function(event){consultarCookies();event.preventDefault();var href=$(this).attr('href'),ids=href.substring(href.indexOf('=')+1,href.length),uHn,cat=CATFETC,act,term=$(this).text();if(ids.indexOf('#')===0){document.querySelector("[id='"+ids.substring(1,ids.length)+"']").scrollIntoView();var arts=document.getElementsByTagName('article');if(arts.length!=0){ids=arts[0].getAttribute('id')+ids;uHn=uHistFetId+ids;}
history.pushState({u:fetch,uH:uHn,p:{'id':ids}},document.title,uHn);gaDat=[cat,ACTFNAVE,term];gaDLE(gaDat);}else{var idDiv=$(this).parents('div').attr('id');if(idDiv==='l0')
act=ACTFLISDES;else if(idDiv==='l1')
act=ACTFLISAPR;else if(idDiv==='l2')
act=ACTFLISANA;else if(idDiv==='l3')
act=ACTFLISTER;else{if($(this).hasClass('e1')||$(this).hasClass('e2')){act=ACTFCONJUGW;term=$(this).prev().html();}else
act=ACTFNAVE;}
uHn=uHistFetId+ids;gaDat=[cat,act,term];consultar(fetch,uHn,{'id':ids},true,gaDat,false);}},consultarText=function(event){consultarCookies();var href=$(this).attr('href');if(href.indexOf('http')==-1){var name=href.substring(1,href.length),url='/docs/';if($('#ayuda').length!=0)
url+='ayuda.html';else if($('#advertencias').length!=0)
url+='advertencias.html';else if($('abreviaturas').length!=0)
url+='abreviaturas-y-signos-empleados.html';else if($('edicion').length!=0)
url+='la-vigesimotercera-edicion.html';else if($('preambulo').length!=0)
url+='preambulo.html';url+='#'+name;uHist='/';document.querySelector("[name='"+name+"']").scrollIntoView();history.pushState({u:url,uH:uHist,p:null},document.title,uHist);event.preventDefault();}},consultarMark=function(event){consultarCookies();var ids=$(this).attr('data-id'),fw=$(this).text(),p,uHn;gaDat=[CATFETC,ACTFNAVE,fw];if(ids===undefined){uHn=uHistFetW+fw;p={'w':fw};}else{uHn=uHistFetId+ids;p={'id':ids};}
consultar(fetch,uHn,p,true,gaDat,false);},pagInicio=function(gaDat){consultar(search,uHist+'diccionario',{w:'diccionario'},true,gaDat,true);},resaltarEnlace=function(){$(this).css('cursor','pointer');},popup=function(){if($(window).width()<=1024){var targets=$('abbr'),target=false,tooltip=false,title=false;targets.bind('mouseenter',function(){target=$(this);tip=target.attr('title');tooltip=$('<div id="tooltip"></div>');if(!tip||tip=='')
return false;target.removeAttr('title');tooltip.css('opacity',0).html(tip).appendTo('body');var init_tooltip=function(){if($(window).width()<tooltip.outerWidth()*1.5)
tooltip.css('max-width',$(window).width()/2);else
tooltip.css('max-width',340);var pos_left=target.offset().left+(target.outerWidth()/2)-(tooltip.outerWidth()/2),pos_top=target.offset().top-tooltip.outerHeight()-20;if(pos_left<0){pos_left=target.offset().left+target.outerWidth()/2-20;tooltip.addClass('left');}else
tooltip.removeClass('left');if(pos_left+tooltip.outerWidth()>$(window).width()){pos_left=target.offset().left-tooltip.outerWidth()+target.outerWidth()/2+20;tooltip.addClass('right');}else
tooltip.removeClass('right');if(pos_top<0){var pos_top=target.offset().top+target.outerHeight();tooltip.addClass('top');}else
tooltip.removeClass('top');tooltip.css({left:pos_left,top:pos_top}).animate({top:'+=10',opacity:1},50);};init_tooltip();$(window).resize(init_tooltip);var remove_tooltip=function(){tooltip.animate({top:'-=10',opacity:0},50,function(){$(this).remove();});target.attr('title',tip);};target.bind('mouseleave',remove_tooltip);tooltip.bind('click',remove_tooltip);});};};$(function($){if(msie>0&&parseInt(ua.substring(msie+5,ua.indexOf(".",msie)))<=9)
ie9=true;var $select=$('#formList'),$inputLema=$('#wq'),offset=300,duration=500;jQuery(window).scroll(function(){if(jQuery(this).scrollTop()>offset)
jQuery('.back-to-top').fadeIn(duration);else
jQuery('.back-to-top').fadeOut(duration);});jQuery('.back-to-top').click(function(event){event.preventDefault();jQuery('html, body').animate({scrollTop:0},duration);return false;});$select.on('change',function(){if($(this).val()===tran){$inputLema.val('');$inputLema.prop('disabled',true);$('#keyfilter').css('visibility','hidden');}else{$inputLema.prop('disabled',false);$inputLema.focus();$('#keyfilter').css('visibility','visible');}});$('.text').on('click',function(event){event.preventDefault();var href=$(this).attr('href'),uH=href;href=href.substring(4,href.length);gaDat=null;consultar(href,uH,null,true,gaDat,false);});$inputLema.autocomplete({source:function(request,response){var src=$select.val()===BUSESC?$.ajax({dataType:"jsonp",url:"/srv/keys",data:{q:request.term},success:function(data){response(data);}}):'';response(src);},select:function(event,ui){$inputLema.val(ui.item.value);$('#drae23').submit();consultarCookies();},minLength:2});$inputLema.on("keydown",function(event){consultarCookies();$(this).off(event);});$inputLema.bind('keyup',function(e){var code=(e.keyCode?e.keyCode:e.which);if(code==$.ui.keyCode.ENTER){$(this).autocomplete("close");}});$inputLema.keypad({showOn:'',keypadOnly:false,layout:['áéíóúüñ','ÁÉÍÓÚÜÑ'],prompt:'Tabla de caracteres especiales'});$('#keyfilter').on('click',function(event){$inputLema.keypad('show')});function updateContent(data){if(data!==null){if(data.p==null)
data.p={'o':'h'};else
data.p.o='h';gaDat=null;consultar(data.u,data.uH,data.p,false,gaDat,false);}}
window.addEventListener('popstate',function(event){updateContent(event.state);});history.replaceState(null,document.title,document.location.href);popup();$('#drae23').submit(function(event){consultarCookies();var u=search,l=$inputLema.val(),f=$select.val(),uH=uHist+l,p=null,cat,act;if(f===tran){u=random;uH=uHistRan;act=cat=CATACTRAND;l=null;}else if(l.length<1){alert('Es necesario incluir algún término de búsqueda.');return false;}else if(f===tanag){u=anagrama;p={'w':l};uH+=uHistAn;act=cat=CATACTANAG;}else{p={'w':l,'m':f};uH+='&m='+f;cat=CATSEAR;act=tipoActModo(f);}
gaDat=[cat,act,l];consultar(u,uH,p,true,gaDat,false);event.preventDefault();});});function loadPagedile(){var l=getQueryStringValue('w'),p=null,u=search,uH=uHist+l,$select=$('#formList'),location=decodeURIComponent(document.location.href);gaDat=[CATEXTE,location];if(l!=''){l=decodeURIComponent(l);if(getQueryStringValue(tanag)!=''){u=anagrama;p={'w':l};uH+=uHistAn;$select.val(tanag);}else{var f=getQueryStringValue('m');if(f!=''){p={'w':l,'m':f};uH+='&m='+f;$select.val(f);act=tipoActModo(f);}else{p={'w':l};$select.val(BUSESC);}}
consultar(u,uH,p,true,gaDat,false);}else if(getQueryStringValue(tran)!=''){consultar(random,uHistRan,p,true,gaDat,false);$select.val(tran);}else if(getQueryStringValue('id')!=''){var fin=location.indexOf("&")==-1?location.length:location.indexOf('&'),ids=location.substring(location.indexOf('=')+1,fin);uHn=uHistFetId+ids;consultar(fetch,uHn,{'id':ids},true,gaDat,false);}else if(getQueryStringValue('fw')!=''){var fw=decodeURIComponent(getQueryStringValue('fw')),uHn=uHistFetW+fw;consultar(fetch,uHn,{'w':fw},true,gaDat,false);}else if(getQueryStringValue('t')!=''){var url=getQueryStringValue('t'),name='';if(location.indexOf('#')!==-1)
name=location.substring(location.indexOf('#'),location.length);var uHistText='?t='+url+name;consultar(url,uHistText,null,true,gaDat,false);}else
pagInicio(gaDat);var $pd=$('.words'),palabraD=$.ajax({url:'/srv/wotd',type:'GET',dataType:'html'});palabraD.done(function(datos){if(datos.indexOf("<a href")===0){datos=datos.replace('.','');datos=datos.replace('id=','?id=');$pd.html(datos);$('#palabraD a').on('click',consultarA);}else
$pd.html(pdEr);});palabraD.fail(function(jqXHR,textStatus){$pd.html(pdEr);});}
function iFrameLoaded(){var $iframe=$('#fc'),datos=$iframe.contents().find('html').html();if(datos.indexOf('challenge()')===-1&&cont>=3){var nameFT=$iframe.attr('name').split('|'),u=nameFT[0],uH=nameFT[1],p=JSON.parse(nameFT[2]),actHis=nameFT[3];gaDat=JSON.parse(nameFT[4]);doResp(datos,u,uH,p,actHis,gaDat,false);}
cont=cont+1;}
function procesarParentesis($entrada){var $parentesis_ori=$entrada.find(':not(.fc).n4, :not(.fc).n5');var $parentesis_dest=$entrada.find(':not(.fc).n2, :not(.fc).n3');var $seccion;$parentesis_ori.contents().each(function(){if($seccion==null){$seccion=$('<p class="n5"></p>');$parentesis_dest=$parentesis_dest.add($seccion);}
if(this.nodeType==3){var ind=this.textContent.indexOf('\u25C6');if(ind!=-1){var tokens=this.textContent.split('\u25C6');$seccion.append(tokens[0]);var $nueva_seccion=$('<p class="n5"></p>');$parentesis_dest=$parentesis_dest.add($nueva_seccion);$seccion=$nueva_seccion;$seccion.append(tokens[1]);}
else
$seccion.append($(this));}
else{$seccion.append($(this));}});$parentesis_ori.replaceWith($parentesis_dest.wrapAll('<div class="par"></div>').parent());$entrada.find(':not(.fc).n5').wrapAll('<div class="morf_orto"></div>');};function procesarFormasComplejas($entrada){var bloqueFC;$entrada.find('.k, .k5, .k6').each(function(){var $fc=$(this);quitarPunto($fc);if(bloqueFC==null){if($fc.hasClass('k5'))
bloqueFC='k5';else
bloqueFC='k6';}
else{if($fc.hasClass('k'))
$fc.removeClass('k').addClass(bloqueFC);else if(bloqueFC='k5'&&$fc.hasClass('k6'))
bloqueFC='k6';}});$entrada.find('.k5, .k6').each(function(){var $fc=$(this);var $sig=$fc.next();if($sig.hasClass('n1')){$sig.addClass('fc');$sig=$sig.next();}
if($sig.hasClass('n2')||$sig.hasClass('n3')){$sig.addClass('par fc');$sig=$sig.next();}
if($sig.hasClass('n4')||$sig.hasClass('n5')){$sig.addClass('par fc');}
$fc.find('.par').wrapAll('<div class="morf_orto"></div>');});$entrada.find('.av, .af').each(function(){$var=$(this);var $fc=$var.parent().prev();var class_var_fc;if($fc.hasClass('k5')){class_var_fc='var_fc_1';}else if($fc.hasClass('k6')){class_var_fc='var_fc_2';}
if(class_var_fc)
$var.addClass(class_var_fc);});};function procesarNumeroAcep(){$('.m, .j, .j1, .j2').each(function(){$(this).contents().first().wrap('<span class="n_acep"></span>');});};function marcarGuionAcentuado($contenedorLema){var $lema=$contenedorLema.contents().first();var lema=$lema.text();if(lema.indexOf('\u2012\u0301')==0){$lema.remove();$contenedorLema.prepend('<span class="guiona">\u2012\u0301</span>'+lema.substr(2));}};function quitarPunto($contenedor_encab){var $encabezamiento=$contenedor_encab.contents(),$ele_fin_encab=$encabezamiento.last(),fin_encab=$ele_fin_encab.text();if(fin_encab.match(/\.$/)&&!fin_encab.match(/etc\.$/)){fin_encab=fin_encab.substr(0,fin_encab.length-1);}
var $div_temp=$('<div></div>');if($ele_fin_encab[0].nodeType!=3){$ele_fin_encab.text(fin_encab);$div_temp.append($encabezamiento);}
else{Array.prototype.pop.call($encabezamiento);$div_temp.append($encabezamiento);$div_temp.append(fin_encab);}
$contenedor_encab.empty();$contenedor_encab.append($div_temp.contents());};function cambiaBoton($ae,term){var urlH='/?id='+$ae.parents('article').attr('id');$ae.replaceWith(function(){attrs={class:$(this).attr('class'),onclick:"conjugar('"+$(this).attr('href')+"','"+term+"','"+urlH+"') ; return false;",title:$(this).attr('title')};return $("<img />",attrs).attr('src','/images/buscarconj.gif');});}
function conjugar(urlConj,term,urlH){var ids=urlConj.substring(4,urlConj.length),p={'id':ids};gaDat=[CATFETC,ACTFCONJUGW,term];consultar(fetch,urlH,p,true,gaDat,false);}
function marcarAbrAcep(cadena){cadena=cadena.replace(/ acep. /g,' <abbr title="acepción">acep.</abbr> ');cadena=cadena.replace(/ aceps. /g,' <abbr title="acepciones">aceps.</abbr> ');return cadena;};function formateaTag(cadena){cadena=cadena.replace(/(<sup>|<\/sup>|<i>|<\/i>)/g,'');if(/\x{2012}\x{0301}/.test(cadena)){;}
else if(/1/.test(cadena)){cadena=cadena.replace('1','\u00B9');}
else if(/2/.test(cadena)){cadena=cadena.replace('2','\u00B2');}
else if(/3/.test(cadena)){cadena=cadena.replace('3','\u00B3');}
else if(/4/.test(cadena)){cadena=cadena.replace('4','\u2074');}
else if(/5/.test(cadena)){cadena=cadena.replace('5','\u2075');}
else if(/6/.test(cadena)){cadena=cadena.replace('6','\u2076');}
else if(/7/.test(cadena)){cadena=cadena.replace('7','\u2077');}
else if(/8/.test(cadena)){cadena=cadena.replace('8','\u2078');}
else if(/9/.test(cadena)){cadena=cadena.replace('9','\u2079');}
return cadena;}
function transformUrlFecht(cadena){cadena=cadena.replace(/fetch/g,'');return cadena;}
function quitarPunt(valor){if(valor===undefined||valor===null)return valor;var ultCha=valor.substring(valor.length-1,valor.length);if(ultCha==='.'||ultCha==';'||ultCha==',')valor=valor.substring(0,valor.length-1);return valor.replace('.,',',');}
function getQueryStringValue(name){name=name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");var regex=new RegExp("[\\?&]"+name+"=([^&#]*)");var results=regex.exec(window.location.href);if(results==null)return"";else return results[1];}
function getQueryString(){return window.location.href.substr(window.location.href.indexOf('?')+1);}
function Fecha(){var fecha=new Date();var kFecha=fecha.getFullYear();return kFecha;}
function ponFechaS(){document.write('<span class="date">'+Fecha()+'</span>');}
function Fechaa(){var fecha=new Date();var semana=new Array("Domingo","Lunes","Martes","Mi&eacute;rcoles","Jueves","Viernes","S&aacute;bado");var meses=new Array("enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre");var kFecha=semana[fecha.getDay()]+', ';kFecha+=fecha.getDate()+' de ';kFecha+=meses[fecha.getMonth()]+' de ';kFecha+=fecha.getFullYear();return kFecha;}
function ponFechaa(){document.write('<span class="date">'+Fechaa()+'</span>');}
function Fecharb(){var fecharb=new Date();var kFecharb=fecharb.getDate()+'-';kFecharb+=fecharb.getMonth()+1+'-';kFecharb+=fecharb.getFullYear();return kFecharb;}
function ponFecharb(){document.write('<span class="date">&nbsp;&nbsp;'+Fecharb()+'</span>');}
function goToTopPage(){document.body.scrollTop=document.documentElement.scrollTop=0;}