var visibleMenuId = null;
var menuHiderIntervalId = null;
var menuHiderSecondIntervalId = null;
var visibleSecondMenuId = null;
var lastArrowHolderId = null;

function overMenu(id, xoff, yoff) {
	if (xoff == undefined) {
		xoff = 150;
	}
	if (yoff == undefined) {
		yoff = 0;
	}
	cancelFloatingHide();
	hideVisibleMenu();
	var pos = $("#MI" + id).offset();
	$("#" + id).css("left",pos.left + xoff);
	$("#" + id).css("top",pos.top + yoff);
	$("#" + id).show();
	
	visibleMenuId = id;

	hideLastArrowHolder();

}

function outMenu(id) {
	scheduleFloatingHide();
}

function hideVisibleMenu() {
	$("#" + visibleMenuId).hide();
	visibleMenuId = null;
}

function hideSecondVisibleMenu() {
	$("#" + visibleSecondMenuId).hide();
	visibleSecondMenuId = null;
}

function cancelFloatingHide() {
	clearTimeout(menuHiderIntervalId);
}

function cancelFloatingSecondHide() {
	clearTimeout(menuHiderSecondIntervalId);
}

function scheduleFloatingHide() {
	menuHiderIntervalId = setTimeout('hideVisibleMenu()', 1000);
}

function scheduleSecondFloatingHide() {
	menuHiderSecondIntervalId = setTimeout('hideSecondVisibleMenu()', 1000);
}

function overFloatingMenu(id) {
	cancelFloatingHide();
}

function outFloatingMenu(id) {
	scheduleFloatingHide();
}

function overSecondFloatingMenu(id) {
	cancelFloatingHide();
	cancelFloatingSecondHide();
}

function outSecondFloatingMenu(id) {
	scheduleSecondFloatingHide();
	scheduleFloatingHide();
}

function faqClicked(id) {
	$("#faq_a_" + id).toggle("fast");
}

function courseClicked(id) {
	$("#course_" + id).toggle("fast");
}

var maxSelectCount = new Array();
maxSelectCount[1] = 2; //nyelv
maxSelectCount[2] = 3; //orszag
maxSelectCount[3] = 3; //varos
maxSelectCount[4] = 3; //tanfolyam_tipus
maxSelectCount[5] = 3; //szallas_tipus
maxSelectCount[6] = 2; //ellatas
maxSelectCount[7] = 2; //agyak_szama

var maxCourseSearchSelectCount = new Array();
maxCourseSearchSelectCount[1] = 3; //tanfolyam_tipus
maxCourseSearchSelectCount[2] = 2; //nyelv
maxCourseSearchSelectCount[3] = 3; //orszag
maxCourseSearchSelectCount[4] = 3; //varos

function offerSearchGotoNextStep(id) {
	var selectElement = $("#wizardStep" + id)[0];
	var selectedCount = 0;
	for(var i=0; i<selectElement.options.length; i++) {
		if (selectElement.options[i].selected && i != 0) {
			selectedCount ++;
		}
	}
	if (selectedCount == 0) {
		alert('Kérjük válasszon');
	} else if (selectedCount > maxSelectCount[id]) {
		alert('Kérjük válasszon maximum ' + maxSelectCount[id] + ' darabot');
	} else {
		$("#goToNext")[0].value = "true";
		$("#offer_step")[0].value = id;
		$("#wizardForm")[0].action = 'index.php#wizardStep' + (id);
		$("#requestedAction")[0].value = 'advanceStep';
		$("#wizardForm")[0].submit();
	}

}

function offerSearchNewSearchFromStep(id) {
		$("#goToNext")[0].value = "true";
		$("#offer_step")[0].value = id -1;
		$("#wizardForm")[0].action = 'index.php#wizardStep' + (id);
		$("#requestedAction")[0].value = 'advanceStep';
		$("#wizardForm")[0].submit();
}

function courseSearchGotoNextStep(id) {
	maxSelectCount = maxCourseSearchSelectCount;
	offerSearchGotoNextStep(id);
}

function courseSearchNewSearchFromStep(id) {
	offerSearchNewSearchFromStep(id)
}

function resetFormAction() {
	$("#wizardForm")[0].action = 'index.php';
	return true;
}

// Quick navigation, second level

function overSecondMenu(id, xoff, yoff) {
	if (xoff == undefined) {
		xoff = 150;
	}
	if (yoff == undefined) {
		yoff = 0;
	}
	cancelFloatingHide();
	cancelFloatingSecondHide();
	hideSecondVisibleMenu();
	var pos = $("#MI" + id).offset();
	$("#" + id).css("left",pos.left + xoff);
	$("#" + id).css("top",pos.top + yoff);
	$("#" + id).show();
	
	hideLastArrowHolder();
	showArrow(id);
	
	visibleSecondMenuId = id;
}

function showArrow(id) {
	$("#Arrow" + id).html("►");
	lastArrowHolderId = id;
}

function hideLastArrowHolder() {
	$("#Arrow" + lastArrowHolderId).html("");
	lastArrowHolderId = null;
}

function outSecondMenu(id) {
	scheduleFloatingHide();
	scheduleSecondFloatingHide();
}