/***************************************/
/*                                     */
/*          DWR Related Functions      */
/*                                     */
/** ************************************ */
function retrieveVenueOptions() {
	var selection = DWRUtil.getValue("cityBox");
	if (selection == 0) {
		return;
	}
	CityManager.getActiveVenuesForCity(selection, populateVenueBox);
}

// Callback function
function populateVenueBox(venueList) {
	DWRUtil.removeAllOptions("venueBox");
	DWRUtil.addOptions("venueBox", [ {
		name :lutfenSeciniz,
		id :""
	} ], "id", "name");
	DWRUtil.addOptions("venueBox", venueList, "code", "shortName");
	DWRUtil.setValue("venueBox", '<bean:message key="label.select"/>');
}

function reloadFilms(regionComboId, venueComboId) {
	var regionCombo = document.getElementById(regionComboId);
	var venueCombo = document.getElementById(venueComboId);
	if (regionCombo.value >= 0 && venueCombo.value < 0) {
		// film listeseni silelim
		// loadFilmCombo([]);
		BiletteManager.getShowNames(regionCombo.value, -1, loadFilmCombo);
	} else if (regionCombo.value >= 0 && venueCombo.value >= 0) {
		BiletteManager.getShowNames(regionCombo.value, venueCombo.value,
				loadFilmCombo);
	} else if (regionCombo.value < 0 && venueCombo.value >= 0) {
		BiletteManager.getShowNames(regionCombo.value, venueCombo.value,
				loadFilmCombo);
	} else {
		BiletteManager.getShowNames(-1, -1, loadFilmCombo);
	}
}

function reloadVenue(regionComboId) {
	var regionCombo = document.getElementById(regionComboId);
	if (regionCombo.value < 0) {
		BiletteManager.getVenueNames(regionCombo.value, loadVenueCombo);
		// regionCombo.value, -1 geldi
		BiletteManager.getShowNames(regionCombo.value, -1, loadFilmCombo);
	} else {
		BiletteManager.getVenueNames(regionCombo.value, loadVenueCombo);
		reloadFilms(regionComboId, '_city');
	}
}

/*
 * refill the venue combobox.
 */
function loadVenueCombo(venues) {
	var emptyOption = [ {
		label :sinemaSeciniz,
		value :-1
	} ];
	DWRUtil.removeAllOptions("_city");
	DWRUtil.addOptions("_city", emptyOption, 'value', 'label');
	DWRUtil.addOptions("_city", venues, 'value', 'label');
}

/*
 * refill the film combobox.
 */
function loadFilmCombo(films) {
	var emptyOption = [ {
		value :-1,
		label :filmSeciniz
	} ];
	DWRUtil.removeAllOptions("_film");
	DWRUtil.addOptions("_film", emptyOption, 'value', 'label');
	var listOfOnSale = films[FILM_STATUS_ONSALE];
	var listOfSoon = films[FILM_STATUS_SOON];
	if (listOfOnSale != null && listOfOnSale.length > 0) {
		var option = [ {
			value :-2,
			label :' '
		}, {
			value :-3,
			label :'------ ' + LABEL_STATUS_ONSALE + ' ------'
		} ];
		DWRUtil.addOptions("_film", option, 'value', 'label');
		DWRUtil.addOptions("_film", listOfOnSale, 'value', 'label');
	}

	if (listOfSoon != null && listOfSoon.length > 0) {
		var option = [ {
			value :-4,
			label :' '
		}, {
			value :-5,
			label :'------ ' + LABEL_STATUS_SOON + ' ------'
		} ];
		DWRUtil.addOptions("_film", option, 'value', 'label');
		DWRUtil.addOptions("_film", listOfSoon, 'value', 'label');
	}
}

/** ************************************* */
/*                                      */
/* Client Side Functions               */
/*                                      */
/** ************************************* */
var inSearchBoxEffect = false;

function checkSearchCriterias(_id_venueBox, _id_cityBox, _id_daysBox){
	var venueBox = document.getElementById(_id_venueBox);
	var cityBox = document.getElementById(_id_cityBox);
	var daysBox = document.getElementById(_id_daysBox);
	
	var count = 0;
	if(venueBox != null && 
			(venueBox.options[venueBox.selectedIndex].value == "" 
				|| venueBox.options[venueBox.selectedIndex].value * 1  < 0)){
		count++;
	}
	if(cityBox != null && 
			( cityBox.options[cityBox.selectedIndex].value == "" 
				|| cityBox.options[cityBox.selectedIndex].value * 1 < 0 )){
		count++;
	}
	if(daysBox != null && 
			(daysBox.options[daysBox.selectedIndex].value == "" 
				|| daysBox.options[daysBox.selectedIndex].value * 1 < 0)){
		count++;
	}
	
	if(count == 3){
		alert(msg_selectcriteria);
		return false;
	} else {
		return true;
	}
}

function switchSearchBox(box, locale) {
	if (inSearchBoxEffect)
		return;
	
	inSearchBoxEffect = true;

	var left;
	var right;

	if (box == 'movies') {
		left = 'liveSearchBox';
		right = 'moviesSearchBox';
	} else {
		right= 'liveSearchBox';
		left = 'moviesSearchBox';
	}
	
	new Effect.Fade(left, {
		duration :'0.2'
	});

	new Effect.Appear(right, {
		duration :'0.2',
		queue : 'end',
		afterFinish : function(effect) {
			switchSearchBoxCleanup(box, locale);
		}
	});
}

function switchSearchBoxCleanup(box, locale) {
	inSearchBoxEffect = false;
	
	var liveBox = document.getElementById('liveSearchBox');
	var moviesBox = document.getElementById('moviesSearchBox');

	var liveButton = document.getElementById('liveBoxButton');
	var moviesButton = document.getElementById('moviesBoxButton');

	if (box == 'movies') {
		moviesButton.src = "/static/images/"+locale+"/search_btn_sinema_off.gif";
		liveButton.src = "/static/images/"+locale+"/search_btn_eglence_on.gif";

		moviesBox.style.display = '';
		liveBox.style.display = 'none';
	} else {
		moviesButton.src = "/static/images/"+locale+"/search_btn_sinema_on.gif";
		liveButton.src = "/static/images/"+locale+"/search_btn_eglence_off.gif";

		moviesBox.style.display = 'none';
		liveBox.style.display = '';
	}
	
}
