/* Trida
* Informace o velikosti a scrollbarech hlavniho okna window
* return: this.width - sirka clientske casti okna
* this.height - vyska clientske casti okna
* this.scrollLeft - x offset scrollbaru (o kolik je horizontalni scroll posunuty)
* this.scrollTop - y offset scrollbaru (o kolik je verticalni scroll posunuty) */
//  var winInfo = new WindowInfo();
//alert(winInfo.scrollOffsetLeft);
//alert(winInfo.scrollOffsetTop);
function WindowInfo() {
if (BrowserType().ie) {
this.scrollOffsetLeft = document.body.scrollLeft;
this.scrollOffsetTop = document.body.scrollTop;
this.width = document.body.clientWidth;
this.height = document.body.clientHeight;
} else {
this.scrollOffsetLeft = window.pageXOffset;
this.scrollOffsetTop = window.pageYOffset;
this.width = window.innerWidth;
this.height = window.innerHeight;
}
return this;
}
/* Trida
* zjisti rodinu a verzi prohlizece na strane clienta
* return: ... viz kod tridy ;-) */
function BrowserType(){
this.ie4 = (document.all && !window.opera && !document.fireEvent && !document.createComment) ? true : false;
this.ie50 = (document.all && !document.fireEvent && !window.opera) ? true : false;
this.ie55 = (document.all && document.fireEvent && !document.createComment) ? true : false;
this.ie6 = (document.all && document.fireEvent && document.createComment) ? true : false;
this.ns6 = (!document.all && document.getElementById) ? true : false;
this.opera7 = (window.opera && document.createComment) ? true : false;
this.opera6 = (window.opera && !document.createComment) ? true : false;

this.ie = this.ie4 || this.ie50 || this.ie55 || this.ie6;
this.ns = this.ns6;
this.opera = this.opera7 || this.opera6;

// zkusebni alert s vypisem zjisteneho browseru
/* var test ="rodina IE:" + this.ie + " (ie4:" + this.ie4 + ", ie5.0:" + this.ie50 + ", ie5.5:" + this.ie55 + ", ie6:" + this.ie6 + ")\n";
test += "rodina Netscape:" + this.ns + " (ns6:" + this.ns6 + ")\n";
test += "rodina Opera:" + this.opera + " (opera6:" + this.opera6 + ", opera7:" + this.opera7 +")\n";
alert(test) */

return this;
}
// funkce vybere urcity pocet znaku z retezce bez opakovani
function RandomChars(length, chars){
  var charsArray= new Array();
  var step=0;
  var result='';
  for (var i=0;i<chars.length;i++){
  charsArray[step]=chars.slice(i,i+1);
  step++;
  }
  for (var i=0; i<length;i++){
    index = Math.floor(Math.random()*charsArray.length);
    result+=charsArray[index] ;
    charsArray.splice (index, 1);
  }
  return result;
}

// removes leading and trailing spaces from the string 
function trim(s){
  return s.replace(/(^\s+)|(\s+$)/g, "")
}
// zobrazi nebo skryje element
function toggleDisplay(elementId,display){
  var element = document.getElementById(elementId);
  try
  {
    if(display) element.style.display='block';
    else element.style.display='none';
  }
  catch(e) {}
}

// zmeni nastaveni trid u lichych radku na Un a u sudych radku na Ev
// vyzaduje globalni promennou, pro uchovani smazanych radku, ktere jsou
// pouze skrite
var FireRow=new Array();
function SetTableRowClass(TableId, FireId, Un, Ev){
  var SizeOf=FireRow.length;
  FireRow[SizeOf]=FireId; // pole uchovava informace o skritych smazanych radcich
  var length = document.getElementById(TableId).childNodes.length;
  var BackgroundColor = Un;
  for (i = 0; i < length; i++){
    var Fire = false;
    var tr = document.getElementById(TableId).childNodes[i];
    for(j=0;j<=SizeOf;j++){
      if(FireRow[j]==tr.id){
        Fire=true;
      }
    }
    if(Fire!=true){
      tr.className=BackgroundColor;
      if(BackgroundColor==Un) BackgroundColor=Ev;
      else BackgroundColor=Un;
    }
  }
}
// odstrani diakritiku
function stripDia(text){
  var sDia = "áäčďéěíĺľňóôöŕšťúůüýřžÁÄČĎÉĚÍĹĽŇÓÔÖŔŠŤÚŮÜÝŘŽ";
  var bDia = "aacdeeillnooorstuuuyrzAACDEEILLNOOORSTUUUYRZ";
  var newtext = '';
  for(j = 0; j < text.length; j++){
    if (sDia.indexOf(text.charAt(j)) != -1){
      newtext += bDia.charAt(sDia.indexOf(text.charAt(j)));
    }else newtext += text.charAt(j);
  }
  return newtext;
}
// urlname, prevede text pro pouziti jako urlname
function urlName(name){
  name=stripDia(name);  // odstrani diakritiky
  name=trim(name);  // odstrani mezery z kraje
  name=name.toLowerCase();  // prevede na male znaky
  name = name.replace(/[\W_]+/ig, "-"); // nahradi vsechny znaky krome a-z A-Z 0-9 za -
  return name;
}
// overi zda je cislo integer
function is_int(numero){
    return !isNaN(numero);
} 




// handles keydown to detect when enter is pressed
function handleKey(e) 
{
  // get the event
  e = (!e) ? window.event : e;
  // get the code of the character that has been pressed        
  code = (e.charCode) ? e.charCode :
         ((e.keyCode) ? e.keyCode :
         ((e.which) ? e.which : 0));
  // handle the keydown event       
  if (e.type == "keydown") 
  {
    // if enter (code 13) is pressed
    if(code == 13)
    {
      // send the current message  
      process("txtNewTask", "addNewTask");
    }
  }
}