/**
 * URL/selected values from parent (window.opener)
 *
 * functions for hotellist
 *
 * Author Mario Diaz (4fb) Created 2008-09-30 Modified by Bernhard Bezdek
 * (2010-02-03) Updatet function fot
 * BUGFIX -> Line (#949 - #952) Fixes a Problem switching Roomtype and Calculate Price MATRIX[2010/04/23] (Bernhard Bezdek)
 * BUGFIX -> Line #1105 Fixed a Problem if there is a minammount and just on day with a possible arrival and or just one day with a possiople leave
 *
 */
var pFound = false;
var sPriceDisplay = '';
var sUrlContingent = false;
var sBookingKind = false;

var aImages = new Array('upload/zimages/bg_day.gif', 'upload/zimages/hl_choose_active.gif', 'upload/zimages/hl_choose_green_g.gif', 'upload/zimages/hl_choose_green_w.gif', 'upload/zimages/hl_choose_orange_g.gif', 'upload/zimages/hl_choose_orange_w.gif');
preloadImages(aImages);
/**
 * calls function for displaying layer
 *
 * @param string
 *            sLocation
 * @return void
 */
function popWinCenter(sLocation){
	showTermsLayer('legal_notice');
}

/**
 * shows full minbooking string in layer
 *
 * @param string
 *            sMin
 * @param int
 *            iIdCaller
 * @return void
 */
function toggleMinBookingLayer(sMin, oCaller){
	if (document.getElementById('minbooking_info')) {
		oLayer = document.getElementById('minbooking_info');
		if (sMin == '') {
			oLayer.style.display = 'none';
		}
		else {
			oLayer.innerHTML = sMin;
			aTmp = findPos(oCaller);
			oLayer.style.display = 'inline';
			oLayer.style.left = aTmp[0] - oLayer.offsetWidth + oCaller.offsetWidth + 'px';
			oLayer.style.top = (aTmp[1] - oLayer.offsetHeight) + 'px';
		}
	}
}

/**
 * for submitting hotellist view: check if choosen value == 'unlimited'
 *
 * @return void
 */
function submitHotelList(){
	sValue = selectValue(document.forms['frmSearch_Hotel'].count_rooms);
	if (sValue != 'unlimited' || bLogged) {
		bCanSubmit = true;
		if (sBookingKind != "new_contingent" && bLogged && sValue == 'unlimited') {
			if (!confirm(sHintGoToNewContingent)) {
				bCanSubmit = false;
			}
		}
		if (bCanSubmit) {
			document.forms['frmSearch_Hotel'].submit();
		}
		else {
			document.getElementById('count_rooms').selectedIndex = iSelectedIndexRoomCount;
		}
	}
	else {
		popWinCenter(sLocationChoose);
	}
}




/*
 * *** functions for hotellist specials
 * *****************************************************************************
 */
/**
 * shows possible dates arrival
 *
 * @param string
 *            sHtmlId
 * @return void
 */
function showLayer(sHtmlId){
	// position X and Y:
	// first find element to position:
	aTmp = sHtmlId.split('_');
	oLayerPos = document.getElementById('select_' + aTmp[2]);
	aTmp = findPos(oLayerPos);
	document.getElementById(sHtmlId).style.left = aTmp[0] + 'px';
	document.getElementById(sHtmlId).style.top = aTmp[1] + 'px';
	document.getElementById(sHtmlId).style.visibility = 'visible';
}

var aLowestIndices = new Array();
aLowestIndices['arrival'] = 0;
aLowestIndices['departure'] = 0;
aLowestIndices['amount'] = 0;
aLowestIndices['roomcat'] = 0;

/**
 * if user clicks a value in absolute layer then change hide that absolute layer
 * and change display value
 *
 * @param string
 *            sType (arrival etc)
 * @param string
 *            sValue
 * @return void
 */
function changeSelValue(sType, sValue){

	bWasfirst = false;
	bHotellist = false;
	var bResetAll = false;
	
	if (!document.getElementById('hotel_matrix')) {
		bHotellist = true;
	}
	if (document.getElementById('hotellist_sel_' + sType + '_layer')) {
		document.getElementById('hotellist_sel_' + sType + '_layer').style.visibility = 'hidden';
	}
	else {
		document.getElementById('hotelmatrix_sel_' + sType + '_layer').style.visibility = 'hidden';
	}
	sHtmlIdValue = 'value_' + sType;
	
	if (sType == 'amount') {
		document.getElementById(sHtmlIdValue).innerHTML = sValue;
	}
	else {
		if (sType == 'roomcat') {
			bResetAll = true;
			iRoomcat = parseIntReal(sValue);
			sRoomdesc = aRoomCats[iRoomcat];
			aTmp = sRoomdesc.split(',');
			document.getElementById(sHtmlIdValue).innerHTML = (aTmp[0].length > 9) ? '<span style="font-size: 14px;">' + aTmp[0] + '</span>' : aTmp[0];
			document.getElementById('value_' + sType + '_bottom').innerHTML = (aTmp.length > 1) ? aTmp[1] : '';
		}
		else {
			aTmp = sValue.split(' ');
			document.getElementById(sHtmlIdValue).innerHTML = aTmp[0];
			// Rest of date
			document.getElementById('value_' + sType + '_bottom').innerHTML = aTmp[1] + ' ' + aTmp[2];
		}
	}
	// now change active styles in list:
	iCounter = aLowestIndices[sType];
	while (true) {
		if (!document.getElementById('a_sel_' + sType + '_' + iCounter)) {
			break;
		}
		oElement = document.getElementById('a_sel_' + sType + '_' + iCounter);
		if (sType != 'roomcat') {
			if (oElement.innerHTML == sValue) {
				oElement.className = 'red';
			}
			else {
				oElement.className = '';
			}
		}
		else {
			if (iCounter == iRoomcat) {
				oElement.className = 'roomcat red';
			}
			else {
				oElement.className = 'roomcat';
			}
		}
		iCounter++;
	}
	
	// Correct arrival or departure if user has chosen departure < arrival or
	// arrival > departure
	if (arguments.length == 2 && (sType == 'arrival' || sType == 'departure')) {
		oDateArrival = new Date();
		oDateDeparture = new Date();
		aTmp = sValue.split(' ');
		sTmp = aTmp[0];
		if (sTmp.charAt(0) == '0') {
			sTmp = sTmp.charAt(1);
		}
		iDay = parseIntReal(sTmp);
		iMonth = getMonthAsInt(aTmp[1]) - 1;
		iYear = parseInt("20" + aTmp[2]);
		
		if (sType == 'arrival') {
			oDateArrival.setFullYear(iYear);
			oDateArrival.setDate(iDay);
			oDateArrival.setMonth(iMonth);
		}
		else {
			oDateDeparture.setFullYear(iYear);
			oDateDeparture.setDate(iDay);
			oDateDeparture.setMonth(iMonth);
		}
		// get other value
		sTypeOther = (sType == 'arrival') ? 'departure' : 'arrival';
		if (bHotellist && !document.getElementById('value_' + sTypeOther)) {
			return 1; // we are on matrix site
		}
		aDate = getDateFromHTML(sTypeOther);
		iDay = aDate[0];
		iMonth = aDate[1];
		iYear = aDate[2];
		
		if (sTypeOther == 'arrival') {
			oDateArrival.setFullYear(iYear);
			oDateArrival.setDate(iDay);
			oDateArrival.setMonth(iMonth);
		}
		else {
			oDateDeparture.setFullYear(iYear);
			oDateDeparture.setDate(iDay);
			oDateDeparture.setMonth(iMonth);
		}
		
		// now compare:
		if (oDateArrival >= oDateDeparture && 3 == 2) {
			oDate = new Date();
			if (sType == 'arrival') {
				oDateArrival.setDate(oDateArrival.getDate() + 1);
				oDate = oDateArrival;
			}
			else {
				oDateDeparture.setDate(oDateDeparture.getDate() - 1);
				oDate = oDateDeparture;
			}
			// now set that value:
			iDay = oDate.getDate();
			sMonth = aMonths[(oDate.getMonth() + 1)];
			iYear = oDate.getFullYear();
			sYear = (iYear.toString()).substring(2, 4);
			sValue = iDay + ' ' + sMonth + ' ' + sYear;
			if (bHotellist) {
				changeSelValue(sTypeOther, sValue, true);
			}
		}
	}
	if (bMsie) {
		document.all.V1.focus();
	}
	if (bHotellist) {
		refreshHotellist();
	}
	else 
		if (document.getElementById('hotel_matrix')) {
			refreshHotelMatrix(bResetAll);
		}
	return 1;
}

/**
 * gets date from html and returns array
 *
 * @param string
 *            sType
 * @return array
 */
function getDateFromHTML(sType){
	var aReturn = new Array();
	if (document.getElementById('value_' + sType)) {
		sTmp = trimAll(document.getElementById('value_' + sType).innerHTML);
		
		// alert(sTmp.charAt(0));
		if (sTmp.charAt(0) == '0') {
			sTmp = sTmp.charAt(1);
		}
		aReturn[0] = parseIntReal(sTmp);
		
		// alert(aReturn[0]);
		sTmp = trimAll(document.getElementById('value_' + sType + '_bottom').innerHTML);
		aTmp = sTmp.split(' ');
		
		aReturn[1] = getMonthAsInt(aTmp[0]) - 1;
		aReturn[2] = parseInt("20" + aTmp[1]);
	}
	return aReturn;
}

/**
 * adds dates before or after existing dates (departure or arrival layer)
 *
 * @param string
 *            sType
 * @param string
 *            sAction
 * @return void
 */
function addDatesSelLayer(sType, sAction){
	sNewContent = '';
	if (sAction == 'earlier') { // add 5 days before
		// get first date:
		if (document.getElementById('a_sel_' + sType + '_' + aLowestIndices[sType])) {
			sDateFirst = document.getElementById('a_sel_' + sType + '_' + aLowestIndices[sType]).innerHTML;
			aTmp = sDateFirst.split(' ');
			iMonth = getMonthAsInt(aTmp[1]) - 1;
			aLowestIndices[sType] -= 5;
			oDate = new Date();
			oDate.setFullYear(parseInt("20" + aTmp[2]));
			oDate.setDate(parseIntReal(aTmp[0]));
			oDate.setMonth(iMonth);
			oDate.setDate(oDate.getDate() - 6);
			for (i = aLowestIndices[sType]; i < aLowestIndices[sType] + 5; i++) {
				oDate.setDate(oDate.getDate() + 1);
				iDay = oDate.getDate();
				sDay = (iDay < 10) ? '0' + iDay : '' + iDay;
				sMonth = aMonths[oDate.getMonth() + 1];
				iYear = oDate.getFullYear();
				sYear = (iYear.toString()).substring(2, 4);
				sNewDate = sDay + ' ' + sMonth + ' ' + sYear;
				sNewContent += '<div class="item"><a id="a_sel_' + sType + '_' + i + '" href="#" onclick="changeSelValue (\'' + sType + '\', \'' + sNewDate + '\'); return false;">' + sNewDate + '</a></div>';
			}
			document.getElementById('sel_list_' + sType).innerHTML = sNewContent + document.getElementById('sel_list_' + sType).innerHTML;
			document.getElementById('sel_layer_top_' + sType).innerHTML = '&nbsp;';
		}
	}
	else { // add 5 days after
		// find highest:
		if (document.getElementById('a_sel_' + sType + '_0')) {
			iCounter = 0;
			while (true) {
				if (!document.getElementById('a_sel_' + sType + '_' + iCounter)) {
					break;
				}
				iCounter++;
			}
			sDateLast = document.getElementById('a_sel_' + sType + '_' + (iCounter - 1)).innerHTML;
			aTmp = sDateLast.split(' ');
			iMonth = getMonthAsInt(aTmp[1]) - 1;
			oDate = new Date();
			oDate.setFullYear(parseInt("20" + aTmp[2]));
			// alert(parseIntReal(aTmp[0]));
			oDate.setDate(parseIntReal(aTmp[0]));
			oDate.setMonth(iMonth);
			for (i = 0; i < 5; i++) {
				oDate.setDate(oDate.getDate() + 1);
				iDay = oDate.getDate();
				sDay = (iDay < 10) ? '0' + iDay : '' + iDay;
				sMonth = aMonths[oDate.getMonth() + 1];
				iYear = oDate.getFullYear();
				sYear = (iYear.toString()).substring(2, 4);
				sNewDate = sDay + ' ' + sMonth + ' ' + sYear;
				sNewContent += '<div class="item"><a id="a_sel_' + sType + '_' + (iCounter + i) + '" href="#" onclick="changeSelValue (\'' + sType + '\', \'' + sNewDate + '\'); return false;">' + sNewDate + '</a></div>';
			}
			document.getElementById('sel_list_' + sType).innerHTML += sNewContent;
			document.getElementById('sel_layer_bottom_' + sType).innerHTML = '&nbsp;';
		}
	}
}

/**
 * help function for date: Get month as int from array aMonths
 *
 * @param string
 *            sMonth
 * @return int
 */
function getMonthAsInt(sMonth){
	// no use of indexOf because of browser comp.
	for (i = 1; i < 13; i++) {
		if (aMonths[i] == sMonth) {
			return i;
		}
	}
	return 0;
}

/**
 * checks if user can book more rooms than given in list
 *
 * @return void
 */
function checkMoreRooms(){
	sValue = "unlimited"; // selectValue
	// (document.forms['frmSearch_Hotel'].count_rooms);
	if (sValue != 'unlimited' || bLogged) {
		bCanSubmit = true;
		if (sBookingKind != "new_contingent" && bLogged && sValue == 'unlimited') {
			if (!confirm(sHintGoToNewContingent)) {
				bCanSubmit = false;
			}
		}
		if (bCanSubmit) {
			// reload page with change of booking type #count_rooms=unlimited
			if (!sUrlContingent) {
				location.href = sAction + '?idcat=' + iIdcat + '&idart=' + iIdart + '&ex_id=' + iExId + '&count_rooms=unlimited&more=1';
			}
			else {
				location.href = sUrlContingent;
			}
		}
	}
	else {
		if (window.location.href.search('https') == -1) {
			sSecureUrl = window.location.href.replace(/http/g, 'https');
			window.location.href = sSecureUrl + '?morerooms=yes';
		}
		else {
			popWinCenter(sLocationChoose);
		}
	}
}

function domContains(container, containee){
	while (containee) {
		if (container === containee) {
			return true;
		}
		containee = containee.parentNode;
	}
	return false;
}

function checkMouseLeave(node, evt){
	if (typeof evt.relatedTarget != 'undefined') {
		return !domContains(node, evt.relatedTarget);
	}
	else 
		if (typeof evt.toElement != 'undefined' && typeof node.contains != 'undefined') {
			// return !node.contains(evt.toElement);
			return (evt.fromElement.tagName == "DIV" && !node.contains(evt.toElement));
		}
}

// active hotel details (rooms/availibility)
var iActiveHotelDetails = 0;
// save img src for reset:
var sChooseImgSrc = '';
/**
 * shows layer with details (rooms/availibility) and changes styles for hotel
 * row:
 *
 * @param int
 *            iHotelId
 * @return void
 */
function showHotelDetails(iHotelId){
	if (document.getElementById('hotel_row_' + iHotelId)) {
		if (iActiveHotelDetails == iHotelId) {
			hideHotelDetails();
		}
		else {
			// if other is opened then close it:
			if (iActiveHotelDetails != 0) {
				hideHotelDetails();
			}
			oHotelRow = document.getElementById('hotel_row_' + iHotelId);
			aTmp = (oHotelRow.className).split(' ');
			// oHotelRow.className = (aTmp[0] + ' bg_dark_grey');
			if (!bMsie6) {
				oHotelRow.style.backgroundColor = '#C8C8C8';
			}
			sChooseImgSrc = document.getElementById('choose_img_' + iHotelId).src;
			// active button depends on color:
			aTmp = sChooseImgSrc.split('_');
			iTmp = aTmp.length;
			sColor = '';
			for (i = 0; i < iTmp; i++) {
				switch (aTmp[i]) {
					case 'green':
						sColor = 'green';
						break;
						
					case 'orange':
						sColor = 'orange';
						break;
						
					case 'red':
						sColor = 'red';
						break;
						
					default:
						break;
				}
				
				if (sColor != '') {
					break;
				}
			}
			// alert(sColor);
			sBaseHref = document.getElementsByTagName('base')[0].href;
			
			document.getElementById('choose_img_' + iHotelId).src = sBaseHref + 'upload/zimages/hl_choose_active_' + sColor + '.gif';
			iActiveHotelDetails = iHotelId;
			document.getElementById('big_details_' + iHotelId).style.display = 'block';
			document.getElementById('big_details_' + iHotelId).style.backgroundColor = '#FFF';
			// position and show next button
			if (document.getElementById('hotellist_next_button')) {
				oNextButtonLayer = document.getElementById('hotellist_next_button');
				aTmp = findPos(document.getElementById('big_details_' + iHotelId));
				oNextButtonLayer.style.visibility = 'visible';
				oNextButtonLayer.style.top = (aTmp[1] + 10) + 'px';
				oNextButtonLayer.style.left = (aTmp[0] + 758) + 'px';
				correctMsieBugs();
			}
		}
	}
}

/**
 * hides active hotel details
 *
 * @return void
 */
function hideHotelDetails(){
	if (iActiveHotelDetails != 0) {
		oHotelRow = document.getElementById('hotel_row_' + iActiveHotelDetails);
		// aTmp = (oHotelRow.className).split(' ');
		// oHotelRow.className = (aTmp[0] + ' black');
		oHotelRow.style.backgroundColor = '#FFF';
		document.getElementById('choose_img_' + iActiveHotelDetails).src = sChooseImgSrc;
		document.getElementById('big_details_' + iActiveHotelDetails).style.display = 'none';
		iActiveHotelDetails = 0;
		document.getElementById('hotellist_next_button').style.visibility = 'hidden';
		if (document.getElementById('hotellist_room_desc')) {
			document.getElementById('hotellist_room_desc').style.visibility = 'hidden';
		}
		if (document.getElementById('hotellist_room_desc_locked')) {
			document.getElementById('hotellist_room_desc_locked').style.visibility = 'hidden';
		}
	}
}

// for show more/less days in big details:
var aShowDays = new Array();
/**
 * if more than 10 days in big details list then days-paging function (here next
 * (max 5)
 *
 * @param int
 *            iHotelId
 * @param int
 *            iFirst
 * @param int
 *            iLast
 * @return void
 */
function showMoreDays(iHotelId, iFirst, iLast){
	if (!aShowDays[iHotelId]) { // save current
		aShowDays[iHotelId] = new Array();
		aShowDays[iHotelId][0] = iFirst;
		aShowDays[iHotelId][1] = iLast;
	}
	iCounterHide = aShowDays[iHotelId][0];
	iCounterShow = aShowDays[iHotelId][1];
	iCounter = 0; // only 5 each time
	while (document.getElementById('day_header_' + iHotelId + '_' + iCounterShow)) {
		aShowDays[iHotelId][0] = iCounterHide;
		aShowDays[iHotelId][1] = iCounterShow;
		document.getElementById('day_header_' + iHotelId + '_' + iCounterShow).style.display = 'inline';
		document.getElementById('day_header_' + iHotelId + '_' + iCounterHide).style.display = 'none';
		// now show/hide days of rooms:
		iCounterRoom = 0;
		while (document.getElementById('day_details_' + iHotelId + '_' + iCounterRoom + '_' + iCounterShow)) {
			document.getElementById('day_details_' + iHotelId + '_' + iCounterRoom + '_' + iCounterShow).style.display = 'inline';
			document.getElementById('day_details_' + iHotelId + '_' + iCounterRoom + '_' + iCounterHide).style.display = 'none';
			iCounterRoom++;
		}
		iCounterHide++;
		iCounterShow++;
		iCounter++;
		if (iCounter == 5) {
			break;
		}
	}
	// if no more rooms later then hide button:
	if (!document.getElementById('day_header_' + iHotelId + '_' + iCounterShow)) {
		document.getElementById('show_more_days_' + iHotelId).style.display = 'none';
	}
	// show prev button:
	document.getElementById('show_less_days_' + iHotelId).style.display = 'inline';
}

/**
 * if more than 10 days in big details list then days-paging function (here:
 * paging back)
 *
 * @param int
 *            iHotelId
 * @param int
 *            iFirst
 * @param int
 *            iLast
 * @return void
 */
function showLessDays(iHotelId, iFirst, iLast){
	if (!aShowDays[iHotelId]) { // save current
		aShowDays[iHotelId] = new Array();
		aShowDays[iHotelId][0] = iFirst;
		aShowDays[iHotelId][1] = iLast;
	}
	iCounterHide = aShowDays[iHotelId][1];
	iCounterShow = aShowDays[iHotelId][0];
	iCounter = 0;
	while (document.getElementById('day_header_' + iHotelId + '_' + iCounterShow)) {
		aShowDays[iHotelId][1] = iCounterHide;
		aShowDays[iHotelId][0] = iCounterShow;
		document.getElementById('day_header_' + iHotelId + '_' + iCounterShow).style.display = 'inline';
		if (document.getElementById('day_header_' + iHotelId + '_' + iCounterHide)) {
			document.getElementById('day_header_' + iHotelId + '_' + iCounterHide).style.display = 'none';
		}
		// now show/hide days of rooms:
		iCounterRoom = 0;
		while (document.getElementById('day_details_' + iHotelId + '_' + iCounterRoom + '_' + iCounterShow)) {
			document.getElementById('day_details_' + iHotelId + '_' + iCounterRoom + '_' + iCounterShow).style.display = 'inline';
			if (document.getElementById('day_details_' + iHotelId + '_' + iCounterRoom + '_' + iCounterHide)) {
				document.getElementById('day_details_' + iHotelId + '_' + iCounterRoom + '_' + iCounterHide).style.display = 'none';
			}
			else {
				// alert ('day_details_' + iHotelId + '_' + iCounterRoom + '_' +
				// iCounterHide);
			}
			iCounterRoom++;
		}
		iCounterHide--;
		iCounterShow--;
		iCounter++;
		if (iCounter == 5) {
			break;
		}
	}
	// if no more rooms later then hide button:
	if (!document.getElementById('day_header_' + iHotelId + '_' + iCounterShow)) {
		document.getElementById('show_less_days_' + iHotelId).style.display = 'none';
	}
	document.getElementById('show_more_days_' + iHotelId).style.display = 'inline';
}

/**
 * shows room desc (alpha layer) Thus find pos and display room desc in layer
 *
 * @param int
 *            iRoomRowId
 * @return void
 */
function showRoomDesc(iRoomRowId, iRoomIndex){
	oRoomRow = document.getElementById('room_days_row_' + iRoomRowId);
	aTmp = findPos(oRoomRow);
	oLayerAlpha = document.getElementById('hotellist_room_desc');
	if (!bMsie6) {
		oLayerAlpha.style.left = (aTmp[0] + 44) + 'px';
	}
	else {
		oLayerAlpha.style.left = (aTmp[0] - 74) + 'px';
	}
	oLayerAlpha.style.top = aTmp[1] + 'px';
	oTmp = document.getElementById('room_desc_img_' + iRoomRowId).getAttributeNode('alt');
	document.getElementById('hotellist_room_desc_inner').innerHTML = oTmp.nodeValue;
	oLayerAlpha.style.visibility = 'visible';
	iCurrRoomSelectedIndex = iRoomIndex;
}

var iCurrRoomSelectedIndex = 0;
var iSelectedRoomIndex = 0;
/**
 * lock room selection or hide it: 1. if user clicks on room desc layer then
 * position the second layer (same look) exactly where other is and fill
 * innerHTML (innerHTML of room desc layer) and set selected room index 2. if
 * user clicks on this second layer then hide it and reset iRoomIndex
 *
 * @param bool
 *            bShow
 */
function lockRoomSelection(bShow){
	oLayerDescLocked = document.getElementById('hotellist_room_desc_locked');
	if (bShow) {
		iSelectedRoomIndex = iCurrRoomSelectedIndex;
		aTmp = findPos(document.getElementById('hotellist_room_desc'));
		oLayerDescLocked.style.left = aTmp[0] + 'px';
		oLayerDescLocked.style.top = aTmp[1] + 'px';
		document.getElementById('hotellist_room_desc_inner_l').innerHTML = document.getElementById('hotellist_room_desc_inner').innerHTML;
		oLayerDescLocked.style.visibility = 'visible';
	}
	else {
		iSelectedRoomIndex = 0;
		oLayerDescLocked.style.visibility = 'hidden';
		oLayerDescLocked.style.top = '0px';
	}
}

// AJAX without XML: Get more fairs:
var bRefresh = true;
/**
 * refreshes hotel list with AJAX gets values, creates URL ad creates script
 * element for ajax
 *
 * @return void
 */
function refreshHotellist(bResetRadios){
	hideHotelDetails();
	if (bRefresh) {
		if (document.getElementById('hotellist_hotels')) {
			bRefresh = false;
			document.getElementById('message_layer').innerHTML = '';
			document.getElementById('hotellist_next_button').style.visibility = 'hidden';
			document.getElementById('hotellist_hotels').innerHTML = document.getElementById('loading_stuff').innerHTML;
			aArrival = getDateFromHTML('arrival');
			aArrival[1]++;
			aDeparture = getDateFromHTML('departure');
			aDeparture[1]++;
			iAmount = parseInt((document.getElementById('value_amount')) ? document.getElementById('value_amount').innerHTML : '');
			sURL = 'index.html?idart=' + iAjaxHotellistIdart + '&ex_id=' + iExId + '&datefrom=' + aArrival.join('/') + '&dateuntil=' + aDeparture.join('/') + '&room_count=' + iAmount;
			if (iAjaxSortBy != 0) {
				sURL += '&sortby=' + iAjaxSortBy;
			}
			if (iAjaxSortOrder != 0) {
				sURL += '&sortorder=' + iAjaxSortOrder;
			}
			var jsel = document.createElement('SCRIPT');
			jsel.type = 'text/javascript';
			jsel.src = sURL;
			// Append JS element (therefore executing the 'AJAX' call)
			document.body.appendChild(jsel);
			bRefresh = true;
		}
		else {
			if (!bMsie) {
				setTimeout("refreshHotellist ()", 1000);
			}
		}
	}
}

/**
 * changes sorting of hotellist
 *
 * @param int
 *            iSortBy
 * @param int
 *            iSortOrder
 * @return void
 */
function changeHotellistSort(iSortBy, iSortOrder){
	aArrival = getDateFromHTML('arrival');
	aArrival[1]++;
	aDeparture = getDateFromHTML('departure');
	aDeparture[1]++;
	iAmount = parseInt((document.getElementById('value_amount')) ? document.getElementById('value_amount').innerHTML : '');
	sBaseHref = document.getElementsByTagName('base')[0].href; // msie again
	// and again...
	sUrl = sBaseHref + 'index.html?idcat=' + iIdcat + '&idart=' + iIdart + '&ex_id=' + iExId + '&datefrom=' + aArrival.join('/') + '&dateuntil=' + aDeparture.join('/') + '&room_count=' + iAmount + '&sortby=' + iSortBy + '&sortorder=' + iSortOrder;
	location.href = sUrl;
}

/**
 * refreshes hotel matrix gets values, creates URL ad creates script element for
 * ajax
 *
 * @return void
 */
function refreshHotelMatrix(bResetArrivalDeparture){
	if (bRefresh) {
	
		$('#price_all').text('EUR 0,00');
		bRefresh = false;
		document.getElementById('text_fair_period').style.display = 'none';
		document.getElementById('message_layer').innerHTML = '';
		sArrival = '';
		sRadioValue = '';
		if (document.forms['hotel_matrix_form'].datefrom) {
			sArrival = radioValue(document.forms['hotel_matrix_form'].datefrom);
		}
		if (radioValue(document.forms['hotel_matrix_form'].dateuntil)) {
			sRadioValue = radioValue(document.forms['hotel_matrix_form'].dateuntil);
		}
		
		document.getElementById('hotel_matrix_selection').innerHTML = document.getElementById('loading_stuff').innerHTML;
		iAmount = parseInt((document.getElementById('value_amount')) ? document.getElementById('value_amount').innerHTML : 1);
		document.forms['hotel_matrix_form'].room_amount.value = iAmount;
		sDateUntilPar = '';
		
		if (sRadioValue != false) {
			sDateUntilPar = '&dateuntil=' + sRadioValue;
		}
		sURL = 'front_content.php?ajax_req=1&idart=' + iAjaxHotelmatrixIdart + '&ex_id=' + iExId + '&datefrom=' + sArrival + '&hotelId=' + iHotelId + '&room_count=' + iAmount + '&room_index=' + iRoomcat + sDateUntilPar;
		
		// Check if all radios should be reseted by server
		if (bResetArrivalDeparture == true) {
			sURL += '&resetall=yes';
		}
		
		var jsel = document.createElement('SCRIPT');
		jsel.type = 'text/javascript';
		jsel.src = sURL;
		// Append JS element (therefore executing the 'AJAX' call)
		document.body.appendChild(jsel);
		bRefresh = true;
		
		// now change min_booking:
		iCounterMinb = 0;
		// alert(iRoomcat);
		while (document.getElementById('minbooking_room_' + iCounterMinb)) {
			document.getElementById('minbooking_room_' + iCounterMinb).style.display = (iCounterMinb == iRoomcat) ? 'block' : 'none';
			if (document.getElementById('room_cond_' + iCounterMinb)) {
				document.getElementById('room_cond_' + iCounterMinb).style.display = (iCounterMinb == iRoomcat) ? 'block' : 'none';
			}
			iCounterMinb++;
		}
	}
}

/**
 * shows layer with explanations
 *
 * @return void
 */
function showDistanceExpl(){
	if (document.getElementById('explanations_bottom')) {
		oLayer = document.getElementById('explanations_bottom');
		aTmp = findPos(document.getElementById('header_distance'));
		oLayer.style.left = (aTmp[0] - 10) + 'px';
		oLayer.style.top = (aTmp[1] + document.getElementById('header_distance').offsetHeight) + 'px';
		oLayer.style.display = (oLayer.style.display == 'inline') ? 'none' : 'inline';
	}
}

/**
 * goes to hotel matrix if no hotel selected (no hotel avail) then go to manual
 * form else collect selected values and pass them to matrix
 *
 * @return void
 */
function goToMatrix(){
	if (iActiveHotelDetails == -1) { // manual
		if (document.getElementById('r_0').checked) {
			window.open(document.getElementById('href_der_hotel').value);
		}
		else 
			if (document.getElementById('r_1').checked) {
				location.href = document.getElementById('manual_booking_link').value;
			}
	}
	else 
		if (iActiveHotelDetails != 0) {
			aArrival = getDateFromHTML('arrival');
			aArrival[1]++;
			if (aArrival[0] < 10) {
				aArrival[0] = '0' + aArrival[0];
			}
			if (aArrival[1] < 10) {
				aArrival[1] = '0' + aArrival[1];
			}
			aDeparture = getDateFromHTML('departure');
			aDeparture[1]++;
			if (aDeparture[0] < 10) {
				aDeparture[0] = '0' + aDeparture[0];
			}
			if (aDeparture[1] < 10) {
				aDeparture[1] = '0' + aDeparture[1];
			}
			iAmount = 1;
			if (document.getElementById('value_amount')) {
				iAmount = parseInt((document.getElementById('value_amount')) ? document.getElementById('value_amount').innerHTML : '');
			}
			if (isNaN(iAmount)) {
				iAmount = 1;
			}
			var sBaseHref = $('base').attr('href');
			sHrefMatrix = sBaseHref + sUrlFirst + ',' + iCUST_ID + ',' + iADD_ID + ',' + iFairLogoId + ',' + iExId + ',' + iVacId + ',' + aArrival.join('/') + '-' + aDeparture.join('/') + ',' + iAmount + ',' + iActiveHotelDetails + '|' + iSelectedRoomIndex + '|matrix,' + iLang + '.html';
			
			// if iframe then open in new win:
			if (document.getElementById('iframe')) {
				window.open(sHrefMatrix);
			}
			else {
				location.href = sHrefMatrix;
			}
		}
		else {
			alert('No hotel selected!');
		}
}

/**
 * goes back to hotellist from matrix (fetch params and create url)
 *
 * @return void
 */
function goBackToHotellist(){
	aArrival = getDateFromHTML('arrival');
	aArrival[1]++;
	if (aArrival[1] < 10) {
		aArrival[1] = '0' + aArrival[1];
	}
	sHrefHotellist = 'index-v-33-45-' + iExId + '-' + aArrival.join('/') + '-([0-9]{2}\/[0-9]{2}\/[0-9]{4})_' + iIdlang + '.html';
	// alert(sHrefHotellist);
}

/**
 * positions fair period text (vertical text)
 *
 * @return void
 */
function positionFairPeriodText(){
	// good possibility to mark fair period:
	if (document.getElementById('icon_fair_first_day')) {
		aTmp = findPos(document.getElementById('icon_fair_first_day'));
		oLayer = document.getElementById('text_fair_period');
		oLayer.style.display = 'inline';
		oLayer.style.left = (aTmp[0] - 13) + 'px';
		if (document.getElementById('icon_fair_last_day')) {
			aTmpB = findPos(document.getElementById('icon_fair_last_day'));
			aTmp[1] = aTmp[1] + Math.round((aTmpB[1] - aTmp[1] - oLayer.offsetHeight) / 2);
		}
		oLayer.style.top = aTmp[1] + 'px';
	}
	else {
		document.getElementById('text_fair_period').style.display = 'none';
	}
}

/**
 * matrix: Calculate price if user checks radio button
 *
 * @return iStatus (-2 minbooking error, -1: not enough selected, 0: arrival >
 *         departure, 1: ok)
 */
var bFirstCalc = true;
var bWasfirst = false;

function calculatePrice(sCallId){

	if (iMinAmountNights == -1 && !bWasfirst) {
		if (!bFirstCalc) {
			iMinAmountNights = 0;
			
		}
		else {
			bFirstCalc = false;
			bWasfirst = true;
		}
	}
	else {
		bFirstCalc = false;
	}
	if (parseInt(iMinAmountNights) == 0) {
	
		positionFairPeriodText();
		
		sValue = false;
		sValueArrival = false;
		
		sValue = radioValue(document.forms['hotel_matrix_form'].dateuntil);
		
		sValueArrival = radioValue(document.forms['hotel_matrix_form'].datefrom);
		// /alert('Anreise laut URL: '+sValueArrival+' - '+sValue);
		if (sCallId != undefined) {
		
			var iRadios = parseInt(document.forms['hotel_matrix_form'].datefrom.length);
			var iChecked = sCallId.split("_");
			
			iChecked = parseInt(iChecked[1]);
			
			var sLastInRange = false;
			
			for (i = iChecked; i < iRadios; i++) {
				var tmpa = document.forms['hotel_matrix_form'].datefrom[i].value.split("/");
				if (sLastInRange == false || parseInt(sLastInRange) + 1 == parseIntReal(tmpa[0])) {
					sLastInRange = parseIntReal(tmpa[0]);
					
				}
			}
			tmpa = sValue.split("/");
			tmpb = sValueArrival.split("/");
			
			if (parseIntReal(tmpa[0]) <= parseIntReal(tmpb[0]) || parseIntReal(tmpa[0]) - 1 > sLastInRange) {
				//document.forms['hotel_matrix_form'].dateuntil[iChecked].checked = true;
			}
		}
		
		else {
			var iRadios = parseInt(document.forms['hotel_matrix_form'].dateuntil.length);
			
			var iChecked = 0;
			for (var i = 0; i < document.forms['hotel_matrix_form'].dateuntil.length; i++) {
				if (document.forms['hotel_matrix_form'].dateuntil[i].checked == true) {
					iChecked = i;
				}
			}
			// alert('Areisebubble Nr '+ iChecked);
			
			var sFirstInRange = false;
			
			
			
			
			for (var i = iChecked; i >= 0; i = i - 1) {
				var tmpa = document.forms['hotel_matrix_form'].dateuntil[i].value.split("/");
				
				// Kill the Bug if there is a date with a 0 as first char
				
				/*
				 * if(tmpa.charAt(0)==0){ tmpa = tmpa.charAt(1); }
				 */
				// alert(parseInt(sFirstInRange)-1+' - '+parseInt(tmpa[0]));
				// alert(parseIntReal(tmpa[0]));
				if (sFirstInRange == false || parseIntReal(sFirstInRange) - 1 == parseIntReal(tmpa[0])) {
					sFirstInRange = tmpa[0];
					// alert(sFirstInRange);
				
				}
			}
			
			tmpa = sValueArrival.split("/");
			tmpb = sValue.split("/");
			if(iChecked>0)
			{
				if (parseIntReal(tmpa[0]) >= parseIntReal(tmpb[0]) || parseIntReal(tmpa[0]) + 1 < sFirstInRange) {
					document.forms['hotel_matrix_form'].datefrom[iChecked].checked = true;
				}
			} else {
				document.forms['hotel_matrix_form'].datefrom[0].checked = true;
			}
				
		}
	}
	// Minbooking support
	else {
		// check MinAmmount
		if (iMinAmountNights != -1) {
		
			positionFairPeriodText();
			
			sValue = false;
			sValueArrival = false;
			if (document.forms['hotel_matrix_form'].dateuntil) 
				sValue = radioValue(document.forms['hotel_matrix_form'].dateuntil);
			if (document.forms['hotel_matrix_form'].datefrom) 
				sValueArrival = radioValue(document.forms['hotel_matrix_form'].datefrom);
			
			if (sValue != false && sValueArrival != false) {
				// check for negative:
				aTmp = sValue.split('/');
				oDeparture = new Date(aTmp[2], parseIntReal(aTmp[1]) - 1, parseIntReal(aTmp[0]));
				aTmp = sValueArrival.split('/');
				oArrival = new Date(aTmp[2], parseIntReal(aTmp[1]) - 1, parseIntReal(aTmp[0]));
				if (oDeparture.getTime() - oArrival.getTime() <= 0) {
					displayCurrentPrice(0.0);
					return 0;
				}
			}
		}
	}
	
	
	sValueArrival = radioValue(document.forms['hotel_matrix_form'].datefrom);
	sValue = radioValue(document.forms['hotel_matrix_form'].dateuntil);
	// Fixed a BUG if there is just one Element in Array function radioValue will not work!
	//STARTFIX
	if (!sValueArrival) {
		sValueArrival = document.forms['hotel_matrix_form'].datefrom.value;
	}
	if (!sValue) {
		sValue = document.forms['hotel_matrix_form'].dateuntil.value;
	}
	/// ENDFIX
	
	// alert(sTmp);
	if (sValue != false && sValueArrival != false) {
		// check for negative:
		aTmp = sValue.split('/');
		oDeparture = new Date(aTmp[2], parseIntReal(aTmp[1]) - 1, parseIntReal(aTmp[0]));
		aTmp = sValueArrival.split('/');
		oArrival = new Date(aTmp[2], parseIntReal(aTmp[1]) - 1, parseIntReal(aTmp[0]));
		if (oDeparture.getTime() - oArrival.getTime() <= 0) {
			displayCurrentPrice(0.0);
			return 0;
		}
		
		// check for minbooking
		if (iMinAmountNights > 0) {
			if ((oDeparture.getTime() - oArrival.getTime()) / (1000 * 60 * 60 * 24) < iMinAmountNights) {
				displayCurrentPrice(0.0);
				return -2;
			}
		}
		
		sDateUntilPassed = sValue;
		aTmp = sValue.split('/');
		sValue = aTmp[0] + '.' + aTmp[1] + '.' + aTmp[2].substring(2, 4);
		aTmp = sValueArrival.split('/');
		sValueArrival = aTmp[0] + '.' + aTmp[1] + '.' + aTmp[2].substring(2, 4);
		iCounter = 0;
		fPrice = 0.0;
		
		iAmount = parseInt((document.getElementById('value_amount')) ? document.getElementById('value_amount').innerHTML : 1);
		bAlreadyArrived = false;
		while (document.getElementById('room_date_' + iCounter)) {
			if (document.getElementById('room_radio_' + iCounter).innerHTML == ''			/*
			 * ||
			 * !document.getElementById('room_price_' +
			 * (iCounter -
			 * 1))
			 */
			) {
				iCounter++;
				continue;
			}
			sDate = document.getElementById('room_date_' + iCounter).innerHTML;
			aTmp = sDate.split(' ');
			sDate = aTmp[1];
			
			if (!bAlreadyArrived) {
				if (sDate == sValueArrival) {
					bAlreadyArrived = true;
				}
				iCounter++;
				continue;
			}
			
			// if
			// (document.forms['hotel_matrix_form'].elements['status_overbooking_'
			// + (iCounter - 1)].value == '1') {
			// bOverbooking = true;
			// }
			sPrice = document.getElementById('room_price_' + (iCounter - 1)).innerHTML;
			aTmp = sPrice.split(' ');
			if(typeof(aTmp[1])!='undefined'){
				sPrice = aTmp[1].replace('-', '00');
				sPrice = sPrice.replace(',', '.');
				if(!pFound){
					pFound = sPrice;
				}
			}else{
				if(pFound){
					sPrice = 0;
				}
			}
			fPrice += iAmount * parseFloat(sPrice);
			
			if (sDate == sValue) {
				break;
			}
			iCounter++;
		}
		
		fPrice = Math.round(fPrice * 100) / 100;
		
		displayCurrentPrice(fPrice);
		return 2;
	}
	else {
		displayCurrentPrice(0.0);
		return -1;
	}
}

/**
 * Matrix: Display current price
 *
 * @param float
 *            fPrice
 * @return void
 */
function displayCurrentPrice(fPrice){
	sPriceDisplay = fPrice.toString();
	if (sPriceDisplay.indexOf('.') == -1) {
		sPriceDisplay += ",00";
	}
	else {
		aTmp = sPriceDisplay.split('.');
		sCents = aTmp[1];
		if (sCents.length == 1) {
			sCents += "0";
		}
		sPriceDisplay = aTmp[0] + "," + sCents;
	}
	if (document.getElementById('price_all')) {
		if (sPriceDisplay == 'NaN,-') {
			document.getElementById('price_all').innerHTML = '';
			document.getElementById('expl_price_all').style.display = 'none';
		}
		else {
			document.getElementById('price_all').innerHTML = "EUR " + sPriceDisplay;
			document.getElementById('expl_price_all').style.display = 'inline';
		}
	}
}

/**
 * if no departure possible throw errormessage
 * called by module hotelmatrix-ajax and bookingprocessclass hotelmtrix
 * @param {Integer} iDepartures
 */
function handleDepartureRequest(iDepartures){
	if (iDepartures == 0 && sDisplayStartupError == true) {
		$("input[name=datefrom], input[name=dateuntil]").attr('checked', false);
		alert(sNoDeparturePossible);
	}
}

/**
 *
 * Matrix: Calculate current price for "new contingent" booking loop over all
 * days and check for input
 *
 * @return bool (for checking complete)
 */
function calculatePriceTm(){
	iCounter = 0;
	fPrice = 0.0;
	fPriceMinBookingDaysBeforeLast = 0.0;
	while (document.getElementById('room_date_' + iCounter)) {
		var sPrice = document.getElementById('room_price_' + iCounter).innerHTML;
		aTmp = sPrice.split(' ');
		if(typeof(aTmp[1])!='undefined'){
				sPrice = aTmp[1].replace('-', '00');
				sPrice = sPrice.replace(',', '.');
				if(!pFound){
					pFound = sPrice;
				}
			}else{
				if(pFound){
					sPrice = 0;
				}
			}
		iAmount = 0;
		if (document.forms['hotel_matrix_form'].elements['minbooking_until_' + iCounter]) {
			fPriceMinBookingDaysBeforeLast += parseFloat(sPrice);
		}
		else 
			if (document.getElementById('count_' + iCounter)) {
				iAmount = parseInt(document.getElementById('count_' + iCounter).value);
				
				if (fPriceMinBookingDaysBeforeLast > 0.0 && iAmount == 0) {
					fPriceMinBookingDaysBeforeLast = 0.0;
				}
			}
		iCounter++;
		if (isNaN(iAmount) || iAmount == 0) {
			continue;
		}
		if (fPriceMinBookingDaysBeforeLast != 0) {
			fPrice += iAmount * fPriceMinBookingDaysBeforeLast;
			fPriceMinBookingDaysBeforeLast = 0;
			iCounterTmp = iCounter - 2;
			while (document.forms['hotel_matrix_form'].elements['minbooking_until_' + iCounterTmp]) {
				document.forms['hotel_matrix_form'].elements['count_' + iCounterTmp].value = iAmount;
				iCounterTmp--;
			}
		}
		fPrice += iAmount * parseFloat(sPrice);
	}
	displayCurrentPrice(fPrice);
	return (parseIntReal(fPrice) > 0);
}


$('document').ready(function(){
	$('[name="datefrom"]').each( function()
	{
		//alert($(this).attr("checked"));
		if($(this).attr("checked"))$(this).click();
	});
	$('[name="dateuntil"]').each( function()
	{
		//alert($(this).attr("checked"));
		if($(this).attr("checked"))$(this).click();
	});
});
/**
 * checks if room selection (matrix) is complete
 *
 * @return void
 */
 
function checkComplete(){

	if (parseInt($('div#price_all').text().replace(/EUR/g, '')) > 0) {
		bOk = false;
		iStatus = -1;
		if (!document.getElementById('count_0')) { // no new contingent
			//alert('Error 1256');
			iStatus = calculatePrice();
			if (iStatus > 0) {
				bOk = true;
			}
		}
		else {
			bOk = calculatePriceTm();
			
		}
		
		if (bOk) {
			document.forms['hotel_matrix_form'].submit();
		}
		else {
			if (!document.getElementById('count_0')) { // no new contingent
				if (!document.forms['hotel_matrix_form'].dateuntil) {
				
					//location.href = sHrefManualbooking;
				}
				else {
					if (iStatus == -1) {
						alert(sErrorNothingChosen);
					}
					else 
						if (iStatus == -2) {
							alert(sErrorMinDays);
						}
						else {
							alert(sErrorDateArrival);
						}
				}
			}
		}
	}
	else {
		if($('#hotel_matrix_form').find('input:radio').length > 0 || ($('#hotel_matrix_form').find('input:text').length > 0))
		{
			alert(sMessageNoDeparture);
			return false;
		}
		else
		{
			// goto individual offer page ??
			
			document.forms['hotel_matrix_form'].submit();
		}
	}
}

// msie again...
if (bMsie) {
	document.write("<a href='#' onclick='return false;' id='V1'>&nbsp;</a>");
}

var bLoadedComplete = false;

var iCurrentImgLargeId = 0;
/**
 * hotel gallery zoom img
 *
 * @param int
 *            iId
 * @return void
 */
function zoomHotelImg(iId){
	document.getElementById('gallery_prev_img').style.visibility = 'hidden';
	document.getElementById('gallery_next_img').style.visibility = 'hidden';
	iCurrentImgLargeId = iId;
	bLoadedComplete = false; // reset value
	oLayerAlpha = document.getElementById('gallery_alpha_layer');
	if (bMsie) {
		oLayerAlpha.style.height = screen.height + 'px';// '100%';
		oLayerAlpha.style.width = screen.width + 'px';// '100%';
	}
	else {
		oLayerAlpha.style.height = '100%';
		oLayerAlpha.style.width = '100%';
	}
	// document.documentElement.style.overflow = 'hidden'; // firefox, chrome
	// document.body.scroll = "no"; // ie only
	oLayerAlpha.style.visibility = 'visible';
	oImgZoom = document.getElementById('h_img_zoom');
	oImgZoom.src = aImagesLarge[iId];
	// no screen.width (screen.width + MAC + 2 monitors => some problems ...
	// LOL)
	oLayerLarge = document.getElementById('container_main_content_large');
	aTmp = findPos(oLayerLarge);
	// now adjust Img Layer to scroll pos:
	iScrollY = (bMsie) ? document.documentElement.scrollTop : window.pageYOffset;
	oLayerAlpha.style.top = iScrollY + 'px';
	oLayerImg = document.getElementById('img_zoom');
	oLayerImg.style.top = (190 + iScrollY) + 'px';
	oLayerImg.style.textAlign = 'center';
	oLayerImg.style.left = (aTmp[0] + 20) + 'px';
	
	// show loading image:
	oLoadingLayer = document.getElementById('img_zoom_loading');
	
	// oLoadingLayer.style.left = ((screen.width - oLoadingLayer.offsetWidth) /
	// 2) + 'px';
	
	oLoadingLayer.style.left = (aTmp[0] + (oLayerLarge.offsetWidth - oLoadingLayer.offsetWidth) / 2) + 'px';
	oLoadingLayer.style.top = (210 + iScrollY) + 'px';
	oLoadingLayer.style.visibility = 'visible';
	
	aTmp = findPos(oLayerImg);
	oLayer = document.getElementById('close_button2');
	iY = aTmp[1] - 10;
	iX = aTmp[0] - 10;
	oLayer.style.left = iX + 'px';
	oLayer.style.top = iY + 'px';
	oLayer.style.display = 'inline';
	
	setTimeout("zoomHotelImgFinal()", 300);
}

function showGalleryPrev(){
	hideZoomHotelImg();
	if (aImagesLarge[iCurrentImgLargeId - 1]) {
		zoomHotelImg(iCurrentImgLargeId - 1);
	}
}

function showGalleryNext(){
	hideZoomHotelImg();
	if (aImagesLarge[iCurrentImgLargeId + 1]) {
		zoomHotelImg(iCurrentImgLargeId + 1);
	}
}

/**
 * final zoom: if image is loaded completely
 *
 * @return void
 */
function zoomHotelImgFinal(){
	oImgZoom = document.getElementById('h_img_zoom');
	if (oImgZoom.complete) {
		if (bLoadedComplete) {
			oLayerImg = document.getElementById('img_zoom');
			oImg = document.getElementById('h_img_zoom');
			document.getElementById('img_zoom_loading').style.visibility = 'hidden';
			document.getElementById('img_zoom').style.visibility = 'visible';
			
			// check for prev and next button
			document.getElementById('gallery_prev_img').style.visibility = (iCurrentImgLargeId == 0) ? 'hidden' : 'visible';
			document.getElementById('gallery_next_img').style.visibility = (iCurrentImgLargeId == aImagesLarge.length - 1) ? 'hidden' : 'visible';
		}
		else {
			bLoadedComplete = true;
			setTimeout("zoomHotelImgFinal ()", 100);
		}
	}
	else {
		setTimeout("zoomHotelImgFinal ()", 50);
	}
}

/**
 * hides img zoom
 *
 * @return void
 */
function hideZoomHotelImg(){
	document.getElementById('gallery_prev_img').style.visibility = 'hidden';
	document.getElementById('gallery_next_img').style.visibility = 'hidden';
	document.getElementById('img_zoom').style.visibility = 'hidden';
	oLayerAlpha = document.getElementById('gallery_alpha_layer');
	oLayerAlpha.style.width = '10%';
	oLayerAlpha.style.height = '10%';
	oLayerAlpha.style.visibility = 'hidden';
	if (bMsie) {
		document.body.scroll = "yes";
	}
	else {
		document.documentElement.style.overflow = 'visible'; // firefox,
		// chrome
	}
	document.getElementById('close_button2').style.display = 'none';
}

/**
 * corrects msie display bugs
 *
 * @return void
 */
function correctMsieBugs(){
	if (bMsie) {
		if (document.getElementById('expl_headline')) {
			window.focus();
		}
	}
}

// gallery
var aImagesLarge = new Array();

/**
 * calls onload stuff
 *
 * @return void
 */
function callOnloadStuff(){
	if (typeof this.window['loadMap'] == 'function') {
		loadMap(); // load google map
	}
	correctMsieBugs();
	// gallery images:
	if (aImagesLarge.length > 0) { // array gallery template
		preloadImages(aImagesLarge);
	}
	
	// matrix:
	if (document.getElementById('room_date_0') && !document.getElementById('count_0')) {
		// First Call Here
		// Removed on 08.09.2010 for better Errorhandling by no departure selection
		//calculatePrice();
		var iDepartures = $('input[name=dateuntil]').length;
		handleDepartureRequest(iDepartures);
	}
	
	
}

/**
 * shows message in message layer only one message at a time
 *
 * @param string
 *            sContentMessage
 * @return void
 */
function showMessageV2(sContentMessage){
	if (document.getElementById('message_layer')) {
		bOk = true;
		// only one message at a time
		if (document.getElementById('message_layer').innerHTML != '') {
			bOk = false;
		}
		else 
			if (document.getElementById('a_message') && document.getElementById('a_message').innerHTML != '') {
				bOk = false;
			}
		if (bOk) {
			document.getElementById('message_layer').innerHTML = sContentMessage;
		}
	}
	else {
		var sContentMessage = sContentMessage;
		setTimeout("showMessageV2()", 40);
	}
}

/* *** shopping cart functions *** */

/**
 * shows shopping cart confirm layer and sets href for cancelling reservation
 *
 * @return void
 */
function confirmCancelReservation(sHrefCancel){
	document.getElementById('message_layer_confirm').style.display = 'inline';
	sCancelReservationLink = sHrefCancel;
}

/**
 * locates to href for deleting reservation
 *
 * @return void
 */
function deleteReservation(){
	location.href = sCancelReservationLink;
}

/**
 * hides message (booking)
 *
 * @return void
 */
function hideMessage(){
	sHtmlId = (arguments.length > 0) ? arguments[0] : 'message_layer_confirm';
	if (document.getElementById(sHtmlId)) {
		document.getElementById(sHtmlId).style.display = 'none';
	}
	else 
		if (document.getElementById('a_message')) {
			document.getElementById('a_message').style.display = 'none';
		}
		else {
			window.history.back();
		}
}

/**
 * parses integer without zero at first place
 *
 * @param string
 *            sString
 * @return int
 */
function parseIntReal(sString){
	return (parseInt(sString * 1));
}

/** * new matrix functions ***************** */
/**
 * shows chapter stuff matrix left side
 *
 * @param string
 *            sItem (which to show)
 * @return void
 */
function showMatrixFurtherStuff(sItem){
	aTmp = new Array('info', 'gallery', 'map');
	for (i = 0; i < 3; i++) {
		if (sItem != aTmp[i]) {
			document.getElementById('matrix_' + aTmp[i]).className = 'dn';
			document.getElementById('a_chapter_' + aTmp[i]).className = 'black matrix_chapter_nav';
		}
		else {
			document.getElementById('matrix_' + aTmp[i]).className = '';
			document.getElementById('a_chapter_' + aTmp[i]).className = 'black matrix_chapter_nav matrix_chapter_nav_a';
		}
	}
}

/**
 * matrix: shows more room row
 *
 * @param int
 *            iDir (-1 or 1)
 * @return void
 */
function showAnotherRoomRow(iDir){
	if (document.getElementById("room_row_0")) {
		iCounter = 0;
		if (iDir == -1) {
			while (document.getElementById("room_row_" + iCounter)) {
				if (document.getElementById("room_row_" + iCounter).className.indexOf('dn') == -1) {
					if (document.getElementById("room_row_" + (iCounter - 1))) {
						document.getElementById("room_row_" + (iCounter - 1)).className = document.getElementById("room_row_" + (iCounter - 1)).className.replace(/ dn/, '');
					}
					if (iCounter - 1 == 0) {
						document.getElementById('room_earlier_caller').style.display = 'none';
					}
					break;
				}
				iCounter++;
			}
		}
		else {
			iCounterEnd = -1;
			while (document.getElementById("room_row_" + iCounter)) {
				if (document.getElementById("room_row_" + iCounter).className.indexOf('dn') == -1) {
					iCounterEnd = iCounter;
					break;
				}
				iCounter++;
			}
			if (iCounterEnd != -1) {
				while (document.getElementById("room_row_" + iCounterEnd)) {
					if (document.getElementById("room_row_" + iCounterEnd).className.indexOf('dn') != -1) {
						document.getElementById("room_row_" + iCounterEnd).className = document.getElementById("room_row_" + iCounterEnd).className.replace(/ dn/, '');
						window.scrollBy(0, 36);
						if (!document.getElementById("room_row_" + (iCounterEnd + 1))) {
							document.getElementById('room_later_caller').style.display = 'none';
						}
						break;
					}
					iCounterEnd++;
				}
			}
		}
		positionFairPeriodText();
	}
}

window.onload = callOnloadStuff;

