/**
 * JS for fair search
 * Created:			2009-01-20
 * Author:			Mario Diaz
 */ 
 
 
// preload images for selections (all because of msie)
// for preloading images:
var aTmpPreload = new Array();

/**
 * preloads images:
 * @param aImgArr
 * @return void
 */
function preloadImages (aImgArr) {
	iStart = aTmpPreload.length;
	for (i = 0; i < aImgArr.length; i++) {
		aTmpPreload[iStart + i] = new Image();
		aTmpPreload[iStart + i].src = aImgArr[i];
	}
}

var aImages = new Array('upload/zimages/icon_zum_angebot_grau.gif', 'upload/zimages/icon_zum_angebot_weiss.gif', 'upload/zimages/icon_zum_angebot.gif');
preloadImages(aImages);
 
 
/**
 * shows or hides filters for detail search
 * @return void
 */
function changeDisplayFilters () {
	if (document.getElementById('detail_filters')) {
		bShowDetailSearch = (document.forms['fair_search'].detailsearch.value == '1');
		bShowDetailSearch = !bShowDetailSearch;
		document.getElementById('detail_filters').style.display = (bShowDetailSearch) ? 'block' : 'none';
		document.forms['fair_search'].detailsearch.value = (bShowDetailSearch) ? '1' : '0';
		document.getElementById('link_show_details').className = (bShowDetailSearch) ? 'open' : '';
	}
}


function findPos (obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft,curtop];
}
 

/**
 * shows large button ('book' or 'request') for one icon on right side
 * @param int iBookingState (1 or 0 for 'book' or 'request')
 * @param int iNo
 * @param bool bVisible
 * @return void
 */
function showBookOrRequestButton (iBookingState, iNo, bVisible) {
	oLayer = (iBookingState == 1) ? document.getElementById('large_button_book') : document.getElementById('large_button_request');
	oButton = document.getElementById('icon_booking_' + iNo);
	aTmp = findPos(oButton);
	if (bVisible) {
		oLayer.style.left = (aTmp[0] - oLayer.offsetWidth + 2) + 'px';
		oLayer.style.top = aTmp[1] + 'px';
		oLayer.style.visibility = 'visible';
		oButton.src = 'upload/zimages/icon_zum_angebot.gif';
	} else {
		oLayer.style.visibility = 'hidden';
		oButton.src = 'upload/zimages/icon_zum_angebot_grau.gif';
	}
}

	
/**
 * top cities:
 * if <= 5 then display directly. If more than 5 then display only link 'show' first
 * this function shows layer if more than 5
 * @return void
 */
function showAllTopCities () {
	document.getElementById('content_top_cities').className = 'bottom last';
	document.getElementById('show_all_cities').style.display = 'none';
	document.getElementById('all_cities').style.display = 'block';
	document.getElementById('quick_search_items').style.height = (133 + ((iCountTopCities - 5) * 12)) + 'px';
}


function hideAllTopCities () {
	if (iCountTopCities > 5) {
		document.getElementById('show_all_cities').style.display = 'block';
		document.getElementById('all_cities').style.display = 'none';
		document.getElementById('content_top_cities').className = 'bottom';
		document.getElementById('quick_search_items').style.height = 133 + 'px';
	}
}


/**
 * shows sub details of fair (mouseover): fair long name and link 'details'
 * @param int iNum
 * @return void
 */
function showSubFairDetails (iNum) {
	document.getElementById('fair_sub_details_' + iNum).style.display = 'block';
}


/**
 * hides sub details of fair (mouseout): fair long name and link 'details'
 * @param int iNum
 * @return void
 */
function hideSubFairDetails (iNum) {
	document.getElementById('fair_sub_details_' + iNum).style.display = 'none';
}


/**
 * submits fair search.
 * !!!If country != 'DE' or city != 'munich' then go to www.tradefairs.com search!!!
 * @return void
 */
function submitFairSearch () {
	if (selectValue (document.getElementById('selCountry')) != 'DE' || selectValue (document.getElementById('selCity')) != '411') {
		sBaseHref = document.getElementsByTagName('base')[0].href;
		if (sBaseHref.indexOf('messe') != -1) {
			document.forms['fair_search'].action = 'http://www.tradefairs.com/index.html';
		}
	}
	document.forms['fair_search'].submit();
}



