﻿$(document).ready(function(){

	if ($("a[rel^='lightbox']").length >= 1) {
		$("a[rel^='lightbox']").prettyPhoto({
			animationSpeed: 'fast', /* fast/slow/normal */
			padding: 0, /* padding for each side of the picture */
			opacity: 0.8, /* Value betwee 0 and 1 */
			showTitle: true, /* true/false */
			allowresize: true, /* true/false */
			counter_separator_label: ' z ' /* The separator for the gallery counter 1 "of" 2 */
		});
	};	
	$(".chooseBox1").click(function () {
		$("#descriptionBox1").toggle("slow");
		$("#loginBox1").toggle("slow");
		
		$("#chooseBox1a").toggle("slow");
		$("#chooseBox1b").toggle("slow");
	});
	
	$(".chooseBox2").click(function () {
		$("#descriptionBox2").toggle("slow");
		$("#loginBox2").toggle("slow");
		
		$("#chooseBox2a").toggle("slow");
		$("#chooseBox2b").toggle("slow");
	});
	
	
	$('#submitForm').click(function() {
	
		$('#LoginForm').attr('target', '_blank')
		$('#LoginForm').attr('action', 'http://webshop.floraplaza.nl/kbtipro/default.asp')
		$('#LoginForm').submit()
		
		$('#LoginForm').attr('target', '_blank')
		$('#LoginForm').attr('action', 'http://shop.flowersviainternet.net/checklogin.asp')
		$('#LoginForm').submit()
	
	});
	
	$('.prohlidka1').click(function () {
		$("#prohlidka1").show();
		$("#prohlidka2").hide();
	});
	$('.prohlidka2').click(function () {
		$("#prohlidka1").hide();
		$("#prohlidka2").show();
	});
	
	
	/*
	$("#goodsListPotted table tr[id^='store']").click(function(){
		idNumber = this.id.substring(5,this.id.length);
		storeNumber = $('#' + this.id + ' .' + this.id).html();
		valueNumber = $('#input' + idNumber).attr('value');
		allNumber = storeNumber - valueNumber

		if (allNumber < 0) {
			alert('Objednat můžete maximálně počet kusů, který máme na skladě')
			$('#input' + idNumber).attr('value', storeNumber)
		}

	});
	*/
// CHECKBOXY V KOSIKU

	//OZNACENI CHECKBOXU U DOPRAVY PO KLIKU NA LI A PRIDANI AKTIVNOSTI
	$("#basketContent li[id^='li.Transfer']").click(function(){
		
		$('ul.transfer li.clearfix').removeClass('act');
		$(this).addClass('act');
		$(this).find('input').attr('checked', 'checked')
	
		TransferID = this.id.replace('li', 'basket')
		
		// VSECHNY ZAKAZEME
		$("#basketContent input:radio[id^='basket.Payment']").each(function(index, htmlObject){
			htmlObject.disabled = true;

			$(htmlObject).parent().get(0).className='pDisabled clearfix';//.addClass("pDisabled");
		});
		
		// POKUD JE NEAKTIVNI A JE CHECKED => ODEBER MU JEJ
		$("#basketContent input:radio[id^='basket.Payment']").each(function(index, htmlObject){
			if(htmlObject.disabled && htmlObject.checked)
				htmlObject.checked = false;
		});

		// ZAKTIVNIME POVOLENE
		$("#basketContent input:radio[class*='"+TransferID+"']").each(function(index, htmlObject){
			htmlObject.disabled = false;

			$(htmlObject).parent().get(0).className='clearfix';
			//$(htmlObject).parent().removeClass("pDisabled");
		});
		
		PrepocetCenyVKosiku(this, null);
	});
	
	//SLOZENI CENY PO KLIKU NA LI U PLATBY
	$("#basketContent li[id^='li.Payment']").click(function(){
		//ZJISTENI ZASKRKLEHO CHECKBOXU U DOPRAVY
		$("li[id^='li.Transfer']").each(function() {
			
			if ($(this).find('input.transferChecked').attr('checked') == true) {
				transport = this
			}
			
		});
		
		PrepocetCenyVKosiku(transport, this);
	});
});

//ZANECHANI AKTIVNOSTI NA LI, PO REFRESI A ZANECHANI PRISLUSNE CENY ZA DOVOZ A PLATBU - STEJNA FUNKCE VYSSE AKORAT NA KLIK! (FUNKCE SE VOLA V BASKET/DOPRAVA-A-PLATBA.WP)
function recountPaymentAndTransfer(){

	//PROCHAZENI CHECKBOXU U DOPRAVY
	$("#basketContent li[id^='li.Transfer']").each(function() {
		if ($(this).find('input.transferChecked').attr('checked') == true) {
			$(this).addClass('act')
			
			PrepocetCenyVKosiku(this, null);	
		}
	});
	
	//PROCHAZENI CHECKBOXU U PLATBY
	$("#basketContent li[id^='li.Payment']").each(function(){
		if ($(this).find('input.paymentChecked').attr('checked') == true) {
			$(this).addClass('act')
			
			//SLOZENI CENY
			//ZJISTENI ZASKRKLEHO CHECKBOXU U DOPRAVY
			$("li[id^='li.Transfer']").each(function() {
			
				if ($(this).find('input.transferChecked').attr('checked') == true) {
					transport = this
				}
			});
			
			PrepocetCenyVKosiku(transport, this);
		}
	});
}

function PrepocetCenyVKosiku(transport, payment) {
	thisTransferPrice = $(transport).find('.inputTransfer').attr('value');
	thisTransferPriceWithout = Math.abs((thisTransferPrice.substring(0, thisTransferPrice.indexOf('-'))).replace(',','.'));
	thisTransferPriceWith = Math.abs((thisTransferPrice.substring(thisTransferPrice.indexOf('-') + 1)).replace(',','.'));
	
	if(payment) {
		thisPaymentPrice = $(payment).find('.inputPayment').attr('value');
		thisPaymentPriceWithout = Math.abs((thisPaymentPrice.substring(0, thisPaymentPrice.indexOf('-'))).replace(',','.'));
		thisPaymentPriceWith = Math.abs((thisPaymentPrice.substring(thisPaymentPrice.indexOf('-') + 1)).replace(',','.'));
	} else {
		thisPaymentPriceWithout = 0
		thisPaymentPriceWith = 0
	}

	//NAPLNENI TABULKY SLOZENOU CENOU
	$("td.transfer").html((thisPaymentPriceWithout + thisTransferPriceWithout).toFixed(2));
	$('td.transfer').priceFormat();
	$("td.transferVat").html((thisPaymentPriceWith + thisTransferPriceWith).toFixed(2));
	$('td.transferVat').priceFormat();
	$("td.totalPrice").html("<strong>" + (thisPaymentPriceWithout + thisTransferPriceWithout + goodsPrice).toFixed(2) + "</strong>");
	$('td.totalPrice strong').priceFormat();
	$("td.totalPriceVat").html("<strong>" + (thisPaymentPriceWith + thisTransferPriceWith + goodsPriceVat).toFixed(2) + "</strong>");
	$('td.totalPriceVat strong').priceFormat();
}


//OZNACENI CHECKBOXU U PLATBY PO KLIKU NA LI A PRIDANI AKTIVNOSTI
function addClassPayment(li){
	$('ul.payment li.clearfix').removeClass('act');
	$(li).addClass('act');
	
	//ODSTRANENI AKTIVNOSTI POKUD JE CHECKBOX DISABLED
	$(li).find('input').attr('checked', 'checked').each(function(index, htmlObject){
		if(htmlObject.disabled && htmlObject.checked) {
			$(li).removeClass('act');
			htmlObject.checked = false;
		}
	});
}

// PREPOCITANI CENY V KOSIKU

function UpdateBasket(sender, args) {

	// ZISKANI NADRAZENEHO FORMULARE
    var form1 = $(sender).parents('form:first').get(0);

	$.post(
		"/ajax-basket",
		$(form1).find("input.recount").serializeArray(),
		
		function(data){

			$.get(
				"/ajax-basket-info",
				function(data){
					$("#basket-info").html(data);
				}
			);
		}
	);
}

// KONTROLA HODNOT JESTLI NENI OBJEDNANO VIC KUSU, NEZ JE NA SKLADE

function CheckStock(input, stock) {
	if(stock >= 0) {
		if(input.value > stock) {
			input.value = stock;
			alert('Objednat můžete maximálně počet kusů, který máme na skladě.')
		}
	}
}
// PO KLIKU DO INPUTU SE MI VYPRAZNI HODNOTA VALUE - (fragments/eshop-department.wp)

function RemoveZero(input) {
	if(input.value==0) {
		input.value="";
	}
}
function IsDigit() {
  return (((event.keyCode >= 48) && (event.keyCode <= 57)) || (event.keyCode == 32) || (event.keyCode == 43));
}

// POSILANI DO KOSIKU POUZE NENULOVYCH PRVKU - (fragments/eshop-department.wp)

function SubmitBasket() {
	$("form#basket input[id^='input']").each(function() {
		if ($(this).attr('value') == '0') {
			$(this).attr('value', '')
		}
		
	});
}

function showListGoodsCupPicture(ean) {

	$(document).ready(function(){
		actualPosition = ($(window).width() - 980) / 2
	
		var imageHeight = Math.abs(document.getElementById('listCupVisible' + ean).clientHeight) / 2;
	
		$(".rollPicture").mouseover(function(e){
			
			if ((e.clientY - imageHeight - 10) < 0) {
				$("#ListGoodsCupPictureVisible").find('#listCupVisible' + ean).css('top', e.pageY)
				
			} else if ((e.clientY + imageHeight + 10) < $(window).height()) {
				$("#ListGoodsCupPictureVisible").find('#listCupVisible' + ean).css('top', e.pageY - imageHeight)
				
			} else {
				$("#ListGoodsCupPictureVisible").find('#listCupVisible' + ean).css('top', e.pageY - (imageHeight * 2))
				
			}
			$("#ListGoodsCupPictureVisible").find('#listCupVisible' + ean).css('left', e.pageX - actualPosition + 40)

		});
	});
	document.getElementById('listCupVisible' + ean).style.visibility = 'visible';
}


function hideListGoodsCupPicture(ean) {

	document.getElementById('listCupVisible' + ean).style.visibility = 'hidden';

}
