/**
 * functions for selecting more than 3 rooms if user is not logged in
 * get URL/selected values from parent (window.opener)
 *
 * Author Mario Diaz (4fb)
 * Created 2007-12-13
 */
/**
 * function for opening popup center
 * @param string sLocation
 *
 */
function popWinCenter(sLocation){
	document.getElementById('confirm_agb').style.display = 'inline';
	document.getElementById('confirm_agb_content').style.display = 'inline';
	hideSelects();
	prepareOverlay();
}


/**
 * calls hiding selects and adjusts height of overlay
 * @return void
 */
function prepareOverlay(){
	hideSelects();
	// TODO adjust overlay:
	if (!bMsie) {
		iHeightNew = document.height - 130;
	}
	else {
		if (document.getElementById('a_cancel_link_bottom')) {
			aTmp = findPos(document.getElementById('a_cancel_link_bottom'));
			iHeightNew = aTmp[1] - 97;
		}
		else {
			iHeightNew = document.body.scrollHeight - 130;
		}
	}
	oOverlayStyle = document.getElementById('confirm_agb').style;
	if (bMsie) {
		oOverlayStyle.height = iHeightNew;
	}
	else {
		oOverlayStyle.height = iHeightNew + "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);
	}
}

// for resetting selectedIndex of room count select
var iSelectedIndexRoomCount;
/**
 * gets selected index of room count select
 */
function getSelectedIndexRoomCount(){
	if (document.getElementById('count_rooms')) {
		iSelectedIndexRoomCount = document.getElementById('count_rooms').selectedIndex;
	}
}

window.onload = getSelectedIndexRoomCount;

/**
 * hides overlay
 * @return void
 */
function hideOverlay(){
	document.getElementById('confirm_agb').style.display = 'none';
	document.getElementById('confirm_agb_content').style.display = 'none';
	showSelects();
}

/**
 * if user chooses to registrate or login
 * @return void
 * @deprecated 2010.02.09 because this function is also defined in hotellist.js
 */
/*
 * function goToReg(bLogin){
	alert('dede');
	if (bLogin) {
		if (document.forms['change_sel_form']) {
			if (document.forms['change_sel_form'].start_date) {
				sDateFrom = selectValue(document.forms['change_sel_form'].start_date);
				document.forms['frmLoginO'].datefrom.value = sDateFrom;
			}
			if (document.forms['change_sel_form'].room_category) {
				sRoomCat = selectValue(document.forms['change_sel_form'].room_category); // chosen_ind!!!!!!!
				document.forms['frmLoginO'].chosen_ind.value = sRoomCat;
			}
		}
		else 
			if (document.forms['frmSearch_Hotel']) {
				if (document.forms['frmSearch_Hotel'].dateuntil) {
					sDateUntil = selectValue(document.forms['frmSearch_Hotel'].dateuntil);
					document.forms['frmLoginO'].dateuntil.value = sDateUntil;
				}
				if (document.forms['frmSearch_Hotel'].datefrom) {
					sDateFrom = selectValue(document.forms['frmSearch_Hotel'].datefrom); // datefrom!!!!!!!!!!!!!
					document.forms['frmLoginO'].datefrom.value = sDateFrom;
				}
			}
		
	}
	
	if (bLogin) { // go to login
		document.forms['frmLoginO'].goback_reg_or_login.value = "login";
	}
	else {
		alert('come');
		//document.forms['frmLoginO'].goback_reg_or_login.value = "reg";
		window.location.href = '/My-TRADEFAIRS';
	}
	
	document.forms['frmLoginO'].submit();
}*/

function showInfos(iNum, sText){
	// get Position:
	aTmp = findPos(document.getElementById('caller_' + iNum));
	aTmp[1] += 18;
	var eInfoLayer = document.getElementById('details_layer');
	if (bMsie) {
		eInfoLayer.style.top = aTmp[1];
	}
	else {
		eInfoLayer.style.top = aTmp[1] + "px";
	}
	eInfoLayer.style.top = aTmp[1];
	eInfoLayer.style.visibility = "visible";
	eInfoLayer.innerHTML = sText;
}

function hideInfos(){
	document.getElementById('details_layer').style.visibility = "hidden";
}

/**
 * fills dateuntil after datefrom is selected (start from datefrom)
 * @return void
 */
function fillDateUntil(){
	// if the first value is selected
	bFirst = false;
	if (document.getElementById('datefrom').selectedIndex == 0) {
		bFirst = true;
	}
	// fist find the selected value:
	sSelValue = selectValue(document.getElementById('datefrom'));
	sSelValueUntil = selectValue(document.getElementById('dateuntil')); // for setting selected if in range
	var i, j;
	var prompt;
	selectCtrl = document.getElementById('dateuntil');
	// empty existing items
	for (i = selectCtrl.options.length; i >= 0; i--) {
		selectCtrl.options[i] = null;
	}
	if (prompt == null) {
		j = 0;
	}
	else {
		selectCtrl.options[0] = new Option(prompt);
		j = 1;
	}
	iResetIndex = -1;
	bReached = bFirst;
	if (aDateUntil != null) {
		// add new items
		for (i = 0; i < aDateUntil.length; i++) {
			if (!bReached) {
				if (aDateUntil[i] == sSelValue) {
					bReached = true;
				}
			}
			if (!bReached) {
				continue;
			}
			
			if (aDateUntil[i] == sSelValueUntil) {
				iResetIndex = j;
			}
			selectCtrl.options[j] = new Option(aDateUntil[i]);
			if (aDateUntil[i] != null) {
				selectCtrl.options[j].value = aDateUntil[i];
			}
			j++;
		}
		if (iResetIndex != -1) {
			selectCtrl.options[iResetIndex].selected = true;
		}
	}
}

