var presenterInterval;

function runPresenter(){
	presenterInterval = window.setInterval("nextPresenterItem()", 8000);
}

function nextPresenterItem(){
	var liElms = document.getElementById('presenter').getElementsByTagName('ul')[0].getElementsByTagName('li');
	for(var i=0; i<liElms.length; i++){
		if(liElms[i].className=='hi'){
			liElms[i].className='';
			activeI = (i+1)%liElms.length;
			liElms[activeI].className = 'hi';
			break;
		}
	}
}

function setPresenter(elm){
	if(presenterInterval)
		window.clearInterval(presenterInterval);
	var liElms = document.getElementById('presenter').getElementsByTagName('ul')[0].getElementsByTagName('li');
	for(var i=0; i<liElms.length; i++){
		if(liElms[i].className == 'hi'){
			liElms[i].className = '';
			break;
		}
	}
	elm.parentNode.parentNode.className='hi';
}

/* *********************************************************************************************************** */

function showVideo(){
	videoframe = document.createElement('div');
	videoframe.setAttribute('id', 'videoframe');
	document.getElementById('wrapper').appendChild(videoframe);
	document.getElementById('videoframe').innerHTML = '<div id="fader"></div><div id="video"><a onclick="closeVideo();" href="#">close</a><video src="videoplayback.webm" width="640" height="329" controls autoplay></video><div>';
	document.getElementsByTagName('body')[0].style.backgroundImage='';
}

function closeVideo(){
	if(videoframe)
		document.getElementById('wrapper').removeChild(videoframe);
}

/* *********************************************************************************************************** */

function setTool(elm){
	var toolboxElms = document.getElementById('toolbox').getElementsByTagName('div');
	var formDivElms = [];
	for(var i=0; i<toolboxElms.length; i++){
		if(toolboxElms[i].className == 'toolboxitemform hi'){
			toolboxElms[i].className = 'toolboxitemform';
			
			// wenn click auf 'hi': alle 'hi' loeschen
			var testnode =  elm.parentNode.nextSibling;
			while(testnode.nodeType == 3) //Textknoten ueberspringen
				testnode=testnode.nextSibling;
			if(toolboxElms[i] == testnode)
				return;
				
			break;
		}
	}
	
	var h2elm = elm.parentNode;
	
	var toolboxH2 = document.getElementById('toolbox').getElementsByTagName('h2');
	for(var i=0; i<toolboxH2.length; i++){
		if(toolboxH2[i] == h2elm){
			toolboxH2[i].className = toolboxH2[i].className=='hi?' ? '' : 'hi';
		}
		else{
			toolboxH2[i].className = '';
		}
	}
	
	var formDivElm = h2elm.nextSibling;
	while(formDivElm.nodeType == 3) //Textknoten ueberspringen
		formDivElm=formDivElm.nextSibling;
	formDivElm.className += ' hi';
	return false;
}

function setToolSub(elm){
	var toolboxElms = elm.parentNode.parentNode.getElementsByTagName('div');
	var formDivElms = [];
	for(var i=0; i<toolboxElms.length; i++){
		if(toolboxElms[i].className == 'toolboxsubitem hi'){
			toolboxElms[i].className = 'toolboxsubitem';
			break;
		}
	}
	
	var h3Elms = elm.parentNode.parentNode.getElementsByTagName('h3');
	for(i=0; i<h3Elms.length; i++){
		if(h3Elms[i].className == 'hi'){
			h3Elms[i].className = '';
			break;
		}
	}
	
	var h3elm = elm.parentNode;
	h3elm.className = 'hi';
	var formDivElm = h3elm.nextSibling;
	while(formDivElm.nodeType == 3) //Textknoten ueberspringen
		formDivElm=formDivElm.nextSibling;
	formDivElm.className += ' hi';
	return false;
}

/* *********************************************************************************************************** */

function showBookformChildren(elm){
	var fs = elm.parentNode;
	var spacer = fs;
	while (spacer.nodeType != 1 || spacer.className.indexOf('flightspacer') <0)
		spacer = spacer.nextSibling;
	if(fs.getElementsByTagName('div')[0].className == 'withchildren'){
		fs.className = 'toolbox_persons';
		fs.getElementsByTagName('div')[0].className = 'adultsonly';
		spacer.className = 'flightspacer';
		elm.className='';
	}
	else{
		fs.className = 'toolbox_persons triple';
		fs.getElementsByTagName('div')[0].className = 'withchildren';
		spacer.className = 'flightspacer withchildren';
		elm.className='hi';
	}
	return false;
}

/* *********************************************************************************************************** */

function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}

addEvent(window, 'load', closeCalendar);

function closeCalendar(){
	var tb = document.getElementById('toolbox');
	if(tb != null){
		var a = tb.getElementsByTagName('a');
		for(var i=0; i<a.length; i++){
			a[i].setAttribute('onfocus', 'runToggleDIVCalendar(false, null);')
		}
	}
}

/*JS-VERSION:2.17.0.0*/
/*ROSH: global variable if calendar displayed on screen*/
var onScreen = false;
var actualDate = new Date();
var limitDate = actualDate;


/*ROSH: 28.03.07*/
function runToggleDIVCalendar(hide, ele){
	

	if(hide){
		$('calendarwrapper').style.display='';
	}
	else{
		$('calendarwrapper').style.display='none';	
	}
		

	/*switch to identify the correct ref. text html element this is
	needed that the calendar writes selected date into html text marup element.*/
	if(ele)
	{
		switch(ele.id)
		{
			case 'f_inbound':
			case 'f_depart':
			     $('title_depart').innerHTML = cal1.title;
			     $('title_inbound').innerHTML = cal2.title;
			     $('titleImage_depart').src = cal1.titleImage;
			     $('titleImage_inbound').src = cal2.titleImage;
				cal1.updateRefTextHtml('f_depart');
				cal2.updateRefTextHtml('f_inbound');
				break;

			case 'h_checkin':
			case 'h_checkout':
			    $('title_depart').innerHTML = "Check-In";
			    $('title_inbound').innerHTML = "Check-Out";
			    $('titleImage_depart').src = 'http://www.swiss.com/PublishingImages/booking/icon_check-in.gif';
			    $('titleImage_inbound').src = 'http://www.swiss.com/PublishingImages/booking/icon_check-out.gif';
				cal1.updateRefTextHtml('h_checkin');
				cal2.updateRefTextHtml('h_checkout');
				break;

			case 'c_pickupDate':
			case 'c_returnDate':
			    $('title_depart').innerHTML = "Check-In";
			    $('title_inbound').innerHTML = "Check-Out";
			    $('titleImage_depart').src = 'http://www.swiss.com/PublishingImages/misc/icon_carRental_begin.gif';
			    $('titleImage_inbound').src = 'http://www.swiss.com/PublishingImages/misc/icon_carRental_end.gif';
				cal1.updateRefTextHtml('c_pickupDate');
				cal2.updateRefTextHtml('c_returnDate');
				break;
		}
	}
}

function setDate(cal, dateString, ele)
{    
	var dateArr = getDayMonthArray(dateString);

	if(dateArr && dateArr.length)
	{
		var day = parseInt(dateArr[0]);
	    var month = parseInt(dateArr[1]);
	    
	    if(ele)
        {
            if(cal.id == 'cal2' && (ele.id == 'checkout' || ele.id == 'checkin'))
            {
                if(dateString && dateString.length == 10 && month && day)
                {
                    var year =  dateString.substr(dateString.length-4, 4);
                    var newDate = new Date(year, month-1, day);
                    newDate.setDate(day+1);
                    
                    day = newDate.getDate();
                    month = newDate.getMonth()+1;
                }
            }
        }
		cal.calendar(null, month, day, cal.id);
		cal.showSpecificCal('select_'+cal.id, month);
		cal.setSelected($(cal.id+'_possibleSlelecteDay_'+day), day);
	}
}

function getDayMonthArray(dateString)
{
	var dateValue = dateString.split('.');
	if (dateValue &&
		(dateValue.length) &&
		(parseInt(dateValue[0]) >= 1) &&
		(parseInt(dateValue[0]) <= 31) &&
		(parseInt(dateValue[1]) >= 1) &&
		(parseInt(dateValue[1]) <= 12))
	{
		return dateValue;
	}
	return null;
}

/*ROSH: 28.03.07 Calender Object
	@id - need to be unique name
	@containerId - container id is a predefined div, this forces to write content into div
	@title - header title
	@refTextHtml - reference to text markup field.
	@preSelected - an offset, e.g. 3 will premark the today+3
	@titleImage - title image
	@prevImage - navigation image previous
	@nextImage - navigation image next
	@refId - reference id of different calendar

	@=====================================================
	usage example:

	#define instance

	var cal1 = new SwissCalendar('cal1','divCalendarOutbound','Hinflug','depart',1,
									'/PublishingImages/booking/icon_outward.gif',
									'/PublishingImages/booking/button_arrowleft.gif',
									'/PublishingImages/booking/button_arrowright.gif',
									null);
	var cal2 = new SwissCalendar('cal2','divCalendarInbound','Rückflug','inbound',9,
									'/PublishingImages/booking/icon_return.gif',
									'/PublishingImages/booking/button_arrowleft.gif',
									'/PublishingImages/booking/button_arrowright.gif',
									'cal1');


	#render content into specific place
	<script>cal1.Print();</script>
	<script>cal2.Print();</script>
*/

var SwissCalendar = function (id, containerId, title, refTextHtml, preSelected, titleImage, prevImage, nextImage, refId)
{
	/*calendar unique id*/
	this.id = id;
	/*calendar container unique id - thats the place were its render content*/
	this.containerId = containerId;
	/*title e.g. to / back*/
	this.title = title;
	/*refer text input type*/
	this.refTextHtml = refTextHtml;
	/*months select html element which rendered automatically*/
	this.currentSelected;
	/*current selected day within the calendar*/
	this.currentSelectElement;
	/*optional preselection*/
	if(!preSelected)
		preSelected = -1;
	this.preSelected = preSelected;
	/*calendars title text, e.g. Outbound / Inbound*/
	this.titleImage = titleImage;
	/*right click image*/
	this.prevImage = prevImage;
	this.prevImageDis = replace(prevImage, ".gif", "_disabled.gif");
	/*left click image*/
	this.nextImage = nextImage;
	this.nextImageDis = replace(nextImage, ".gif", "_disabled.gif");

	/* ref. / parent / controlling parameters */
	this.arrayParentControls = new Array();
	/*observer ref id.*/
	this.refId = refId;
	if(refId)
	{
		this.refObject = eval(refId);
		this.refObject.registerReferences(this.id);
	}
	/*current slected day*/
	this.day = 0;
	/*current slected month*/
	this.month = 0;

	if(!this.id)
	{
		alert('config problem with id!');
	}
	if(!this.containerId)
	{
		alert('config problem with containerId!');
	}
	if(!this.title)
	{
		alert('config problem with title!');
	}
	if(!this.refTextHtml)
	{
		alert('config problem with refTextHtml!');
	}
}

/*SwissCalendar prototype extensions*/
SwissCalendar.prototype = {
	/*core funtion which renders calendar details*/
	Print : function()
	{
		/*calendar navigation back / forward - select html element to choose the month*/
		this.currentSelectElement = 'select_'+this.id;
		var buffer = '';

		buffer += '<img id="titleImage_' + this.refTextHtml +'" src="'+this.titleImage+'" alt="'+this.title+'" /> <span class="data" id="title_' + this.refTextHtml + '">'+this.title+'</span>';

		if(this.id == 'cal1')
		{
		    buffer += '<span style="position:absolute;display:block;left:527px;top:8px;"><a href="#" onclick="javascript:runToggleDIVCalendar(false);return false;"><img src="/PublishingImages/booking/button_close.gif" /></a></span>';
		}

		buffer += '<div class="line months">';

		buffer += '	<a href="#" onclick=\''+this.id+'.showPrevCal("select_'+this.id+'");void(0);return false;\'>';
		buffer += '		<img class="arrowleft" id="'+this.id+'_arrowleft" src="'+this.prevImage+'" alt="" />';
		buffer += '	</a>';
		buffer += '	<a href="#" onclick=\''+this.id+'.showNextCal("select_'+this.id+'");void(0);return false;\'>';
		buffer += '		<img class="arrowright" id="'+this.id+'_arrowright"  src="'+this.nextImage+'" alt="" />';
		buffer += '	</a>';
		buffer += '	<select id=\'select_'+this.id+'\' onchange=\''+this.id+'.onNavigationMonthChange(this);\'></select>';
		buffer += '</div>';
		document.write(buffer);

		/* update the select html element */
		this.fillNavigationMonths('select_'+this.id);

		var requestDate = new Date();
		requestDate = new Date(requestDate.getFullYear(), requestDate.getMonth(), requestDate.getDate());

		/*set preselected dates*/
		if(this.preSelected>0)
		{
			requestDate = new Date(requestDate.getFullYear(), requestDate.getMonth(), requestDate.getDate() + this.preSelected);
			this.calendar(requestDate.getFullYear(), requestDate.getMonth()+1, requestDate.getDate(), this.id, null);
			var toSelect = this.id+'_possibleSlelecteDay_'+ requestDate.getDate();
			this.setSelected($(toSelect), requestDate.getDate());

			/* update the dropdown box with correct preselected month */
			setDropDownValue( $('select_'+this.id), requestDate.getMonth()+1 );
		}
		else
		{
			/* no preselection */
			this.calendar(requestDate.getFullYear(), requestDate.getMonth()+1, requestDate.getDate(), this.id, null);
		}

		this.month = requestDate.getMonth()+1;
		this.day = requestDate.getDate();
		this.initRefernceTextbox();

		/*bugfix:disabled button upon startup and backup link*/
		if(this.month <= (new Date().getMonth()+1))
		{
			$(this.id+'_arrowleft').src = this.prevImageDis;
			this.backupHref($(this.id+'_arrowleft').parentNode);
		}
	},
	backupHref : function(ele)
	{
		/*ensure element and that this runs just on a markup elements*/
		if(ele && ele.tagName == "A")
		{
			var href = ele.getAttribute("href");
			var onclick = ele.getAttribute("onclick");

			if(href && href != "" && href != null){
				ele.setAttribute('href_bak', href);
			}
			if(onclick != null && onclick != "void(0);"){
				ele.setAttribute('onclick_bak', onclick);
				ele.setAttribute('onclick', "void(0);");
			}
		}
	},
	restoreHref : function(ele)
	{
		/*ensure element and that this runs just on a markup elements*/
		if(ele && ele.tagName == "A")
		{
			if(ele.attributes['onclick_bak']!=null)
			{
				ele.setAttribute('onclick', ele.attributes['onclick_bak'].nodeValue);
			}

			if(ele.attributes['href_bak']!=null)
			{
				ele.setAttribute('href', ele.attributes['href_bak'].nodeValue);
			}
		}
	},
	/*register if other controls have a referneces - observer*/
	registerReferences : function(obj)
	{
		if(obj)
			this.arrayParentControls.push(obj);
	},
	/*handling selection of a new date*/
	updateDateSelection : function()
	{
		if(this.arrayParentControls.length >0)
		{
			/* update parent controls */
			for(var t=0;t<this.arrayParentControls.length;++t)
			{
				if(this.arrayParentControls[t])
				{
					var parentObject = eval(this.arrayParentControls[t]);
					if(parentObject)
					{
						parentObject.updateDateSelection();
					}
				}
			}
		}
		/*
		disable fields in reference object.
		e.g. cal1. has a ref. to cal2;
		*/
		if(this.refObject)
		{

			/*first restore all links and prepare them as possible seleactable day's*/
		    for(var x=1;x<=31;++x)
		    {
			    if($(this.id+'_possibleSlelecteDay_'+x))
			    {
				    this.enableDay(x);
			    }
				
		    }
		    
			if ($(this.refTextHtml).value){
				var textData = $(this.refTextHtml).value.split('.');
			}

			var loc_parentDay = parseInt(this.refObject.day);
		
			if(this.refTextHtml == 'h_checkin' || this.refTextHtml == 'h_checkout')
			{
			    loc_parentDay = parseInt(this.refObject.day)+1;
			}
			
			var loc_parentMonth = parseInt(this.refObject.month);
			var loc_textDay,loc_textMonth;
			if(textData.length > 2)
			{
				loc_textDay = parseInt(textData[0]);
				loc_textMonth = parseInt(textData[1]);
			}

			/*mark first the selected day*/
			if($(this.id+'_possibleSlelecteDay_'+this.day))
			{
				this.markDay( $(this.id+'_possibleSlelecteDay_'+this.day) );
			}

			if(loc_parentMonth == this.month && parseInt(this.day) <= loc_parentDay)
			{
				this.unmarkDay( $(this.id+'_possibleSlelecteDay_'+this.day) );
			}

			var loc_tmpDay = parseInt(this.day) <= loc_parentDay ? loc_parentDay : parseInt(this.day);

            //Calc limit Date
			if(loc_parentMonth < (actualDate.getMonth()+1))
		    {
		        limitDate = new Date(actualDate.getFullYear()+1, loc_parentMonth-1, loc_parentDay+maxNumberOfBookableNightsKuoni);
		    }else
		    {
		        limitDate = new Date(actualDate.getFullYear(), loc_parentMonth-1,loc_parentDay+maxNumberOfBookableNightsKuoni);
		    }
					
			/*disble*/
			for(var d=1;d<=31;++d)
			{
				if($(this.id+'_possibleSlelecteDay_'+d))
				{					
					if(loc_parentMonth == this.month)
					{
						if(loc_parentDay >= d && (this.refTextHtml == 'h_checkin' || this.refTextHtml == 'h_checkout'))
						{
							/* if the day is not unmarked, a css problem appears.*/
							this.unmarkDay( $(this.id+'_possibleSlelecteDay_'+loc_tmpDay) );
							this.day = loc_parentDay;
							//Do not disable the first possible selectable day
							if(d != loc_parentDay)
							{
							    this.disableDay(d);
							}
						}else if(loc_parentDay > d)
						{
							/* if the day is not unmarked, a css problem appears.*/
							this.unmarkDay( $(this.id+'_possibleSlelecteDay_'+loc_tmpDay) );
							this.day = loc_parentDay;
							this.disableDay(d);
						}
						/*ensure previous selected fields are unmarked*/
						else if(this.refTextHtml == 'h_checkin' || this.refTextHtml == 'h_checkout')
						{
							this.unmarkDay( $(this.id+'_possibleSlelecteDay_'+(d-1)));
						}
						else
						{
							this.unmarkDay( $(this.id+'_possibleSlelecteDay_'+d) );
						}
						/*mark the new selected date, this.day get every loop updated */
					    if(d == loc_tmpDay)
					    {
					        this.markDay($(this.id+'_possibleSlelecteDay_'+loc_tmpDay));
							
						    this.printFormattedTextToReference(loc_tmpDay);
					    }else if(((d-1)== loc_tmpDay ) && (this.refTextHtml == 'h_checkin' || this.refTextHtml == 'h_checkout'))
					    {
					        this.markDay($(this.id+'_possibleSlelecteDay_'+(loc_tmpDay)));
							
						    this.printFormattedTextToReference((loc_tmpDay));
					    }
					}
				}
			} 
		}
	},
	disableDay : function(d)
	{
        if($(this.id+'_possibleSlelecteDay_'+d))
		{
		    var href = $(this.id+'_possibleSlelecteDay_'+d).getAttribute("href");
		    var onclick = $(this.id+'_possibleSlelecteDay_'+d).getAttribute("onclick");

		    if(href && href != "" && href != null){
			    $(this.id+'_possibleSlelecteDay_'+d).setAttribute('href_bak', href);
		    }
		    if(onclick != null){
			    $(this.id+'_possibleSlelecteDay_'+d).setAttribute('onclick_bak', onclick);
			    $(this.id+'_possibleSlelecteDay_'+d).setAttribute('onclick', "void(0);");
		    }
    		
	
		    $(this.id+'_possibleSlelecteDay_'+d).removeAttribute('href');
		    $(this.id+'_possibleSlelecteDay_'+d).className='';
		    $(this.id+'_possibleSlelecteDay_'+d).parentNode.className='';
		    $(this.id+'_possibleSlelecteDay_'+d).style.textDecoration = 'none';
		    $(this.id+'_possibleSlelecteDay_'+d).parentNode.className="";
		    $(this.id+'_possibleSlelecteDay_'+d).parentNode.disable = 1;
		}
	},
	enableDay : function(x)
	{
		this.unmarkDay($(this.id+'_possibleSlelecteDay_'+x));
		$(this.id+'_possibleSlelecteDay_'+x).parentNode.className = "possible";

		if($(this.id+'_possibleSlelecteDay_'+x).attributes['onclick_bak']!=null)
			$(this.id+'_possibleSlelecteDay_'+x).setAttribute('onclick', $(this.id+'_possibleSlelecteDay_'+x).attributes['onclick_bak'].nodeValue);

		if($(this.id+'_possibleSlelecteDay_'+x).attributes['href_bak']!=null)
			$(this.id+'_possibleSlelecteDay_'+x).setAttribute('href', $(this.id+'_possibleSlelecteDay_'+x).attributes['href_bak'].nodeValue);

		$(this.id+'_possibleSlelecteDay_'+x).style.textDecoration = 'underline';
		$(this.id+'_possibleSlelecteDay_'+x).style.fontStyle = '';
	},
	/*sets a specific day and set it marked*/
	setSelected : function(link, day)
	{
		if(this.arrayParentControls.length >0)
		{
			// update parent controls
			for(var t=0;t<this.arrayParentControls.length;++t)
			{
				if(this.arrayParentControls[t])
				{
					var parentObject = eval(this.arrayParentControls[t]);
					if(parentObject)
					{
						parentObject.unmarkAll();
					}
				}
			}
		}
		
		this.unmarkAll();

		if($(this.currentSelected)){
			$(this.currentSelected).parentNode.className="possible";
		}
		if(link)
		{
			this.currentSelected = link.id;
		}
		this.printFormattedTextToReference(day);
		if(link)
		{
			this.markDay(link);
		}

		this.day = day;

		/*update links*/
		this.updateDateSelection();

		return false;
	},
	/*mark a specific day*/
	markDay : function(ele)
	{
		ele.parentNode.className="selected";
		ele.style.color="#fff";
		ele.style.textDecoration = 'none';
	},
	/*unmark a specific day*/
	unmarkDay : function(ele)
	{
		if(ele)
		{
			ele.parentNode.className="possible";
			ele.className="possible";
			ele.style.color="#656565";
			ele.style.textDecoration = 'underline';
		}
	},
	unmarkAll : function()
	{
		for(var x=1;x<=31;++x)
		{
			if($(this.id+'_possibleSlelecteDay_'+x))
			{
				this.unmarkDay($(this.id+'_possibleSlelecteDay_'+x));
			}
		}
	},
	/*prints the formatted text to ref. text box*/
	printFormattedTextToReference : function(day)
	{
		var requestDate = new Date();

		if(requestDate.getMonth()+1 <= this.month){
			requestDate = new	Date(requestDate.getFullYear(), this.month -1, 1);
		}
		else{
			requestDate = new	Date(requestDate.getFullYear()+1, this.month -1, 1);
		}

		if(this.refTextHtml && $(this.refTextHtml) && $(this.currentSelectElement))
			$(this.refTextHtml).value = this.printFormatter(day) + '.' + this.printFormatter(this.month) + '.' + requestDate.getFullYear();

	},
	/*
	rosh: 30.05.2007: changes 1-9 to 01 - 09
	*/
	printFormatter : function (val)
	{
		if(val)
		{
			var tmp = parseInt(val);

			if(tmp >9)
				return tmp;
			else
				return '0'+tmp;
		}
	},
	/*init ref. textbox.*/
	initRefernceTextbox : function()
	{
		var day, month;
		var textData = $(this.refTextHtml).value.split('.');
		if(textData.length > 2)
		{
			day = parseInt(textData[0]);
			month = parseInt(textData[1]);
		}
		if(!isNaN(day) && !isNaN(month))
		{
			if(this.month == parseInt(month))
			{
				if(day == 0)
					day = this.day;

				this.setSelected($(this.id+'_possibleSlelecteDay_'+day), day);
				setDropDownValue( $('select_'+this.id), month );
			}
		}
	},
	/*display month*/
	printMonth : function(ele, month){
		ele = $(ele);
		var requestDate = new Date();

		if(requestDate.getMonth()+1 <= month){
			requestDate = new	Date(requestDate.getFullYear(), month -1, 1);
		}
		else{
			requestDate = new	Date(requestDate.getFullYear()+1, month -1, 1);
		}
		this.calendar(requestDate.getFullYear(), requestDate.getMonth()+1, requestDate.getDate(), this.id, null);
	},
	/*
	toggles the images to navigate between months
	@dir = true[next] / false[previous]
	@val = true[enable] / false[disable]
	*/
	toggleMonthSelection : function(dir,val){
		/*next month*/
		if(dir){
			/*enable*/
			if(val){
				$(this.id+'_arrowright').src = this.nextImage;
				this.restoreHref($(this.id+'_arrowright').parentNode);
			}
			/*disable*/
			else{
				$(this.id+'_arrowright').src = this.nextImageDis;
				this.backupHref($(this.id+'_arrowright').parentNode);
			}
		}
		/*previous month*/
		else{
			/*enable*/
			if(val){
				$(this.id+'_arrowleft').src = this.prevImage;
				this.restoreHref($(this.id+'_arrowleft').parentNode);
			}
			/*disable*/
			else{
				$(this.id+'_arrowleft').src = this.prevImageDis;
				this.backupHref($(this.id+'_arrowleft').parentNode);
			}
		}
	},
	/*
		enables / disable the buttons to navigate to next / previous month
		@ele - element
	*/
	activateMonthSelection : function()
	{
		/*validate just forward is enable*/
		if(parseInt( $('select_'+this.id).selectedIndex ) == 0)
		{
			/*previous month, disable*/
			this.toggleMonthSelection(false, false);
			/*next month, enable*/
			this.toggleMonthSelection(true, true);
		}
		/*validate just backwards is enable*/
		else if(parseInt( $('select_'+this.id).selectedIndex ) == 11)
		{
			/*next month, disable*/
			this.toggleMonthSelection(true, false);
			/*previous month, enable*/
			this.toggleMonthSelection(false, true);
		}
		/*validate both directions are enabled*/
		else
		{
			/*next month, enable*/
			this.toggleMonthSelection(true, true);
			/*previous month, enable*/
			this.toggleMonthSelection(false, true);
		}
	},
	/*randomize month, so it works as a circle*/
	checkMonthStep : function(val, ele)
	{
		if(val == 0)
		{
			val = 12;
		}
		else if ( val == 13)
		{
			val = 1;
		}
		return val;
	},
	/*display previous month*/
	showPrevCal : function(ele)
	{
		setDropDownValue($(ele), this.checkMonthStep( parseInt($(ele).options[$(ele).selectedIndex].value) - 1));
		this.onNavigationMonthChange($(ele));
	},
	/*display next month*/
	showNextCal : function(ele)
	{
		setDropDownValue($(ele), this.checkMonthStep( parseInt($(ele).options[$(ele).selectedIndex].value) + 1));
		this.onNavigationMonthChange($(ele));
	},
	/*display specific month*/
	showSpecificCal : function(ele, month)
	{
		setDropDownValue($(ele), month);
		this.onNavigationMonthChange($(ele));
	},
	/*ROSH: 29.03.07: event handler for day overview within month*/
	onNavigationMonthChange : function(ele)
	{
		var setMark = false;

		if(this.month == $(ele).options[$(ele).selectedIndex].value)
		{
			setMark = true;
		}

		this.printMonth(ele, $(ele).options[$(ele).selectedIndex].value);
		this.month = $(ele).options[$(ele).selectedIndex].value;

		if(this.arrayParentControls.length >0)
		{
			// update parent controls
			for(var t=0;t<this.arrayParentControls.length;++t)
			{
				if(this.arrayParentControls[t])
				{
					var parentObject = eval(this.arrayParentControls[t]);
					if(parentObject)
					{
						parentObject.showSpecificCal('select_'+parentObject.id, this.month);
					}
				}
			}
		}

		/*BUGFIX:ROSH:28.05.07: ensure the correct arrows are enabled / disabled*/
		this.activateMonthSelection();

		if(setMark)
		{
			this.markDay( $(this.id+'_possibleSlelecteDay_'+this.day) );
		}

		/* add here the date dif fix of 340 day's - everything which is behind this date, has to be deactivated*/
		if(this.refTextHtml == 'h_checkin' || this.refTextHtml == 'h_checkout')
		{
		    //Deactiveate all Days after a specified period
		    if(this.refTextHtml == 'h_checkout')
		    {
                if(actualDate != limitDate)
                {
		            if((limitDate.getMonth()+1) >= (actualDate.getMonth()+1))
		            {
                        if(Number(this.month) > (limitDate.getMonth()+1))
                        {
                            try
                            {
                                for(var i=1;i<32;++i)
                                {
                                    this.disableDay( i );
                                }
                            }catch(e)
                           {
                           }      
                        }else if(Number(this.month) < (limitDate.getMonth()+1))
                        {
                           if(Number(this.month) < actualDate.getMonth()+1)
                           {
                                try
                                {
                                    for(var i=1;i<32;++i)
                                    {
                                        this.disableDay( i );
                                    }
                                }catch(e)
                               {
                               } 
                           }
                        }else
                        {
                            try
                            {
                                for(var i=limitDate.getDate()+1;i<32;++i)
                                {
                                    this.disableDay( i );
                                }
                           }catch(e)
                           {
                           }  
                        }
		            }
		            else
		            {
                        if(Number(this.month) < limitDate.getMonth()+1)
                        {
                            //do not deactivate anything
                        }
                        else if(Number(this.month) == limitDate.getMonth()+1)
                        {
                            try
                            {
                                for(var i=limitDate.getDate()+1;i<32;++i)
                                {
                                    this.disableDay( i );
                                }
                            }catch(e)
                           {
                           }  
                        }
                        else if(actualDate.getMonth()+1 <= Number(this.month))
		                {
		                    //do not deactivate anything
		                }
                        else if(Number(this.month) > limitDate.getMonth()+1)
                        {
                            try
                            {
                                for(var i=1;i<32;++i)
                                {
                                    this.disableDay( i );
                                }
                            }catch(e)
                           {
                           }  
                        }else
                        {
                            //unhandled case
                        }
		            }                 
                }
                //Error
                else
                {
                    //Error: could not calculate limitDate!
                }
            }
		    
            //Last possible Month
	        if($(ele).selectedIndex == (maxCheckInNumberOfMonthKuoni-1))
	        {
	            var calcDate = new Date();
                var starttime = new Date(calcDate.getFullYear(),calcDate.getMonth(),calcDate.getDate());

                for(var i=starttime.getDate();i<32;++i)
                {
                    this.disableDay( i );
                }
            //Anything else after the  last possible month
            }else if($(ele).selectedIndex > (maxCheckInNumberOfMonthKuoni-1))
            {	           
               try{
                    for(var i=1;i<32;++i)
                    {
                        this.disableDay( i );
                    }
               }catch(e)
               {
               }      
            }    
		}else if($(ele).selectedIndex == 11)
		{
		    var calcDate = new Date();
			var starttime = new Date(calcDate.getFullYear(),calcDate.getMonth(),calcDate.getDate());
			
			var dateSpan = 339;
			starttime = new Date(starttime.valueOf()+(dateSpan*86400000));
			for(var i=starttime.getDate();i<32;++i)
			{
				this.disableDay( i );
			}
		}		
	},
	/*ROSH: 29.03.07: fill up next 12 months to select markup html element*/
	fillNavigationMonths : function(ele)
	{
		var today = new Date();
		today = new Date(today.getFullYear(), today.getMonth(), today.getDate());

		var twoDiggitYear = today.getFullYear().toString();
		var maxMonth = 11;
	   
	    for(var i=0;i<=maxMonth;++i){
		    $(ele).options[i] = new Option(calendarData.short_month[today.getMonth()] + ' ' + twoDiggitYear.substring(2,4),today.getMonth()+1);
		    today = new Date(today.getFullYear(), today.getMonth()+1, 1);
		    twoDiggitYear = today.getFullYear().toString();
	    }
	},
	/*prints the calendar into container*/
	calendar : function(year, month, day, ContainerId)
	{
		this.month = month;

		/* If no parameter is passed use the current date. */
		var calDate = new Date();
		var tmpToday = calDate.getDate();
		var tmpMonth = calDate.getMonth();
		var calYear = (year == null) ? calDate.getFullYear() : year;
		var calMte = (month == null) ? calDate.getMonth() : month - 1;
		while(calMte < 0)
		{
				calMte += 12;
				calYear--;
		}
		while(calMte >= 12)
		{
			calMte -= 12;
			calYear++;
		}

		var calDay = (day == null) ? 0 : day;
		calDate = new Date(calYear, calMte, 1);
		NextMonth = new Date(calYear, calMte + 1, 1);

		var firstDayOfMonth = new Date(calDate.getFullYear(),calDate.getMonth(),1);
		var weekDaysArray = new Array(6,0,1,2,3,4,5);

		// WeekStart = calDate.getDay();
		WeekStart = weekDaysArray[firstDayOfMonth.getDay()];

		/* Get the number of days in current month */
		MonthDays = Math.round((NextMonth.getTime() - calDate.getTime()) / 86400000) + 1;

		/* Check whether the Container Id is null */
		if(ContainerId != null)
		{
			ContainerId = ContainerId;
			Container = document.getElementById(ContainerId);
			/* If an element doesnot exists with the given ContainerId then create it */
			if(!Container)
				document.write('<div id="' + ContainerId + '">&nbsp;</div>');
		}
		else
		{
			// Loop until a unique id is obtained for the container
			do
			{
				ContainerId = 'tblCalendar' + Math.round(Math.random() * 1000);
			}
			while(document.getElementById(ContainerId));
			// create an element with the new id
			document.write('<div id="' + ContainerId + '">&nbsp;</div>');
		}
		Container = document.getElementById(ContainerId);
		HTML = '<table>';
		// Title bar
		// HTML += '<tr><td class="Nav"><a href="javascript:void(0)" onMouseDown="Calendar(' + calYear + ', ' + calMte + ', ' + calDay+', \''+ContainerId+'\');">&laquo;</a></td><td colspan="5" class="Title">' + monthNames[calMte] + ' ' + calYear + '</td><td class="Nav"><a href="javascript:void(0)" onMouseDown="Calendar(' + calYear + ', ' + (calMte + 2) + ', ' + calDay+', \''+ContainerId+'\');">&raquo;</a></td></tr>';

		// Week Names
		HTML += '<tr>';
		HTML += '	<th>'+calendarData.short_days[1]+'</th>';
		HTML += '	<th>'+calendarData.short_days[2]+'</th>';
		HTML += '	<th>'+calendarData.short_days[3]+'</th>';
		HTML += '	<th>'+calendarData.short_days[4]+'</th>';
		HTML += '	<th>'+calendarData.short_days[5]+'</th>';
		HTML += '	<th>'+calendarData.short_days[6]+'</th>';
		HTML += '	<th>'+calendarData.short_days[0]+'</th>';
		HTML += '</tr>';
		HTML += '<tr>';

		// Fill the previous month days with space
		for(DayCounter = 0; DayCounter < WeekStart; DayCounter++)
		{
			HTML += '<td>&nbsp;</td>';
		}

		// Populate current month
		for(DayCounter = 1; DayCounter < MonthDays; DayCounter++)
		{
			if((DayCounter + WeekStart) % 7 == 1)
				HTML += '<tr>';

			/*non-optional days*/
			if( tmpMonth == calMte && (DayCounter < tmpToday) )
			{
				HTML += '<td class="" style="	color: #656565;font-weight: bold;">' + DayCounter + '</td>';
			}
			/*selected day*/
			else if(DayCounter == calDay)
			{
				HTML += '<td class="possible"><a href="#" id="'+this.id+'_possibleSlelecteDay_'+DayCounter+'" onclick="'+this.id+'.setSelected(this, \''+DayCounter+'\');return false;">' + DayCounter + '</a></td>';
			}
			/*optional days*/
			else
			{
				HTML += '<td class="possible"><a href="#" id="'+this.id+'_possibleSlelecteDay_'+DayCounter+'" onclick="'+this.id+'.setSelected(this, \''+DayCounter+'\');return false;">' + DayCounter + '</a></td>';
			}

			if((DayCounter + WeekStart) % 7 == 0)
				HTML += '</tr>';
		}

		// Fill the next month days with space
		for(j = (42 - (MonthDays + WeekStart)), DayCounter = 0; DayCounter <= j; DayCounter++)
		{
			HTML += '<td>&nbsp;</td>';
			if((j - DayCounter) % 7 == 0) HTML += '</tr>';
		}
		HTML += '</table>';
		Container.innerHTML = HTML;

		// Returns Id of the element containing the calendar
		return ContainerId;
	},
	updateRefTextHtml : function(elementName)
	{
		this.refTextHtml = elementName;
	}
} /*end class*/

