var days = new Array(
                      "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
                      "Friday", "Saturday"
                    );
                    
var months = new Array(
                        "January", "February", "March", "April", "May",
                        "June", "July", "August", "September", "October",
                        "November", "December"
                      );


/**
 *  Funkce pro mesic vrati svatky (vyuziva AJAXu)
 */
function _getHolidays( month, country )
{
  var url           = 'ajax/get_holidays.php';
  
  var ajax          = new sack();
  
  ajax.requestFile  = url;
  ajax.setVar( 'month', month );
  ajax.setVar( 'country', country );
  
  ajax.onCompletion = function(){ writeHolidays(ajax, month); };
  ajax.runAJAX();
}


/**
 *  Funkce zapise svatky do kalendare
 */
function writeHolidays(ajax, month)
{
  var response      = ajax.response;
  var lines         = response.split("\n");

  if ( lines.length )
  {
    var i, element, day, title;
    var holiday;
    
    for ( i=0; i<lines.length; i++ )
    {
      holiday = lines[i].split("###SEPARATOR###");
      
      if ( holiday.length==2 ) {
        day     = holiday[0];
        title   = holiday[1];

        element = document.getElementById( month+'-'+ day );
        
        if ( element )
        {
          element.className = 'dayHoliday';
          element.title     = title;
        }
      }
    }
  }
}


/**
 *  Funkce provadena po nacteni HP stranky
 */
function onload_page_hp( country )
{
  if ( document.getElementById('kalendar_left') )
  {
    var cal = new Calendar('kalendar_left', country);

    cal.create();
    write_calendar_date();
  }
  
}
      
      
/**
 *  Funkce se vola po nacteni stranky - nastavi spravne vysku u DIVu
 */
function page_init()
{

  var content_in            = document.getElementById( 'content_in' );
  var content_left          = document.getElementById( 'content_left' );
  var content_right         = document.getElementById( 'content_right' );
  
  var content_in_height     = 0;
  var content_left_height   = 0;
  var content_right_height  = 0;
  
  var flash_div             = document.getElementById( 'naborova_kampan' );
  
  if ( content_in )
    content_in_height     = content_in.offsetHeight;
    
  if ( content_left )
    content_left_height   = content_left.offsetHeight;
    
  if ( content_right )    
    content_right_height  = content_right.offsetHeight;

  
  var left_boxes            = getElementsByClass( 'left_box',  'div' );
  var right_boxes           = getElementsByClass( 'right_box', 'div' );
    
  /**
   *  Ted nastavime aby se stranka roztahla na celou vysku monitoru pokud bude prilis kratka
   */
  var content_middle_in     = document.getElementById( 'content_middle_in' );
  var content               = document.getElementById( 'content' );
  var content_height        = content.offsetHeight;
  var winHeightPx           = winHeight();

  if ( flash_div )
  {
    content_in_height     -= 242;
    content_left_height   -= 242;
    content_right_height  -= 242;

  }
  
  
  var contentMinHeight      = winHeightPx - ( 102 + 2 /* top */ + 30 + 2 /* menu */ + 19 /* footer */ + 80 /* footer2*/ );
    
  if ( content_height<contentMinHeight )
  {
    content.style.height      = contentMinHeight + 'px';
    content_in.style.height   = (contentMinHeight-4) + 'px';

    content_in_height         = content_in.offsetHeight;
  }
  
  
  if ( content_middle_in )
    content_middle_in.style.height = (content_in_height-10)+'px';
    
  
  //alert(content_in_height + ' - ' + content_left_height);
  // natahneme LEVY sloupecek
  
      
  if ( content_in_height>content_left_height )
  {
    var new_height  = content_left_height = content_in_height;
    
    
    content_left.style.height = new_height + 'px';
  }

  // v levem sloupecku natahneme nakonec posledni boxik
  if ( left_boxes.length )
  {
    var i;
    var height_all      = 0;
    var last_left_box   = false;
    
    var border_height   = 0;

    for ( i=0; i<left_boxes.length; i++ ) {
      if ( left_boxes[i] ) {
        height_all    += left_boxes[i].offsetHeight;
        border_height += 2;
        
        if ( i==left_boxes.length-1 )
          last_left_box = left_boxes[i];
      }
    }


    // vypocitame o kolik musime natahnout posledni box aby se sloupecek protahl az dolu
    if ( last_left_box ) {
      if ( height_all<=content_in_height )
      {
        var new_height              = last_left_box.offsetHeight + (content_in_height-height_all-border_height)+2;
      
    
        last_left_box.style.height  = new_height + 'px';
        last_left_box.style.marginBottom = '0px';
      }
      else
      {
        content_in_height       = height_all+1;
        content_in.style.height = content_in_height + 'px';
      }
    }
  }
  
  
  // natahneme PRAVY sloupecek
  if ( content_in_height>content_right_height )
  {
    var new_height = content_right_height = content_in_height;
    content_right.style.height = (new_height) + 'px';
  }

  // v levem sloupecku natahneme nakonec posledni boxik
  if ( right_boxes.length )
  {
    var i;
    var height_all     = 0;
    var last_right_box = false;

    var border_height  = 0;

    for ( i=0; i<right_boxes.length; i++ ) {
      if ( right_boxes[i] ) {
        height_all    += right_boxes[i].offsetHeight;
        border_height += 4;
        
        if ( i==right_boxes.length-1 )
          last_right_box = right_boxes[i];
      }
    }

    // vypocitame o kolik musime natahnout posledni box aby se sloupecek protahl az dolu
    if ( last_right_box ) {
      if ( height_all<content_in_height )
      {
        var new_height               = last_right_box.offsetHeight + (content_in_height-height_all-border_height)-4;
        last_right_box.style.height  = new_height + 'px';
        last_right_box.style.marginBottom = '0px';
      }
      else
      {
        content_in.style.height = content_in_height = (height_all+1) + 'px';
      }
    }
  }
  
  
}




/**
 *  Funkce zapise aktualni den do boxiku s kalendarem
 */
function write_calendar_date()
{
  var div = document.getElementById( 'calenar_actual_date' );

  if ( !div )
    return false;

  var datum     = new Date();
  var month     = datum.getMonth();
  var dayW      = datum.getDay();
  var dayM      = datum.getDate();

  var datum_txt = days[dayW] + ', ' + months[month] + ' ' + dayM;

  div.innerHTML = datum_txt;
  
  window.setTimeout( 'write_calendar_date();', 1000 );
}


function checkHelpdeskForm(frm)
{
  if ( !frm )
    return false;
    
  if ( frm.name.value.length<=0 ) {
    alert( 'All fields are required to be filled in' );
    return false;
  }
  else
  if ( frm.email.value.length<=0 ) {
    alert( 'All fields are required to be filled in' );
    return false;
  }
  else
  if ( frm.message.value.length<=0 ) {
    alert( 'All fields are required to be filled in' );
    return false;
  }
  
  return true;
}
