nextShabatOffset = 0;
nextShabatMotzeiTime = {'time': 0, 'date': 0, 'month': 0, 'year': 0};
nextShabatKnissatTime = {'time': 0, 'date': 0, 'month': 0, 'year': 0};
nextShabatNewDate = true;
nextShabatNewCity = true;

luachDateLock = false;

function cellhover(id, hover) {
	$('td[cellid="'+id+'"]').each(function() {
		if (hover) {
			$(this).attr('oldbg', $(this).css('background-color'));
			$(this).css('background-color', '#E2EAF0');
			if ($(this).children('.triplediv').length > 0) {
				$(this).children('.triplediv').css('background', '#E2EAF0');
				$(this).children('.triplediv').css('border-left-color', '#E2EAF0');
			}
			if ($(this).children('.tripledivTerm').length > 0) {
				$(this).children('.tripledivTerm').css('background', '#E2EAF0');
				$(this).children('.tripledivTerm').css('border-left-color', '#E2EAF0');
			}
		} else {
			$(this).css('background-color', $(this).attr('oldbg'));
			if ($(this).children('.triplediv').length > 0) {
				$(this).children('.triplediv').css('background', $(this).attr('oldbg'));
				$(this).children('.triplediv').css('border-left-color', $(this).attr('oldbg'));
			}
			if ($(this).children('.tripledivTerm').length > 0) {
				$(this).children('.tripledivTerm').css('background', $(this).attr('oldbg'));
				$(this).children('.tripledivTerm').css('border-left-color', $(this).attr('oldbg'));
			}
		}
	});
}

function luach_change_date (luach_cdate, luach_cmonth, luach_cyear, current_cdate, current_cmonth, current_cyear, city, env, moadim) {
	if (luachDateLock == false || CLuach.luach_cmonth == luach_cmonth) {
		CLuach = new Luach (luach_cdate, luach_cmonth, luach_cyear, current_cdate, current_cmonth, current_cyear, city, env, moadim);
		luachDateLock = false;
	} else {
		CLuach = new Luach (CLuach.luach_cdate, CLuach.luach_cmonth, CLuach.luach_cyear, current_cdate, current_cmonth, current_cyear, city, env, moadim);
	}
	CLuach.change_set(env);
	CLuach.change_set_header(env);
	
	if (currentCity != city) {
		nextShabatNewCity = true;
	} else {
		nextShabatNewCity = false;
	}
	CLuach.change_nextshabat(city, env);
	CLuach.change_moadim (city);
} 


function luach_rewind (luach_cdate, luach_cmonth, luach_cyear, current_cdate, current_cmonth, current_cyear, currentCity, env, moadim) {
	luach_cmonth--;
	if (luach_cmonth < 1) {
		luach_cmonth = 12;
		luach_cyear--;
	}
	CLuach = new Luach (luach_cdate, luach_cmonth, luach_cyear, current_cdate, current_cmonth, current_cyear, currentCity, env, moadim);
	CLuach.change_set(env);
	CLuach.change_set_header(env);
	if (luach_cmonth != current_cmonth)
		luachDateLock = true;
	else
		luachDateLock = false;
}

function luach_forward (luach_cdate, luach_cmonth, luach_cyear, current_cdate, current_cmonth, current_cyear, currentCity, env, moadim) {
	luach_cmonth++;
	if (luach_cmonth > 12) {
		luach_cmonth = 1;
		luach_cyear++;
	}
	CLuach = new Luach (luach_cdate, luach_cmonth, luach_cyear, current_cdate, current_cmonth, current_cyear, currentCity, env, moadim);
	CLuach.change_set(env);
	CLuach.change_set_header(env);
	if (luach_cmonth != current_cmonth)
		luachDateLock = true;
	else
		luachDateLock = false;
}

function tc_city_history_add_blank () {
	$('.titlecal_custom_city_name_history_div > b').append("<a href='#' onclick='custom_city_history_click (\"titlecal\", " + (currentCity_stack.length - 1) +");' style='display: none;' id='titlecal_custom_city" + (currentCity_stack.length - 1) + "_a' class='mycity'><span class='custom_city" + (currentCity_stack.length - 1) + "_name' id='titlecal_custom_city" + (currentCity_stack.length - 1) + "_name'></span></a>");
	$('#tc_city_history_ff').attr('src','/img/arr_term_ff.gif');
}

function tc_city_history_rewind () {
	while (TCcityStackVisIndex != 1) {
		$('#tc_city_history_rew').click();	
	}
}
