  /*
  * Funkcia na odpocitavanie po sekundach
  *  - pouzitie pri loade obrazovky
  *  source - id hiddenu s nastavenymi pociatocnymi sekundami
  *  target - id spanu kde sa sekundy vypisuju vo formate hodina:minuta:sekunda  
  */
  
  function runSeconds(source, target, message) {

    seconds_left = parseInt(document.getElementById(source).value);

    //seconds_left = parseInt(0.25 * seconds_left);
    
    hours = parseInt(seconds_left/3600);
    
    if (hours < 0) {
      hours = 0;
    }
    if (hours < 10) {
      hours = '0' + hours;
    }
    
    pom = seconds_left%3600;
    
    minutes = parseInt(pom/60);
    if (minutes < 0) {
      minutes = 0;
    }
    if (minutes < 10) {
      minutes = '0' + minutes;
    }
    
    seconds = pom%60;
    if (seconds < 0) {
      seconds = 0;
    }
    if (seconds < 10) {
      seconds = '0' + seconds;
    }
    
    document.getElementById(target).innerHTML = hours + ":" + minutes + ":" + seconds;
    document.getElementById(source).value = parseInt(document.getElementById(source).value) - 1;

    if (document.getElementById(source).value > 0) {
      timerID = setTimeout("runSeconds('" + source + "', '" + target + "', '" + message + "')", 1000);
    } else {
      document.getElementById(target).innerHTML = message;
    }
    
  
  }

  /*
  * Funkcia na odpocitavanie po sekundach
  *  - pouzitie pri loade obrazovky
  *  source - id hiddenu s nastavenymi pociatocnymi sekundami
  *  target - id spanu kde sa sekundy vypisuju vo formate hodina:minuta:sekunda  
  */
  
  function runTimeSeconds(source, target) {

    hours = parseInt(document.getElementById(source).value/3600);
    if (hours < 10) {
      hours = '0' + hours;
    }
    
    pom = document.getElementById(source).value%3600;
    
    minutes = parseInt(pom/60);
    if (minutes < 10) {
      minutes = '0' + minutes;
    }
    
    seconds = pom%60;
    if (seconds < 10) {
      seconds = '0' + seconds;
    }
    
    document.getElementById(target).innerHTML = hours + ":" + minutes + ":" + seconds;
    document.getElementById(source).value = parseInt(document.getElementById(source).value) + 1;
    if (document.getElementById(source).value >= (24*60*60)) {
      document.getElementById(source).value = document.getElementById(source).value - (24*60*60);
    }
    
    timerID = setTimeout("runTimeSeconds('" + source + "', '" + target + "')", 1000);
  
  }

  /*
  * Funkcia na zmenu obrazka v IMG tagu
  *  - pouzitie pri onMouseover a onMouseout
  */
  
  function changeImg(file, obj) {

    obj.src = file;
  
  }  
  
  
function addText(insert, textAreaId){

	//Get the textarea
	area = document.getElementById(textAreaId);
 
	//Get the selection bounds
	var start = area.selectionStart;
	var end = area.selectionEnd;
 
	//Break up the text by selection
	var text = area.value;
	var pre = text.substring(0, start);
	var sel = text.substring(start, end);
	var post = text.substring(end);
 
	//Insert the text at the beginning of the selection
	text = pre + insert + sel + post;
 
	//Put the text in the textarea
	area.value = text;
 
	//Re-establish the selection, adjusted for the added characters.
	area.selectionStart = start+insert.length;
	area.selectionEnd = end+insert.length;
}  


function countTextareaLines(obj) {
    var hard_lines = 0;
    var soft_lines = 0;
    var last = -1;
    while ( true ) {
        last_before = last;
        last = obj.value.indexOf("\n", last+1);
        if (last == (last_before + 1) || (last_before + 1) == obj.value.length) {
          hard_lines ++;
        } else {
          if (last > 0) {
            soft_lines = soft_lines + Math.ceil(obj.value.substring(last_before, last).length / (obj.cols-1));
          } else {
            soft_lines = soft_lines + Math.ceil(obj.value.substring(last_before).length / (obj.cols-1));
          }
        }
        if ( last == -1 ) break;
    }
    return soft_lines + hard_lines;
}
function resizeTextarea(obj, numberlines) {
    num = countTextareaLines(obj) + 1;
    if (num > numberlines) {
      obj.rows = num;
    } else {
      obj.rows = numberlines;
    }
}

