function openCalendar(FormElement){
	var calendarwindow;
	url = "mini-cal.html?formname=iform&formelement=" + FormElement;
	calendarwindow = window.open(url,"thewindow","toolbar=no,LEFT=700,TOP=400,WIDTH=170,HEIGHT=140,status=no,scrollbars=no,resize=no,menubar=no");
	calendarwindow.focus();
	}
	
/* PERFECT POP-UP WINDOWS */
function addEvent(elm, evType, fn, useCapture){if(elm.addEventListener){elm.addEventListener(evType, fn, useCapture);return true;}else if (elm.attachEvent){var r = elm.attachEvent('on' + evType, fn);return r;}else{elm['on' + evType] = fn;}}
			var newWindow = null;

			function closeWin(){
				if (newWindow != null){
					if(!newWindow.closed)
						newWindow.close();
				}
			}

			function popUpWin(url, type, strWidth, strHeight){

				closeWin();

				type = type.toLowerCase();

				if (type == "fullscreen"){
					strWidth = screen.availWidth;
					strHeight = screen.availHeight;
				}
				var tools="";
				if (type == "standard") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
				if (type == "console" || type == "fullscreen") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
				newWindow = window.open(url, "newWin", tools);
				newWindow.focus();
			}

			function doPopUp(e)
			{
			//set defaults - if nothing in rel attrib, these will be used
			var t = "standard";
			var w = "780";
			var h = "580";
			//look for parameters
			attribs = this.rel.split(" ");
			if (attribs[1]!=null) {t = attribs[1];}
			if (attribs[2]!=null) {w = attribs[2];}
			if (attribs[3]!=null) {h = attribs[3];}
			//call the popup script
			popUpWin(this.href,t,w,h);
			//cancel the default link action if pop-up activated
			if (window.event) 
				{
				window.event.returnValue = false;
				window.event.cancelBubble = true;
				} 
			else if (e) 
				{
				e.stopPropagation();
				e.preventDefault();
				}
			}

			function findPopUps()
			{
			var popups = document.getElementsByTagName("a");
			for (i=0;i<popups.length;i++)
				{
				if (popups[i].rel.indexOf("popup")!=-1)
					{
					// attach popup behaviour
					popups[i].onclick = doPopUp;
					// add popup indicator
					if (popups[i].rel.indexOf("noicon")==-1)
						{
						popups[i].style.backgroundImage = "url(pop-up.gif)";
						popups[i].style.backgroundPosition = "0 center";
						popups[i].style.backgroundRepeat = "no-repeat";
						popups[i].style.paddingLeft = "15px";
						}
					// add info to title attribute to alert fact that it's a pop-up window
					popups[i].title = popups[i].title + " [Opens in pop-up window]";
					}
				}
			}

			addEvent(window, "load", findPopUps, false);	






//large rotating photos			

function theRotator() {
	//Set the opacity of all images to 0
	$('div.rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div.rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	
	setInterval('rotate()',6000);
	
}

function rotate() {	
	//Get the first image
	var current = ($('div.rotator ul li.show')?  $('div.rotator ul li.show') : $('div.rotator ul li:first'));

    if ( current.length == 0 ) current = $('div.rotator ul li:first');

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.rotator ul li:first') :current.next()) : $('div.rotator ul li:first'));
	
	//Un-comment the 3 lines below to get the images in random order
	
	//var sibs = current.siblings();
    //var rndNum = Math.floor(Math.random() * sibs.length );
    //var next = $( sibs[ rndNum ] );
			

	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};

	//Load the slideshow
	theRotator();
	$('div.rotator').fadeIn(1000);
	$('div.rotator ul li').fadeIn(1000); // tweek for IE


	
function theRotator2() {
	//Set the opacity of all images to 0
	$('div.rotatorhome ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div.rotatorhome ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	
	setInterval('rotate2()',6000);
	
}

function rotate2() {	
	//Get the first image
	var current = ($('div.rotatorhome ul li.show')?  $('div.rotatorhome ul li.show') : $('div.rotatorhome ul li:first'));

    if ( current.length == 0 ) current = $('div.rotatorhome ul li:first');

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.rotatorhome ul li:first') :current.next()) : $('div.rotatorhome ul li:first'));
	
	//Un-comment the 3 lines below to get the images in random order
	
	//var sibs = current.siblings();
    //var rndNum = Math.floor(Math.random() * sibs.length );
    //var next = $( sibs[ rndNum ] );
			

	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};




$(document).ready(function() {		

	//Load the slideshow
					
			// offer slider
			$('#restaurants').hide();
			$('#colleges').hide();
			$('#golf').hide();
			$('#group').hide();
			$('#museums').hide();
			$('#worship').hide();
			$('#shopping').hide();
			$('#sports').hide();
			$('#theater').hide();

			$('a#restaurants-toggle').click(function() { 				
				$('#restaurants').slideToggle(200); 
				$('#colleges').hide();
				$('#golf').hide(); 
				$('#group').hide(); 
				$('#museums').hide(); 
				$('#worship').hide(); 
				$('#shopping').hide();  
				$('#sports').hide(); 
				$('#theater').hide();
				return false;
			});
		
			$('a#colleges-toggle').click(function() { 				
				$('#colleges').slideToggle(200); 
				$('#restaurants').hide();
				$('#golf').hide(); 
				$('#group').hide(); 
				$('#museums').hide(); 
				$('#worship').hide(); 
				$('#shopping').hide();  
				$('#sports').hide(); 
				$('#theater').hide();
				return false;
			});
		   
			$('a#golf-toggle').click(function() {
				$('#golf').slideToggle(200);
				$('#restaurants').hide();
				$('#colleges').hide();
				$('#group').hide();
				$('#museums').hide();
				$('#worship').hide();
				$('#shopping').hide();
				$('#sports').hide();	
				$('#theater').hide();
				return false;
			});
			
			$('a#group-toggle').click(function() {
				$('#group').slideToggle(200);
				$('#restaurants').hide();
				$('#colleges').hide();
				$('#golf').hide();
				$('#museums').hide();
				$('#worship').hide();
				$('#shopping').hide();
				$('#sports').hide();	
				$('#theater').hide();	
				return false;
			});
			   
			$('a#museums-toggle').click(function() {
				$('#museums').slideToggle(200);
				$('#restaurants').hide();
				$('#colleges').hide();
				$('#golf').hide();
				$('#group').hide();
				$('#worship').hide();
				$('#shopping').hide();
				$('#sports').hide();	
				$('#theater').hide();	
				return false;
			});	 
		
			$('a#worship-toggle').click(function() {
				$('#worship').slideToggle(200);
				$('#restaurants').hide();
				$('#colleges').hide();
				$('#golf').hide();
				$('#group').hide();
				$('#museums').hide();
				$('#shopping').hide();
				$('#sports').hide();	
				$('#theater').hide();
				return false;
			});
			
			$('a#shopping-toggle').click(function() {
				$('#shopping').slideToggle(200);
				$('#restaurants').hide();
				$('#colleges').hide();
				$('#golf').hide();
				$('#group').hide();
				$('#museums').hide();
				$('#worship').hide();
				$('#sports').hide();	
				$('#theater').hide();
				return false;
			});
			   
			$('a#sports-toggle').click(function() {
				$('#sports').slideToggle(200);
				$('#restaurants').hide();
				$('#colleges').hide();
				$('#golf').hide();
				$('#group').hide();
				$('#museums').hide();
				$('#worship').hide();
				$('#shopping').hide();
				$('#theater').hide();	
				return false;
			});	

			$('a#theater-toggle').click(function() {
				$('#theater').slideToggle(200);
				$('#restaurants').hide();
				$('#colleges').hide();
				$('#golf').hide();
				$('#group').hide();
				$('#museums').hide();
				$('#worship').hide();
				$('#shopping').hide();
				$('#sports').hide();	
				return false;
			});				
			
});


	var setSelectBoxesCountry = function(){
		
		$('city').getChildren().inject($('options_city'));
		$('hotel').getChildren().inject($('options_hotels'));
		
		$('options_city').getElements( '.country_id_' + $('country').value ).inject($('city'));
		$('options_hotels').getElements( '.city_id_' + $('city').value ).inject($('hotel'));
		
		$('ccpSelectCountry').value = $('country').value;
		$('ccpSelectCity').value = $('city').value;
		$('ccpSelectHotel').value = $('hotel').value;
	}
	
	var setSelectBoxesCity = function(){

		$('hotel').getChildren().inject($('options_hotels'));
		
		$('options_hotels').getElements( '.city_id_' + $('city').value ).inject( $('hotel') );
		
		$('ccpSelectCity').value = $('city').value;
		$('ccpSelectHotel').value = $('hotel').value;
	}
	
	var setSelectBoxesHotel = function(){
		$('ccpSelectHotel').value = $('hotel').value;
	}
	
	window.addEvent('domready', function(){
		
		if($('country') && $('city') && $('hotel'))
			setSelectBoxesCountry();
		
		if($('city') && $('hotel'))
			setSelectBoxesCity();
		
		if($('country'))
			$('country').addEvent('change', setSelectBoxesCountry);
		
		if($('city'))
			$('city').addEvent('change', setSelectBoxesCity);
		
		if($('hotel'))
			$('hotel').addEvent('change', setSelectBoxesHotel);
			
			
		var jetzt = new Date();
		var morgen = jetzt.clone().increment('day');
		var uebermorgen = jetzt.clone().increment('day', 2);
		
		
		$('calArrivalDateField').value = jetzt.format("%Y-%m-%d");
		$('calDepartureDateField').value = morgen.format("%Y-%m-%d");
		
		
		var d1 = new DatePicker($('calArrivalDateField'), {
			pickerClass		: 'datepicker_vista', 
			format			:'d.m.Y',
			inputOutputFormat	:'Y-m-d',
			onSelect: function(a){
				var nights =  parseInt( $('nights').value );				
				var departure = Date.parse($('calArrivalDateField').value).increment('day', nights);
				
				d2.input = $('calDepartureDateField');
				d2.visual = $('calDepartureDateField').getNext();
				d2.select({
					day: 	(departure.format("%d").toInt()), 
					month: 	(departure.format("%m").toInt() -1 ),  // month werden ab 0 gez�hlt
					year:  	(departure.format("%Y").toInt())
				});
				
				
				if( new Date().clearTime().diff( Date.parse($('calArrivalDateField').value), 'day') < 0){
					alert('Arrival date has to be in future.');
				}				
			}
		});
		
		var d2 = new DatePicker($('calDepartureDateField'), {
			pickerClass		: 'datepicker_vista',
			format			:'d.m.Y',
			inputOutputFormat	:'Y-m-d',
			onSelect: function(d){				
				var a = Date.parse( $('calArrivalDateField').value );
				d.clearTime();
				
				var nights = a.diff(d, 'day' );
				if(nights <= 0){
					alert('Departure has to be after arrival!');
				}else{					
					$$('select#nights option').each(function(opt){
						if(opt.value == nights) 
							opt.selected = true;
					});
				}
			}
		});		
		
		$('nights').addEvent('change', function(e){
			var nights =  parseInt(e.target.value);				
			var departure = Date.parse($('calArrivalDateField').value).increment('day', nights);
			
			d2.input = $('calDepartureDateField');
			d2.visual = $('calDepartureDateField').getNext();
			d2.select({
				day: 	(departure.format("%d").toInt()), 
				month: 	(departure.format("%m").toInt() -1 ),  // month werden ab 0 gez�hlt
				year:  	(departure.format("%Y").toInt())
			});

		});	
		
		
		var occupancy_fields = $$('select[name=numberOfAdults]').combine($$('.child_selects')).combine($$('select[name=prsRoomCount]'));

		occupancy_fields.addEvent('change', function(){
			var temp_val = "room_1:numberOfAdults=";
			temp_val += $('numberOfAdults').value;
			temp_val += ";childrenAges=";
			ages_array = new Array();
			$$('.child_selects').each(function(i){
				if(i.value != '')
					ages_array.push( i.value );
			});
			temp_val += ages_array.join(",");
			var rooms = 1;
			$$('select[name=prsRoomCount]').each(function(i) {
				if(i.value > 1){
					for(var y=1;y<i.value;y++) {
						rooms++;
						temp_val += "-room_"+rooms+":numberOfAdults=";
						temp_val += $('numberOfAdults').value;
						temp_val += ";childrenAges=";
					}
				}
			});
			$('occupancy').value = temp_val ;
		});
	});
