var linexlegal = {
  'searches':{
    'linex': {
      'favourites': {},
      'favouritesId': '0'
    }, 
    'news': {}, 
    'nexis': {}, 
    'plc': {}, 
    'source': {
      'favourites': {},
      'favouritesId': '0'
    }, 
    'favourites': {
      'content_id': {}, 
      'org_id': {},
      'favouritesId': '0'
    }
  }, 
  'classifiers':{
    'sectors':{}, 
    'locations':{}
  }
};

function urlencode (str) {
  str = (str+'').toString();
  return encodeURIComponent(str).
    replace(/!/g, '%21').
    replace(/'/g, '%27').
    replace(/\(/g, '%28').
    replace(/\)/g, '%29').
    replace(/\*/g, '%2A').
    replace(/%20/g, '+').
    replace(/~/g, '%7E');
}

$(document).ready(function(){

  $.ajaxSetup({
    error : function(jqXHR, textStatus, errorThrown) {
      var notify = true;
      
      //Timeouts
      if (jqXHR.status == 403) {
        window.location.reload(true);
        notify = false;
      }
      
      if (jqXHR.status == 400 && (jqXHR.responseText.match(/undefined field/im) || jqXHR.responseText.match(/ParseException/im))) {
        alert("Invalid characters in Linex search\nPlease prefix with a forward slash any of the following special characters in your search:\n    + - && || ! ( ) { } [ ] ^ \" ~ * ? : \ \nFor assistance please contact support@linexsystems.com");
        notify = false;
      }
      
      if (notify) {
        $('.blockUI').remove();
        var test = {
        'url': window.location.href,
        'textStatus': textStatus,
        'errorThrown': errorThrown,
        'jqXHR': {
          readyState:jqXHR.readyState,
          responseText:jqXHR.responseText,
          responseXML:jqXHR.responseXML,
          status:jqXHR.status,
          statusText:jqXHR.statusText
        }
        };
        
        $.post(
          '/support_forms/silentLog',
          test,
          function (data){},
          'json');
        alert("A communications error occured and the last action failed completely.\nShould this problem persist please contact support@linexsystems.com.");
      }
    }
  });

  
  $('#site-tabs li.admin > a').click(function(e){
    e.preventDefault();
    if ($(this).parent().hasClass('intranet')) {
      $('<div><p>You are accessing Linex through your company&#039;s intranet account. For access to more functionality and to personalize the site please create your own account. <a href="/logout">Click here to login</a>.</p></div>').dialog({
        modal:true,
        resizable:true,
        title: 'Please register for a personal account',
        dialogClass: 'linex-dialog',
        buttons: {
          'Ok': function() {
            $(this).dialog('close');
          }
        }
      });
    }
  });
  
  if ($.browser.msie && parseInt($.browser.version) < 7) {
    // $('#content').empty().append('<div id="unsupported-browser-version"><p>Linex does not support versions of Internet Explorer less than version 7.</p></div>');
    $('#site-tabs li').hover(function(){
      $(this).children('ul').show().css({left:'auto',right:'0px'});
    },function(){
      $(this).children('ul').hide().css({left:'-99999px', right:'auto'});
    });
  }

  if ($.browser.msie && parseInt($.browser.version) <= 7) {
    $('.icon-menu').mouseover(function(e){
      var timeout = $(this).data('timeout');
      if(timeout) { clearTimeout(timeout); }
      $(this).addClass('icon-menu-hover');
      
      $(this).css('z-index', 19).parents().each(function() {
        if (this.tagName == 'body') { return false; }
        if ('relative' == $(this).css('position')) {
          $(this).css('z-index', 19);
        }
      });
      $(this).children('.icon-menu-ul').css('z-index', 20);
    }).mouseout(function(e){
      var timeout = $(this).data('timeout');
      if(timeout) { clearTimeout(timeout); }
      $(this).data('timeout', setTimeout($.proxy(function() {
        $(this).removeClass('icon-menu-hover');
        $(this).css('z-index', 'auto').parents().each(function() {
          if (this.tagName == 'body') { return false; }
          if ('relative' == $(this).css('position')) {
            $(this).css('z-index', 'auto');
          }
        });
        $(this).children('.icon-menu-ul').css('z-index', 'auto');
      }, this), 200));
      
    });
  }
  
  setTimeout("$('#flashMessage').hide('blind', 'slow');", 7000);
  
  $('form').submit(function() {
    _gaq.push(['_linkByPost', this]);
  });
  
});
