Drupal.locale = { 'pluralFormula': function ($n) { return Number(($n!=1)); }, 'strings': {"":{"An AJAX HTTP error occurred.":"Ocorreu um erro HTTP no AJAX","HTTP Result Code: !status":"C\u00f3digo do Resultado HTTP:  !status","An AJAX HTTP request terminated abnormally.":"Uma requisi\u00e7\u00e3o HTTP AJAX terminou de forma anormal.","Debugging information follows.":"Estas s\u00e3o as informa\u00e7\u00f5es de depura\u00e7\u00e3o.","Path: !uri":"Caminho: !url","StatusText: !statusText":"Texto de Status: !statusText","ResponseText: !responseText":"Texto de Resposta: !responseText","ReadyState: !readyState":"ReadyState: !readyState","Configure":"Configurar","Show shortcuts":"Mostrar atalhos","Hide shortcuts":"Esconder atalhos","(active tab)":"(aba ativa)","Select all rows in this table":"Selecionar todas as linhas da tabela","Deselect all rows in this table":"Desmarcar todas as linhas da tabela","Re-order rows by numerical weight instead of dragging.":"Re-ordernar as linhas por campos n\u00famericos de peso ao inv\u00e9s de arrastar-e-soltar.","Show row weights":"Exibir pesos das linhas","Hide row weights":"Ocultar pesos das linhas","Drag to re-order":"Arraste para reordenar","Changes made in this table will not be saved until the form is submitted.":"Mudan\u00e7as feitas nesta tabela n\u00e3o ser\u00e3o salvas at\u00e9 que o formul\u00e1rio seja enviado.","Hide":"Ocultar","Show":"Exibir","Automatic alias":"Endere\u00e7o autom\u00e1tico","Alias: @alias":"URL Alternativa: @alias","No alias":"Nenhuma URL alternativa","Not published":"N\u00e3o publicado","Please wait...":"Por favor, espere um pouco...","@number comments per page":"@number coment\u00e1rios por p\u00e1gina","Not in menu":"Fora do menu","New revision":"Nova revis\u00e3o","No revision":"Sem revis\u00e3o","By @name on @date":"Por @name em @date","By @name":"Por @name","Autocomplete popup":"Popup de autocompletar","Searching for matches...":"Procurando por dados correspondentes...","Not customizable":"N\u00e3o \u00e9 personaliz\u00e1vel","Not restricted":"Sem restri\u00e7\u00f5es","Restricted to certain pages":"Restrito para certas p\u00e1ginas","The selected file %filename cannot be uploaded. Only files with the following extensions are allowed: %extensions.":"O arquivo selecionado %filename n\u00e3o p\u00f4de ser transferido. Somente arquivos com as seguintes extens\u00f5es s\u00e3o permitidos: %extensions.","Hide layout designer":"Esconder interface de cria\u00e7\u00e3o de layout","Not tracked":"N\u00e3o monitorado","One domain with multiple subdomains":"Um Dom\u00ednio com multiplos subdom\u00ednios","Multiple top-level domains":"M\u00faltiplos dom\u00ednios prim\u00e1rios","All pages with exceptions":"Todas as p\u00e1ginas com exce\u00e7\u00f5es","Excepted: @roles":"Exce\u00e7\u00f5es: @roles","A single domain":"Um \u00fanico dom\u00ednio","@label: @value":"@label: @value","Using defaults":"Utilizar padr\u00f5es","The annotation field is required.":"O campo anota\u00e7\u00e3o \u00e9 obrigat\u00f3rio.","You must enter the tag name. Please try again.":"Voc\u00ea precisa informar um nome para a tag. Tente novamente."}} };;
(function($) {

Drupal.behaviors.commonPlugger = {
  attach: function(context) {

    //HTML para as validações de url
    var html_check = '<div class="address-check"><span></span><div class="address-check-msg"></div></div>';
    var delay_keyup = 1200; //Delay para validação dos campos após digitar algum caracter
    
    // verifica se o user está livre, tela Novo Usuario
    $('#user-register-form input#edit-name').unbind('keyup').bind('keyup',
      debounce(delay_keyup, function() {
        $this = $(this);
        
        if ($this.val() == '') {
          $('.form-item-name .form-campo-error').removeClass('form-campo-error');
          $('.form-item-name .address-check').removeClass('unavailable').removeClass('available');
          return;  
        }
        
        $this.addClass('throbbing');
        $el = $('.form-item-name');
        if($el.find('.address-check').length == 0) $el.append(html_check);
        $check = $el.find('.address-check');       

        $.post(Drupal.settings.basePath + 'ajax/user/' + this.value, function(data) {
          if (data.uid) {
            $check.removeClass('available').addClass('unavailable');
            $this.parents('.form-campo-item').addClass('form-campo-error');
            $check.find('div').html('O nome <strong>'+$this.val()+'</strong> já esta em uso. Escolha um usuário diferente.');
            $this.focus();
          } else {
            $('.form-item-name .form-campo-error').removeClass('form-campo-error');
            $check.removeClass('unavailable').addClass('available');
          }
          
          $this.removeClass('throbbing');
        });
      })
    );

    // verifica se o email está livre, tela Novo Usuario
    $('#user-register-form input#edit-mail').bind('keyup',
      debounce(delay_keyup, function() {
        $this = $(this);
        
        //Verificando se é o formulário de conta, do Plugger ou se é o form de cadastro do hotsite
        $link_account_exists = $('body').hasClass('page-convite')?'':'<br /><a href="javascript:;">Já possui usuário?</a>';
        console.log($this.parents('form').attr('id'));
        
        if ($this.val() == '') {
          $('.form-item-mail .form-campo-error').removeClass('form-campo-error');
          $('.form-item-mail .address-check').removeClass('unavailable').removeClass('available');  
          return;  
        }
        
        $el = $this.parents('.form-item-mail');
        if($el.find('.address-check').length == 0) $el.append(html_check);
        $check = $el.find('.address-check');
        $this.addClass('throbbing');

        $.post(Drupal.settings.basePath + 'ajax/mail/' + this.value, function(data) {
          $this.removeClass('throbbing');
          
          if (!data.mailValid) {
            $check.removeClass('available').addClass('unavailable');
            $this.parents('.form-campo-item').addClass('form-campo-error');
            $check.find('div').html('<strong>'+$this.val()+'</strong> não é um e-mail válido.');
            $this.focus();
          } else if (data.uid) {
            $check.removeClass('available').addClass('unavailable');
            $this.parents('.form-campo-item').addClass('form-campo-error');
            $check.find('div').html('O e-mail <strong>'+$this.val()+'</strong> já está em uso.'+$link_account_exists);
            $this.focus();
          } else {
            $check.find('div').html('');
            $check.removeClass('unavailable').addClass('available');
            $this.parents('.form-campo-item').removeClass('form-campo-error');
          }
        });
      })
    );

    // verifica se a URL está livre, tela Nova/Editar Conta
    $('#edit-url').bind('keyup', function() {
      this.value = this.value.replace(/\//g, '');
      if (!$('span#url'))
        $(this).find('.description').html('Seu endereço: http://<span id=url>exemplo</span>.plugger.com.br');
     
      if (!this.value) {
        $('.form-item-url .form-campo-error').removeClass('form-campo-error');
        $this.parents('.form-item').find('.description').html('Endereço do seu site. Exemplo: http://<span id=url>modelo</span>.plugger.com.br');
        $('.form-item-url .address-check').removeClass('unavailable').removeClass('available');
        clearTimeout(vTime);
        return;
      } else
        $('span#url').html(this.value);

      if (typeof vTime != 'undefined')
        clearTimeout(vTime);
        vTime = setTimeout( function() { $("#edit-url").autocompleteUrl(); }, delay_keyup);
    });

    // função de autocomplete pra buscar a URL
    jQuery.fn.autocompleteUrl = function() {
      $(this).addClass('throbbing');
      params = new Array();
      $this = $(this);
      $el = $('.form-item-url');
      if($el.find('.address-check').length == 0) $el.append(html_check);
      $check = $el.find('.address-check');

      if ($this.val()) {
        $(this).addClass('throbbing');
        $.post(Drupal.settings.basePath + 'ajax/url/' + $this.val(), params, function(data) {
        if (data.available==0) {
          $check.removeClass('available').addClass('unavailable');
          $this.focus();
          $check.find('div').html(data.msg);
          $this.parents('.form-campo-item').addClass('form-campo-error');
          //$('.form-submit').attr('disabled', 'disabled');
        } else {
          $('span#url').html($this.val());
          $check.removeClass('unavailable').addClass('available').find('.address-check-msg').html('Seu endereço: http://<strong>' + $this.val() + '</strong>.plugger.com.br');
          $this.parents('.form-campo-item').removeClass('form-campo-error');
          //$('.form-submit').attr('disabled', '');
        }
        $this.removeClass('throbbing');
      });
      }
    };

    // valida a confirmação de senha, adicionando o icone de OK ou ERRO ao lado
    $('#edit-pass-pass1').bind('keyup', function(){
      $('#edit-pass-pass2').keyup();
    });

    $('#edit-pass-pass2').bind('keyup',
      debounce(delay_keyup, function() {
        $this = $(this);
        $el = $this.closest('.form-item');
        
        if($el.find('.address-check').length == 0) $el.append(html_check);
        $check = $el.find('.address-check');
        
        if ($this.val() == '') {
          $el.find('.form-campo-item').removeClass('form-campo-error');
          $check.removeClass('unavailable').removeClass('available');  
          return;  
        }
      
        match = $('#edit-pass-pass1').val() == this.value;
        $check.addClass( (!match ? 'un' : '') + 'available').removeClass( (match ? 'un' : '') + 'available');
        $el.find('.form-campo-item').addClass((!match ? 'form-campo-error' : '')).removeClass((match ? 'form-campo-error' : ''));
        $el.find('.address-check-msg').html(match ? '' : 'A senha não confere');
      })
    );

  } // behavior
} // (function)

})(jQuery);

// Returns a function, that, as long as it continues to be invoked, will not
  // be triggered. The function will be called after it stops being called for
  // N milliseconds.
debounce = function(wait, func) {
  var timeout;
  return function() {
    var context = this, args = arguments;
    var later = function() {
      timeout = null;
      func.apply(context, args);
    };
    clearTimeout(timeout);
    timeout = setTimeout(later, wait);
  };
};

//Valida e-mail
emailValidate = function(email) {
  er = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2}/;
  if(er.exec(email))
    return true;
  else
    return false;
}

;
(function ($) {

$(document).ready(function() {

  // Accepts a string; returns the string with regex metacharacters escaped. The returned string
  // can safely be used at any point within a regex to match the provided literal string. Escaped
  // characters are [ ] { } ( ) * + ? - . , \ ^ $ # and whitespace. The character | is excluded
  // in this function as it's used to separate the domains names.
  RegExp.escapeDomains = function(text) {
    return (text) ? text.replace(/[-[\]{}()*+?.,\\^$#\s]/g, "\\$&") : '';
  }

  // Attach onclick event to document only and catch clicks on all elements.
  $(document.body).click(function(event) {
    // Catch the closest surrounding link of a clicked element.
    $(event.target).closest("a,area").each(function() {

      var ga = Drupal.settings.googleanalytics;
      // Expression to check for absolute internal links.
      var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i");
      // Expression to check for special links like gotwo.module /go/* links.
      var isInternalSpecial = new RegExp("(\/go\/.*)$", "i");
      // Expression to check for download links.
      var isDownload = new RegExp("\\.(" + ga.trackDownloadExtensions + ")$", "i");
      // Expression to check for the sites cross domains.
      var isCrossDomain = new RegExp("^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\/.*(" + RegExp.escapeDomains(ga.trackCrossDomains) + ")", "i");

      // Is the clicked URL internal?
      if (isInternal.test(this.href)) {
        // Is download tracking activated and the file extension configured for download tracking?
        if (ga.trackDownload && isDownload.test(this.href)) {
          // Download link clicked.
          var extension = isDownload.exec(this.href);
          _gaq.push(["_trackEvent", "Downloads", extension[1].toUpperCase(), this.href.replace(isInternal, '')]);
        }
        else if (isInternalSpecial.test(this.href)) {
          // Keep the internal URL for Google Analytics website overlay intact.
          _gaq.push(["_trackPageview", this.href.replace(isInternal, '')]);
        }
      }
      else {
        if (ga.trackMailto && $(this).is("a[href^=mailto:],area[href^=mailto:]")) {
          // Mailto link clicked.
          _gaq.push(["_trackEvent", "Mails", "Click", this.href.substring(7)]);
        }
        else if (ga.trackOutbound && this.href) {
          if (ga.trackDomainMode == 2 && isCrossDomain.test(this.href)) {
            // Top-level cross domain clicked. document.location is handled by _link internally.
            _gaq.push(["_link", this.href]);
          }
          else if (ga.trackOutboundAsPageview) {
            // Track all external links as page views after URL cleanup.
            // Currently required, if click should be tracked as goal.
            _gaq.push(["_trackPageview", '/outbound/' + this.href.replace(/^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\//i, '').split('/').join('--')]);
          }
          else {
            // External link clicked.
            _gaq.push(["_trackEvent", "Outbound links", "Click", this.href]);
          }
        }
      }
    });
  });
});

})(jQuery);
;

