/*******************************************************************
 * load_software.js                                                *
 *                                                                 *
 * Copyright (c) de-bit GmbH. All Rights Reserved.                 *
 *                                                                 *
 * Permission to use, copy, modify, and distribute this software   *
 * and its documentation for any purposes and without              *
 * fee is hereby denied!                                           *
 *                                                                 *
 ******************************************************************/

var popupstyle = "system/css/mainstyles_racmeongui_v1/popups_racemongui_v1/popups_racemongui_v1.css";
var loaded = 0;
var window_open = 0;
var settedheight = 0;

function initprogramm() {
  cache.length = 0
  get = superclass_get();
  start_lang = (array_key_exists('lang', get) ? get['lang'].toLowerCase() : 'en');
  com_ini = null;
  lang_ini = [];
  req = new ajax_request();
  x_timer = new common_clock_timer('x_timer');
  change_lang(start_lang, true);
}

function displayitem(htmlobjtoshow, secstoshow, style) {
  env.style = style;

  var ditem = htmlobjtoshow;

  load_style(popupstyle);

  if(window_open == 1) {

    // alert("schliessen Sie erst das andere Fenster");
    document.getElementById(ditem).style.display = 'none';
    unload_style(popupstyle);
    
    return true;
    
  } else {

    handlepopup(ditem);
  }

  if(ditem == "popup_loading") {
    self.moveTo(0,0)
    var width = ((window.screen.availWidth - 8) + 8) * 1;
    var height = ((window.screen.availHeight - 34) + 34) * 1;
    self.resizeTo(width, height)

    // here we init the programm ;-)
    initprogramm();    
  } else {
  	window_open = 1;
  }

  setTimeout("hideitem('" + ditem + "')", secstoshow * 1000);
}

function hideitem(htmlobjtohide) {
  var hitem = htmlobjtohide;

  if(hitem == "popup_loading") {
    document.getElementById('loading_programmisloading').style.display = 'none';
    document.getElementById('loading_languageselect').style.display = 'block';
    return true;
  } else {
  	window_open = 0;
  }

  document.getElementById(hitem).style.display = 'none';
  unload_style(popupstyle);
}

function mainlanguageselect(lang) {
  document.getElementById('popup_loading').style.display = 'none';
  unload_style(popupstyle);
  change_lang(lang);
  document.getElementById('page_margins').style.display = 'block';

  if(env.style != 'mobile' && env.style != null) {
    document.getElementById('informations').style.display = 'block';
  }

  loaded = 1;
  
  // set the results_box element dynamically for the first time... by manual...
  var RightKey = true;
  keyUp();
  var RightKey = false;
  
  // now register the functions for pressing the f11 button for
  // setting the results_box element dynamically by pressing this key...
  document.onkeydown = keyDown;
  document.onkeyup = keyUp;
 }

function tabelwidth() {

  var ScrollerWidth = 18;
  var tmp_array1 = [];
  var tmp_array2 = [];
  var tmp_array3 = [];
  var headertable = document.getElementById('header_table');
  var contenttable = document.getElementById('results_table');

  for( var a = 0; a < headertable.tBodies.length; a++ ) {
    for( var s = 0; s < 1; s++ ) {
      for( var d = 0; d < headertable.tBodies[a].rows[s].cells.length; d++ ) {      	
        tmp_array1[tmp_array1.length] = headertable.tBodies[a].rows[s].cells[d].offsetWidth;
      }
    }
  }
  for( var q = 0; q < contenttable.tBodies.length; q++ ) {
    for( var w = 0; w < 1; w++ ) {
      for( var e = 0; e < contenttable.tBodies[q].rows[w].cells.length; e++ ) {
        tmp_array2[tmp_array2.length] = contenttable.tBodies[q].rows[w].cells[e].offsetWidth;
      }
    }
  }

  var len1 = tmp_array1.length;
  var len2 = tmp_array2.length;

  for(var y = 0; y < len1 && y < len2; y++) {
    tmp_array3[y] = (tmp_array1[y] > tmp_array2[y] ? tmp_array1[y] : tmp_array2[y]);
  }

  for( var r = 0; r < headertable.tBodies.length; r++ ) {
    for( var t = 0; t < 1; t++ ) {
      for( var z = 0; z < headertable.tBodies[r].rows[t].cells.length; z++ ) {
      	
        width = 1*(tmp_array3[z] - 4);
      	if(width > 0) {
      	  headertable.tBodies[r].rows[t].cells[z].style.width = width + "px";
      	}
     	
      }
    }
  }
  
  for( var f = 0; f < contenttable.tBodies.length; f++ ) {
    for( var g = 0; g < 1; g++ ) {
      for( var h = 0; h < contenttable.tBodies[f].rows[g].cells.length; h++ ) {

        width = 1*(tmp_array3[h] - 4);
      	if(width > 0) {
      	  contenttable.tBodies[f].rows[g].cells[h].style.width = width + "px";
      	}
        
      }
    }
  }
  
  var completeHeaderBoxWidth = 1*(document.getElementById("header_box").offsetWidth);
  // for( var r = 0; r < headertable.tBodies.length; r++ ) {
    // for( var t = 0; t < 1; t++ ) {
      // for( var z = 0; z < headertable.tBodies[r].rows[t].cells.length; z++ ) {
      	if(completeHeaderBoxWidth > 0) {
      	  headertable.style.width = 1*(completeHeaderBoxWidth - ScrollerWidth) + "px";
      	}
      // }
    // }
  // }
  
  var completeContentBoxWidth = 1*(document.getElementById("results_box").offsetWidth);
  // for( var f = 0; f < contenttable.tBodies.length; f++ ) {
    // for( var g = 0; g < 1; g++ ) {
      // for( var h = 0; h < contenttable.tBodies[f].rows[g].cells.length; h++ ) {
      	if(completeContentBoxWidth > 0) {
      	  contenttable.style.width = 1*(completeContentBoxWidth - ScrollerWidth) + "px";
      	}
      // }
    // }
  // }
}

function handlepopup(item) {

  document.getElementById(item).style.display = 'block';

  var maxW;
  var maxH;
 
  // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
  if (typeof window.innerWidth != 'undefined') {
    maxW = window.innerWidth,
    maxH = window.innerHeight

  // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
  } else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
     maxW = document.documentElement.clientWidth,
     maxH = document.documentElement.clientHeight

  } else {
    maxW = document.getElementsByTagName('body')[0].clientWidth,
    maxH = document.getElementsByTagName('body')[0].clientHeight
  }

  elementW = document.getElementById(item).offsetWidth;
  elementH = document.getElementById(item).offsetHeight;

  document.getElementById(item).style.left = 1*((maxW-elementW)/2) + 'px';
  document.getElementById(item).style.top = 1*((maxH-elementH)/2) + 'px';

  return true;
}
