var aReservations = new Array();
var aRooms = new Array();
var aDisplacement = new Array();
var aPlaces = new Array();
var aTransfer = new Array();
var aRestTypes = new Array();

_init_rooms()
function _init_rooms() {
	var oH, oR;

	oH = new Object();
	oH[ "hotel" ] = "Адмиралтейская";
	oR = new Array();
	oR.add( "Стандарт" );
	oR.add( "Арт-стандарт" );
	oR.add( "Блочный" );
	oH[ "rooms" ] = oR;
	aRooms.add( oH );


	oH = new Object();
	oH[ "hotel" ] = "Матисов домик";
	oR = new Array();
	oR.add( "Стандарт" );
	oR.add( "Люкс" );
	oH[ "rooms" ] = oR;
	aRooms.add( oH );

	oH = new Object();
	oH[ "hotel" ] = "Манифест";
	oR = new Array();
	oR.add( "Стандарт" );
	oR.add( "Стандарт-эконом" );
	oH[ "rooms" ] = oR;
	aRooms.add( oH );

	aDisplacement.add( "" );
	aDisplacement.add( "Раздельные кровати" );
	aDisplacement.add( "Большая кровать" );
}

//function _init_places() {
	aPlaces.add( "Адмиралтейская - Большой зал" );
	aPlaces.add( "Адмиралтейская - Малый зал" );
	aPlaces.add( "Матисов домик" );
//}

//function _init_transfer() {
	aTransfer.add( "Аэропорт Пулково" );
	aTransfer.add( "Аэропорт Пулково-2" );
	aTransfer.add( "Московский вокзал" );
	aTransfer.add( "Ладожский вокзал" );
	aTransfer.add( "Финляндский вокзал" );
	aTransfer.add( "Балтийский вокзал" );
	aTransfer.add( "Витебский вокзал" );
	aTransfer.add( "Иное (доп. информация)" );
//}

//function _init_rest() {
	aRestTypes.add( "Столик" );
	aRestTypes.add( "Банкет" );
	aRestTypes.add( "Фуршет" );
	aRestTypes.add( "Групповое питание" );
//}

function select_fill_hotels( cId ) {
	var oSelect = document.getElementById( cId ), oOpt, i;
	for ( i=0; i < aRooms.length; i++ ) {
		oOpt = document.createElement( "OPTION" );
		oOpt.text = aRooms[ i ].hotel;
		oOpt.value = aRooms[ i ].hotel;
		oSelect.options.add( oOpt );
	}

}

function select_fill_rooms( cHotelSelectId, cId ) {
	var oSelect = document.getElementById( cId ), oOpt, i;
	oHotel = select_value_get( cHotelSelectId );
	for ( i=0; i < aRooms.length; i++ ) {
		if ( aRooms[ i ].hotel == oHotel ) {
			oHotel = aRooms[ i ];
			while ( oSelect.firstChild ) oSelect.removeChild( oSelect.firstChild );
			for ( j=0; j < oHotel.rooms.length; j++ ) {
				oOpt = document.createElement( "OPTION" );
				oOpt.text = oHotel.rooms[ j ];
				oOpt.value = oHotel.rooms[ j ];
				oSelect.options.add( oOpt );
			}
		}
	}
}

function select_fill_places( cId ) {
	var oSelect = document.getElementById( cId ), oOpt, i;
	for ( i=0; i < aPlaces.length; i++ ) {
		oOpt = document.createElement( "OPTION" );
		oOpt.text = aPlaces[ i ];
		oOpt.value = aPlaces[ i ];
		oSelect.options.add( oOpt );
	}

}

function select_fill_displacement( cId ) {
	var oSelect = document.getElementById( cId ), oOpt, i;
	for ( i=0; i < aDisplacement.length; i++ ) {
		oOpt = document.createElement( "OPTION" );
		oOpt.text = aDisplacement[ i ];
		oOpt.value = aDisplacement[ i ];
		oSelect.options.add( oOpt );
	}

}

function select_fill_sex( cId ) {
	var oSelect = document.getElementById( cId ), oOpt, i, aSex = new Array( "", "Мужской", "Женский" );
	for ( i=0; i < aSex.length; i++ ) {
		oOpt = document.createElement( "OPTION" );
		oOpt.text = aSex[ i ];
		oOpt.value = aSex[ i ];
		oSelect.options.add( oOpt );
	}

}

function select_fill_transfer( cId ) {
	var oSelect = document.getElementById( cId ), oOpt, i;
	for ( i=0; i < aTransfer.length; i++ ) {
		oOpt = document.createElement( "OPTION" );
		oOpt.text = aTransfer[ i ];
		oOpt.value = aTransfer[ i ];
		oSelect.options.add( oOpt );
	}

}

function select_fill_extplaces( cId ) {
	var oSelect = document.getElementById( cId ), oOpt, i;
	for ( i=0; i < 3; i++ ) {
		oOpt = document.createElement( "OPTION" );
		oOpt.text = i;
		oOpt.value = i;
		oSelect.options.add( oOpt );
	};
}

function select_fill_resttypes( cId ) {
	var oSelect = document.getElementById( cId ), oOpt, i;
	for ( i=0; i < aRestTypes.length; i++ ) {
		oOpt = document.createElement( "OPTION" );
		oOpt.text = aRestTypes[ i ];
		oOpt.value = aRestTypes[ i ];
		oSelect.options.add( oOpt );
	}

}

function select_fill_days( cId ) {
	var oSelect = document.getElementById( cId ), oOpt, i;
	for ( i=1; i < 32; i++ ) {
		oOpt = document.createElement( "OPTION" );
		oOpt.text = i;
		oOpt.value = i;
		oSelect.options.add( oOpt );
	};
}

function select_fill_years( cId ) {
	var oSelect = document.getElementById( cId ), oOpt, i;
	for ( i=2009; i < 2011; i++ ) {
		oOpt = document.createElement( "OPTION" );
		oOpt.text = i;
		oOpt.value = i;
		oSelect.options.add( oOpt );
	};
}

function select_fill_years_all( cId ) {
	var oSelect = document.getElementById( cId ), oOpt, i;
	for ( i=2000; i < 2050; i++ ) {
		oOpt = document.createElement( "OPTION" );
		oOpt.text = i;
		oOpt.value = i;
		oSelect.options.add( oOpt );
	};
}


function select_fill_months( cId ) {
	var oSelect = document.getElementById( cId ), oOpt, i;
	for ( i=0; i < aMonths.length; i++ ) {
		oOpt = document.createElement( "OPTION" );
		oOpt.text = aMonths[ i ];
		oOpt.value = i;
		oSelect.options.add( oOpt );
	};
}

function update_results() {
	var oResultDIV, oEmptyResultDIV, oUL, obj, obj1;
	oResultDIV = document.getElementById( "ReservationResultDIV" );
	oEmptyResultDIV = document.getElementById( "ReservationResultEmptyDIV" );
	oUL = document.getElementById( "ReservationResultUL" )

	while (oUL.firstChild) oUL.removeChild( oUL.firstChild );
	if ( aReservations.length == 0 ) {
		oResultDIV.style.display = "none";
		oEmptyResultDIV.style.display = "block";
	} else {
		for( nIndex=0; nIndex<aReservations.length; nIndex++ ) {
			obj1 = document.createElement( 'A' )
			obj1.href='javascript:on_delete_reservation('+nIndex+')';
			obj1.appendChild( document.createTextNode( aReservations[ nIndex ].getText()));
			obj = document.createElement( 'LI' );
			obj.appendChild( obj1 );
			oUL.appendChild( obj );
		};
		oResultDIV.style.display = "block";
		oEmptyResultDIV.style.display = "none";
	};
}

function switch_page( cName ) {
	document.getElementById( "ReservationRoomsDIV" ).style.display = "none";
	document.getElementById( "ReservationServiceDIV" ).style.display = "none";
	document.getElementById( "ReservationRestDIV" ).style.display = "none";
	document.getElementById( "ReservationTransferDIV" ).style.display = "none";
	document.getElementById( "ReservationVisaDIV" ).style.display = "none";
	document.getElementById( "Reservation" + cName + "DIV" ).style.display = "block";
}

function add_value_pair( aArray, cName, cValue ) {
	if (cValue) {
		aArray.add( new Array( cName, cValue ));
	};
}

//////////////////////////////////////////////////////////////////////////////////////////

function ReservationRooms() {
	this.resType = "Rooms";
	this.startDate = new Date();
	this.endDate = new Date();
	this.guestCount = 0;
	this.displacement = "";
	this.earlyIn = false;
	this.lateOut = false;
	this.hotel = null;
	this.room = null;
	this.comment = "";

	this.getText = _ReservationRooms_getText;
	this.fromPage = _ReservationRooms_fromPage;
	this.toPage = _ReservationRooms_toPage;
	this.check = _ReservationRooms_check;
	this.getData = _ReservationRooms_getData;
}

function _ReservationRooms_getData() {
	var oData;
	oData = new Object();
	oData[ "name" ] = "Гостиница";
	oData[ "info" ] = new Array();
	add_value_pair( oData.info, "Дата заезда", this.startDate.toLongString());
	add_value_pair( oData.info, "Дата выезда", this.endDate.toLongString());
	add_value_pair( oData.info, "Гостиница", this.hotel );
	add_value_pair( oData.info, "Тип номера", this.room );
	add_value_pair( oData.info, "Ранний заезд", ( this.earlyIn ? "Да" : "" ));
	add_value_pair( oData.info, "Поздний выезд", ( this.lateOut ? "Да" : "" ));
	add_value_pair( oData.info, "Размещение", this.displacement );
	add_value_pair( oData.info, "Кол-во Гостей", this.guestCount );
	add_value_pair( oData.info, "Дополнительно", this.comment );
	return oData;
}

function _ReservationRooms_fromPage() {
	this.startDate = select_date_group_get( "ReservationRoomsIn" );
	this.endDate = select_date_group_get( "ReservationRoomsOut" );
	this.guestCount = document.getElementById( "ReservationRoomsGuestCountINPUT" ).value;
	this.earlyIn = document.getElementById( "ReservationRoomsEarlyInINPUT" ).checked;
	this.lateOut = document.getElementById( "ReservationRoomsLateOutINPUT" ).checked;
	this.comment = document.getElementById( "ReservationRoomsCommentsTEXTAREA" ).value;
	this.hotel = select_value_get( "ReservationRoomsHotelSELECT" );
	this.room = select_value_get( "ReservationRoomsTypeSELECT" );
	this.displacement = select_value_get( "ReservationRoomsDisplacementSELECT" );
	return this.check();
}

function _ReservationRooms_toPage() {
	select_date_group_set( "ReservationRoomsIn", this.startDate );
	select_date_group_set( "ReservationRoomsOut", this.endDate );
	document.getElementById( "ReservationRoomsGuestCountINPUT" ).value = this.guestCount;
	document.getElementById( "ReservationRoomsEarlyInINPUT" ).checked = this.earlyIn;
	document.getElementById( "ReservationRoomsLateOutINPUT" ).checked = this.lateOut;
	select_value_set( "ReservationRoomsHotelSELECT", this.hotel );
	select_fill_rooms( "ReservationRoomsHotelSELECT", "ReservationRoomsTypeSELECT" );
	select_value_set( "ReservationRoomsTypeSELECT", this.room );
	select_value_set( "ReservationRoomsDisplacementSELECT", this.displacement );
	document.getElementById( "ReservationRoomsCommentsTEXTAREA" ).value = this.comment;
}


function _ReservationRooms_check() {
	if (( ! this.startDate ) || ( this.endDate < new Date().midnight())) {
		return "Неправильная дата заезда";
	};
	if (( ! this.endDate ) || ( this.endDate < this.startDate )) {
		return "Неправильная дата выезда";
	};
	if ( ! this.hotel ) {
		return "Не указан отель";
	};
	if ( ! this.room ) {
		return "Не указан тип номера";
	};
	if ( ! this.guestCount ) {
		return "Не указано количество Гостей";
	};
	return "";
}

function _ReservationRooms_getText() {
	return 	"Гостиница " + 
		this.startDate.toDDMMYYYYString() + "-" + this.endDate.toDDMMYYYYString() + ", " +
		this.hotel + ", " + this.room +  
		", " + this.guestCount + " чел." + 
		( this.displacement ? ", " + this.displacement : "" ) +
		( this.earlyIn ? ", ранний заезд" : "" ) +
		( this.lateOut ? ", поздний выезд" : "" ) +
		( this.comment ? ", с доп. информацией" : "" );
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////

function ReservationTransfer() {
	this.resType = "Transfer";
	this.eventDate = new Date();
	this.eventTime = "";
	this.guestCount = 0;
	this.transfer = null;
	this.transportInfo = "";
	this.comment = "";

	this.getText = _ReservationTransfer_getText;
	this.fromPage = _ReservationTransfer_fromPage;
	this.toPage = _ReservationTransfer_toPage;
	this.check = _ReservationTransfer_check;
	this.getData = _ReservationTransfer_getData;
}

function _ReservationTransfer_getData() {
	var oData;
	oData = new Object();
	oData[ "name" ] = "Трансфер";
	oData[ "info" ] = new Array();
	add_value_pair( oData.info, "Дата", this.eventDate.toLongString());
	add_value_pair( oData.info, "Время", this.eventTime );
	add_value_pair( oData.info, "Рейс", this.transportInfo );
	add_value_pair( oData.info, "Кол-во Гостей", this.guestCount );
	add_value_pair( oData.info, "Место", this.transfer );
	add_value_pair( oData.info, "Дополнительно", this.comment );
	return oData;
}

function _ReservationTransfer_fromPage() {
	this.eventDate = select_date_group_get( "ReservationTransfer" );
	this.eventTime = document.getElementById( "ReservationTransferTimeINPUT" ).value;
	this.guestCount = document.getElementById( "ReservationTransferGuestCountINPUT" ).value;
	this.comment = document.getElementById( "ReservationTransferCommentsTEXTAREA" ).value;
	this.transfer = select_value_get( "ReservationTransferSELECT" );
	this.transportInfo = document.getElementById( "ReservationTransferInfoINPUT" ).value;
	return this.check();
}

function _ReservationTransfer_toPage() {
	select_date_group_set( "ReservationTransfer", this.eventDate );
	document.getElementById( "ReservationTransferTimeINPUT" ).value = this.eventTime;
	document.getElementById( "ReservationTransferGuestCountINPUT" ).value = this.guestCount;
	select_value_set( "ReservationTransferSELECT", this.transfer );
	document.getElementById( "ReservationTransferCommentsTEXTAREA" ).value = this.comment;
	document.getElementById( "ReservationTransferInfoINPUT" ).value = this.transportInfo;
}


function _ReservationTransfer_check() {
	if (( ! this.eventDate ) || ( this.eventDate < new Date().midnight())) {
		return "Неправильная дата трансфера";
	};
	if ( ! this.eventTime ) {
		return "Не указано время трансфера";
	};
	if ( ! this.transfer ) {
		return "Не указан пункт назначения";
	};
	if ( ! this.transportInfo ) {
		return "Не указан номер рейса";
	};
	if ( ! this.guestCount ) {
		return "Не указано количество Гостей";
	};
	return "";
}

function _ReservationTransfer_getText() {
	return 	"Трансфер " + 
		this.eventDate.toDDMMYYYYString() + " " + this.eventTime + ", " +
		this.transfer + ", рейс " + this.transportInfo + ", " +  
		this.guestCount + " чел." + 
		( this.comment ? ", с доп. информацией" : "" );
}
////////////////////////////////////////////////////////////////////////////////////////////////

function ReservationService() {
	this.resType = "Service";
	this.eventDate = new Date();
	this.eventTime = "";
	this.eventDuration = "";
	this.guestCount = 0;
	this.place = null;
	this.comment = "";

	this.getText = _ReservationService_getText;
	this.fromPage = _ReservationService_fromPage;
	this.toPage = _ReservationService_toPage;
	this.check = _ReservationService_check;
	this.getData = _ReservationService_getData;
}

function _ReservationService_getData() {
	var oData;
	oData = new Object();
	oData[ "name" ] = "Конференц-зал";
	oData[ "info" ] = new Array();
	add_value_pair( oData.info, "Дата", this.eventDate.toLongString());
	add_value_pair( oData.info, "Время", this.eventTime );
	add_value_pair( oData.info, "Продолжительность", this.eventDuration );
	add_value_pair( oData.info, "Кол-во Гостей", this.guestCount );
	add_value_pair( oData.info, "Зал", this.place );
	add_value_pair( oData.info, "Дополнительно", this.comment );
	return oData;
}

function _ReservationService_fromPage() {
	this.eventDate = select_date_group_get( "ReservationService" );
	this.guestCount = document.getElementById( "ReservationServiceGuestCountINPUT" ).value;
	this.comment = document.getElementById( "ReservationServiceCommentsTEXTAREA" ).value;
	this.eventTime = document.getElementById( "ReservationServiceTimeINPUT" ).value;
	this.eventDuration = document.getElementById( "ReservationServiceTimeCountINPUT" ).value;
	this.place = select_value_get( "ReservationServicePlaceSELECT" );
	return this.check();
}

function _ReservationService_toPage() {
	select_date_group_set( "ReservationService", this.eventDate );
	document.getElementById( "ReservationServiceGuestCountINPUT" ).value = this.guestCount;
	select_value_set( "ReservationServicePlaceSELECT", this.place );
	document.getElementById( "ReservationServiceCommentsTEXTAREA" ).value = this.comment;
	document.getElementById( "ReservationServiceTimeINPUT" ).value = this.eventTime;
	document.getElementById( "ReservationServiceTimeCountINPUT" ).value = this.eventDuration;
}


function _ReservationService_check() {
	if (( ! this.eventDate ) || ( this.eventDate < new Date().midnight())) {
		return "Неправильная дата мероприятия";
	};
	if ( ! this.eventTime ) {
		return "Не указано время начала мероприятия";
	};
	if ( ! this.eventDuration ) {
		return "Не указана продолжительость мероприятия";
	};
	if ( ! this.place ) {
		return "Не указано место проведения мероприятия";
	};
	if ( ! this.guestCount ) {
		return "Не указано количество Гостей";
	};
	return "";
}
function _ReservationService_getText() {
	return	"Конференция " + 
		this.eventDate.toDDMMYYYYString() + " " + this.eventTime +"(" + this.eventDuration + "), " +
		this.place + 
		this.guestCount + " чел." +
		( this.comment ? ", с доп. информацией" : "" );

}

////////////////////////////////////////////////////////////////////////////////////////////////

function ReservationVisa() {
	this.resType = "Visa";
	this.guestName = "";
	this.passport = "";
	this.country = "";
	this.passportDate = new Date();
	this.passportEndDate = new Date();
	this.sex = "";
	this.comment = "";

	this.getText = _ReservationVisa_getText;
	this.fromPage = _ReservationVisa_fromPage;
	this.toPage = _ReservationVisa_toPage;
	this.check = _ReservationVisa_check;
	this.getData = _ReservationVisa_getData;
}

function _ReservationVisa_getData() {
	var oData;
	oData = new Object();
	oData[ "name" ] = "Визовая поддержка";
	oData[ "info" ] = new Array();
	add_value_pair( oData.info, "Ф.И.О.", this.guestName );
	add_value_pair( oData.info, "Пол", this.sex );
	add_value_pair( oData.info, "Страна", this.country );
	add_value_pair( oData.info, "Паспорт", this.passport );
	add_value_pair( oData.info, "Выдан", this.passportDate.toLongString());
	add_value_pair( oData.info, "Срок действия", this.passportEndDate.toLongString() );
	add_value_pair( oData.info, "Дополнительно", this.comment );
	return oData;
}

function _ReservationVisa_fromPage() {
	this.passportDate = select_date_group_get( "ReservationVisaPassport" );
	this.passportEndDate = select_date_group_get( "ReservationVisaPassportEnd" );
	this.guestName = document.getElementById( "ReservationVisaGuestNameINPUT" ).value;
	this.passport = document.getElementById( "ReservationVisaPassportINPUT" ).value;
	this.country = document.getElementById( "ReservationVisaCountryINPUT" ).value;
	this.comment = document.getElementById( "ReservationVisaCommentsTEXTAREA" ).value;
	this.sex = select_value_get( "ReservationVisaSexSELECT" );
	return this.check();
}

function _ReservationVisa_toPage() {
	select_date_group_set( "ReservationVisaPassport", this.passportDate );
	select_date_group_set( "ReservationVisaPassportEnd", this.passportEndDate );
	document.getElementById( "ReservationVisaGuestNameINPUT" ).value = this.guestName;
	document.getElementById( "ReservationVisaPassportINPUT" ).value = this.passport;
	document.getElementById( "ReservationVisaCountryINPUT" ).value = this.country;
	document.getElementById( "ReservationVisaCommentsTEXTAREA" ).value = this.comment;
	select_value_set( "ReservationVisaSexSELECT", this.sex );
}


function _ReservationVisa_check() {
	if ( ! this.guestName ) {
		return "Не указаны фамилия, имя и отчество";
	};
	if ( ! this.passport ) {
		return "Не указан номер паспорта";
	};
	if ( ! this.passportDate ) {
		return "Неправильная дата выдачи паспорта";
	};
	if ( ! this.passportEndDate ) {
		return "Неправильный срок действия паспорта";
	};
	if ( ! this.country ) {
		return "Не указана страна постоянного проживания";
	};
	return "";
}
function _ReservationVisa_getText() {
	return	"Визовая поддержка, " + 
		this.guestName +
		( this.comment ? ", с доп. информацией" : "" );

}

////////////////////////////////////////////////////////////////////////////////////////////////

function ReservationRest() {
	this.resType = "Rest";
	this.eventDate = new Date();
	this.eventTime = "";
	this.eventType = null;
	this.guestCount = 0;
	this.comment = "";

	this.getText = _ReservationRest_getText;
	this.fromPage = _ReservationRest_fromPage;
	this.toPage = _ReservationRest_toPage;
	this.check = _ReservationRest_check;
	this.getData = _ReservationRest_getData;
}

function _ReservationRest_getData() {
	var oData;
	oData = new Object();
	oData[ "name" ] = "Ресторан";
	oData[ "info" ] = new Array();
	add_value_pair( oData.info, "Дата", this.eventDate.toLongString());
	add_value_pair( oData.info, "Время", this.eventTime );
	add_value_pair( oData.info, "Тип", this.eventType );
	add_value_pair( oData.info, "Кол-во Гостей", this.guestCount );
	add_value_pair( oData.info, "Дополнительно", this.comment );
	return oData;
}

function _ReservationRest_fromPage() {
	this.eventDate = select_date_group_get( "ReservationRest" );
	this.eventType = select_value_get( "ReservationRestTypeSELECT" );
	this.guestCount = document.getElementById( "ReservationRestGuestCountINPUT" ).value;
	this.comment = document.getElementById( "ReservationRestCommentsTEXTAREA" ).value;
	this.eventTime = document.getElementById( "ReservationRestTimeINPUT" ).value;
	return this.check();
}

function _ReservationRest_toPage() {
	select_date_group_set( "ReservationRest", this.eventDate );
	select_value_set( "ReservationRestTypeSELECT", this.eventType );
	document.getElementById( "ReservationRestGuestCountINPUT" ).value = this.guestCount;
	document.getElementById( "ReservationRestTimeINPUT" ).value = this.eventTime;
	document.getElementById( "ReservationRestCommentsTEXTAREA" ).value = this.comment;
}


function _ReservationRest_check() {
	if (( ! this.eventDate ) || ( this.eventDate < new Date().midnight())) {
		return "Неправильная дата визита";
	};
	if ( ! this.eventTime ) {
		return "Не указано время визита";
	};
	if ( ! this.eventTime ) {
		return "Не указан тип сервиса";
	};
	if ( ! this.guestCount ) {
		return "Не указано количество Гостей";
	};
	return "";
}
function _ReservationRest_getText() {
	return "Ресторан ," + this.eventType + ", " + 
		this.eventDate.toDDMMYYYYString() + " " + this.eventTime + 
		this.guestCount + " чел." + 
		( this.comment ? ", с доп. информацией" : "" );
}

/////////////////////////////////////////////////////////////////////////////////////////////


function on_add_reservation( oRsv ) {
	var sError;
	sError = oRsv.fromPage();
	if (sError.length) window.alert( sError );
	else {
		aReservations.add( oRsv );
		update_results();
	}
}

function on_add_rooms() { on_add_reservation( new ReservationRooms()) };
function on_add_service() { on_add_reservation( new ReservationService()) };
function on_add_rest() { on_add_reservation( new ReservationRest()) };
function on_add_transfer() { on_add_reservation( new ReservationTransfer()) };
function on_add_visa() { on_add_reservation( new ReservationVisa()) };

function on_delete_reservation( iIndex ) {
	var oRsv = aReservations[ iIndex ];
	aReservations.splice( iIndex, 1 );
	oRsv.toPage();
	switch_page( oRsv.resType );
	update_results();
}

function on_submit() {
	var cCustName, cCustOrg, cCustPhone, cCustMail, cMailText, cMailHTML, i, j, oData;
	cCustName = document.getElementById( "ReservationCustomerNameINPUT" ).value;
	cCustOrg = document.getElementById( "ReservationCustomerOrgINPUT" ).value;
	cCustPhone = document.getElementById( "ReservationCustomerPhoneINPUT" ).value;
	cCustMail = document.getElementById( "ReservationCustomerMailINPUT" ).value;
	if ( ! cCustName ) sError = "Вы не указали свои фамилию, имя, отчество";
	else if ( ! ( cCustPhone || cCustMail )) sError = "Укажите адрес электронной почты или телефон для связи";
	else sError = "";
	if (sError) window.alert( sError )
	else {
		cMailText = 
			"ЗАКАЗЧИК:\r\n" + 
			"Ф.И.О.:" + cCustName + "\r\n" + 
			( cCustOrg ? "Организация: " + cCustOrg + "\r\n" : "" ) +
			( cCustPhone ? "Телефон: " + cCustPhone + "\r\n" : "" ) +
			( cCustMail ? "E-mail: " + cCustMail + "\r\n" : "" ) +
			"\r\n";
		cMailHTML =
			"<HTML><HEAD>" +
			"<STYLE>" +
			"H1{ font-family: Arial; font-size: 12pt; } "+
			"TABLE { border: solid 2px black; margin-bottom: 10px; } "+
			"TD { border: solid 1px black; font-family: Arial; font-size: 9pt; padding-left: 10px; padding-right: 10px; }" +
			".name { width: 150px; } .data { width: 300px; }" + 
			"P { font-family: Arial; font-size: 9pt; }" +
			"THEAD TD { font-size: 12pt; } " +
			"</STYLE>" +
			"</HEAD><BODY>";
		cMailHTML += "<H1>Заказчик</H1><P>" +
			"Ф.И.О.:" + cCustName + "<BR>" + 
			( cCustOrg ? "Организация: " + cCustOrg + "<BR>" : "" ) +
			( cCustPhone ? "Телефон: " + cCustPhone + "<BR>" : "" ) +
			( cCustMail ? "E-mail: " + cCustMail + "<BR>" : "" ) +
			"</P>";
		cMailText += "БРОНЬ:\r\n";
		cMailHTML += '<H1>Бронь</H1>';
		for ( i = 0; i < aReservations.length; i ++ ) {
			oData = aReservations[ i ].getData();
			cMailText += "\r\n" + oData.name + "\r\n";
			cMailHTML += '<TABLE cellspacing="0" cellpading="0"><THEAD><TR><TD colspan="2">' + 
				oData.name + "</TD></TR></THEAD><TBODY>";
			for ( j = 0; j < oData.info.length; j ++ ) {
				cMailText += oData.info[ j ][ 0 ] + ": " + oData.info[ j ][ 1 ] + "\r\n";
				cMailHTML += '<TR><TD class="name">' + oData.info[ j ][ 0 ] + '</TD><TD class="data">' + oData.info[ j ][ 1 ] + "</TD></TR>";
			};
			cMailHTML += "</TBODY></TABLE>";
		};
		cMailHTML += "</BODY></HTML>";
		document.getElementById( "ReservationTextDataINPUT" ).value = cMailText;
		document.getElementById( "ReservationHTMLDataINPUT" ).value = cMailHTML;
		//window.alert( cMailHTML );
		document.getElementById( "ReservationFORM" ).submit();
			

	}
}

/////////////////////////////////////////////////////////////////////////////////////////////

