var digits = "0123456789";
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 9;

function ge(id){
  return document.getElementById(id);
}

function isNull(a) {
    return typeof a == 'object' && !a;
}
function LTrim(str){
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

function RTrim(str){
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}	

function trim(str){
	return RTrim(LTrim(str));
}

function js_contain(the_needle, the_haystack){
    if(the_haystack == ''){
        return false;
    }
    var the_pattern = new RegExp(the_needle, 'g');
    var matched = the_pattern.test(the_haystack);
    return matched;
}

/* 29.11.2005 21:28:37 - Otevre obrazek podle parametru */
function openPic(pictureId,width,height){
  popupWin = window.open("/img.php?image_id="+pictureId,"window_"+pictureId,"width="+width+",height="+height+",resizable,scrollbars=no,status=0");
  if(window.moveTo) popupWin.moveTo(((screen.availWidth-width)/2),((screen.availHeight-height)/2) );
  if (window.focus) {popupWin.focus()}  
  return false;
}

function openParam(url){
  return opnWin(url,340,200);
}

function resizeWindow(win,w,h) {
 if (parseInt(navigator.appVersion)>3) {
   if (navigator.appName=="Netscape") {
    win.outerWidth=w;
    win.outerHeight=h;
   }
   else win.resizeTo(w,h);
 }
}

function sizeWindow(){
  var img = ge("foto");
  resizeWindow(self,img.width,img.height);
}

function opnImg(url){
  popupWin = window.open("/img.php?url="+url,"nahled","width=200,height=200,resizable,scrollbars=no,status=0");
  //if(window.moveTo) popupWin.moveTo(((screen.availWidth-width)/2),((screen.availHeight-height)/2) );
  //if (window.focus) {popupWin.focus()}  
  //return false;
}

function opnVylet(url){
  return opnWin(url,400,250);
}

function opnWin(url,width,height){
  popupWin = window.open(url,"_blank","width="+width+",height="+height+",resizable,scrollbars=yes,status=0");
  if(window.moveTo) popupWin.moveTo(((screen.availWidth-width)/2),((screen.availHeight-height)/2) );
  if (window.focus) {popupWin.focus()}  
  return false;
}

function tisk(){
  self.print();
}

function isEmail(str)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(str);
}

function isEmpty(str){
  var str = trim(str);
  return (str.length == 0);
}

function isPSC(str){
  var filter  = /^(\d{5})+$/;
	return filter.test(str);
}

function isRC(str){
  var filter  = /^(\d{10})+$/;
	return filter.test(str);
}

function isDatumNarozeni(str){
  var filter  = /^(\d{2}\.\d{2}.\d{4})+$/;
	return filter.test(str);
}

function focus(id){
  ge(id).focus();
}

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function isTel(id){
  s = stripCharsInBag(trim(ge(id).value),validWorldPhoneChars);
  return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}


function formatPrice(price)
{
	price += '';
	x = price.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ' ' + '$2');
	}
	return x1 + x2;
}

function chngStatus(status){
  
  if(status != ""){
    window.defaultStatus = "Zobraziť obrázok \""+status+"\"";
  }else{
    window.defaultStatus = "";
  } 
  return true;
}

function opnWindow(url) {
	window.open(url,"","");
}

$().ready(function(){
	$('#srchtopval').val(Math.ceil(100*Math.random()));

        $('#kvysl').val(parseInt($('#konta').val())+parseInt($('#kontb').val()));
        $('#kontrola').hide();
});
