function getDay(date) {
	var result=date.split(new RegExp("\. {1}"));
//	console.debug(date + " -> " + result[0]);
	return result[0];
}

function getMonth(date){
	var result=date.split(new RegExp("\. {1}"));
// console.debug(date + " -> " + result[1]);
	return result[1];
}


function getYear(date){
	var result=date.split(new RegExp("\. {1}"));
//	console.debug(date + " -> " + result[2]);
	return result[2];
}

function swap(el, val) {
   var box = getElem(el);
   if(val=='date'){
      addClass(box, 'visible')
   } else {
      remClass(box, 'visible');
   }
}

function swap2(el, val) {
   var box = getElem(el);
   if(val==''){
      addClass(box, 'hidden')
   } else {
      remClass(box, 'hidden');
   }
}

/*- calendar -*/
function calendar(input1,input2,trigger1,trigger2,frmt){
   var trigger1x = getElem(trigger1);
   var trigger2x = getElem(trigger2);

   var input1x = getElem(input1);
   var input2x = getElem(input2);
   var dateformat = frmt;


   if (!input1x || !input2x) return;

      trigger1x.style.display='inline';
      trigger2x.style.display='inline';

			var startDate;
			var endDate;
			var callbacks = 0;

			function resetDates() {
				startDate = endDate = null;
			}


			/*
			* Given two dates (in seconds) find out if date1 is bigger, date2 is bigger or
			 * they're the same, taking only the dates, not the time into account.
			 * In other words, different times on the same date returns equal.
			 * returns -1 for date1 bigger, 1 for date2 is bigger 0 for equal
			 */

			function compareDatesOnly(date1, date2) {
				var year1 = date1.getYear();
				var year2 = date2.getYear();
				var month1 = date1.getMonth();
				var month2 = date2.getMonth();
				var day1 = date1.getDate();
				var day2 = date2.getDate();

				if (year1 > year2) {
					return -1;
				}
				if (year2 > year1) {
					return 1;
				}

				//years are equal
				if (month1 > month2) {
					return -1;
				}
				if (month2 > month1) {
					return 1;
				}

				//years and months are equal
				if (day1 > day2) {
					return -1;
				}
				if (day2 > day1) {
					return 1;
				}

				//days are equal
				return 0;


				/* Can't do this because of timezone issues
				var days1 = Math.floor(date1.getTime()/Date.DAY);
				var days2 = Math.floor(date2.getTime()/Date.DAY);
				return (days1 - days2);
				*/
			}

			function filterDates1(cal) {
				startDate = cal.date;
				/* If they haven't chosen an
				end date before we'll set it to the same date as the start date This
				way if the user scrolls in the start date 5 months forward, they don't
				need to do it again for the end date.
				*/

				if (endDate == null) {
					Zapatec.Calendar.setup({
						inputField     :    input2,
						button         :    trigger2,  // What will trigger the popup of the calendar
						ifFormat       :    dateformat,
						timeFormat     :    "24",
						date           :    startDate,
						electric       :    false,
						showsTime      :    false,          //no time
						disableFunc    :    dateInRange2, //the function to call
						onUpdate       :    filterDates2,
						firstDay       :    1
					});
					input2x.value=input1x.value;
				}
			}

			function filterDates2(cal) {
				endDate = cal.date;
			}

			/*
			* Both functions disable and hilight dates.
			*/

			/*
			* Can't choose days after the
			* end date if it is choosen, hilights start and end dates with one style and dates between them with another
			*/
			function dateInRange1(date) {

				if (endDate != null) {

					// Disable dates after end date
					var compareEnd = compareDatesOnly(date, endDate);
					if  (compareEnd < 0) {
						return (true);
					}

					// Hilight end date with "edges" style
					if  (compareEnd == 0) {
						{return "edges";}
					}


					// Hilight inner dates with "between" style
					if (startDate != null){
						var compareStart = compareDatesOnly(date, startDate);
						if  (compareStart < 0) {
							return "between";
						}
					}
				}

				//disable days prior to today
				var today = new Date();
				var compareToday = compareDatesOnly(date, today);
				if (compareToday > 0) {
					return(true);
				}


				//all other days are enabled
				return false;
				//alert(ret + " " + today + ":" + date + ":" + compareToday + ":" + days1 + ":" + days2);
				return(ret);
			}

			/*
			* Can't choose days before the
			* start date if it is choosen, hilights start and end dates with one style and dates between them with another
			*/

			function dateInRange2(date) {
				if (startDate != null) {
					// Disable dates before start date
					var compareDays = compareDatesOnly(startDate, date);
					if  (compareDays < 0) {
						return (true);
					}

					// Hilight end date with "edges" style
					if  (compareDays == 0) {
						{return "edges";}
					}

					// Hilight inner dates with "between" style
					if ((endDate != null) && (date > startDate) && (date < endDate)) {
						return "between";
					}
				}

				var now = new Date();
				if (compareDatesOnly(now, date) < 0) {
					return (true);
				}

				//all other days are enabled
				return false;
			}

		var cal = new Zapatec.Calendar.setup({

				inputField     :    input1,   // id of the input field
				button         :    trigger1,  // What will trigger the popup of the calendar
				ifFormat       :    dateformat,       // format of the input field
				timeFormat     :    "24",
				showsTime      :     false,          //no time
				electric       :     false,
				dateStatusFunc :    dateInRange1, //the function to call
				onUpdate       :    filterDates1,
				firstDay       :    1
		});

			Zapatec.Calendar.setup({
				inputField     :    input2,
				button         :    trigger2,  // What will trigger the popup of the calendar
				ifFormat       :    dateformat,
				timeFormat     :    "24",
				showsTime      :     false,          //no time
				electric       :     false,
				dateStatusFunc :    dateInRange2, //the function to call
				onUpdate       :    filterDates2,
				firstDay       :    1
			});
}

var showAsTabs = {
   tabHeadTag : "h4",
   defaultTab : "0",
   tabBox_className : "jsOn",
   tab_className : "tab",
   tab_activeClass : "active",
   tab_overClass : "over",

   init : function(tabDiv) {
      this.tabboxes = getElementsByClass(tabDiv);
      if(!this.tabboxes) return;

      for(var t=0;t<this.tabboxes.length;t++) {
       	addClass(this.tabboxes[t],this.tabBox_className);

         this.tabs = getElementsByClass(this.tab_className,'div',this.tabboxes[t]);
         if(!this.tabs) return;
         this.heads = this.tabboxes[t].getElementsByTagName(this.tabHeadTag);
         if(!this.heads) return;

         // taby
         for(var i=0;i<this.tabs.length;i++) {
          	addClass(this.tabs[i],this.tab_className+[i]);
          	addClass(this.tabs[this.defaultTab],this.tab_activeClass);
         }

         // hlavicky umistime nazacatek
         for(var h=0;h<this.heads.length;h++) {
          	addClass(this.heads[h],this.tab_className+[h]);
          	addClass(this.heads[this.defaultTab],this.tab_activeClass);
            insertBefore(this.heads[h], this.tabs[0])

          	// swaptab
          	this.heads[h].onclick = function (){

               for(var j=0;j<showAsTabs.heads.length;j++) {
          	       remClass(showAsTabs.heads[j],showAsTabs.tab_activeClass);
          	   }
          	   for(var k=0;k<showAsTabs.tabs.length;k++) {
          	       remClass(showAsTabs.tabs[k],showAsTabs.tab_activeClass);

          	       if(hasClass(showAsTabs.tabs[k],this.className)){
                      addClass(showAsTabs.tabs[k],showAsTabs.tab_activeClass);
                   }
         	   }
               addClass(this,showAsTabs.tab_activeClass);
               switchEditors(document.getElementById("tabbox"),"on");
            }
         }


      }
   }
}


var hoverTable = {
   tableClass : 'js-over',
   hoverClass : 'hover',
   tables : null,
   tbodys : null,
   trs : null,
   trsHref : null,
   linkNo : 0,

   init : function() {
      this.tables = getElementsByClassName(this.tableClass);
      if(this.tables==0) return;

   	for(var i=0;i<this.tables.length;i++) {
         this.trs = this.tables[i].getElementsByTagName('tr');
   	}
   	for(var i=0;i<this.trs.length;i++) {
         this.trs[i].onmouseover = function()  {
            swapClass(this,hoverTable.hoverClass);
         }
         this.trs[i].onmouseout = function()  {
            swapClass(this,hoverTable.hoverClass);
         }
         this.trs[i].onclick = function()  {
            trsHref = this.getElementsByTagName('a');
            window.location = trsHref[hoverTable.linkNo].href;
         }
   	}
   }
}

var fadingBoxes = {
   mainBoxId : "js-fader",
   mainBox_className : "fading",
   fadeBox_className : "item",
   fadeBox_className2 : "fader",
   fading_speed : 10,  // in miliseconds
   counter : 0,
   fadeBox_opacity : 300,
   fadeBox_delay : 500,

   init : function() {
      this.mainBox = getElem(this.mainBoxId)
      if(!this.mainBox) return;

   	addClass(this.mainBox,this.mainBox_className);

   	this.fadeBoxes = getElementsByClass(this.fadeBox_className,'div',this.mainBox);
      if(!this.fadeBoxes) return;

      if(this.fadeBoxes.length <= 1) return;

      for(var i=0;i<this.fadeBoxes.length;i++) {
         this.fadeBoxes[i].id=this.fadeBox_className2+i;
         if(i>0){
      	   addClass(this.fadeBoxes[i],this.fadeBox_className2);
         }
      }
      timer = setInterval('timerator()',this.fading_speed);
   }
}

timerator = function() {
   fadingBoxes.fadeBox_opacity -= 1;
   el = getElem(fadingBoxes.fadeBox_className2+fadingBoxes.counter);
   if (fadingBoxes.fadeBox_opacity<=100){
      el.style.opacity = fadingBoxes.fadeBox_opacity/100;
      el.style.filter = 'alpha(opacity="'+fadingBoxes.fadeBox_opacity+'",style=0)';
   }
   if(fadingBoxes.fadeBox_opacity <= 0){
      el.style.opacity = 100;
      el.style.filter = 'alpha(opacity="100")';
      fadingBoxes.fadeBox_opacity = fadingBoxes.fadeBox_delay;
      swapClass(fadingBoxes.fadeBox_className2+fadingBoxes.counter,fadingBoxes.fadeBox_className2);
      if(fadingBoxes.counter == fadingBoxes.fadeBoxes.length-1) fadingBoxes.counter = -1;
      fadingBoxes.counter += 1;
      swapClass(fadingBoxes.fadeBox_className2+fadingBoxes.counter,fadingBoxes.fadeBox_className2);
   }
}



