$(function()
  {
   window.addEvent('domready',
       function() 
       { 
           
           if ($.browser.msie) 
           {
              /*$('h2').textShadow('0px 0px 4px #333');*/
              /*$('#menu li a > em').textShadow('0px 0px 4px #fff');*/
           }
        
           $('#sessionExpiredDialog').dialog(
           {
              autoOpen: false,
              height: 200,
              width: 400,
              closeText: 'hide',
              modal: true,
              closeOnEscape: false,
              position: ['center', 200],
              buttons: [{
                            text: praxem_global.btnCaption,
                            click: function() { new URI('index.htm').go(); }
                        }]
           });   
           
           if (new URI().get('file') != 'account.htm')
              session.isActiveSession();
           
           
       });
  });

var session = {
      isActive: false,
      
      isActiveSession: function()
      {
         AccountService.isActiveSession(
         {    
            callback: function(result) 
            { 
               var data = JSON.decode(result); 
               session.isActive = data['isValidSession'];
               
               if (data['isValidSession'])
               {
                  $('#login').load('/login.htm #logged_' + lang, function() 
                  { 
                     info.init(); info.display();
                     
                     if (new URI().get('file') == 'account.htm' || new URI().get('file') == 'customer.htm')
                     {   
                        $('#myAccountSection').hide();
                        $('#myAccountUpdateProfileSection,#myAccountUpdatePasswordSection').show();
                        $('#myAccountUpdateProfile').click(function() { account.displayUpdateProfile(); $('#notPaidSimulation,#mySimsSection,#myDemosSection,#myArchivesSection,#mustChangePassword').hide(); });
                        $('#myAccountUpdatePassword').click(function() { account.displayUpdatePassword(); $('#notPaidSimulation,#mySimsSection,#myDemosSection,#myArchivesSection,#mustUpdateProfile').hide(); });
                     }
                  });
                  $('#ref').load('/ref.htm #refContent_' + lang);  
               }
               else
               {  
                  var fileName = new URI().get('file');
                  
                  if (fileName == 'account.htm' || fileName == 'paymentRecovery.htm')
                  {
                     $('#sessionExpiredDialogMsg').text(praxem_global.expiredSessionMsg);
                     $('#sessionExpiredDialog').dialog('open');
                  }
                  
                  loader.load();
               }
            },
            timeout: 10000,
            errorHandler: function(message) { loader.load(); }
         });   
      }
}

var loader = {
      load: function()
      {
         if (new URI().get('file') != 'register.htm' && new URI().get('file') != 'demo.htm')
            $('#login').load('/login.htm #loginContent_' + lang, function() { login.init(); });
         
         $('#ref').load('/ref.htm #refContent_' + lang);                 
      }
}

var contextHelp = {
      text: new Array(),
      
      hide: function()
      {
         $('#contextHelp').hide();
      },
      
      getElement: function()
      {
         return '<div class="help" id="contextHelp" style="display: none;"><div class="hContent"></div></div>'; 
      },
      
      showHelpAlt: function(id)
      {
         this.showHelp(document.getElementById(id)); 
      },

      showHelp: function(obj)
      {
        var txt = this.text[obj.id];
        
        $('#contextHelp').html('<div class="hContent">' + txt + '</div>');
        
        var padding = 12;
        
        /*if (obj.id == 'paypal')
           padding = -35;*/
        
        //console.log($('#' + obj.id).parent().offset());
        var offsetTop = $('#' + obj.id).offset().top;
        
        $('#contextHelp').animate({top: offsetTop - padding + 'px'}, 200, function() { $('#contextHelp').show(); });
      }
}
