var url_for_types = { 'NE': "/dynamic_news/0",
                      'DT': "/dynamic_documentals/0",
                      'BL': "/dynamic_documentals/0",
                      'EX': "/dynamic_documentals/0",
                      'PR': "/questions/0",
                      'JU': "/jurisprudences/0",
                      'LE': "/legislations/0"};
var wk_debug = true;

jQuery(function($) {

  $('#dTxT a:not(.nt)').each(function(){
    var link_ref = $(this)[0].href;
    var redirection = wk_redirection(link_ref);

    if(wk_debug){$(this).attr('debug', redirection);}

    if(redirection!=''){
        $(this).click(function(){
          document.location = redirection;
          return false;
        });
    }
  });

});

function wk_redirection(string){
  var wk_id = anchor = url ='';
  var reg_ex_wk = /(NE|DT|BL|EX|PR|JU|LE)[0-9]+/i;
  var exc_reg_ex_wk = /consulta_juris|SaltoExt/i;
  var reg_ex_anchor = /#[a-z0-9]+/i;

  if( string.search(exc_reg_ex_wk) == -1 ){
    if(string.match(reg_ex_wk)){
      wk_id = string.match(reg_ex_wk)[0];
      url = url_for_types[wk_id.substring(0,2)];
    }

    if(string.match(reg_ex_anchor)){
      anchor = string.match(reg_ex_anchor)[0];
    }

    return url.replace('0',wk_id)+anchor;
  }
  else{
    return '';
  }
}
