/**
 * this js requires jquery and cbClientArea to be loaded before.
 *
 * base.js contains some general functions for cb-applications and is   
 * automatically included with class.cb_ui_page_layout_cb_app.php
 *
 *
 */

/**
 * showLanguageWindow - draw the languageselection window
 *
 * This function automaticaly disables the page on click and shows the
 * language window. The language window will be given an project param
 * which is needed for showing the supported languages and no others.
 */
function showLanguageWindow(project) {
   var langLayer  = jQuery('<div style="width:100%;height:100%;position:fixed;top:0px;left:0px;z-index:1337;"></div>');
   var langWindow = jQuery('<div style="border:2px solid #b40000;border-radius:32px;-webkit-border-radius:32px;-moz-border-radius:32px;padding:35px 20px 35px 20px;width:280px;height:310px;position:fixed;z-index:1337;background-color:#ffffff;"></div>');
   jQuery('body').append(jQuery(langLayer));
   jQuery(langWindow)
      .css('left',window.innerWidth/2-162+'px')
      .css('top',window.innerHeight/2-192+'px')
      .load('/module/lib/framework/getLanguageWindow.php?project='+project,
         function()
         {
            jQuery('body').append(jQuery(langWindow));
         }
      );
   return false;
}

function toggleLanguage() {
   // @todo implement. should be in a seperate, optional file.
}

function toggleWindowSize() {
   // @todo implement
}

function submitLoginForm() {
   jQuery("#loginForm").submit();
}
/* this is used from cb-in/event/cbstage_status.php */
function cbGetHeight(elem) 
{
  var isIE6 = navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1;
  $elem = jQuery(elem);
  if (!$elem.length) return 0;
  var result = $elem.height(); 
  if (!isIE6)
  {
     result += parseInt($elem.css('margin-top'));
     result += parseInt($elem.css('margin-bottom'));
     result += parseInt($elem.css('padding-bottom'));
     result += parseInt($elem.css('padding-top'));
  }
  return result;
}

function maximizeContentHeight()
{
   var isIE6 = navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1;
                    
   var h_head = cbGetHeight('#top') + cbGetHeight('#tabAnchors') + 
                parseInt(jQuery('#container').css('margin-top'));
   var h_foot = cbGetHeight('#footer');
   var screenHeight = jQuery(window).height() || 600;

   var offset = 0;
   if (!isIE6)
      offset = parseInt(jQuery('#content').css('padding-top')) + 
               parseInt(jQuery('#content').css('padding-bottom')) ;

   jQuery('#content').height(screenHeight - h_head - h_foot - offset);
}

jQuery(document).ready(function(){
   // initialize size
//   cbMaximizeHeight('content');
   maximizeContentHeight();

   // install hook for window resizing
   jQuery(window).resize(maximizeContentHeight);

   // hide all elements with jsHidden class
   jQuery('.jsHidden').hide();

   jQuery('#loginForm').keydown(function(e) {
      if(e.keyCode == 13) {
        submitLoginForm();
      }
   });
});

