// detekuje browser
function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  //this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    //this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    //this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    //this.version = 6.1;
    return;
  }
  s = "Firefox";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    return;
  }
  s = "Opera"
  if ((i = ua.indexOf(s)) >= 0){
    this.isIE = true;
    return;
  }
}

var browser = new Browser();

function preventSecondSubmit() {
  submitCount++;
  // alert("submitCount = " + submitCount);
  if (submitCount < 2) return true;
  alert("Požadovná akce již byla zadána.");
  submitCount = 0;
  return false;
}

function onLoadMessage(msg) {
  alert(msg);
}

function inpToNumber(inpVal) {
 if (inpVal == null || inpVal.length <= 0) return 0;
 //alert(inpVal);
 
 re = /[\u00a0\s]/;
 val = inpVal.replace(re ,'').replace(re ,'').replace(re ,'').replace(re ,'').replace(',','.');
 //alert(val);
 
 num = new Number(val);
 if (isNaN(num)) {
  return 0;
 }
 return num.valueOf();
}

function roundNum(num, precision) {
 if (num == null || num.length <= 0) return num;
 cin = 1;
 for (i = 0; i < precision; i++) { cin = cin * 10; }
 num = num * cin;
 num = Math.round(num);
 num = num / cin;
 return num;
}

function setFocus(){
	var bFound = false;

  // for each form
  for (f=0; f < document.forms.length; f++)
  {
    // for each element in each form
    for(i=0; i < document.forms[f].length; i++)
    {
      // if it's not a hidden element
      if (document.forms[f][i].type != "hidden")
      {
        // and it's not disabled
        if (document.forms[f][i].disabled != true)
        {
            // set the focus to it
            document.forms[f][i].focus();
            var bFound = true;
        }
      }
      // if found in this element, stop looking
      if (bFound == true)
        break;
    }
    // if found in this form, stop looking
    if (bFound == true)
      break;
  }
}

String.prototype.reverse = function() {
    r = '';
    for (var i = this.length-1; i >= 0; i--)
      r += this.charAt(i);
    return r;
}

Number.prototype.toCurrency = function()
{
var s = parseInt(this).toString().reverse(), r = '';
for (var i = 0; i < s.length; i++)
r += (i > 0 && i % 3 == 0 ? ' ' : '') + s.charAt(i);

return r.reverse();
}
String.prototype.toInt = function() {
        return parseInt(this.replace(/\s+/g,''));
}