// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var hash = "";
var section_id = 1;

function check_all_with_classname(classname) {
  process_all_with_classname(classname, true);
}

function uncheck_all_with_classname(classname) {
  process_all_with_classname(classname, false);
}

function process_all_with_classname(classname, checked) {
  elements = document.getElementsByClassName(classname);
  for (var i=0; i<elements.length; i++) {
    elements[i].checked = checked;
  }  
}

function show_indicator() {
  $('content').style.height = "auto";
  Element.show('indicator');
}

function hide_indicator() {
  Element.hide('indicator');
}

function ajaxComplete() {
    $$('a[href=/goscie]').each(function(el) {
        el.setAttribute("rel", "history");
        initLinks();
    });


  height = $('content').getDimensions().height;
  times = height / 144;
  times = Math.ceil(times);
  new_height = 144 * (times);
  var minus = 2;
  if(new_height<= 144) { 
    new_height = 144;
    times = 1;
  }
  $('content').style.height = (new_height-minus) +"px";
  $('content-middle-left').innerHTML = "";
  $('content-middle-right').innerHTML = "";
  for(var i=0;i<times;i++) {
      $('content-middle-left').innerHTML += '<div class="left-background"></div>';
      $('content-middle-right').innerHTML += '<div class="right-background"></div>';
  }
  
  //$('content').setHeight(height);
  
  
  hide_indicator();
}

function historyLinkedClicked() {
  $('content-middle-left').innerHTML = '<div class="left-background"></div>';
  $('content-middle-right').innerHTML = '<div class="right-background"></div>';
  $('content').style.height = "142px";
  
}

	function swap_img(id,ac) {
		var ha = (ac == 0) ? '':'h';
		document.getElementById('link_img_'+id).src='/images/layout/top_link_'+id+ha+'.gif';
	}

  function get_folder_name() {
    return "new_folder=" + window.prompt('Podaj nazwę dla nowego folderu');
  }

  function change_active(id) {
    var actives = $$('#menu .active');
    actives.each(function(item) {
      Element.removeClassName(item, 'active');
    });
    if(id != "")
      Element.addClassName(id, 'active');
  }

  function remove_flash() {
    if($('headerFlash')) {
      $('headerFlash').hide();
    }
    return true;
  }

  // TODO remove_actives
  
  
function clearOnInitialFocus ( fieldName ) {
  var clearedOnce = false;
  document.getElementById( fieldName ).onfocus = (function () {
    if (clearedOnce == false) {
      this.value = '';
      clearedOnce = true;
    }
  })
}

function submit_on_key_press(fieldName) {
  document.getElementById(fieldName).setAttribute('onsubmit', $('submit_form').getAttribute('onclick'));
}

function check_form() {
  if($('contact_mail').value == '') {
    alert('Należy wypełnić wszystkie pola.');
    return false; 
  }
  return true;
}

