document.write('<style type="text/css">.hide-from-js{display:none}</style>');

$(document).ready(function () {
  $('.hide-no-js').removeClass('hide-no-js');
})

// prevence proti stisku enteru u poctu zbozi do kosiku
$('input.count').live('keydown', function (e) {
  if (e.keyCode == 13) return false;
});

// image mover
$(document).ready(function() {
    $(".slider").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
        circular: false
    });
});


// pokud je filter vzbran, tak zekroljuji pod filtr
$(document).ready(function () {
  
  if ($('#JSfilterChoosen').length > 0)
  {
    myScrollToHref('JSfilterChoosen');
  }
});


function fc(sPhrase, iProductId) // fulltextClick - meri a uklada do databaze, kdyz nekdo pri hledani konkretni fraze na neco klikne
{
  var img = new Image();
      img.src = HTTP_PATH+'/fulltextClick.php?sPhrase='+sPhrase+'&iProductId='+iProductId;
}

/**
   * nStr: The number to be formatted, as a string or number. No validation is done, so don't input
   * a formatted number. If inD is something other than a period, then nStr must be passed in as a string.
   * outD: The decimal character for the output, such as ',' for the number 100,2
   * sep: The separator character for the output, such as ',' for the number 1,000.2
   */
  function numberFormat(nStr, outD, sep)
  {
    if (outD == null) outD = ',';
    if (sep == null) sep = ' ';
    nStr += '';
    var dpos;
    if (nStr.indexOf('.') != -1)
      dpos = nStr.indexOf('.');
    else
      dpos = nStr.indexOf(',');
    var nStrEnd = '';
    if (dpos != -1) {
      nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
      nStr = nStr.substring(0, dpos);
    }
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(nStr)) {
      nStr = nStr.replace(rgx, '$1' + sep + '$2');
    }
    return nStr + nStrEnd;
  }

function priceFormat(sPrice) {
  //iPrice = parseFloat(sPrice);
  //sPrice = Math.round(iPrice);
  if (typeof sPrice === 'undefined') return '';
  sPrice = sPrice.toString();
  sPrice = sPrice.replace("\.", ",");
  var rgx;
  re = /^([0-9]*),([0-9]*)$/;
  regs = sPrice.match(re);
  if (regs) {
    sHalere = regs[2];
    sKoruny = regs[1];
    if (sHalere.length == 1) sHalere += '0';
    if (sHalere.length > 2) sHalere = sHalere.substr(0,2);
    rgx = /(\d+)(\d{3})/;
    while (rgx.test(sKoruny)) {
      sKoruny = sKoruny.replace(rgx, '$1' + ' ' + '$2');
    }
    sPrice = sKoruny+','+sHalere;
  }
  else
  {
    rgx = /(\d+)(\d{3})/;
    while (rgx.test(sPrice)) {
      sPrice = sPrice.replace(rgx, '$1' + ' ' + '$2');
    }
    sPrice += ',-';
  }

  return sPrice;
}


function myScrollTo(elm)
{
  re = /.*Chrome.*/;
  var srcName; var target; var offset; var iTop;
  srcName = $(elm).attr('href');
  srcName = srcName.substring(1);
  
  target = $('#'+srcName+'');
  
  offset = $(target).offset();
  iTop = offset.top;

  if (navigator.userAgent.match(re))
  {
    location.href="#"+srcName;
    return false;
  }
  $('html,body').animate({scrollTop: iTop}, 1000);
  
  return true;
}

function myScrollToHref(srcName)
{
  re = /.*Chrome.*/;
  var target; var offset; var top;

  target = $('#'+srcName+'');
  //alert($(target).offset().top);

  offset = $(target).offset();
  top = offset.top;
  /*if (navigator.userAgent.match(re))
  {
    location.href="#"+srcName;
    return false;
  }*/


  $('html,body').animate({scrollTop: top}, 1000);
  return true;
}



// fill in captcha code
$(document).ready(function () {
  if ($('#captchaCode').length) {
    $.get(HTTP_PATH+'/inc/captcha/AJAX_captcha.php', function (data) {
      $('#captchaCode').val(data);
    });
  }
});

// fill in captcha code
/*$(document).ready(function () {
  if ($('#captchaCodeNew').length) {
    $.get(HTTP_PATH+'/inc/securImage/AJAX_captcha.php', function (data) {
      $('#captchaCodeNew').val(data);
    });
  }
});*/


// fancybox
$(document).ready(function () {
  $("#play-multimedia").fancybox({frameWidth:800, frameHeight:600});
});


// fotogalerie
$(document).ready(function() {
  $("a.fotogalery").fancybox({'overlayOpacity':0.7});  
});


function shopGoodsImgDetail(href) {
  return window.open(href,"shopGoodsImgDetail","scrollbars=yes,resizable=yes,height=330,width=350,left=10,top=10");
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function setCookie(cookieName, cookieValue, expires, path, domain, secure) {
  if (!expires) {
  	var dnes = new Date();
  	var expires = new Date(dnes.getTime() + 1000 * 60 * 60 * 24); // za 24 hodin
  }
	document.cookie =
		escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '; path=/')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
	//alert(document.cookie)
}
function getCookie(cookieName) {
	var cookieValue = '';
	var posName = document.cookie.indexOf(escape(cookieName) + '=');
	if (posName != -1) {
		var posValue = posName + (escape(cookieName) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);
		if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
		else cookieValue = unescape(document.cookie.substring(posValue));
	}
	return (cookieValue);
}



  window.onload = function(){
  if(document.all && navigator.appVersion.indexOf("MSIE")>-1 && navigator.appVersion.indexOf("Windows")>-1)
  {
    var a = document.getElementsByTagName("label");
    for(var i=0,j=a.length;i<j;i++){
      if(a[i].hasChildNodes && a[i].childNodes.item(0).tagName == "IMG")
      {
        a[i].childNodes.item(0).forid = a[i].htmlFor;
        a[i].childNodes.item(0).onclick = function(){
          var e = document.getElementById(this.forid);
          switch(e.type){
            case "radio": e.checked|=1;break;
            case "checkbox": e.checked=!e.checked;break;
            case "text": case "password": case "textarea": e.focus(); break;
          }
        }
      }
    }
  }
}
  

