﻿// JScript File

function ChangeDirection(selectedCellId, selectedDivId, cellId1, divId1, cellId2, divId2, directionId)
{
	var selCell = document.getElementById(selectedCellId);
	var cell1 = document.getElementById(cellId1);
	var cell2 = document.getElementById(cellId2);
	var selDiv = document.getElementById(selectedDivId);
	var div1 = document.getElementById(divId1);
	var div2 = document.getElementById(divId2);
	
	selCell.className = "am_direction_td_selected";
	cell1.className = cell2.className = "am_direction_td";
	selDiv.className = "am_direction_div_selected";
	div1.className = div2.className  = "am_direction_div";
	tripType.value = directionId;
	if (directionId == "O" || directionId == "M")
	{
		tblBack.style.display = "none";
	}
	else
	{
		tblBack.style.display = "block";
	}
	
	if (directionId == "M")
	{
		tblTo2.style.display  = tblTo3.style.display = "block";
		dvTo1.style.display = dvTo2.style.display  = tblTo3.style.display = "block";
	}
	else
	{
		tblTo2.style.display  = tblTo3.style.display = "none";
		dvTo1.style.display = dvTo2.style.display  = tblTo3.style.display = "none";
	}
	
}

var mounths = new Array
("Янв",
 "Фев",
 "Мар",
 "Апр",
 "Май",
 "Июн",
 "Июл",
 "Авг",
 "Сен",
 "Окт",
 "Ноя",
 "Дек");
 
 
 function LoadDatesFrom(listMounth, listDat, countBefore)
 {
	var date = 	new Date();
	date.setDate(date.getDate() + countBefore);
	var d_list = document.getElementById(listDat);
	var mou_list = document.getElementById(listMounth);
	ShowMounth(mou_list, date);
	ChangeMounth(listMounth, listDat);
	mou_list.selectedIndex = GetMounthSelectedIndex(mou_list, date.getMonth() + 1);
	d_list.selectedIndex = GetDaySelectedIndex(d_list, date.getDate());
 }
 
 function ShowMounth(list, date)
 {
	for (i=0;i<12;i++)
	{
		var mou = date.getMonth()+1;
		mou = mou < 10 ? "0" + mou : mou;
		$("<option />")	
		.attr("value", date.getFullYear()+""+mou)
		.html(mounths[date.getMonth()] + " " + date.getFullYear())
		.appendTo(list)
		date.setMonth(date.getMonth() + 1);
	}
 }
 function ChangeMounth(listMounth, listDat)
 {
	
 	var m_list = document.getElementById(listMounth);
	var d_list = document.getElementById(listDat);
	d_list.options.length = 0;
	var m = m_list.value.substring(4,2);
	var mounth = m -1;
	var date = new Date();
	date.setDate(1);
	date.setMonth(mounth);
	date.setYear(date.getYear());
	while(mounth == date.getMonth())
	{
		var day = date.getDate();
		day = day < 10 ? "0" + day : day;
		$("<option />")	
		.attr("value", day)
		.html(day)
		.appendTo(d_list)
		date.setDate(date.getDate() + 1);
	}
 }
 
 function GetMounthSelectedIndex(list, number)
 {
	for (i=0; i< list.length; i++)
	{
		if (list[i].value == number)
			return i;
	}
	return 0;
 }
 
 function GetDaySelectedIndex(list, number)
 {
	for (i=0; i< list.length; i++)
	{
		if (list[i].value == number)
			return i;
	}
	return 0;
 }
 
 function LoadTime(list)
 {
	var t_list = document.getElementById(list);
	t_list.options.length = 0;
	$("<option />")	
		.attr("value", "ANY")
		.html("В любое время")
		.appendTo(t_list)
	for (i = 0; i< 24; i++)
	{
		var val = i<10 ? "0" + i : i;
		$("<option />")	
			.attr("value", val + "00")
			.html(val + ":00")
			.appendTo(t_list)
	}
 }