//--------------------------------------------//
//- Funkce nahrazuje alert (vyzaduje jQuery) -//
//--------------------------------------------//
function todo(str) {
  x = Math.round(Math.random()*10000);
  $("body").append("<div class=\"todo\" id=\"todo" + x + "\"><br/>" + str + "<br/><br/></div>");
  $("#todo" + x).slideDown(300, function() {
    $("#todo" + x).wait(4000);
    $("#todo" + x).slideUp(300, function() {
      $("#todo" + x).remove();
    });
  });
}
//--------------------------------------------//

//---------------------------------------//
//- Prepinani panelu produkty / vyrobci -//
//---------------------------------------//
//- Vyuziti cookies pro zapamatovani zvolene zalozky i na dalsich strankach webu
function tabsLoad() {
    // tato zakomentovana cast nefunguje pri EnableSEO=true
//  var tab = $.cookie('tab');
//  if (tab != null) {
//    $("#tab" + tab + " a").addClass("selected");
//    $("#ul" + tab).fadeIn("normal");
//  }
//  else {
//    $("#tabProducts a").addClass("selected");
//    $("#ulProducts").fadeIn("normal");
//  }
    $("#tabs").fadeIn();
    $("ul.selected").fadeIn();
  //- Fukce pro prepinani panelu
    $("#tabs li a").click(function() {
        $("#tabs li a").removeClass("selected");
        $(this).addClass("selected");
        var id = $(this).parent().attr("id").substr(3);
        $("#ulProducts").hide();
        $("#ulProducers").hide();
        $("#ul" + id).show();
        //$.cookie('tab', id);
        var rnd = Math.floor(Math.random() * 1000000);
        $.ajax({
            url: "savePanel.aspx?tabid=" + id + "&rand=" + rnd,
            cache: false,
            data: {},
            beforeSend: function() {
            },
            success: function(obj) {
            }
        });
        return false;
    });

  $(".s0click").click(function() {
    var id = $(this).attr("id").substring(2);
    $("#Category" + id).toggle();
    $.cookie('s0' + id, $("#Category" + id).css("display"));
  });

  $(".s0click").each(function() {
    var id = $(this).attr("id").substring(2);
    if ($.cookie('s0' + id) == 'block') $("#Category" + id).show();
    else $("#Category" + id).hide();
  });
  
  // funkce v hlavicce / print - katalog (todo: katalog)
  //$(".pagePrint").click(function() { return !window.open(this.href, "print" ,"width=530, height=750, resizable=no, status=no"); });
}
//---------------------------------------//

//----------------------------------------//
//- Simulace udalosti focus a blur pro   -//
//- prvky formulare - reseni nefunkcnich -//
//- selektoru CSS v IE                   -//
//----------------------------------------//
//- Ciste graficka fukce - neni nezbytne nutne
function formControl() {
  // upravi sirku textboxu u Opery a IE
  if (typeof(BrowserDetect) != "undefined") if (BrowserDetect.browser == 'Opera' || BrowserDetect.browser == 'Explorer') { $("textarea").each(function() { $(this).css("width", (parseInt($(this).css("width")) - 2) + "px"); }); }
  
  $(".fieldset input").focus(function() { $(this).parent().parent().addClass('fieldsetover'); });
  $(".fieldset input").blur(function() { $(this).parent().parent().removeClass('fieldsetover'); });
  $(".fieldset select").focus(function() { $(this).parent().parent().addClass('fieldsetover'); });
  $(".fieldset select").blur(function() { $(this).parent().parent().removeClass('fieldsetover'); });
  $(".fieldset textarea").focus(function() { $(this).parent().parent().addClass('fieldsetover'); });
  $(".fieldset textarea").blur(function() { $(this).parent().parent().removeClass('fieldsetover'); });
  // resi nedostatek ms xslt procesoru a text v poli typu textarea oreze pocatecni i konecne mezery
  $(".fieldset textarea").each(function() { $(this).html($(this).html().replace(/^\s\s*/, '').replace(/\s\s*$/, '')); });
}
//----------------------------------------//

//----------------------------------------//
//- Simulace udalosti hover pro          -//
//- bunky tabulek - reseni nefunkcnich   -//
//- selektoru CSS v IE                   -//
//----------------------------------------//
//- Ciste graficka fukce - neni nezbytne nutne
function tableControl() {
  $("table.common th.sort").mouseover(function() { $(this).addClass('over'); });
  $("table.common th.sort").mouseout(function() { $(this).removeClass('over'); });
  $("table.common th.sort").click(function() {
    $(this).find("a").get(0).click();
  });
}
//----------------------------------------//

$.fn.opacity = function(amount) {
  if (amount > 1) amount = 1;
  if (amount < 0) amount = 0;
  if ($.browser.msie) {
    amount = (parseFloat(amount) * 100);
    this.css('filter', 'alpha(opacity='+amount+')');
  } else {
    this.css('opacity', amount);
    this.css('-moz-opacity', amount);
  }
  return this;
}

function getPosition(e) {
  e = e || window.event;
  var cursor = {x:0, y:0};
  if (e.pageX || e.pageY) {
    cursor.x = e.pageX;
    cursor.y = e.pageY;
  }
  else {
    cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
    cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
  }
  return cursor;
}

function enterPressed(e) {
  var e = e || window.event;
	if (e.keyCode == 13) return true;
	else return false;
}

function FillBasket()
{

$.post("JqueryPages/AjBasketPanel.aspx",           
            function(obj)
               {
               $("#lista").html("&#160;");
               $("#lista").html(obj);
               }
               );
}

function ProductAddedToCart() {
  $("#msgAddedToCart").slideDown(300, function() {
    $(this).wait(4000);
    $(this).slideUp(300);
  });
}

function ProductAddedToFavorite() {
  $("#msgAddedToFavorite").slideDown(300, function() {
    $(this).wait(4000);
    $(this).slideUp(300);
  });
}

function checkDateEU(value) {
  if(value == "") return false;
  var dtArr = value.split(".");
  if(dtArr.length != 3) return false;
  var dx = new Date(dtArr[2], dtArr[1]-1, dtArr[0]);
  if(dx.getDate() != dtArr[0]) return false;
  if(dx.getMonth()+1 != dtArr[1]) return false;
  return true;
}

function startWait() {
  div = jQuery("<div>").attr("id", "waitBlock").css("width", $(window).width()).css("height", $(window).height());
  $("body").append(div);
}

function stopWait() {
  $("#waitBlock").remove();
}
