/* $Id: base.js,v 1.1 2006-09-21 08:05:11 fiser Exp $ */
function setCookie(name,value,hours) {
  if (hours) {
    var date = new Date();
    date.setTime(date.getTime()+(hours*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}


function deleteCookie(name) {
  setCookie(name,"",-1);
}



function getElementsByClass(searchClass,node,tag) {
  var classElements = new Array();
  if ( node == null )
    node = document;
  if ( tag == null )
    tag = '*';
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
  for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}


function showHide(id){
  if (document.getElementById(id).style.display == 'none'){
    document.getElementById(id).style.display = 'block';
  }else{
    document.getElementById(id).style.display = 'none';
  }
}



/**
 * Vlozi do textarey obj na soucasnou pozici kursoru 
 * text.
*/
function insertText(obj,text){
  //IE support
  if (document.selection){
    obj.focus();
    sel = document.selection.createRange();
    sel.text = text;
  }
  //MOZILLA/NETSCAPE support
  else if (obj.selectionStart || obj.selectionStart == '0'){
    var startPos = obj.selectionStart;
    var endPos = obj.selectionEnd;
    obj.value = obj.value.substring(0, startPos) + text + obj.value.substring(endPos, obj.value.length);
  }else{
    obj.value += text;
  }
}

/**
 * Zaskrtne vsechny checkboxy ve formulari form
 */
function checkAll(form){
    var array = form.elements;
    for (var i=0;i<array.length;i++){
        if (array[i].type == "checkbox"){
            array[i].checked = 'checked';
        }
    }
}


/**
 * Odskrtne vsechny checkboxy ve formulari form
 */
function clearAll(form){
    var array = form.elements;
    for (var i=0;i<array.length;i++){
        if (array[i].type == "checkbox"){
            array[i].checked = false;
        }
    }
}


/* PRINTABLE/NON-PRINTABLE VERSION */
var printable_indicator = false;
var printable_backup;
function printable_getObsahValues(){
    var objs = getElementsByClass("obsah");
    return Array(objs[0].style.top,objs[0].style.left);
}
function printable_hideShow(classes,displayValue){
    var i,j,objs;
    for (i=0;i<classes.length;i++){
        objs = getElementsByClass(classes[i]);
        for (j=0;j<objs.length;j++){
            objs[j].style.display = displayValue;
        }
    }
}
function printable(){
    var hideShowClasses = Array("leve_menu","horni_menu","search_bar","seznam_horni_linka","submit","listing","to_be_displayed");
    var objs = getElementsByClass("obsah");

    if (printable_indicator == false){
        printable_backup = printable_getObsahValues();
        printable_hideShow(hideShowClasses,"none");
        objs[0].style.top = "10px";
        objs[0].style.left = "10px";
        
        printable_indicator = true;
    }else{
        objs[0].style.top = printable_backup[0];
        objs[0].style.left = printable_backup[1];
        printable_hideShow(hideShowClasses,"block");
        printable_indicator = false;
    }
}
/* PRINTABLE/NON-PRINTABLE VERSION END */

