// Email protection — first of all
  window.addEvent('domready', function() {
    var regEmail = /\/([a-zA-Z0-9\-\.]+)\.m\.([a-zA-Z0-9\-\.]+)\/([a-zA-Z]{2,6})\//g;
    $$('a').each(function(el) {
      if(el.href.match(regEmail)) {
        var str = el.href.replace(document.location.protocol + '//' + document.location.hostname, '');
        str = str.replace(regEmail, '$1@$2.$3');
        el.href = 'mailto:' + str;
        el.innerHTML = el.innerHTML.replace(regEmail, '$1@$2.$3');
      }
    });
    if(document.body.innerHTML.match(regEmail)) {
      document.body.innerHTML = document.body.innerHTML.replace(regEmail, '$1@$2.$3');
    };
    document.getElementById('searchQuery').setAttribute('autocomplete', 'off');
    if($('bannerTop')) {
      var divH = 0;
      if($('breadcrumbs')) {
        $('breadcrumbs').style.marginTop = '-5px';
      } else {
        divH = -37;
      }
      $$('h1').each(function(h) {
        if($('bannerTop').offsetHeight) {
            h.style.top = ($('bannerTop').offsetHeight + 198 + divH) + 'px';
        } else if($('bannerTop').clientHeight) {
            h.style.top = ($('bannerTop').clientHeight + 198 + divH) + 'px';
        }
      });
    }
	  $$('textarea').each(function(el) {
  		if(el.title) {
  			el.setAttribute('alt', el.title);
			}
		});
		if($('bannerLeft')) {
			var windowWidth = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth : document.body.clientWidth;
			if(windowWidth <= 1250 && windowWidth >= 1125) {
				$('mother').setStyle('margin-left', '-60px');
				$('bannerLeft').setStyle('margin-left', '440px');
			}	else if(windowWidth < 1125) {
				$('bannerLeft').setStyle('display', 'none');
			}
		}
		if($('home')) {
			/*
		  if(navigator.appVersion.indexOf('MSIE') > -1) {
				var bannerOffsetTop = $('bannersIndex').getStyle('margin-top').replace('px', '') - 0;
				$('bannersIndex').style.marginTop = (bannerOffsetTop - 125) + 'px';
				
				var lineOffsetTop = $('lineIndex').getStyle('margin-top').replace('px', '') - 0;
				$('lineIndex').style.marginTop = (lineOffsetTop + 100) + 'px';
				
		  } 
		  */
			var homeOffsetTop = $('home').getStyle('margin-top').replace('px', '') - 0;
			if(!$('visitedProducts') && homeOffsetTop) {
				if(navigator.appVersion.indexOf('MSIE') > -1) {
       		$('home').style.marginTop = (homeOffsetTop - 280) + 'px';
				} else {
					$('home').style.marginTop = (homeOffsetTop - 280) + 'px';
				}
			}
			//var windowHeight = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight : document.body.clientHeight;
			
		}
	});
  
  if(navigator.appVersion.indexOf('MSIE 6') > -1) {
    window.addEvent('resize', function() {    
      if($('mother')) {
        $('mother').style.display = 'none';
        $('mother').style.display = 'block';
      }
    });
  }

PageClass = function() {
  this.cetelemCalculator = false; // Use onw calculator or redirect to cetelem.cz
  this.useCookies = false;
  this.cookies = new Array();
  this.maxBuyngItems = 900;
  this.orderDisabled = false;
  this.orderId = 0;
  this.emailLastTested = '';
  this.searchHelperTimeout = 0;
  this.searchHelperInProgress = 0;
  this.searchHelperLast = '';
  this.questionType = '';
  this.domain = document.location.hostname;
  this.defaultTransport = 0;
  this.defaultPayment = 0;
  this.affilateCodePrevious = '';
//  this.openedCategories = new Array();
}

/*
PageClass.prototype.CategorySwitcher = function(who) {
  var li = $('Category_li_' + who);
  var ul = $('Category_ul_' + who);
  if(!li) {
    return false;
  }
  if(li.className.indexOf('selected') > -1) {
    li.className = li.className.replace('selected', '');
    if(ul) {
      ul.className = 'hide';
    }
    if(this.useCookies) {
        // It`s strange mootool`s bug - cookies doesn`t removes. Let`s assign 0;
        delete this.cookies[who];
        Cookie.write('CategoryOpened_' + who, 0, {path: '/'});
        Cookie.dispose('CategoryOpened_' + who);
    }
  } else {
    li.className += ' selected';
    if(ul) {
      ul.className = '';
    }
    if(this.useCookies) {
      Cookie.write('CategoryOpened_' + who, 1, {path: '/', duration: 365});
      this.cookies[who] = who;
    }
  }
  if(this.useCookies) {
    Cookie.write('openedCategories', JSON.encode(this.cookies), {path: '/', duration: 365});
  }
}

PageClass.prototype.CategoryRestore = function() {
  if(!this.useCookies) return false;
  var is_opened;
  var cookies = Cookie.read('openedCategories');
  if(cookies) {
    this.openedCategories = JSON.decode(cookies);
    for(i in this.openedCategories) {
      if(this.openedCategories[i]-0 > 0) {
        is_opened = Cookie.read('CategoryOpened_' + this.openedCategories[i]);
        if(is_opened) {
          this.cookies[this.openedCategories[i]] = this.openedCategories[i];
          this.CategorySwitcher(this.openedCategories[i]);
        }
      }
    }
  }
}
*/
PageClass.prototype.ProductTabSwitcher = function(tab) {
  var els = $('detail-tabs').getElementsByTagName('a');
  tab = tab.substr(tab.indexOf('?'), 100)
  for(i=0; i<els.length; i++) {
    if(els[i].href.substr(els[i].href.indexOf('?'), 100) == tab) {
      els[i].className = 'selected';
    } else {
      els[i].className = '';
    }
  }
  tab = tab.substr(tab.indexOf('?')+1, tab.length);
  var tabElement;
  if(tabElement = $('tab_' + tab)) {
    var els = tabElement.parentNode.getElementsByTagName('div');
    for(i=0; i<els.length; i++) {
      if(els[i].id.indexOf('tab_') > -1) {
        if(els[i].id == 'tab_' + tab) {
          els[i].style.display = 'block';
          document.location.hash = tab;
        } else {
          els[i].style.display = 'none';
        }
      }
    }
  }
}

PageClass.prototype.registrationSameAddress = function(what) {
  if(!$('form_who_2')) {
    return false;
  }
  if(!what || !$('form_who_2').checked) {
    $('form_deliveryCompany').disabled = what;
  }
  $('form_deliveryFirstname').disabled = (what ? 'disabled' : false);
  $('form_deliverySurname').disabled = (what ? 'disabled' : false);
  $('form_deliveryStreet').disabled = (what ? 'disabled' : false);
  $('form_deliveryTown').disabled = (what ? 'disabled' : false);
  $('form_deliveryPostcode').disabled = (what ? 'disabled' : false);

  if($('form_delivery_table')) {
    $('form_delivery_table').style.display = (what ? 'none' : 'block');
  }
  if(what) {
/*
    if($('form_who_2').checked) {
      $('form_deliveryCompany').className = $('form_deliveryCompany').className.replace('disabled', '');;
      $('tr_deliveryCompany').style.display = 'none';
    }
*/
/*
    $('form_deliveryCompany').className += ' disabled';
    $('form_deliveryFirstname').className += ' disabled';
    $('form_deliverySurname').className += ' disabled';
    $('form_deliveryStreet').className += ' disabled';
    $('form_deliveryTown').className += ' disabled';
    $('form_deliveryPostcode').className += ' disabled';
*/
    $('form_deliveryFirstname').className = $('form_deliveryFirstname').className.replace('inputError', '-inputError');;
    $('form_deliverySurname').className = $('form_deliverySurname').className.replace('inputError', '-inputError');;
    $('form_deliveryStreet').className = $('form_deliveryStreet').className.replace('inputError', '-inputError');;
    $('form_deliveryTown').className = $('form_deliveryTown').className.replace('inputError', '-inputError');;
    $('form_deliveryPostcode').className = $('form_deliveryPostcode').className.replace('inputError', '-inputError');;
    if($('changeAddress')) {
      $('changeAddress').style.display = 'block';
    }
  } else {
    if($('form_who_2').checked) {
      $('form_deliveryCompany').className = $('form_deliveryCompany').className.replace('disabled', '');;
      $('tr_deliveryCompany').style.display = '';
    }
    $('form_deliveryFirstname').className = $('form_deliveryFirstname').className.replace('disabled', '');;
    $('form_deliverySurname').className = $('form_deliverySurname').className.replace('disabled', '');;
    $('form_deliveryStreet').className = $('form_deliveryStreet').className.replace('disabled', '');;
    $('form_deliveryTown').className = $('form_deliveryTown').className.replace('disabled', '');;
    $('form_deliveryPostcode').className = $('form_deliveryPostcode').className.replace('disabled', '');;

    $('form_deliveryFirstname').className = $('form_deliveryFirstname').className.replace('-inputError', 'inputError');;
    $('form_deliverySurname').className = $('form_deliverySurname').className.replace('-inputError', 'inputError');;
    $('form_deliveryStreet').className = $('form_deliveryStreet').className.replace('-inputError', 'inputError');;
    $('form_deliveryTown').className = $('form_deliveryTown').className.replace('-inputError', 'inputError');;
    $('form_deliveryPostcode').className = $('form_deliveryPostcode').className.replace('-inputError', 'inputError');;
  }
}

PageClass.prototype.registrationChangePassword = function(flag) {
  $('tr_oldpass').style.display = flag ? '' : 'none';
  $('tr_pass').style.display = flag ? '' : 'none';
  $('tr_repass').style.display = flag ? '' : 'none';

  $('form_oldpass').disabled = flag ? false : true;
  $('form_pass').disabled = flag ? false : true;
  $('form_repass').disabled = flag ? false : true;
}

PageClass.prototype.registrationWhoIs = function(isCompany) {
  isCompany = (isCompany == 2 ? true : false);
  $('form_company').disabled = !isCompany;
  $('form_ic').disabled = !isCompany;
  $('form_dic').disabled = !isCompany;
  if($('tr_company')) {
    $('tr_company').style.display = (isCompany ? '' : 'none');
  }
  if($('tr_ic')) {
    $('tr_ic').style.display = (isCompany ? '' : 'none');
  }
  if($('tr_dic')) {
    $('tr_dic').style.display = (isCompany ? '' : 'none');
  }
  if($('tr_ic_info')) {
    $('tr_ic_info').style.display = (isCompany ? '' : 'none');
  }
  if(!isCompany) {
    $('form_deliveryCompany').disabled = true;
    $('tr_deliveryCompany').style.display = 'none';
  }
  else if($('form_same_adresses').checked) {
    $('form_deliveryCompany').disabled = false;
    $('tr_deliveryCompany').style.display = '';
    $('form_deliveryCompany').className = $('form_deliveryCompany').className.replace('disabled', '');;
    $('form_deliveryCompany').className = $('form_deliveryCompany').className.replace('disabled', '');;
  }
}

PageClass.prototype.photoPopup = function() {
  var original = $('productPhoto');
  if(original) {
    if(!$('photoPopup')) {
      var popup = document.createElement('div');
      popup.className = 'basePopup photoPopup';
      popup.id = 'photoPopup';

      var close = document.createElement('a');
      close.className = 'popupClose red';
      close.innerHTML = 'x Zavřít';
      close.title = 'Zavřít';
      close.onclick = function() {Page.closePopup(this.parentNode); return false;};
      popup.appendChild(close);

      var photo = document.createElement('img');
      photo.className = 'photoPopupPhoto';
      photo.id = 'photoPopupPhoto';
      photo.title = 'Zavřít';
      photo.onclick = function() {this.parentNode.style.display = 'none'};
      popup.appendChild(photo);

      $('detail').appendChild(popup);
    }
    this.showOverlay();
    $('photoPopupPhoto').src = $('productPhoto').src.replace('preview1', 'preview3');
    $('photoPopup').style.display = 'block';
  }
}

PageClass.prototype.phePopup = function() {
    this.showOverlay();
    if(!$('phePopup')) {
      var popup = document.createElement('div');
      popup.className = 'basePopup phePopup loader';
      popup.id = 'phePopup';

      var close = document.createElement('a');
      close.className = 'popupClose red';
      close.innerHTML = 'x Zavřít';
      close.title = 'Zavřít';
      close.onclick = function() {Page.closePopup(this.parentNode); return false;};
      popup.appendChild(close);

      var h2 = document.createElement('h2');
      h2.innerHTML = 'Recyklační poplatek';
      popup.appendChild(h2);

      var div = document.createElement('div');
      div.id = 'phePopupContent'
      popup.appendChild(div);

      $('detail').appendChild(popup);

      var jsonRequest = new Request.HTML({url: "/ajax.php", onSuccess: function(elTree, elList, elHtml){
          $('phePopupContent').innerHTML = elHtml;
          $('phePopup').className = $('phePopup').className.replace(' loader', '');
      }}).post({action:'getBlock', 'blockId': 42});
    }
    $('phePopup').style.display = 'block';
}

PageClass.prototype.dostupnostPopup = function(element, name, count, date) {
    this.showOverlay();
    if(count == 'Skladem') {
      $('contentDostupnostH2').innerHTML = 'Skladem u dodavatele';
      blockId = 85;
    } else if(count == 'Ihned k odběru') {
      $('contentDostupnostH2').innerHTML = 'Zboží je Ihned k odběru na prodejně v Brně';
      blockId = 86;
    } else if(count == '3-4 dny' || count == '5-7 dnů') {
      $('contentDostupnostH2').innerHTML = 'Zboží je Skladem u dodavatele';
      blockId = 85;
    } else {
      $('contentDostupnostH2').innerHTML = 'Zboží je k dispozici na centrálním skladu';
      blockId = 84;
    }
    if(!$('dostupnostPopup')) {
      var popup = document.createElement('div');
      popup.className = 'basePopup dostupnostPopup loader';
      popup.id = 'dostupnostPopup';

      var close = document.createElement('a');
      close.className = 'popupClose red';
      close.innerHTML = 'x Zavřít';
      close.title = 'Zavřít';
      close.name = 'contentDostupnostAnchor';
      close.onclick = function() {Page.closePopup(this.parentNode); return false;};
      popup.appendChild(close);

      if(typeof element != 'undefined') {
        popup.style.top = (this.findPosY(element) - 50) + 'px';
        popup.style.left = (this.findPosX(element) ) + 'px';
      }

      if($('detail')) {
        $('detail').appendChild(popup);
      } else {
        $('mother').appendChild(popup);
      }
      $('dostupnostPopup').style.display = 'block';

    } else {
      if(typeof element != 'undefined') {
        $('dostupnostPopup').style.top = (this.findPosY(element) - 50) + 'px';
        $('dostupnostPopup').style.left = (this.findPosX(element) ) + 'px';
      }
      $('dostupnostPopup').style.display = 'block';
    }
      var jsonRequest = new Request.HTML({url: "/ajax.php", onSuccess: function(elTree, elList, elHtml){
          if(!name) name = '';
          if(!count) count = '';
          if(!date) date = '';
          elHtml = elHtml.replace('%name%', name);
          elHtml = elHtml.replace('%count%', count);
          elHtml = elHtml.replace('%date%', date);
          $('contentDostupnostHtml').innerHTML = elHtml;

          if(!$('dostupnostContentHolderInner')) {
            var div = document.createElement('div');
            div.id = 'dostupnostContentHolderInner';
            div.innerHTML = $('contentDostupnost').innerHTML;
            $('dostupnostPopup').className = $('dostupnostPopup').className.replace(' loader', '');
            $('dostupnostPopup').appendChild(div);
          } else {
            $('dostupnostContentHolderInner').innerHTML = $('contentDostupnost').innerHTML;
          }
      }}).post({action:'getBlock', 'blockId': blockId});
}

PageClass.prototype.paymentsPopup = function() {
    if(!$('paymentsPopup')) {
      var popup = document.createElement('div');
      popup.className = 'basePopup phePopup';
      //popup.style.height = '580px';
      popup.id = 'paymentsPopup';

      var close = document.createElement('a');
      close.className = 'popupClose red';
      close.innerHTML = 'x Zavřít';
      close.title = 'Zavřít';
      close.onclick = function() {Page.closePopup(this.parentNode); return false;};
      popup.appendChild(close);

      popup.appendChild($('delivery'));

      $('detail').appendChild(popup);
    }
    this.showOverlay();
    $('paymentsPopup').style.display = 'block';
}

PageClass.prototype.recommendPopup = function() {
    if(!$('recomendPopup')) {
      var popup = document.createElement('div');
      popup.className = 'basePopup recomendPopup';
      popup.id = 'recomendPopup';

      var close = document.createElement('a');
      close.className = 'popupClose red';
      close.innerHTML = 'x Zavřít';
      close.title = 'Zavřít';
      close.onclick = function() {Page.closePopup(this.parentNode); return false;};
      popup.appendChild(close);

      $('contentRecomend').style.display = 'block';
      popup.appendChild($('contentRecomend'));

      var message = document.createElement('p');
      message.id = 'recomendMessage';
      popup.appendChild(message);

      $('detail').appendChild(popup);
    }
    this.showOverlay();
    $('recommendCaptchaImage').onload = function() {this.style.visibility = 'visible';}
    $('recommendCaptchaImage').src = $('recommendCaptchaImage').src.substr(0, $('recommendCaptchaImage').src.indexOf('&nc=')) + '&nc=' + (new String((new Date).getTime())).substr(8,5);
    $('recommendCaptchaImage').style.visibility = 'hidden';
    $('recomendForm').style.display = 'block';
    $('recomendMessage').style.display = 'none';
    $('recomendPopup').style.display = 'block';
}

PageClass.prototype.questionPopup = function(productId, type) {
    this.questionType = type;
    if(!$('questionPopup')) {
      var popup = document.createElement('div');
      popup.className = 'basePopup recomendPopup questionPopup';
      popup.id = 'questionPopup';

      var close = document.createElement('a');
      close.className = 'popupClose red';
      close.innerHTML = 'x Zavřít';
      close.title = 'Zavřít';
      close.onclick = function() {Page.closePopup(this.parentNode); return false;};
      popup.appendChild(close);

      $('contentQuestion').style.display = 'block';
      popup.appendChild($('contentQuestion'));

      var message = document.createElement('p');
      message.id = 'questionMessage';
      popup.appendChild(message);

      $('detail').appendChild(popup);
    }
    this.showOverlay();
    $('questionCaptchaImage').onload = function() {this.style.visibility = 'visible';}
    $('questionCaptchaImage').src = $('questionCaptchaImage').src.substr(0, $('questionCaptchaImage').src.indexOf('&nc=')) + '&nc=' + (new String((new Date).getTime())).substr(8,5);
    $('questionCaptchaImage').style.visibility = 'hidden';
    $('questionForm').style.display = 'block';
    $('questionMessage').style.display = 'none';
    $('questionPopup').style.display = 'block';
}

PageClass.prototype.notifyPopup = function(productId, element, name, productCode) {
    if(!$('notifyPopup')) {
      var popup = document.createElement('div');
      popup.className = 'basePopup recomendPopup questionPopup';
      popup.id = 'notifyPopup';

      var close = document.createElement('a');
      close.className = 'popupClose red';
      close.innerHTML = 'x Zavřít';
      close.title = 'Zavřít';
      close.onclick = function() {Page.closePopup(this.parentNode); return false;};
      popup.appendChild(close);

      if(!name) name = '';
      $('contentNotify').style.display = 'block';
      $('contentNotify').innerHTML = $('contentNotify').innerHTML.replace('%name%', name);
      popup.appendChild($('contentNotify'));

      var message = document.createElement('p');
      message.id = 'notifyMessage';
      message.className = 'green';
      popup.appendChild(message);

      if($('detail')) {
        $('detail').appendChild(popup);
      } else {
        $('mother').appendChild(popup);
      }
    }
    this.showOverlay();
    if(typeof element != 'undefined') {
      $('notifyPopup').style.top = (this.findPosY(element) - 50) + 'px';
    }
    if(productCode) {
      if(!$('productCode')) {
        var span = document.createElement('span');
        span.className = 'hide';
        span.id = 'productCode';
        if($('notifyForm')) {
          $('notifyForm').appendChild(span);
        } else {
          $('mother').appendChild(span);
        }
      }
      $('productCode').innerHTML = productCode;//productId;
    }
    $('notifyCaptchaImage').onload = function() {this.style.visibility = 'visible';}
    $('notifyCaptchaImage').src = $('notifyCaptchaImage').src.substr(0, $('notifyCaptchaImage').src.indexOf('&nc=')) + '&nc=' + (new String((new Date).getTime())).substr(8,5);
    $('notifyCaptchaImage').style.visibility = 'hidden';
    $('notifyForm').style.display = 'block';
    $('notifyMessage').style.display = 'none';
    $('notifyPopup').style.display = 'block';
}

PageClass.prototype.restorePopup = function() {
    if(!$('restorePopup')) {
      var popup = document.createElement('div');
      popup.className = 'basePopup restorePopup';
      popup.id = 'restorePopup';

      var close = document.createElement('a');
      close.className = 'popupClose red';
      close.innerHTML = 'x Zavřít';
      close.title = 'Zavřít';
      close.onclick = function() {Page.closePopup(this.parentNode); return false;};
      popup.appendChild(close);

      $('contentRestore').style.display = 'block';
      popup.appendChild($('contentRestore'));

      var message = document.createElement('p');
      message.id = 'restoreMessage';
      popup.appendChild(message);

      $('mother').appendChild(popup);
    }
    this.showOverlay();
    $('restoreCaptchaImage').src = $('restoreCaptchaImage').src.substr(0, $('restoreCaptchaImage').src.indexOf('&nc=')) + '&nc=' + (new String((new Date).getTime())).substr(8,5);
    $('restoreForm').style.display = 'block';
    $('restoreMessage').style.display = 'none';
    $('restorePopup').style.display = 'block';
}

PageClass.prototype.watchDogPopup = function(productId, forseChecked) {
    if(!$('watchDogPopup')) {
      var popup = document.createElement('div');
      popup.className = 'basePopup recomendPopup';
      popup.id = 'watchDogPopup';

      var close = document.createElement('a');
      close.className = 'popupClose red';
      close.innerHTML = 'x Zavřít';
      close.title = 'Zavřít';
      close.onclick = function() {Page.closePopup(this.parentNode); return false;};
      popup.appendChild(close);

      $('contentDog').style.display = 'block';
      popup.appendChild($('contentDog'));

      var message = document.createElement('p');
      message.id = 'dogMessage';
      popup.appendChild(message);

      $('detail').appendChild(popup);
    }
    this.showOverlay();
    $('dogForm').style.display = 'block';
    $('dogMessage').style.display = 'none';
    $('watchDogPopup').style.display = 'block';
    if(forseChecked && $(forseChecked)) {
      $(forseChecked).checked = true;
    }
}

PageClass.prototype.votePopup = function(who) {
    if(!$('votePopup')) {
      var popup = document.createElement('div');
      popup.className = 'basePopup votePopup';
      popup.id = 'votePopup';
      var close = document.createElement('a');
      close.className = 'popupClose red';
      close.innerHTML = 'x Zavřít';
      close.title = 'Zavřít';
      close.onclick = function() {Page.closePopup(this.parentNode); return false;};
      popup.appendChild(close);

      $('contentVote').style.display = 'block';
      popup.appendChild($('contentVote'));

      var message = document.createElement('p');
      message.id = 'voteMessage';
      popup.appendChild(message);

      $('detail').appendChild(popup);
    }
    this.showOverlay();
    $('voteForm').style.display = 'block';
    $('voteMessage').style.display = 'none';
    $('votePopup').style.display = 'block';
}

PageClass.prototype.votePopupRecenze = function(who) {
    if(!$('votePopup')) {
      var popup = document.createElement('div');
      popup.className = 'basePopup votePopup';
      popup.id = 'votePopup';
      var close = document.createElement('a');
      close.className = 'popupClose red';
      close.innerHTML = 'x Zavřít';
      close.title = 'Zavřít';
      close.onclick = function() {Page.closePopup(this.parentNode); return false;};
      popup.appendChild(close);

      $('contentVote').style.display = 'block';
      popup.appendChild($('contentVote'));

      var message = document.createElement('p');
      message.id = 'voteMessage';
      popup.appendChild(message);

      $('detail').appendChild(popup);
    }
    this.showOverlay();
    $('voteForm').style.display = 'block';
    $('voteMessage').style.display = 'none';
    $('votePopup').style.top = (this.findPosY(who) - 50) + 'px';
    $('votePopup').style.left = (this.findPosX(who) + 150) + 'px';
    $('votePopup').style.display = 'block';
}

PageClass.prototype.cetelemPopup = function(who) {
    if(!$('cetelemPopup')) {
      var popup = document.createElement('div');
      popup.className = 'basePopup recomendPopup';
      popup.id = 'cetelemPopup';

      var close = document.createElement('a');
      close.className = 'popupClose red';
      close.innerHTML = 'x Zavřít';
      close.title = 'Zavřít';
      close.onclick = function() {Page.closePopup(this.parentNode); return false;};
      popup.appendChild(close);

      $('contentCetelem').style.display = 'block';
      popup.appendChild($('contentCetelem'));
      if($('paymentPage')) {
        $('paymentPage').appendChild(popup);
      } else if(!$('detail') && $('delivery')) {
        $('delivery').appendChild(popup);
      } else if($('detail')) {
        $('detail').appendChild(popup);
      } else {
        $('mother').appendChild(popup);
      }

      
      var jsonRequest = new Request.HTML({url: "/ajax.php", onSuccess: function(elTree, elList, elHtml){
          $('cetelemText').innerHTML = elHtml;
      }}).post({'action':'getBlock', 'blockId': 34});
    }
    this.showOverlay();
    if(document.documentElement.scrollTop && document.body.clientHeight) {
      $('cetelemPopup').style.top = (document.documentElement.scrollTop + Math.round(document.documentElement.clientHeight/2)) + 'px';
    } else {
      $('cetelemPopup').style.top = '200px';
    }
    $('cetelemPopup').style.display = 'block';
}

PageClass.prototype.ccPopup = function(who) {
    if(!$('ccPopup')) {
      var popup = document.createElement('div');
      popup.className = 'basePopup recomendPopup';
      popup.id = 'ccPopup';
      var close = document.createElement('a');
      close.className = 'popupClose red';
      close.innerHTML = 'x Zavřít';
      close.title = 'Zavřít';
      close.onclick = function() {Page.closePopup(this.parentNode); return false;};
      popup.appendChild(close);

      $('contentCC').style.display = 'block';
      popup.appendChild($('contentCC'));
      if($('paymentPage')) {
        $('paymentPage').appendChild(popup);
      } else if(!$('detail')) {
        $('delivery').appendChild(popup);
      } else {
        $('detail').appendChild(popup);
      }
    }
    this.showOverlay();
    if(document.documentElement.scrollTop && document.body.clientHeight) {
      $('ccPopup').style.top = (document.documentElement.scrollTop + Math.round(document.body.clientHeight/2) - 480) + 'px';
    } else {
      $('ccPopup').style.top = '200px';
    }
    $('ccPopup').style.display = 'block';
}

PageClass.prototype.downloadPopup = function(link) {
    if(!$('downloadPopup')) {
      var div = document.createElement('div');
      div.id = 'downloadPopup';
      div.innerHTML = '<h3>Stáhnout soubor</h3>' +
                      '<p><b>Chcete ten soubor:</b><br />' +
                      '<a href="' + link.href +'" onclick="window.open(this.href, \'_blank\'); Page.closePopupAll(); Page.hideOverlay(); return false;">otevřít v novém okně</a> nebo <a href="/download' + link.href.replace(document.location.protocol + '//' + document.location.hostname, '') +'" onclick="Page.closePopupAll(); Page.hideOverlay();">stáhnout</a></p>';
      $('mother').appendChild(div);
    }
    $('downloadPopup').style.left = (Page.findPosX(link)-0) + 'px';
    $('downloadPopup').style.top = (Page.findPosY(link)-60) + 'px';
    $('downloadPopup').style.display = 'block';
    this.showOverlay();
}

PageClass.prototype.paramPopup = function(id, link) {
    if(!$('paramPopup')) {
      var popup = document.createElement('div');
      popup.className = 'basePopup restorePopup';
      popup.id = 'paramPopup';

      var close = document.createElement('a');
      close.className = 'popupClose red';
      close.innerHTML = 'x Zavřít';
      close.title = 'Zavřít';
      close.onclick = function() {Page.closePopup(this.parentNode); return false;};
      popup.appendChild(close);

      $('popupParamInfo').style.display = 'block';
      popup.appendChild($('popupParamInfo'));

      $('mother').appendChild(popup);
    }
    this.showOverlay();
  	$('popupParamName').innerHTML = $('paramName'+id).innerHTML;
	  $('popupParamDesc').innerHTML = $('paramDesc'+id).innerHTML;
    $('paramPopup').style.display = 'block';
    $('paramPopup').style.top = (Page.findPosY(link)-50) + 'px';
}

PageClass.prototype.cetelemChangeType = function(typeId) {
    $$('#cetelemPaymentTypes select', '#cetelemPaymentTypes span').each(function(element) {
      if(typeId.length > 3) {
        if(typeId == 'Akce 10 x 10') typeId = 104;
        if(typeId == '0%+20x6 - zdarma 6') typeId = 216;
        if(typeId == '1% měsíčně') typeId = 201;
      }
      if(element.id.indexOf('cetelemPayments_') > -1) {
        element.style.display = (element.id == 'cetelemPayments_' + typeId ? 'block' : 'none')
        Cookie.write('cetelemType', typeId, {'path':'/', 'domain': Page.domain});
      }
    });
    $('cetelemFirstPayment').disabled = ((typeId == 104 || typeId == 216) ? true : false);
    $('cetelemFirstPayment').value = (typeId == 104 ?  Math.round($('cetelemPrice').value/10) : 0);
}

PageClass.prototype.cetelemSwitchTabs = function(tab) {
  $('cetelemTab1').className = (tab == 1 ? 'nolink' : '');
  $('cetelemTab2').className = (tab == 2 ? 'nolink' : '');
  $('cetelemFormTable').style.display = (tab == 1 ? 'block' : 'none');
  $('cetelemText').style.display = (tab == 2 ? 'block' : 'none');
/*
  if(tab == 2 || $('cetelemResultVyseSplatkyTr').style.display != 'none') {
    $('cetelemPopup').style.height = '375px';
  } else {
    $('cetelemPopup').style.height = '';
  }
*/
}

PageClass.prototype.cetelemChangeFamily = function(value) {
  var flag = false;
  if(value == 'druh, družka' || value == 'ženatý, vdaná') {
    flag = true;
  }
  $$('b[alt=isPartner]').each(function(item) {
    item.style.display = (flag ? 'inline' : 'none');
    var els = item.parentNode.getElementsByTagName('input');
    if(!els.length) {
      els = item.parentNode.getElementsByTagName('select');
    }
    els[0].alt = (flag ? 'empty' : '');
  });
}

PageClass.prototype.voteChangeMark = function(mark) {
	/*
  $('voteMark_1').className = (mark > 0 ? 'active' : 'deactive');
  $('voteMark_2').className = (mark > 1 ? 'active' : 'deactive');
  $('voteMark_3').className = (mark > 2 ? 'active' : 'deactive');
  $('voteMark_4').className = (mark > 3 ? 'active' : 'deactive');
  $('voteMark_5').className = (mark > 4 ? 'active' : 'deactive');
  */
  $('userRatingRecenze_1').className = (mark > 0 ? 'active' : 'deactive');
  $('userRatingRecenze_2').className = (mark > 1 ? 'active' : 'deactive');
  $('userRatingRecenze_3').className = (mark > 2 ? 'active' : 'deactive');
  $('userRatingRecenze_4').className = (mark > 3 ? 'active' : 'deactive');
  $('userRatingRecenze_5').className = (mark > 4 ? 'active' : 'deactive');
  if(mark == 1) {
  	$('userRatingText').innerHTML = '(Nepoužitelný)';
	} else if(mark == 2) {
  	$('userRatingText').innerHTML = '(Špatný)';
	} else if(mark == 3) {
  	$('userRatingText').innerHTML = '(Průměrný)';
	} else if(mark == 4) {
  	$('userRatingText').innerHTML = '(Velmi dobrý)';
	} else if(mark == 5) {
  	$('userRatingText').innerHTML = '(Perfektní)';
	} else {
		$('userRatingText').innerHTML = '';
	}
  $('voteValue').value = mark;
  if($('voteValueInForm')) {
  	$('voteValueInForm').value = mark;
	}
}

PageClass.prototype.addVote = function(productId, lazy) {
  if(lazy) {
  	this.addVoteDisplay($('voteValue').value);
	}	else {
	  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(mark){
  		Page.addVoteDisplay(mark);
	  }}).post({action:'addVote', 'productId': productId, 'vote': $('voteValue').value});
	}
}

PageClass.prototype.addVoteDisplay = function(mark) {
    mark = Math.round(mark);
    if($('userRating_1')) {
	    $('userRating_1').className = (mark > 0 ? 'active' : 'deactive');
	    $('userRating_2').className = (mark > 1 ? 'active' : 'deactive');
	    $('userRating_3').className = (mark > 2 ? 'active' : 'deactive');
	    $('userRating_4').className = (mark > 3 ? 'active' : 'deactive');
	    $('userRating_5').className = (mark > 4 ? 'active' : 'deactive');
		}
    if($('userRatingRecenze_1')) {
	    $('userRatingRecenze_1').className = (mark > 0 ? 'active' : 'deactive');
		  $('userRatingRecenze_2').className = (mark > 1 ? 'active' : 'deactive');
		  $('userRatingRecenze_3').className = (mark > 2 ? 'active' : 'deactive');
		  $('userRatingRecenze_4').className = (mark > 3 ? 'active' : 'deactive');
		  $('userRatingRecenze_5').className = (mark > 4 ? 'active' : 'deactive');
    }
    $('votePopup').style.display = 'none';
    Page.hideOverlay();
    $('voteLinkRecension').style.display = 'none';
}

PageClass.prototype.compareRecount = function(count) {
  var els = $('right').getElementsByTagName('a');
  for(var i=0; i<els.length; i++) {
    if(els[i].id.indexOf('compareLabel_') > -1) {
      els[i].innerHTML = count;
    }
  }
}

PageClass.prototype.compareAdd = function(productId, redirect, partKey) {
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(count){
      Cookie.write('elCompareAdded', productId, {path: '/', 'domain': Page.domain})
      if(redirect) {
        document.location = '/porovnani/';
      }
      else {
        $('compareIconAdd_' + productId + partKey).style.display = 'none';
        $('compareIconRemove_' + productId + partKey).style.display = 'block';
        var div = document.createElement('div');
        div.className = 'compareLabel';
        div.id = 'compareDiv_' + productId + partKey;
        div.innerHTML = 'Porovnání: <a href="/porovnani/" id="compareLabel_' + productId + partKey + '">' + count + ' zboží</a>';
        $('compareDivHolder_' + productId + partKey).appendChild(div);
        Page.compareRecount(count);
      }
  }}).post({action:'comapreAdd', productId: productId});
}

PageClass.prototype.compareRemove = function(productId, partKey) {
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(count){
      if($('compareIconAdd_' + productId + partKey)) {
        $('compareIconAdd_' + productId + partKey).style.display = 'block';
        $('compareIconRemove_' + productId + partKey).style.display = 'none';
        $('compareDiv_' + productId + partKey).parentNode.removeChild($('compareDiv_' + productId + partKey));
      } else {
        document.location = document.location;
      }
      Page.compareRecount(count);
  }}).post({action:'comapreRemove', productId: productId});
}


// Adding something to basket
PageClass.prototype.basketAdd = function(productId, refresh, go2basket, partKey) {
  var preload = new Image();
  preload.src = '/_data/images/button-add-green.png';
  var params = {action:'basketAdd', productId: productId};
  $$('.productGiftSelectOne').each(function(el) {
		 if(el.checked) {
				Cookie.write('productGiftSelectOne_' + productId, el.value, {path: '/'});
		 }
  });
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(count){
//    alert(count); return false;
    if(refresh) {
      document.location = document.location;
      return true;
    }
    Page.saveBasketLink();
    if(go2basket) {
      document.location = '/kosik/';
      return true;
    }

    Page.basketRecalc();
    if($('basketAddButton_'+productId+partKey)) {
      $('basketAddButton_'+productId+partKey).className += ' justAdded';
      $('basketAddButton_'+productId+partKey).innerHTML = 'V košíku';
      $('basketAddButton_'+productId+partKey).innerHTML += ' (' + count + ')';
      $('basketAddButton_'+productId+partKey).onclick = function() {document.location = '/kosik/'};
    }
    if(!$('basketAddedPopup')) {
      var div = document.createElement('div');
      div.id = 'basketAddedPopup';
      div.innerHTML = '<h3>Košík</h3>' +
                      '<p><b>Produkt přidán do košíku</b><br />' +
                      '<a href="javascript:void(0);" onclick="this.parentNode.parentNode.style.display = \'none\'; Page.hideOverlay();">Pokračovat nakupování</a> | <a href="/kosik/">Do košíku</a></p>';
      $('mother').appendChild(div);
    }
    $('basketAddedPopup').style.left = (Page.findPosX($('basketAddButton_'+productId+partKey))-100) + 'px';
    $('basketAddedPopup').style.top = (Page.findPosY($('basketAddButton_'+productId+partKey))-60) + 'px';
    $('basketAddedPopup').style.display = 'block';
  }}).post(params);
}

// Removing from basket
PageClass.prototype.basketRemove = function(productId) {
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(count){
    //Page.basketRemoveTr(productId);
    //Page.basketRecalc();
    document.location = document.location;
  }}).post({action:'basketRemove', productId: productId});
}

// Changing products count
PageClass.prototype.basketChange = function(productId) {
  var reg = /([0-9]+)([0-9]{3})(,[0-9]{2})?/;
  var count = $('productCount_' + productId).value;
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(count){
    document.location = document.location;
    /*
    var jsonRequestInner = new Request.JSON({url: "/ajax.php", onSuccess: function(count){
      $('productDiscount').innerHTML = new String(count).replace(reg, '$1.$2$3') + '  Kč';
      $('productDiscountValue').value = count - 0;
      Page.basketRecalc();
    }}).post({action:'basketGetDiscount'});
    */
  }}).post({action:'basketChange', productId: productId, productCount: count});
}

// Erasing a product from basket - front
PageClass.prototype.basketRemoveTr = function(productId) {
  $('productTr_' + productId).parentNode.id = 'basketRowsHolder';
  if($('productTrPhe_' + productId)) {
    //$('productTrPhe_' + productId).style.display = 'none';
    $('productTrPhe_' + productId).parentNode.removeChild($('productTrPhe_' + productId));
  }
  if($('productTr_' + productId)) {
    //$('productTr_' + productId).style.display = 'none';
    $('productTr_' + productId).parentNode.removeChild($('productTr_' + productId));
  }
  var color = false;
  $$('#basketRowsHolder tr').each(function(tr, index) {
    if(tr.className != 'head') {
      if(tr.id.indexOf('productTr_') > -1) {
        color = !color;
        tr.className = color ? 'dark' : '';
      }
      else {
        tr.className = color ? 'dark phe' : 'phe';
      }
    }
  });
}

// Recalculating basket
PageClass.prototype.basketRecalc = function() {
  Page.basketTop();
  if(!$('cart')) {
    return false;
  }
  var priductId;
  var price;
  var summ;
  var summAll = 0;
  var phePrice;
  var pheSumm;
  var reg = /([0-9]+)([0-9]{3})(,[0-9]{2})?/;
  // Walking throu quantity inputs and collecting data
  // Yeah, it`s strange MVC ))
  $$('#cart input').each(function(item, index) {
     if(item.id.indexOf('productCount_') > -1) {
       if(item.value-0 > Page.maxBuyngItems-0) {
         item.value = Page.maxBuyngItems;
       }
       priductId = item.id.replace('productCount_', '') - 0;
       price = $('productPrice_' + priductId).value;
       summ = (price * item.value) - 0;
       if(summ) {
         $('productSumm_' + priductId).innerHTML = new String(summ).replace(reg, '$1.$2$3') + ' Kč';
         summAll += summ;
       }
       if($('productPheSumm_' + priductId)) {
         phePrice = $('productPheValue_' + priductId).value;
         pheSumm = Math.round((phePrice * item.value));
         $('productPheSumm_' + priductId).innerHTML = new String(pheSumm).replace(reg, '$1.$2$3') + ' Kč';
         summAll += pheSumm;
       }
     }
  });
  if(!summAll) {
    document.location.href = document.location;
  }
  if($('productDiscountValue').value) {
    summAll += $('productDiscountValue').value - 0;
  }
  $('productPriceSumm').innerHTML = new String(summAll).replace(reg, '$1.$2$3') + ' Kč';
}

PageClass.prototype.basketClear = function(productId) {
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(count){
    Page.basketTop();
  }}).post({action:'basketClear'});
}

PageClass.prototype.basketTop = function(productId) {
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
    if(typeof obj == 'undefined' || !obj) {
      return false;
    }
    var reg = /([0-9]+)([0-9]{3})(,[0-9]{2})?/;
    $('basketTopPrice').innerHTML = new String(obj.price_vat).replace(reg, '$1.$2$3') + ' Kč';
    $('basketTopCount').innerHTML = obj.cnt;
  }}).post({action:'basketTop'});
}

PageClass.prototype.basketGift = function(productId, giftId) {
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
    var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
//      document.location = document.location;
    }}).post({action:'basketGift', 'productId': productId, 'giftId': giftId});
  }}).post({action:'basketGiftRemove', 'productId': productId, 'giftId': giftId});
}


PageClass.prototype.orderAddClick = function(paymentId, price) {
  if(this.orderDisabled) {
    return false;
  }
  this.orderDisabled = true;
  // EBanka
  if(paymentId == 3) {
    Page.orderPayEBanka(price);
  // Aura
  } else if (paymentId == 4) {
    Page.orderPayAURA(price);
  // Cetelem
  } else if(paymentId == 6) {
    var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(orderId) {
      //Page.orderId = orderId;
      if(orderId < 0) {
        document.location = '/shrnuti-objednavky/' + (-orderId) + '/';
        Page.orderFinishCookie(-orderId);
      } else {
        document.location = '/shrnuti-objednavky/';
/*
        if(Page.cetelemCalculator) {
          Page.cetelemPopup();
        } else {
          Page.cetelemCalc(price, 1);
          Page.cetelemPay(price, 1);
        }
*/
        Page.orderFinishCookie(orderId);
      }
      Page.clearBasketCookies();
      return false;
    }}).post({action:'cetelemJustPay'});
    return false;
  // Credit card
  }else if(Cookie.read('elBasketPayment') == 8) {
    this.ccPopup();
    return false;
  // ordinar payment
  } else {
    Page.orderAdd(); 
  }
  return false;
}

PageClass.prototype.orderAdd = function(forse) {
  var params = {
      'action':'orderAdd'
  };
  var jsonRequest = new Request.HTML({url: "/ajax.php", onSuccess: function(fake, tree, orderId) {
    //document.location = '/dokonceni-objednavky/';
    Page.clearBasketCookies();
    Page.orderFinishCookie(orderId);
    //document.location.assign('/shrnuti-objednavky/' + orderId + '/');
    document.location.href = '/shrnuti-objednavky/' + orderId + '/';
    //setTimeout("document.location = '/shrnuti-objednavky/';", 3000);
  }}).post(params);
}

PageClass.prototype.orderFinishCookie = function(orderId) {
  Cookie.write('elOrderFinished_' + orderId, orderId, {'path': '/', 'domain': this.domain});
}

PageClass.prototype.orderPayDelayed = function(orderId, paymentId) {
  if(paymentId == 6) {
    Page.orderId = orderId;
    this.cetelemPopup();
  }
  var jsonRequest = new Request.HTML({url: "/ajax.php", onSuccess: function(fake, fake2, code) {
    // Ebanka + Aura
    if(paymentId == 3 || paymentId == 4) {
      document.location = code;
    }
    // Credit Card
    else if(paymentId == 8) {
      var holder = document.createElement('div');
      holder.innerHTML = code;
      $('mother').appendChild(holder);
      holder.firstChild.submit();
    }
  }}).post({'action':'orderPayDelayed', 'orderId':orderId});
}

PageClass.prototype.orderPayEBanka = function(price_vat) {
  var params = {
     'action':'payRB',
     'price_vat':price_vat
  };
  var jsonRequest = new Request.HTML({url: "/ajax.php", onSuccess: function(result, elements, html) {
      Page.clearBasketCookies();
      if(html == html-0) {
        document.location = '/shrnuti-objednavky/' + html + '/';
        Page.orderFinishCookie(html);
      } else {
        document.location = html;
      }
  }}).post(params);
}

PageClass.prototype.orderPayAURA = function(price_vat) {
  var params = {
     'action':'payAURA',
     'price_vat':price_vat
  };

  var jsonRequest = new Request.HTML({url: "/ajax.php", onSuccess: function(result, elements, html) {
      Page.clearBasketCookies();
      if(html == html-0) {
        document.location = '/shrnuti-objednavky/' + html + '/';
        Page.orderFinishCookie(html);
      } else {
        document.location = html;
      }
  }}).post(params);
}

PageClass.prototype.clearBasketCookies = function() {
  setTimeout('Page.clearBasketCookiesDelayed();', 10);
}

PageClass.prototype.clearBasketCookiesDelayed = function() {
  try {  
    Cookie.write('elBasketTransport', 0, {'path': '/', 'domain': this.domain});
    Cookie.write('elBasketPayment', 0, {'path': '/', 'domain': this.domain});
    Cookie.write('elBasketComment', '', {'path': '/', 'domain': this.domain});
    Cookie.write('elBasketGift', 0, {'path': '/', 'domain': this.domain});
    //Cookie.write('changeAddress', 0, {'path': '/', 'domain': this.domain});
    Cookie.dispose('elBasketTransport');
    Cookie.dispose('elBasketPayment');
    Cookie.dispose('elBasketComment');
    Cookie.dispose('elBasketGift');
    Cookie.dispose('changeAddress');

    var re = /(elBasketService\[\d*\])\s*=\s*[^0]/;
    var cookieName;
    var i = 0;
    while(cookieName = document.cookie.match(re) && i<20) {
      cookieName = cookieName[1];
      if(Cookie.read(cookieName) > 0) {
        Cookie.write(cookieName, 0, {'path': '/', 'domain': this.domain});
        Cookie.dispose(cookieName);
      }
      i++;
    }    
  } catch(err) {alert(err);}
}

PageClass.prototype.addFavorite = function(productId) {
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
  }}).post({action:'addFavorite', productId: productId});
  $('addFavorite').style.display = 'none';
  $('removeFavorite').style.display = 'block';
}

PageClass.prototype.removeFavorite = function(productId) {
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
  }}).post({action:'removeFavorite', productId: productId});
  $('addFavorite').style.display = 'block';
  $('removeFavorite').style.display = 'none';
}

/*
PageClass.prototype.addWatchDog = function(productId) {
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
  }}).post({action:'addWatchDog', productId: productId});
}
*/

PageClass.prototype.discountTest = function() {
  if($('discountCode')) {
    var jsonRequest = new Request.HTML({url: "/ajax.php", onSuccess: function(obj, text, html){
      if(!html) {
        document.location = document.location;
      } else {
        $('voucherError').innerHTML = html;
        $('voucherError').style.display = 'block';
      }
    }}).post({action:'discountTest', discountCode: $('discountCode').value});
  }
}


PageClass.prototype.colorizePaymentAndTransport = function() {
  var parent = false;
  var color = false;
  $$('#delivery tr').each(function(tr) {
    if(tr.parentNode.parentNode.className.indexOf('noColorize') > -1) return true;
    if(tr.style.display != 'none') {
      if(tr.parentNode != parent) {
        color = true;
      } else {
        color = !color;
      }
      parent = tr.parentNode;
      tr.className = (color ? 'dark' : 'light');
    }
  });
}

PageClass.prototype.checkPaymentAndTransport = function() {
  var transportId = 0;
  var paymentId = 0;
  $$('#delivery input').each(function(element) {
    if(element.id.indexOf('transportMethod_') > -1) {
      if(element.checked) {
        transportId = element.id.replace('transportMethod_', '') - 0;
      }
    }
    if(element.id.indexOf('paymentMethod_') > -1) {
      if(element.checked) {
        paymentId = element.id.replace('paymentMethod_', '') - 0;
      }
    }
  });
  if(!transportId) {
    transportId = this.defaultTransport;
  }
  if(!paymentId) {
    paymentId = this.defaultPayment;
    $('paymentMethod_' + paymentId).checked = true;
  }
  if(!transportId) {
    return true;
  }
  $$('#delivery table tr[id^=paymentTr_]').each(function(tr) {
    tr.style.display = '';
  });
  if(transportId == 1) {
    if($('paymentTr_1')) $('paymentTr_1').style.display = 'none';
    if(paymentId == 1) {
      if($('paymentMethod_7')) {
        paymentId = 7;
        $('paymentMethod_7').checked = true;
        this.selectPayment(7, true);
      }
    }
  } else if(transportId == 2 || transportId == 3 || transportId == 4) {
    if($('paymentTr_5')) $('paymentTr_5').style.display = 'none';
    if($('paymentTr_7')) $('paymentTr_7').style.display = 'none';
    if($('paymentTr_8')) $('paymentTr_8').style.display = '';
    if(paymentId == 7) {
      if($('paymentMethod_1')) {
        paymentId = 1;
        $('paymentMethod_1').checked = true;
        this.selectPayment(1, true);
      }
    }
  }
  var price = parseInt($('basketPrice').value) + parseInt($('transportPrice' + transportId).value-0) + parseInt($('paymentPrice' + paymentId).value);
  if(transportId == 2) {
    $$('#transportServices input').each(function(element) {
      if(element.id.indexOf('transportService_') > -1) {
        if(element.checked) {
          var serviceId = element.id.replace('transportService_', '') - 0;
          var quantity = 1;
          if($('transportServiceQuantity_' + serviceId)) {
            quantity = $('transportServiceQuantity_' + serviceId).value - 0;
          }
          if(quantity < 1) {
            quantity = 1;
          }
          price += quantity * ($('servicePrice' + serviceId).value - 0);
        }
      }
    });
  }
  var reg = /([0-9]+)([0-9]{3})(,[0-9]{2})?/;
  $('productPriceSumm').innerHTML = new String(price).replace(reg, '$1.$2$3') + ' Kč';
  this.colorizePaymentAndTransport();
  return true;
}

PageClass.prototype.selectTransport = function(transportId) {
  if(!this.checkPaymentAndTransport()) {
    return false;
  }
  if($('transportServices'))
  $('transportServices').style.display = (transportId == 2 ? '' : 'none');
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
  }}).post({action:'selectTransport', 'transportId': transportId});
}

PageClass.prototype.selectService = function(serviceId, skipAjax) {
/*
  if(serviceId == 12 && $('transportService_15').checked && $('transportService_12').checked) {
    $('transportService_15').disabled = true;
    $('transportService_11').disabled = true;
    if(skipAjax) {
      this.selectService(15);
      this.selectService(11);
    }
  }
  if(serviceId == 15 && $('transportService_15').checked && $('transportService_12').checked) {
    $('transportService_12').disabled = true;
    $('transportService_11').disabled = true;
    if(skipAjax) {
      this.selectService(12);
      this.selectService(11);
    }
  }
  if(serviceId == 11 && $('transportService_15').checked && $('transportService_12').checked) {
    $('transportService_12').disabled = true;
    $('transportService_15').disabled = true;
    if(skipAjax) {
      this.selectService(12);
      this.selectService(11);
    }
  }
*/
  if(serviceId == 11) {
    if(skipAjax) {
      if($('transportService_15').checked) {
        this.selectService(15);
      }
      if($('transportService_12').checked) {
        this.selectService(12);
      }
    }
    $('transportService_15').disabled = true;
    $('transportService_12').disabled = true;
  } else if(serviceId == 12) {
    if(skipAjax) {
      if($('transportService_15').checked) {
        this.selectService(15);
      }
      if($('transportService_11').checked) {
        this.selectService(11);
      }
    }
    $('transportService_15').disabled = true;
    $('transportService_11').disabled = true;
  } else if(serviceId == 15) {
    if(skipAjax) {
      if($('transportService_12').checked) {
        this.selectService(12);
      }
      if($('transportService_11').checked) {
        this.selectService(11);
      }
    }
    $('transportService_12').disabled = true;
    $('transportService_11').disabled = true;
  }
  if(!$('transportService_11').checked && !$('transportService_12').checked && !$('transportService_15').checked) {
    $('transportService_11').disabled = false;
    $('transportService_12').disabled = false;
    $('transportService_15').disabled = false;
  }

  this.checkPaymentAndTransport();
  var value = 0;
  if($('transportService_'+serviceId).checked) {
    if($('transportServiceQuantity_'+serviceId)) {
      value = $('transportServiceQuantity_'+serviceId).value;
    } else {
      value = 1;
    }
    if(value < 1) {
      value = 1;
    }
  }
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
  }}).post({action:'selectService', 'serviceId': serviceId, 'value':value});
}

PageClass.prototype.selectPayment = function(paymentId, skipCheck) {
  if(!skipCheck && !this.checkPaymentAndTransport()) {
    return false;
  }
  var jsonRequest = new Request.HTML({url: "/ajax.php", onSuccess: function(obj, text){
  }}).post({action:'selectPayment', 'paymentId': paymentId});
}

PageClass.prototype.ifEnter = function(e) {
  var keynum;
  if(window.event) {
    keynum = e.keyCode;
  } else if(e.which) {
    keynum = e.which;
  }
  return (keynum == 13);
}

PageClass.prototype.showArticle = function(id, what) {
  $('dmArticleAnnounce_' + id).style.display = (what ? 'none' : 'block');
  $('dmArticleText_' + id).style.display = (what ? 'block' : 'none');
}

PageClass.prototype.basketChangeDelivery = function() {
  if($('form_comment')) {
    Cookie.write('elBasketComment', $('form_comment').value, {path: '/', 'domain': Page.domain});
  }
}

PageClass.prototype.basketChangeComment = function() {
  if($('form_comment')) {
    Cookie.write('elBasketComment', $('form_comment').value, {path: '/', 'domain': Page.domain});
  }
}

PageClass.prototype.basketSetDeliveryAddress = function(addressId) {
  if(addressId > 0) {
    if(typeof this.profileAddreses[addressId] == 'undefined') {
      return false;
    }
    $('form_deliveryCompany').value = this.profileAddreses[addressId].company;
    $('form_deliveryFirstname').value = this.profileAddreses[addressId].firstname;
    $('form_deliverySurname').value = this.profileAddreses[addressId].surname;
    $('form_deliveryStreet').value = this.profileAddreses[addressId].street;
    $('form_deliveryTown').value = this.profileAddreses[addressId].town;
    $('form_deliveryPostcode').value = this.profileAddreses[addressId].postcode;
    if(addressId == this.profileAddresesInvoice) {
      $('deleteAddress').style.display = 'none';
    } else {
      $('deleteAddress').style.display = 'block';
    }
    var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
      //document.location.href = document.location;
    }}).post({action:'basketSetDeliveryAddress', 'addressId': addressId});
  } else {
    this.registrationSameAddress(false);
    $('form_deliveryCompany').value = '';
    $('form_deliveryFirstname').value = '';
    $('form_deliverySurname').value = '';
    $('form_deliveryStreet').value = '';
    $('form_deliveryTown').value = '';
    $('form_deliveryPostcode').value = '';
    $('deleteAddress').style.display = 'none';
  }
}

PageClass.prototype.addressSaveTest = function() {
  var t1 = Validator.validateForm('registrationForm', 'form_deliveryFirstname');
  var t2 = Validator.validateForm('registrationForm', 'form_deliverySurname');
  var t3 = Validator.validateForm('registrationForm', 'form_deliveryStreet');
  var t4 = Validator.validateForm('registrationForm', 'form_deliveryTown');
  var t5 = Validator.validateForm('registrationForm', 'form_deliveryPostcode');
  var res = (t1 && t2 && t3 && t4 && t5)
  if(!res) {
    $('registrationDeivery').style.height = '';
  }
  return res;
}

PageClass.prototype.addressSave = function() {
//  if(!$('form_same_adresses').checked) {
    var addressId = $('existingAdresses').value;
    var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
      var option = false;
      if(!addressId) {
        addressId = text;
        Page.profileAddreses[addressId] = new Array();
        var option = document.createElement('option');
        option.value = addressId;
        option.innerHTML = $('form_deliveryStreet').value + ' ' + $('form_deliveryTown').value;
        $('existingAdresses').appendChild(option);
        $('existingAdresses').value = addressId;
      }
      Page.profileAddreses[addressId].company = $('form_deliveryCompany').value;
      Page.profileAddreses[addressId].firstname = $('form_deliveryFirstname').value;
      Page.profileAddreses[addressId].surname = $('form_deliverySurname').value;
      Page.profileAddreses[addressId].street = $('form_deliveryStreet').value;
      Page.profileAddreses[addressId].town = $('form_deliveryTown').value;
      Page.profileAddreses[addressId].postcode = $('form_deliveryPostcode').value;
      if(option) {
        Page.basketSetDeliveryAddress(addressId);
      }
      //document.location.href = document.location;
    }}).post({
       'action':'addressSave',
       'addressId': addressId,
       'form[company]': $('form_deliveryCompany').value,
       'form[firstname]': $('form_deliveryFirstname').value,
       'form[surname]': $('form_deliverySurname').value,
       'form[street]': $('form_deliveryStreet').value,
       'form[town]': $('form_deliveryTown').value,
       'form[postcode]': $('form_deliveryPostcode').value
    });
//  }
}

PageClass.prototype.addressDelete = function() {
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
    Page.profileAddreses[$('existingAdresses').value] = 'undefined';
    $('existingAdresses').removeChild($('existingAdresses').options[$('existingAdresses').selectedIndex]);
    $('existingAdresses').value = Page.profileAddresesInvoice;
    Page.basketSetDeliveryAddress(Page.profileAddresesInvoice);
    //document.location.href = document.location;
  }}).post({
     'action':'addressDelete',
     'addressId': $('existingAdresses').value
  });
}

PageClass.prototype.recomendIt = function() {
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
    if(text == 'captcha') {
      $('recommendCaptcha').className = ' inputError';
    }
    else {
      $('recomendForm').style.display = 'none';
      $('recomendMessage').style.display = 'block';
      $('recomendMessage').innerHTML = 'Děkujeme, Vaše zpráva byla právě odeslána na ' + $('recommendTarget').value + '.';
      if(typeof pageTracker != 'undefined') {
        pageTracker._trackPageview('http://elektrosvet.cz/ajax.form.doporucit');
      }
    }
  }}).post({
     'action':'recomendIt',
     'recommendSender': $('recommendSender').value,
     'recommendFrom': $('recommendFrom').value,
     'recommendTarget': $('recommendTarget').value,
     'recommendComment': $('recommendComment').value,
     'recommendCaptcha' : $('recommendCaptcha').value
  });
}

PageClass.prototype.questionIt = function() {
  var productName;
  $$('h1').each(function(el) {
    productName = el.innerHTML;
  });
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
    if(text == 'captcha') {
      $('questionCaptcha').className = ' inputError';
    }
    else {
      if(typeof pageTracker != 'undefined') {
        pageTracker._trackPageview('http://elektrosvet.cz/ajax.form.dotaz');
      }
      $('questionForm').style.display = 'none';
      $('questionMessage').style.display = 'block';
      $('questionMessage').innerHTML = 'Děkujeme, Vaš dotaz byl právě odeslán';
    }
  }}).post({
     'action':'questionIt',
     'questionSender': $('questionSender').value,
     'questionFrom': $('questionFrom').value,
     'questionPhone': $('questionPhone').value,
     'questionComment': $('questionComment').value,
     'questionCaptcha': $('questionCaptcha').value,
     'productName': productName,
     'productCode': $('productCode').innerHTML
  });
}

PageClass.prototype.notifyIt = function() {
  var productName;
  $$('h1').each(function(el) {
    productName = el.innerHTML;
  });
  if($('notifyPopup') && $('notifyPopup').style.display == 'block') {
    $$('#notifyPopup div p b').each(function(el) {
      productName = el.innerHTML;
    });
  }
  var code = '';
  if($('productCode')) {
    code = $('productCode').innerHTML;
  }
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
    if(text == 'captcha') {
      $('notifyCaptcha').className = ' inputError';
    }
    else {
      if(typeof pageTracker != 'undefined') {
        pageTracker._trackPageview('http://elektrosvet.cz/ajax.form.zjistit_termin');
      }
      $('notifyForm').style.display = 'none';
      $('notifyMessage').style.display = 'block';
      $('notifyMessage').innerHTML = 'Děkujeme, Vaš dotaz byl právě odeslán';
    }
  }}).post({
     'action':'notifyIt',
     'notifySender': $('notifySender').value,
     'notifyFrom': $('notifyFrom').value,
     'notifyPhone': $('notifyPhone').value,
     'notifyMethod': ($('notifyEmail').checked ? 'email' : 'sms'),
     'notifyCaptcha': $('notifyCaptcha').value,
     'productName': productName,
     'notifyCode': code
  });
}


PageClass.prototype.restoreIt = function() {
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
    if(text == 'captcha') {
      $('restoreCaptcha').className = ' inputError';
    }
    else if(text == 'email') {
      $('restoreEmail').className = ' inputError';
      $('restoreEmailMessage').innerHTML = 'Uživatel tohoto jména nebyl nalezen.';
    }
    else {
      $('restoreForm').style.display = 'none';
      $('restoreMessage').style.display = 'block';
      $('restoreMessage').innerHTML = 'Heslo bylo odesláno na vaší e-mailovou adresu.';
      if(typeof pageTracker != 'undefined') {
        pageTracker._trackPageview('http://elektrosvet.cz/ajax.form.restorePass');
      }
    }
  }}).post({
     'action':'restoreIt',
     'restoreEmail': $('restoreEmail').value,
     'restoreCaptcha' : $('restoreCaptcha').value
  });
}

PageClass.prototype.addWatchDog = function(productId) {
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
    if($('dogForm')) {
      $('dogForm').style.display = 'none';
      $('dogMessage').style.display = 'block';
      $('dogMessage').innerHTML = 'Děkujeme, po změně stavu výrobku, obdržíte e-mail';
      if(typeof pageTracker != 'undefined') {
        pageTracker._trackPageview('http://elektrosvet.cz/ajax.form.watchdog_added');
      }
    }
    if(!$('dogTypeStore')) {
      if(!$('dogTypeStore_' + productId).checked && !$('dogTypePrice_' + productId).checked && !$('dogTypeComment_' + productId).checked) {
        document.location = document.location;
      }
    }
  }}).post({
     'action':'addWatchDog',
     'productId': productId,
     'dogTypeStore': $('dogTypeStore') ? $('dogTypeStore').checked : $('dogTypeStore_' + productId).checked,
     'dogTypePrice': $('dogTypePrice') ? $('dogTypePrice').checked : $('dogTypePrice_' + productId).checked,
     'dogTypeComment': $('dogTypeComment') ? $('dogTypeComment').checked : $('dogTypeComment_' + productId).checked,
     'dogPrice': $('dogPrice').value
  });
}

PageClass.prototype.removeWatchDog = function(productId) {
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
    if(typeof pageTracker != 'undefined') {
      pageTracker._trackPageview('http://elektrosvet.cz/ajax.form.watchdog_removed');
    }
    document.location = document.location;
  }}).post({
     'action':'addWatchDog',
     'productId': productId,
     'dogTypeStore': false,
     'dogTypePrice': false,
     'dogTypeComment': false
  });
}

PageClass.prototype.commentAfterOrder = function() {
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
    if(text == 'captcha') {
      $('commentOrderedCaptcha').className = ' inputError';
    }
    else {
      $('commentOrderedForm').style.display = 'none';
      $('commentOrderedMessage').style.display = 'block';
      $('commentOrderedMessage').innerHTML = 'Děkujeme, Vaše zpráva byla právě odeslána';
      if(typeof pageTracker != 'undefined') {
        pageTracker._trackPageview('http://elektrosvet.cz/ajax.form.comment_after_ordering');
      }
    }
  }}).post({
     'action':'commentAfterOrder',
     'message':  $('commentOrdered').value,
     'captcha' : $('commentOrderedCaptcha').value,
     'orderId' : $('orderId').value
  });
}

PageClass.prototype.printVersion = function() {
  var st = document.createElement("link");
  st.setAttribute("rel", "stylesheet");
  st.setAttribute("media", "screen, projection, print");
  st.setAttribute("href", "/_data/style/print.css");
  document.body.appendChild(st);

  setTimeout('print();', 1000);
}

PageClass.prototype.checkEmailIfExists = function(email) {
  if(this.emailLastTested == email) {
    return false;
  }
  this.emailLastTested = email;
  $('form_email_exists').style.display = 'none';
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(obj, text){
    //$('form_email_exists').style.display = (text ? 'block' : 'none');
  }}).post({'action':'checkEmailIfExists','email': email});
}

PageClass.prototype.cetelemCalc = function(price, isFull) {
  var params = {
     'action':'cetelem',
     'price':price
  };
  if(typeof isFull != 'undefined') {
    params.type = $('cetelemType').value;
    params.insurance = $('cetelemInsurance').value;
    params.firstPayment = $('cetelemFirstPayment').value;
    $$('#cetelemPaymentTypes select', '#cetelemPaymentTypes span').each(function(element) {
      if(element.id.indexOf('cetelemPayments_') > -1 && element.style.display != 'none') {
//        alert(element.style.display);
        params.numPayments = (typeof element.value != 'undefined' && element.value ? element.value : element.innerHTML-0);
      }
    });
    if(!(params.type - 0)) {
      params.type = (params.type == 'Akce 10 x 10' ? 104 : 201); 
    }
    if(params.insurance.length > 2) {
      params.insurance = (params.insurance == 's pojištěním' ? 'A3' : 'B1'); 
    }
    

    $('cetelemResultVyseSplatkyTr').style.display = 'none';
    $('cetelemResultVyseUveruTr').style.display = 'none';
    $('cetelemResultCenaUveruTr').style.display = 'none';
    $('cetelemResultRPSNTr').style.display = 'none';
    if($('cetelemPopup')) {
      $('cetelemPopup').style.height = '';
    }
    if($('cetelemPopup')) {
      //$('cetelemPopup').style.height = '420px';
    }
    if($('cetelemLoader')) {
      $('cetelemLoader').style.display = 'block';
    }
  }
  if($('cetelemPayButton')) {
    $('cetelemPayButton').style.display = 'none';
  }
  if($('cetelemPayAfterButton')) {
    $('cetelemPayAfterButton').style.display = 'none';
  }

  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(result) {
    if(result && result.vyseSplatky > 0) {
      if($('cetelemHolder')) {
        $('cetelemHolder').style.display = 'block';
      }
      if(typeof isFull == 'undefined') {
        if($('cetelemLine')) {
          $('cetelemLine').style.display = 'block';
          $('cetelemSumMonth').innerHTML = result.vyseSplatky;
        }
      } else {
        if($('cetelemLoader')) {
          $('cetelemLoader').style.display = 'none';
        }
        if(result.vyseSplatky) {
          $('cetelemResultVyseSplatky').innerHTML = '';
          var text = document.createTextNode(result.vyseSplatky);
          $('cetelemResultVyseSplatky').appendChild(text);
          //$('cetelemResultVyseSplatky').innerHTML = result.vyseSplatky - 0;
          $('cetelemResultVyseSplatkyTr').style.display = '';
        }
        if(result.vyseSplatky) {
          $('cetelemResultVyseUveru').innerHTML = '';
          var text = document.createTextNode(result.vyseUveru);
          $('cetelemResultVyseUveru').appendChild(text);
          //$('cetelemResultVyseUveru').innerHTML = result.vyseUveru;
          $('cetelemResultVyseUveruTr').style.display = '';
        }
        if(result.cenaUveru) {
          $('cetelemResultCenaUveru').innerHTML = '';
          var text = document.createTextNode(result.cenaUveru);
          $('cetelemResultCenaUveru').appendChild(text);
          //$('cetelemResultCenaUveru').innerHTML = result.cenaUveru;
          $('cetelemResultCenaUveruTr').style.display = '';
        }
        if(result.ursaz) {
          $('cetelemResultUrsaz').innerHTML = '';
          var text = document.createTextNode(result.ursaz);
          $('cetelemResultUrsaz').appendChild(text);
          //$('cetelemResultUrsaz').innerHTML = result.ursaz;
        }
        if(result.RPSN) {
          $('cetelemResultRPSN').innerHTML = '';
          var text = document.createTextNode(result.RPSN);
          $('cetelemResultRPSN').appendChild(text);
          //$('cetelemResultRPSN').innerHTML = result.RPSN;
          $('cetelemResultRPSNTr').style.display = '';

          if(!$('cetelemHolder') && $('cetelemPayButton')) {
            if($('cetelemPayButton')) {
              $('cetelemPayButton').style.display = 'block';
            }
            if($('cetelemPayAfterButton')) {
              $('cetelemPayAfterButton').style.display = 'block';
            }
          }
        }
      }
      if($('cetelemError')) {
        $('cetelemError').style.display = 'none';
      }
      if($('cetelemNextStep')) {
        $('cetelemNextStep').style.display = 'block';
      }
		} else {
      if($('cetelemHolder')) {
        $('cetelemHolder').style.display = 'none';
      }
      if($('cetelemLoader')) {
        $('cetelemLoader').style.display = 'none';
      }
      if($('cetelemError')) {
        $('cetelemError').style.display = 'block';
        $('cetelemError').innerHTML = 'Cena zboží by mělo být více než 3000 Kč';
      }
      if($('cetelemNextStep')) {
        $('cetelemNextStep').style.display = 'none';
      }
		}
  }}).post(params);
}

PageClass.prototype.cetelemTestOrderId = function(orderId) {
  var params = {
     'action':'cetelemTestOrderId',
     'orderId': orderId
  };

  var jsonRequest = new Request.HTML({url: "/ajax.php", onSuccess: function(result, elements, html) {
    if(html-0 > 0) {
      $('cetelemPrice').value = html-0;
      $('orderIdError').style.display = 'none';
    } else if(html-0 < 0) {
      $('orderIdError').innerHTML = 'Nejste přihlášen';
      $('orderIdError').style.display = 'inline';
    } else {
      $('orderIdError').innerHTML = 'Špatné číslo objednávky nebo objednávka patří jinému uživateli';
      $('orderIdError').style.display = 'inline';
    }
  }}).post(params);
}

PageClass.prototype.ccPay = function(price) {
  var params = {
     'action':'ccPay',
     'ccType': $('ccType').value,
     'price':price
  };

  var jsonRequest = new Request.HTML({url: "/ajax.php", onSuccess: function(result, elements, html) {
      var holder = document.createElement('div');
      var reg = /name="merchantref" value="[0-9]+"/;
      var orderId = html.match(reg);
      if(orderId) {
        Page.orderFinishCookie(orderId);
      }
      holder.innerHTML = html;
      $('mother').appendChild(holder);
      holder.firstChild.submit();
  }}).post(params);
}

PageClass.prototype.cetelemPay = function(price, isFull) {
  if($('orderId') && $('orderId').value) {
     Cookie.write('cetelemSent_' + $('orderId').value, 1, {path: '/'});
  }
  var params = {
     'action':'cetelemPay',
     'type': $('cetelemType').value,
     'insurance': $('cetelemInsurance').value,
     'odklad': 0,
     'vyseSplatky': $('cetelemResultVyseSplatky').innerHTML,
     'cenaUveru': $('cetelemResultCenaUveru').innerHTML,
     'ursaz': $('cetelemResultUrsaz').innerHTML,
     'RPSN': $('cetelemResultRPSN').innerHTML,
     'price':price
  };
  var jsonRequest = new Request.HTML({url: "/ajax.php", onSuccess: function(result, elements, html) {
      var holder = document.createElement('div');
      holder.innerHTML = html;
      $('mother').appendChild(holder);
      holder.firstChild.submit();
/*
    if(result[0]['textContent'] && result[1]['textContent']) {
        form = document.createElement('form');
        form.className = 'hide';
        form.action = result[0]['textContent'];
        form.method = 'post';
        var inp = document.createElement('textarea');
//        inp.type = 'hiden';
        inp.name = 'data';
        inp.value = result[1]['textContent'];
        form.appendChild(inp);
        alert(result[1].innerHTML);
        $('mother').appendChild(form);
//        form.submit();
      }
*/
  }}).post(params);
}

PageClass.prototype.cetelemJustMail = function() {
    document.location = '/splatkovy-prodej-formular/?orderId=' + this.orderId;
}

PageClass.prototype.showOverlay = function() {
  if(!$('popupOverlay')) {
    var overlay = document.createElement('div');
    overlay.id = 'popupOverlay';
    overlay.onclick = function() {Page.closePopupAll(); this.style.display = 'none';  return false;}
    $('mother').parentNode.appendChild(overlay);
  }
  $('popupOverlay').style.display = 'block';
}

PageClass.prototype.affilateShowTable = function(table) {
  $$('#cart div[id^=affilateTable]').each(function(tab) {
    tab.style.display = 'none';
  });
  if($('affilateTable' + table)) {
    $('affilateTable' + table).style.display = 'block';
  }
  document.location.hash = 'affilateTables';
}

PageClass.prototype.affilateShowPayForm = function() {
  //$('detail-tabs').style.display = 'none';
  //$('tab-content').style.display = 'none';
  $('affilatePaymentButton').style.display = 'none';  
  $('affilateForm').style.display = 'block';  
  document.location.hash = 'affilatePayment';
}

PageClass.prototype.affilateChangePayment = function(payment) {
    $$('#affilateForm form input').each(function(input) {
      input.disabled = true;
    });
  $$('#affilateForm div[id^=affilatePayment]').each(function(div) {
    div.style.display = 'none';
  });
  if($('affilatePayment' + payment)) {
    $('affilatePayment' + payment).style.display = 'block';
    $$('#affilatePayment' + payment + ' input').each(function(input) {
      input.disabled = false;
    });
  }  
  $('affilatePaymentPay').style.display = 'block';
}

PageClass.prototype.affilatePay = function() {
  var method = '';
  if($('Fakturace').checked) method = 'fakturace';
  if($('Slozenka').checked) method = 'slozenka';
  if($('Bank').checked) method = 'bank';
  if(!method) return false;
  
  var params = {
    'action':'affilatePay',
    'method':method,
    'bankAccaunt':$('affilatePaymentBankNumber').value,
    'slozenkaFirstname':$('affilatePaymenSlozenkaFirstname').value,
    'slozenkaSurname':$('affilatePaymenSlozenkaSurname').value,
    'slozenkaStreet':$('affilatePaymenSlozenkaStreet').value,
    'slozenkaCity':$('affilatePaymenSlozenkaCity').value,
    'slozenkaZip':$('affilatePaymenSlozenkaZip').value
  };
  
  $('affilateErrorMessage').style.display = 'none';
  var jsonRequest = new Request.HTML({url: "/ajax.php", onSuccess: function(tree, list, html) {
    if(html) {
      switch(html) {
        case 'Variable is not a positive integer ("0" is integer)': $('affilateErrorMessage').innerHTML = 'Částka platby musí být větší než 0'; break;
        case 'Wrong account number! It shall be formated like \'account/bankcode\' or use IBAN.': $('affilateErrorMessage').innerHTML = 'Číslo účtu musí být uvedeno přesně ve tvaru: předčíslí-matrika/kód banky'; break;
        default: $('affilateErrorMessage').innerHTML = 'Neznámá chyba';
      }
      $('affilateErrorMessage').style.display = 'block';
    } else {
      $('affilateOkMessage').style.display = 'block';
      $('obrat').style.display = 'none';
      $('affilateText').style.display = 'none';
      $('detail-tabs').style.display = 'none';
      $('tab-content').style.display = 'none';
      $('detail-right').style.display = 'none';
      $('affilateForm').style.display = 'none';
      document.location.hash = 'affilateMessage';
    }
  }}).post(params); 
}

PageClass.prototype.hideOverlay = function() {
  $('popupOverlay').style.display = 'none';
  this.closePopupAll();
}

PageClass.prototype.closePopup = function(el) {
  if(typeof el == 'string') {
    $(el).style.display = 'none';
  } else {
    el.style.display = 'none';
  }
  this.hideOverlay();
  if(document.location.href.indexOf('informace-o-vas') > -1 && !$('restorePopup')) {
    document.location = document.location;
  }
}

PageClass.prototype.closePopupAll = function(el) {
  $$('div').each(function(el) {
    if(
      (el.parentNode.id == 'detail' && el.className.indexOf('basePopup') > -1  && el.style.display == 'block') ||
      el.id == 'downloadPopup' ||
      el.id == 'basketAddedPopup' ||
      el.id == 'ccPopup' ||
      el.id == 'cetelemPopup' || 
      el.id == 'dostupnostPopup' || 
      el.id == 'notifyPopup' || 
      el.id == 'restorePopup'
    ) {
      el.style.display = 'none';
    }
  });
}

PageClass.prototype.brandsUncheck = function() {
    $$('#trade input[id^=filterProducer_]', '#trade input[id^=filterCategory_]').each(function(element) {
      if(element.id != 'filterProducer_all' && element.id != 'filterCategory_all') {
        element.checked = false;
      }
    });
}

PageClass.prototype.comparsionChangeProducer = function(who) {
    $$('#comparsionAddForm select[id^=productSelect_]').each(function(element) {
      element.style.display = (element.id == 'productSelect_'+who ? 'block' : 'none');
      element.disabled = (element.id == 'productSelect_'+who ? false : true);
    });
}

PageClass.prototype.slideOut = function(holder, checkbox, height) {
    var myEffect = new Fx.Morph(holder, {transition: Fx.Transitions.Sine.easeOut});
    if(checkbox.checked) {
      myEffect.start({'height': [0, height]});
    } else {
      myEffect.start({'height': [height, 0]});
    }
}

PageClass.prototype.searchHelperInit = function(search_query) {
  search_query = search_query.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  if(this.searchHelperLast == search_query) {
    return false;
  }
  this.searchHelperLast = search_query;
  this.searchHelperRemove();
  this.searchHelperTimeout = setTimeout('Page.searchHelperShow()', 500);
}

PageClass.prototype.searchHelperRemove = function() {
  if(this.searchHelperTimeout) {
    clearTimeout(this.searchHelperTimeout);
  }
}

PageClass.prototype.searchHelperShow = function() {
  if(this.searchHelperInProgress) {
    this.searchHelperInit($('searchQuery').value);
    return false;
  }
  this.searchHelperInProgress = true;
  if(!$('searchHelper')) {
    var holder = document.createElement('ul');
    holder.id = 'searchHelper';
    $('mother').appendChild(holder);
  } else {
    holder = $('searchHelper');
    holder.innerHTML = '';
  }
  holder.className = 'loader';
  holder.style.display = 'block';
  holder.style.height = '132px';
  var reg = /([0-9]+)([0-9]{3})(,[0-9]{2})?/;
  var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(result) {
      if(!result) {
        holder.style.display = 'none';
        Page.searchHelperInProgress = false;
        return false;
      }
      holder.innerHTML = '';
      var line, a, span;
      holder.style.height = '';
      holder.className = '';
      for(var i=0; i<result.list.length; i++) {
        line = document.createElement('li');
        a = document.createElement('a');
        a.href = result.list[i].url;
        a.innerHTML = result.list[i].full_name_cs;
        span = document.createElement('span');
        span.className = 'red';
        span.innerHTML = new String(result.list[i].price_vat).replace(reg, '$1.$2$3') + '  Kč';
        line.appendChild(span);
        line.appendChild(a);
        holder.appendChild(line);
      }
      line = document.createElement('li');
      a = document.createElement('a');
      a.href = 'javascript:void(0)';
      a.innerHTML = 'zavřít';
      a.onclick="function() {$('searchHelper').style.display = 'none';}";
      line.className = 'close';
      line.appendChild(a);
      holder.appendChild(line);
      Page.searchHelperInProgress = false;
    }}).post({'action':'search', 'search_query':$('searchQuery').value}); 
}

PageClass.prototype.showAffilateCode = function(type, object, affilateCode) {
  var code = '';
  if(!type) {
    if($('codeIndex').checked)    type = 'codeIndex';
    if($('codeCategory').checked) type = 'codeCategory';
    if($('codeProducer').checked) type = 'codeProducer';
    if($('codeProduct').checked)  type = 'codeProduct';
  }
  $('codeError').style.display = 'none';
  $('codeExampleProduct').style.display = 'none';
  $('codeExampleProducer').style.display = 'none';
  $('codeExampleCategory').style.display = 'none';
  switch(type) {
    case 'codeIndex':
      code  = '<a href="http://' + document.location.host + '/?affilateCode=' + affilateCode + '" title="Elektrosvet.cz">';
      code += '<img src="http://' + document.location.host + '/_data/images/logo.png" width="175" height="82" alt="" title="ElektroSvět.cz - expert na bílé zboží, elektroniku, spotřebiče">';
      code += '</a>';
      $('codeObjectHolder').style.display = 'none';
      $('codeHolder').style.display = 'block';
      $('codeExample').style.display = 'block';
      $('codeExampleTitle').style.display = 'block';
      $('codeInput').value = code;
      $('codeExample').innerHTML = code;
      break;
    case 'codeCategory':
    case 'codeProducer':
      if(object) {
        var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(result) {
          if(!result) {
            $('codeError').style.display = 'block';
            return false;
          }
          code  = '<p><a href="http://' + result.url + '/?affilateCode=' + affilateCode + '" title="' + result.name + ' — Elektrosvet.cz">';
          code += result.name + ' — Elektrosvet.cz</a></p>';
          $('codeHolder').style.display = 'block';
          $('codeExample').style.display = 'block';
          $('codeExampleTitle').style.display = 'block';
          $('codeInput').value = code;
          $('codeExample').innerHTML = code;
        }}).post({'action':type, 'url':object}); 
      } else {
        if(this.affilateCodePrevious != type) {
          $('codeObject').value = '';
        }
      }
      $('codeObjectHolder').style.display = 'block';
      $('codeObjectTitle').innerHTML = 'Zadejte URL-adresa ' + (type == 'codeCategory' ? 'kategorie:' : 'výrobce:');
      if(type == 'codeCategory') {
        $('codeExampleCategory').style.display = 'block';
      } else {
        $('codeExampleProducer').style.display = 'block';
      }
      break;
    case 'codeProduct':
      if(object) {
        var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(result) {
          if(!result) {
            $('codeError').style.display = 'block';
            return false;
          }
          code  = '<iframe width="250" height="225" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://' + document.location.host + '/code/product/' + result.id + '/"></iframe><br />';
          code += '<div style="width:250px;"><small><a href="' + object + '?affilateCode= ' + affilateCode + ' " style="color:#4C78A2;text-align:left;">' + result.name + '</a></small></div>';
          $('codeHolder').style.display = 'block';
          $('codeExample').style.display = 'block';
          $('codeExampleTitle').style.display = 'block';
          $('codeInput').value = code;
          $('codeExample').innerHTML = code;
        }}).post({'action':'codeProduct', 'url':object}); 
      } else {
        if(this.affilateCodePrevious != type) {
          $('codeObject').value = '';
        }
      }
      $('codeObjectHolder').style.display = 'block';
      $('codeObjectTitle').innerHTML = 'Zadejte URL-adresa výrobku:';
      $('codeExampleProduct').style.display = 'block';
      break;
  }
  if(!code) {
    $('codeHolder').style.display = 'none';
    $('codeExample').style.display = 'none';
    $('codeExampleTitle').style.display = 'none';
  }
}

PageClass.prototype.showProductHeader = function() {
  var height = 0;
  $$('h1').each(function(el) {
    var oldHeight = el.style.height;
    el.style.paddingLeft = '248px';
    el.style.width = '720px';
    el.style.textIndent = '0';
    el.style.height = 'auto';
    height = el.offsetHeight;
    if(!height || height == 25) {
      el.style.height = oldHeight+'px';
      return false;
    }
  });
  if((10+height-25) > 0)  {
    $('detail-left').style.paddingTop = (10+height-25)+'px';
  }
//  $('desc').style.marginTop = (230+height-25)+'px';
  $('desc').style.marginTop = (210+height-25)+'px';
  if($('iconsHolder')) {
    $('iconsHolder').style.marginTop = (-19+height-25)+'px';
  }
//  $('iconsHolder').style.marginTop = (-2+height-25)+'px';
}

PageClass.prototype.commentLines = function(holder) {
    var oldParent = '';
    $$('#'+holder+' ul li ul li').each(function(li) {
  		if(li.id && li.id.indexOf('commentHolder') > -1) {
  	    var div = document.createElement('div');
	      div.style.position = 'absolute';
      	div.style.width = '40px';
    	  div.style.height = '20px';
  	    div.style.margin = '-10px 0 0 -50px';
	      div.style.borderBottom = '1px dashed #CBD0DE';
      	li.insertBefore(div, $(li.id.replace('commentHolder', 'commentHolderTitle')));
			}
      if(li.nextSibling.nextSibling == null) {
         	div.style.borderLeft = '1px dashed #CBD0DE';
      } else {
          li.style.borderLeft = '1px dashed #CBD0DE';
          li.style.paddingLeft = '50px';
      }
      //li.appendChild(div);
    });
}

PageClass.prototype.saveBasketLink = function() {
	var domain = Page.domain.replace('www.', '');
	var domain = Page.domain.match(/elektrosvet\.[a-z]{2,6}/);
	Cookie.write('elBasketLink', document.location.href, {path: '/', 'domain': '.'+domain});
}

PageClass.prototype.improveGuides = function() {
	var normal = 0;
	var lastParam = new Array();
	var firstParam = true;
	$$('div#guide ul').each(function(el) {
		if(el.childNodes[1] && el.childNodes[1].innerHTML.indexOf('<b>&nbsp;</b>') == -1)  {
			if(lastParam.length) {
				firstParam = false;
			}
			lastParam = new Array();
		} 
		lastParam.push(el);
		if(!normal) {
			normal = el.offsetTop;
		} else {
			if(normal != el.offsetTop && !firstParam) {
				for(var i=0; i<lastParam.length; i++) {
					lastParam[i].style.display = 'none';
				}
			}
		}
	});
}

PageClass.prototype.changeProductsPerPage = function(value) {
		if(value % 3) {
			return false;
		}
		Cookie.write('productsPerPage', value, {'path':'/', 'domain': Page.domain, 'duration': 365});
		document.location = document.location;
}

PageClass.prototype.visitedProductsClear = function() {
		Cookie.write('VisitedProducts', '', {'path':'/', 'domain': Page.domain, 'duration': 365});
		Cookie.dispose('VisitedProducts');
		$('visitedProducts').setStyle('display', 'none');
}

PageClass.prototype.bannerLeftClose = function() {
		$('bannerLeft').setStyle('display', 'none');
		Cookie.write('bannerLeftHidden', 1, {'path':'/', 'domain': Page.domain, 'duration': 365});
}


PageClass.prototype.findPosX = function(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
    do {
        curleft += obj.offsetLeft;
    } while (obj = obj.offsetParent);
    }
    return curleft;
}

PageClass.prototype.findPosY = function(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
    do {
        curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
    }
    return curtop;
}

function turnOff() {
    document.getElementById('user-menu').style.display = 'none';
}
function turnOn() {
    document.getElementById('user-menu').style.display = 'block';
}

function moveCommentForm(id) {
	document.location.hash = 'commentForm';
/*
  var formHolder = document.getElementById('form');
  var oldParent = formHolder.parentNode;
  var commHolder = document.getElementById('commentHolder' + id);
  if(formHolder && commHolder) {
    formHolder.style.marginLeft = '5px';
    formHolder.style.borderTop = '2px solid #756672';
    formHolder.style.paddingBottom = '15px';
    commHolder.appendChild(formHolder);
    document.getElementById('commentHidden').value = id;
    document.location.hash = '#c' + id;
  }
*/
}

var Page = new PageClass();

//document.documentElement.onkeypress(el) {
//  alert(el);
//}