﻿ $(document).ready(function() {
	//hide elements
								
	$("#results").hide();
	// calendat add
	$("input.dateinput").datepicker();
   	//globals
	var errorPrint = false;
//	var roomType = 0;
	var letDay = 0;
	var zimDay = 0; 
	var silDay = 0;
	var svaDay = 0;
	var pocetDnu = 0;
	var quote = 1;
	var oboje = 0;
	var count = 0;
	//ceny
	var single = new Array(4);
	var double = new Array(4);
	var triple = new Array(4);
	var quadro = new Array(4);
	var doubleVIP = new Array(4);
	var tripleVIP = new Array(4);
	
	single[0] = 1890;
	double[0] = 2310;
	triple[0] = 3150;
	quadro[0] = 3990;
	doubleVIP[0] = 2800;
	tripleVIP[0] = 3700;
	
	single[1] = 1300;
	double[1] = 1700;
	triple[1] = 2450;
	quadro[1] = 2980;
	doubleVIP[1] = 2100;
	tripleVIP[1] = 2800;
	
	single[3] = 3800; 
	double[3] = 3800;
	triple[3] = 5300;
	quadro[3] = 6360;
	doubleVIP[3] = 4500;
	tripleVIP[3] = 5760;
	
	single[2] = 2100;
	double[2] = 2500;
	triple[2] = 3500;
	quadro[2] = 4300;
	doubleVIP[2] = 3100;
	tripleVIP[2] = 4100;

	function resPrint(x,y,z,u) {
		$("#results").animate({ height: 'hide', opacity: 'hide' }, 'fast');
		$("#results").empty();
		//výstupy
		$("#results").append("<p>Days: " +pocetDnu +"</p>");
		if (quote != 1) {
			var q = quote;
			var sleva = Math.round(100 - q * 100)
			$("#results").append("<p>Price: " +count+",- Kč </p>");
			$("#results").append("<p>Kids: " +oboje +" </p>");
			$("#results").append("<p>Kids sale: " +sleva +"%</p>");
			
			//$("#results").append("<p><strong>" +q +"</strong></p>");
			};
		
		var final = Math.round(count * quote);
		
		$("#results").append("<p class=\"finalprice\">Final price:<strong> " + final +",- Kč </strong></p>");
		
		//$("#results").append("<p>Výpis vstupů: " +x +" " +y +" "+z +" " +u +" </p>");
		//zobrazení výsledků
		$("#results").animate({ height: 'show', opacity: 'show' }, 'slow');
		
	};
	
	function resError(a) {
		var hlaska = a;
		$("#results").animate({ height: 'hide', opacity: 'hide' }, 'fast');
		$("#results").empty();
		$("#results").append(hlaska);
		//zobrazení výsledků
		$("#results").animate({ height: 'show', opacity: 'show' }, 'slow');
	};
	
	$("#spocitej").click(function() {
		letDay = 0;
		zimDay = 0; 
		silDay = 0;
		svaDay = 0;
		pocetDnu = 0;
		var to = new Date(document.calc.to.value);	
		var since = new Date(document.calc.since.value);
		var msPerDay = 24 * 60 * 60 * 1000 ;
		var daysUp = ( to.getTime() - since.getTime() ) / msPerDay;
		daysUp = Math.round(daysUp) - 1;//		
		var poleDays = new Array();
	//vytvorí pole dní
		for (i = 0; i <= daysUp;i++) {
			poleDays[i] = since.getTime() + msPerDay * i;
				}
		pocetDnu = poleDays.length;
	//	document.getElementById("dny").innerHTML = pocetDnu;
		
		if( pocetDnu >= 1 ) {
		for (i = 0; i <= daysUp;i++) {
			var thisDay = new Date();
			thisDay.setTime(poleDays[i]);
			var thisYear = thisDay.getYear();
			var thisDate = thisDay.getDate();
			var thisMonth = thisDay.getMonth() + 1;
			
//velikonoce	
				if ( thisMonth == 3 && thisDate >= 21 && thisDate <= 23 || thisMonth == 5 && thisDate >= 1 && thisDate <= 3 || thisMonth == 12 && thisDate >= 25 && thisDate <= 26 ) {
				svaDay++;
				}
				
				// velikonoce
				else if ( thisYear == 108 && thisMonth == 3 && thisDate >= 21 && thisDate <= 23 || thisYear == 109 && thisMonth == 4 && thisDate >= 10 && thisDate <= 12 || thisYear == 110 && thisMonth == 4 && thisDate >= 2 && thisDate <= 4 || thisYear == 111 && thisMonth == 4 && thisDate >= 22 && thisDate <= 24 || thisYear == 112 && thisMonth == 4 && thisDate >= 6 && thisDate <= 8 || thisYear == 113 && thisMonth == 3 && thisDate >= 29  || thisYear == 114 && thisMonth == 4 && thisDate >= 18 && thisDate <= 20 || thisYear == 115 && thisMonth == 4 && thisDate >= 3 && thisDate <= 5 || thisYear == 116 && thisMonth == 3 && thisDate >= 25 && thisDate <= 27 || thisYear == 117 && thisMonth == 4 && thisDate >= 14 && thisDate <= 16 || thisYear == 118 && thisMonth == 3 && thisDate >= 30 || thisYear == 118 && thisMonth == 4 && thisDate <= 1 || thisYear == 119 && thisMonth == 4 && thisDate >= 19 && thisDate <= 21 || thisYear == 120 && thisMonth == 4 && thisDate >= 10 && thisDate <= 12  ) {
				svaDay++;
				}
				
				
				// svátky
				/*if ( thisMonth == 3 && thisDate >= 21 && thisDate <= 24 || thisMonth == 5 && thisDate >= 1 && thisDate <= 4 || thisMonth == 12 && thisDate >= 25 && thisDate <= 27) {
				svaDay++;
				}
// velikonoce
				else if ( thisYear == 108 && thisMonth == 3 && thisDate >= 21 && thisDate <= 24 || thisYear == 109 && thisMonth == 4 && thisDate >= 10 && thisDate <= 13 || thisYear == 110 && thisMonth == 4 && thisDate == 5 || thisYear == 111 && thisMonth == 4 && thisDate == 25 || thisYear == 112 && thisMonth == 4 && thisDate == 9 || thisYear == 113 && thisMonth == 4 && thisDate == 1 || thisYear == 114 && thisMonth == 4 && thisDate == 21 || thisYear == 115 && thisMonth == 4 && thisDate == 6 || thisYear == 116 && thisMonth == 3 && thisDate == 28 || thisYear == 117 && thisMonth == 4 && thisDate == 17 || thisYear == 118 && thisMonth == 4 && thisDate == 2 || thisYear == 119 && thisMonth == 4 && thisDate == 22 || thisYear == 120 && thisMonth == 4 && thisDate == 13  ) {
				svaDay++;
				}*/
				
				
				
				
				
				else if (thisMonth == 12 && thisDate >= 28 || thisMonth == 1 && thisDate <= 3) { silDay++; }
				else if (thisMonth > 3 && thisMonth < 11 || thisMonth == 3 && thisDate > 25 || thisMonth == 11 && thisDate < 10 ) { letDay++;	}
				else { zimDay++; }
			};
			countIt();
		}
		else {
			var hlaska = "<p>wrong date</p>";
			resError(hlaska);
			};
				
		});
	
	
	
	function setQuote () {
		roomType = document.calc.pokoj.value
		var maly = parseInt(document.calc.deti1.value);
		var mensi = parseInt(document.calc.deti2.value);
		oboje = maly + mensi;
		 
		var detiMax = 0;
		switch(roomType) {
		   case '0':
			 detiMax = 0;
			 break;
		   case '1':
			 detiMax = 1;
			 break;
		   case '2':
			 detiMax = 2;
			 break;
		   case '3':
			 detiMax = 3;
			 break;
		   case '4':
			 detiMax = 1;
			 break;
		   case '5':
			 detiMax = 2;
			 break;
		 };
		
		 if ( oboje > detiMax ) {
			
			var hlaska = "<p>wrong children</p>";
			resError(hlaska);
		 } else {
			 
			 
			  if ( roomType == 0 ){
				
				
				quote = 1;
					}
			 
			 else if ( roomType == 1 || roomType == 4 ) {
				
				var deti = 2 - 0.5 * maly - 1 * mensi
				quote = deti / 2;
					}
					
			else if ( roomType == 2 || roomType == 5 ) {
				
				var deti = 3 - 0.5 * maly - 1 * mensi
				quote = deti / 3;
				
					}
			else if ( roomType == 3 ) {
				
				var deti = 4 - 0.5 * maly - 1 * mensi
				quote = deti / 4;
				
					};
		
		countIt();
			 };
		};
	
	
	function countIt () {
		
		var roomType = document.calc.pokoj.value
	if ( roomType == 0 ) {
	count = letDay * single[0] + zimDay * single[1] + svaDay * single[2] + silDay * single[3];
		
	}
	
	else if ( roomType == 1 ) {
	count = letDay * double[0] + zimDay * double[1] + svaDay * double[2] + silDay * double[3];
	}
	else if ( roomType == 2 ) {
	count = letDay * triple[0] + zimDay * triple[1] + svaDay * triple[2] + silDay * triple[3];
	}
	else if ( roomType == 3 ) {
	count = letDay * quadro[0] + zimDay * quadro[1] + svaDay * quadro[2] + silDay * quadro[3];
	}
	else if ( roomType == 4 ) {
	count = letDay * doubleVIP[0] + zimDay * doubleVIP[1] + svaDay * doubleVIP[2] + silDay * doubleVIP[3];
	}
	else if ( roomType == 5 ) {
	count = letDay * tripleVIP[0] + zimDay * tripleVIP[1] + svaDay * tripleVIP[2] + silDay * tripleVIP[3];
	
	}
	resPrint();
	}
	
	
	/*
	$("input.dateinput").change(function () {
          var str = "";
          $("select option:selected").each(function () {
                str += $(this).text() + " ";
              });
          $("div").text(str);
        })
        .change();
		
		 $("button").click(function () {
      $(this).replaceWith("<div>" + $(this).text() + "</div>");
    });
		
	*/
	
	
	
	$("#kids-chb").toggle(function(){
    	$("#st3").animate({ height: 'show', opacity: 'show' }, 'slow');
	}, function(){
     	$("#st3").animate({ height: 'hide', opacity: 'hide' }, 'slow');
	});
	
	$(".calculatorstep").hover(function() {
     $(this).addClass("yellow-bg");
   },function(){
     $(this).removeClass("yellow-bg");
   });
   
	
   
   
   
   
   
   
      
 });
   
   