/**
* object met UI functies
* 
* #web_ui_alert_box, #web_ui_alert_box_msg layout via CSS
*/

web_ui = {};
web_ui._timeout_id = null;
  
web_ui.create_element = function(tagname, id)
 {  
  var element = document.createElement(tagname); 
  element.id = id;
  document.getElementsByTagName('body')[0].appendChild(element);    
 } 

web_ui._show_splash_screen = function()
 {
  if ($('#web_ui_splash_screen').length == 0)
   { 
    web_ui.create_element('div', 'web_ui_splash_screen');
   } 
  
  var h = $(document).height(); 
  var w = $(document).width(); 
       
  $('#web_ui_splash_screen').width(w);    
  $('#web_ui_splash_screen').height(h);
  $('#web_ui_splash_screen').css({'background-color': '#c0c0c0'});  
  $('#web_ui_splash_screen').css({position: 'absolute'});  
  $('#web_ui_splash_screen').css({left: '0px'});    
  $('#web_ui_splash_screen').css({top: '0px'});      
  $('#web_ui_splash_screen').css({opacity: 0});
  $('#web_ui_splash_screen').show();
  $('#web_ui_splash_screen').fadeTo('fast', 0.5);
 } 
 
web_ui.show_splash_screen = function()
 {
  this._timeout_id = setTimeout('web_ui._show_splash_screen()', 100); 
 }
    
web_ui.hide_splash_screen = function()
 {
  clearTimeout(web_ui._timeout_id);
  $('#web_ui_splash_screen').hide();
 } 
 
web_ui._hide_alert = function()
 { 
  web_ui.hide_splash_screen();
  $('#web_ui_alert_box').hide();
 } 
 
web_ui.alert = function(msg)
 { 
  web_ui._show_splash_screen();
  
  if ($('#web_ui_alert_box').length == 0)
   {
    html = '<div id="web_ui_alert_box_msg"></div>';
    html+= '<button id="web_ui_alert_box_button" onclick="web_ui._hide_alert()">Sluit</button>';
    
    web_ui.create_element('div', 'web_ui_alert_box');    
    $('#web_ui_alert_box').html(html);
    $('#web_ui_alert_box').css({'z-index': '1000'});    
   }  
   
  var box_width = 300;
  var box_height = 200; 
   
  var w = $(window).width(); 
  var h = $(window).height();   
       
  $('#web_ui_alert_box_msg').height(box_height - 30);
  
  $('#web_ui_alert_box').width(box_width);   
  $('#web_ui_alert_box').height(box_height);
  $('#web_ui_alert_box').css('left', Math.round((w - box_width) / 2) );  
  $('#web_ui_alert_box').css('top', Math.round((h - box_height) / 2) );  
  $('#web_ui_alert_box').css({position: 'fixed'});  
  $('#web_ui_alert_box_msg').html(msg);  
  $('#web_ui_alert_box').show();
 } 
 
web_ui._curr_dialog_id = ''; 
 
web_ui.show_help = function(id)
 {
  if (web_ui._curr_dialog_id != '')
   {
    $('#help_' + web_ui._curr_dialog_id).dialog('close');
   } 
  web_ui._curr_dialog_id = id; 
  
  $('#help_' + id).dialog
   ( 
    { 
     autoOpen: false,   
     modal: false, 
     buttons:
     {
      'Ok': function(){$(this).dialog('close')}
     }
    }
   ); 
      
  $('#help_' + id).dialog('open');
 }

web_ui.set_error = function(fieldname)
 { 
  $('#label_' + fieldname).addClass('error_label');    
 }  
 
web_ui.clear_error = function(fieldname)
 { 
  $('#error_msg').html('&nbsp;');  
  $('#label_' + fieldname).removeClass('error_label'); 
 } 
 
