

/*Array.prototype.has=function(v){
for (i in this){
if (this[i]==v) return i;
}
return false;
}
*/

function isInteger(s) {
  return (s.toString().search(/^-?[0-9]+$/) == 0);
}

function in_array(val, array)
  {
    for (i in array){
      if (this[i]==val) return val;
      }
    return false;
  }

function fmod (x, y) {
    // http://kevin.vanzonneveld.net
    // +   original by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: fmod(5.7, 1.3);
    // *     returns 1: 0.5
    
    var tmp, tmp2, p = 0, pY = 0, l = 0.0, l2 = 0.0;
    
    tmp = x.toExponential().match(/^.\.?(.*)e(.+)$/);
    p = parseInt(tmp[2], 10)-(tmp[1]+'').length;
    tmp = y.toExponential().match(/^.\.?(.*)e(.+)$/);
    pY = parseInt(tmp[2], 10)-(tmp[1]+'').length;
    
    if (pY > p) {
        p = pY;
    }
    
    tmp2 = (x%y);
    
    if (p < -100 || p > 20) {
        // toFixed will give an out of bound error so we fix it like this:
        l  = Math.round(Math.log(tmp2)/Math.log(10));
        l2 = Math.pow(10, l);
        
        return (tmp2 / l2).toFixed(l-p)*l2;
    } else {
        return parseFloat(tmp2.toFixed(-p));
    }
}

function getImgSize(imgSrc)
{
var newImg = new Image();
newImg.src = imgSrc;
//var height = newImg.height;
//var width = newImg.width;
imgSize = new Array(newImg.width, newImg.height);
return imgSize;
}

function removePx(string)
  {
    return string.replace("px", "");
  }

$.maxZIndex = $.fn.maxZIndex = function(opt) {
    /// <summary>
    /// Returns the max zOrder in the document (no parameter)
    /// Sets max zOrder by passing a non-zero number
    /// which gets added to the highest zOrder.
    /// </summary>    
    /// <param name="opt" type="object">
    /// inc: increment value, 
    /// group: selector for zIndex elements to find max for
    /// </param>
    /// <returns type="jQuery" />
    var def = { inc: 10, group: "*" };
    $.extend(def, opt);    
    var zmax = 0;
    $(def.group).each(function() {
        var cur = parseInt($(this).css('z-index'));
        zmax = cur > zmax ? cur : zmax;
    });
    if (!this.jquery)
        return zmax;

    return this.each(function() {
        zmax += def.inc;
        $(this).css("z-index", zmax);
    });
}


function findHighestZIndex(elem)
{
  var elems = document.getElementsByTagName(elem);
  var highest = 0;
  for (var i = 0; i < elems.length; i++)
  {
    var zindex=document.defaultView.getComputedStyle(elems[i],null).getPropertyValue("z-index");
    if ((zindex > highest) && (zindex != 'auto'))
    {
      highest = zindex;
    }
  }
  return highest;
}


function debugLog(text)
  {
    $("body").append('<li>' + text + '</li>');
  }

function o(id) {return document.getElementById(id);} //get element by ID

function modFilePath(path)
  {
    return path.substring(0,1) == "." ? path.substring(1) : path;
  }

function realFilePath(path)
  {
    return path.substring(0,1) == "/" ? "." + path : path;
  }

function FindKey(arr, key, value)
  {
    for(x in arr)
      {
        if(arr[x][key]==value){return x;}
      }
    return 'undefined';
  }

function arrayLength(array)
  {
    var count = 0; 
    for(x in array)
      {
        count++;
      }
    return count;
  }

function arrMaxVal(arr, key)
  {
    var max=0;
    for(x in arr)
      {
        if (arr[x][key] > max) {max = arr[x][key];}
      }
    return max;
  }

function strrpos (haystack, needle, offset) {
    var i = (haystack+'').lastIndexOf( needle, offset ); // returns -1
    return i >= 0 ? i : false;
}

function isNumeric(value) {
  if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
  return true;
}

String.prototype.trim = function()
  {
    return this.replace(/(^\s*)|(\s*$)/g, "");
  }

function isInt(x) { 
   var y=parseInt(x); 
   if (isNaN(y)) return false; 
   return x==y && x.toString()==y.toString(); 
 } 


function ShowHTML(element_id, html)
  {
    try{document.getElementById(element_id).innerHTML="";}
    catch(e){alert("Objekt s ID "+element_id+" nelze najít!");}
    $("#"+element_id).append(html);
  }
  
function DisplayHTML(element_id, html)
  {
    try{document.getElementById(element_id).innerHTML="";}
    catch(e){alert("Objekt s ID "+element_id+" nelze najít!");}
    $("#"+element_id).append(html);
  }
  
function AddHTML(element_id, html)
  {
   $("#"+element_id).append(html);
  }
 
 
function L(group, name)
  {
    try
      {
        return Label[group][name];
      }
    catch(e)
      {
      
      }
  } 
var Label = new Array();