var _mainCatID = 0;
var _mainCatName = '';
var _virtualName = '';
var _allProdFlag = false;

function initMainCatAuct(mainCatID, mainCatName, virtualName, aType, vType, pIndex) {
  _mainCatID = mainCatID;
  _mainCatName = mainCatName;
  _virtualName = virtualName;
  initPageHistory();
  initProdPageDetails(aType, vType, pIndex);
}

function getProductsList() {
  var params = 'mainCatID=' + _mainCatID + '&aType=' + _aType + '&vType=' + _vType + '&sBy=' + _sBy + '&pIndex=' + _pIndex;
  executeServerRequest('GetMainCatAuctions', params);
}

function getResponseMethodEx(methodName) {
  switch (methodName) {
    case 'GetMainCatAuctions': return getProductsResult;
    case 'SetAuctionType': return doNothing;
  }
}

function selectKindEx(linx, aType) {
  _allProdFlag = false;
  if (aType == 0) {
    var fullListUrl = (_virtualName == getApplicationName() ? 'MainCat.aspx?p=1' : _virtualName);
	  document.getElementById("tblFloodings").style.display = '';
	  document.getElementById("divProducts").style.display = 'none';
	  document.getElementById("TopPager_tdPager").style.display = 'none';
    document.getElementById("TopPager_pnlViewType").style.display = 'none';
    document.getElementById("BottomPager_tdPager").style.display = 'none';
    document.getElementById("BottomPager_pnlViewType").style.display = 'none';
    document.getElementById("TopPager_tdRightContent").innerHTML = '<h3>מוצרים נבחרים במחלקת ' + _mainCatName + '&nbsp;&nbsp;<span class="rightTitle">(<a class="rightTitle" href="' + fullListUrl + '" onclick="selectAllProducts(); return false;">לרשימת המכירות המלאה...</a>)</span></h3>';
	  setAuctionType(0);
	  savePageContentToHistory();
	  return false;
	}
	else {
	  document.getElementById("tblFloodings").style.display = 'none';
	  document.getElementById("divProducts").style.display = '';
	  if (aType == 1)
	    document.getElementById("TopPager_tdRightContent").innerHTML = '<h3><span class="auctionsTitle">פומביות</span> במחלקת ' + _mainCatName + '</h3>';
	  else if (aType == 2)
	    document.getElementById("TopPager_tdRightContent").innerHTML = '<h3><span class="groupsTitle">קבוצתיות</span> במחלקת ' + _mainCatName + '</h3>';
	  else if (_ips)
	    document.getElementById("TopPager_tdRightContent").innerHTML = '<h3><span class="premiumTitle">פרימיום</span> במחלקת ' + _mainCatName + '</h3>';
	  else
	    document.getElementById("TopPager_tdRightContent").innerHTML = '<h3><span class="personalTitle">אישיות</span> במחלקת ' + _mainCatName + '</h3>';
	  return true;
	}
}

function selectAllProducts() {
	_aType = 0;
	_pIndex = 0;
	_allProdFlag = true;
	getProducts();
  document.getElementById("tblFloodings").style.display = 'none';
	document.getElementById("divProducts").style.display = '';
	document.getElementById("TopPager_tdRightContent").innerHTML = '<h3>מוצרים במחלקת ' + _mainCatName + '</h3>';
}

function setAuctionType(aType) {
  executeServerRequest('SetAuctionType', 'aType=' + aType);
}

function savePageContentToHistoryEx() {
  historyStorage.put('_allProdFlag', _allProdFlag);
}

function restorePageContentFromHistoryEx() {
  _allProdFlag = historyStorage.get('_allProdFlag');
  if (_allProdFlag == 'true') {
    document.getElementById("tblFloodings").style.display = 'none';
	  document.getElementById("divProducts").style.display = '';
	  return true;
  }
  else if (_aType == 0) {
    document.getElementById("tblFloodings").style.display = '';
	  document.getElementById("divProducts").style.display = 'none';
	  document.getElementById("TopPager_tdPager").style.display = 'none';
    document.getElementById("TopPager_pnlViewType").style.display = 'none';
    document.getElementById("BottomPager_tdPager").style.display = 'none';
    document.getElementById("BottomPager_pnlViewType").style.display = 'none';
	  return false;
	}
	else {
	  document.getElementById("tblFloodings").style.display = 'none';
	  document.getElementById("divProducts").style.display = '';
	  return true;
	}
}

function logMainCatProductClick(shopName, pfID, prodName, stackNum, mutagName) {
  logNuconomyActivity(shopName, '', pfID, prodName, 124, '', _mainCatName, stackNum, mutagName);
}

function logMainCatStripClick(stripLink, stackNum) {
  logNuconomyActivity('', 30, stripLink, '', 125, '', _mainCatName, stackNum);
}