﻿//2010 cats scripts
function groupOpen(num) {
  $('#group' + num + '_databox').toggle();
  if ($('#group' + num).attr('class') == 'groupOpen') $('#group' + num).attr('class', 'groupClose');
  else $('#group' + num).attr('class', 'groupOpen');
}
function e_actcmds(ctr, id, name) {
  actcmds(ctr, name);
  if ($('#' + id).length != 0) {
    var nvid = $('#' + id).attr('checked');
    $('#' + id).attr('checked', !nvid);
  }
}
function actcmds(ctr, name) {
  var sres = ctr.value.split(".");
  var cdata = $("#" + hf_cats_pars).val().split("_");
  var cdata_i = -1;
  var cdata_s = '';
  var cdata_a;
  for (i = 0; i < cdata.length; i++) {
    if (cdata[i] == '')
      continue;
    var tmp = cdata[i].split(".");
    if (tmp[0] == sres[0]) {
      cdata_i = i;
      cdata_s = cdata[i];
      cdata_a = tmp;
      break;
    }
  }
  var cval = "_" + ctr.value + "_";
  if (ctr.checked) {
    if (cdata_i == -1) { //ak taky parameter zatial neexistoval
      $("#" + hf_cats_pars).val($("#" + hf_cats_pars).val() + '_' + ctr.value + '_');
    }
    else { //ak taky parameter s nejakymi hodnotami uz existuje
      var sresnew = ctr.value;
      var newparv = sres[0] + '.';
      for (i = 1; i < cdata_a.length; i++) {
        if (cdata_a[i] != sres[1])
          sresnew += '.' + cdata_a[i];
      }
      $("#" + hf_cats_pars).val($("#" + hf_cats_pars).val().replace('_' + cdata_s + '_', '_' + sresnew + '_'));
    }
  }
  else {
    if (cdata_i == -1) { //ak taky parameter zatial neexistoval
      return;
    }
    else { //ak taky parameter s nejakymi hodnotami uz existuje
      var sresnew = '';
      var newparv = '';
      for (i = 1; i < cdata_a.length; i++) {
        if (cdata_a[i] != sres[1])
          sresnew += '.' + cdata_a[i];
      }
      if (sresnew != '')
        sresnew = '_' + sres[0] + sresnew + '_';
      $("#" + hf_cats_pars).val($("#" + hf_cats_pars).val().replace('_' + cdata_s + '_', sresnew));
    }
  }
  var sd = $("#group" + name + "_sd").html();
  $("#group" + name + "_al").css('visibility', 'visible');
  PageMethods.ActCounts(aspx_c, aspx_r, actnq(), name, sd, ActCounts_OnSucceeded);
}
function act_ldi(ctr, name) {
  var chmin = 99999999;
  var chmax = -1;
  $("#group" + name + "_cont input[type=checkbox]:checked").each(function() {
    var sres = this.value.split(".");
    if (parseInt(sres[0]) < chmin)
      chmin = sres[0];
    if (parseInt(sres[1]) > chmax)
      chmax = sres[1];
  });
  if (chmin == 99999999 || chmin == 0)
    $("#group" + name + "_from").val('');
  else
    $("#group" + name + "_from").val(chmin);
  if (chmax == -1 || chmax == 99999999)
    $("#group" + name + "_to").val('');
  else
    $("#group" + name + "_to").val(chmax);
  $("#group" + name + "_al").css('visibility', 'visible');
  PageMethods.ActCounts(aspx_c, aspx_r, actnq(), name, '', ActCounts_OnSucceeded);
}
function ActCounts_OnSucceeded(res) {
  var result = eval('(' + res + ')');
  for (i = 0; i < result.names.length; i++) {
    $("#group" + result.names[i] + "_cont").html(result.content[i]);
    if (result.sd[i] != '')
      $("#group" + result.names[i] + "_sd").html(result.sd[i]);
  }
  $("#" + hf_records_count).html(result.count);
}
function isNumber(x) {
  return ((typeof x === typeof 1) && (null !== x) && isFinite(x));
}
function actlocate() {
  var nq = actnq();
  if (nq != '')
    nq = 'f=' + nq;
  location.href = cat_base_path + (nq != '' ? (cat_base_path.indexOf('?') == -1 ? '?' : (nq == '' ? '' : '&')) + nq : '');
}
function actnq() {
  var nq = '';
  for (var i = 0; i < f_types.length; i++) {
    if (f_types[i] == 'se') {
      if ($("#group" + f_names[i] + "_search").val() != '')
        nq += '_' + f_abbrs[i] + ':' + encodeURI(diaConvert($("#group" + f_names[i] + "_search").val())) + '_';
    }
    else if (f_types[i] == 'ldi') {
      if ($("#group" + f_names[i] + "_from").val() != '' || $("#group" + f_names[i] + "_to").val() != '')
        nq += '_' + f_abbrs[i] + ':' + encodeURI($("#group" + f_names[i] + "_from").val()) + ':' + encodeURI($("#group" + f_names[i] + "_to").val()) + '_';
    }
  }
  nq += $("#" + hf_cats_pars).val();
  return nq;
}
//GetMoreData
function Show_qp_morepars_P_MPE() {
  var modal = $find(mw_morepars_id);
  if (modal) {
    modal.show();
  }
}
function Hide_qp_morepars_MPE() {
  var modal = $find(mw_morepars_id);
  modal.hide();
}
function Do_qp_morepars_MPE() {
  alert('done aaa');
  Hide_qp_morepars_MPE();
}
function GetMorePars(name) {
  PageMethods.GetMorePars(aspx_c, aspx_r, name, 'all', actnq(), GetMorePars_OnSucceeded);
}
function GetMorePars_OnSucceeded(res) {
  $("#qp_morepars").html(res);
  Show_qp_morepars_P_MPE();
}
function GetMoreParsSort(name, sort) {
  PageMethods.GetMorePars(aspx_c, aspx_r, name, sort, actnq(), GetMoreParsSort_OnSucceeded);
}
function GetMoreParsSort_OnSucceeded(res) {
  $("#qp_morepars").html(res);
}
//2010 pd scripts
//varianty
function chgF(id, s, wstd_id, windowId) {
  var ctr = "box" + id + "s";
  if ($("#ctl00_mp_p_gvp_box" + id + "a").is(':visible')) {    
    $("#ctl00_mp_p_gvp_box" + id + "a").hide();
  }
  else {
    $("#ctl00_mp_p_gvp_box" + id + "a").show();
  }
}
//getWidgets
function getWidgets(pid, cid) {
  Search.GetWidgets(pid, cid, GetWidgets_OnSucceeded);
}
function GetWidgets_OnSucceeded(res) {
  var result = eval('(' + res + ')');
  $("#widgets").toggle();
  $("#widgets").html(result.ret.replace(/¤/g, '"'));
}
function chgD() {
  var ctr = "distpanel";
  $("#distpanel").toggle();
  $("#ctl00_mp_p_txtCity").focus();
}

//set price alert
function Show_qp_pc_P_MPE(product, price, set_alert) {
  var modal = $find(mw_pricealert_id);
  if (modal) {
    modal.show();
    $("#qp_pc_mpe_email").focus();
    $("#qp_pc_opt3_pid").val(product);
    $("#qp_pc_opt3_priceX").val(price);
    $("#qp_pc_opt3_priceX1").val(price);
    if(set_alert == 1)
      $("#qp_pc_opt5").attr('checked', true);
    else
      $("#qp_pc_opt5").attr('checked', false);
  }
}
function Hide_qp_pc_MPE() {
  var modal = $find(mw_pricealert_id);
  modal.hide();
}
function Do_qp_pc_MPE() {
  var pid = $("#qp_pc_opt3_pid").val();
  var me = $("#qp_pc_mpe_email").val();
  var opt = $("input[name='qp_pc_opt5']").attr('checked');
  var price = $("#qp_pc_opt3_priceX").val();
  var price_current = $("#qp_pc_opt3_priceX1").val();
  if ((!me || me.indexOf('@') == -1 || !price || !price_current || !opt) && opt) {
    alert('Najprv je nutné vyplniť všetky povinné polia (označené hviezdičkou)!');
    return true;
  }
  Hide_qp_pc_MPE();
  PageMethods.Set_price_alert(pid, me, opt, price, price_current, PA_OnSucceeded, PA_OnFailed);
}
function PA_OnSucceeded(res) {
  Hide_qp_pc_MPE();
  alert('Produkt bol uložený do Vášho zoznamu prianí.');
  
  var result = eval('(' + res + ')');
  if (result.userAdded == "1") {
    window.location.reload();
  }
  else {
    cDAP();
  }  
}
//Show price alert dimer
function PA_OnFailed(error) {
  alert(error.get_message());
}

function Show_dimmer1_P_MPE(email, page, product) {
  var modal = $find('ctl00_mp_dimmer1_P_MPE');
  if (modal) {
    modal.show();
  }
}
function Hide_dimmer1_P_MPE() {
  var modal = $find('ctl00_mp_dimmer1_P_MPE');
  modal.hide();
}
//pd_ponuky send mail to shop scripts
function Show_qvp_MPE(windowId, email, page, product) {
  last_email = email;
  last_mpe_page = page;
  last_product = product;
  last_windowId = windowId;
  document.getElementById('mpe_propict').src = document.getElementById('ctl00_mp_img2s').innerHTML;
  document.getElementById('mpe_name').innerHTML = last_product;
  document.getElementById('mpe_emailw').innerHTML = last_email;
  document.getElementById('mpe_main').style.display = "";
  var modal = $find(windowId);
  if (modal) modal.show();
}
function Hide_qvp_MPE() {
  var modal = $find(last_windowId);
  modal.hide();
}
function Do_MPE() {
  var me = document.getElementById('mpe_email');
  var mc = document.getElementById('mpe_meno');
  var mt = document.getElementById('mpe_tel');
  var te = document.getElementById('mpe_text');
  if (!me.value || me.value.indexOf('@') == -1 || !te.value) {
    alert('Pred odoslaním je nutné vyplniť všetky povinné polia (označené hviezdičkou)!');
    return false;
  }
  document.getElementById('mpe_page1').style.display = "none";
  document.getElementById('mpe_page2').style.display = "";
  SendEmail(me.value, last_email, 'najnakup.sk | otázka na ' + last_product,
            "email: " + me.value + "\r\nmeno: " + mc.value + "\r\ntelefon: " + mt.value + "\r\n\r\n" + te.value);
  $(".mod_foo_button").toggle();
  setTimeout('Do_MPE1()', 6000);
}
function Do_MPE1() {
  Hide_qvp_MPE();
  window.open(last_mpe_page);
}
//pd_ponuky show info about shop
function Show_qpi_MPE(s, windowId) {
  last_windowId = windowId;
  Search.ShopDetails(-1, s, windowId, Show_qpi_MPE_OnSucceeded);
}
function Show_qpi_MPE_OnSucceeded(res) {
  var modal = $find(last_windowId);
  if (modal) {
    var result = eval('(' + res + ')');
    $('#qpi_content').html(result.ret.replace(/¤/g, '"'));
    modal.show();
  }
}
function Hide_qpi_MPE() {
  var modal = $find(last_windowId);
  modal.hide();
}

