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" ] = "Admiralteyskaya";
	oR = new Array();
	oR.add( "Standard" );
	oR.add( "Art Standard" );
	oR.add( "Standard in Section" );
	oH[ "rooms" ] = oR;
	aRooms.add( oH );


	oH = new Object();
	oH[ "hotel" ] = "Matisov Domik";
	oR = new Array();
	oR.add( "Standard" );
	oR.add( "Deluxe" );
	oH[ "rooms" ] = oR;
	aRooms.add( oH );

	oH = new Object();
	oH[ "hotel" ] = "Shuvalovka";
	oR = new Array();
	oR.add( "Standard" );
	oR.add( "Deluxe" );
	oH[ "rooms" ] = oR;
	aRooms.add( oH );

	aDisplacement.add( "" );
	aDisplacement.add( "Twin" );
	aDisplacement.add( "Double" );
}

//function _init_places() {
	aPlaces.add( "Admiralteyskaya - Large Room" );
	aPlaces.add( "Admiralteyskaya - Small Room" );
	aPlaces.add( "Matisov Domik" );
//}

//function _init_transfer() {
	aTransfer.add( "Pulkovo Airport" );
	aTransfer.add( "Pulkovo-2 Airport" );
	aTransfer.add( "Moskovsky Railroad Terminal" );
	aTransfer.add( "Ladozhsky Railroad Terminal" );
	aTransfer.add( "Finlyandsky Railroad Terminal" );
	aTransfer.add( "Baltyisky Railroad Terminal" );
	aTransfer.add( "Bitebsky Railroad Terminal" );
	aTransfer.add( "Other (additional info)" );
//}

//function _init_rest() {
	aRestTypes.add( "Table" );
	aRestTypes.add( "Banquete" );
	aRestTypes.add( "Buffet" );
	aRestTypes.add( "Group Meal" );
//}

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( "", "Male", "Female" );
	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" ] = "Hotel";
	oData[ "info" ] = new Array();
	add_value_pair( oData.info, "Check-In", this.startDate.toLongString());
	add_value_pair( oData.info, "Check-Out", this.endDate.toLongString());
	add_value_pair( oData.info, "Hotel", this.hotel );
	add_value_pair( oData.info, "Room Type", this.room );
	add_value_pair( oData.info, "Early Check-In", ( this.earlyIn ? "Yes" : "" ));
	add_value_pair( oData.info, "Late Check-Out", ( this.lateOut ? "Yes" : "" ));
	add_value_pair( oData.info, "Bed", this.displacement );
	add_value_pair( oData.info, "Number of persons", this.guestCount );
	add_value_pair( oData.info, "Extra 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 "Invalid Check-In Date";
	};
	if (( ! this.endDate ) || ( this.endDate < this.startDate )) {
		return "Invalid Check-Out Date";
	};
	if ( ! this.hotel ) {
		return "Please, select Hotel";
	};
	if ( ! this.room ) {
		return "Please, select Room Type";
	};
	if ( ! this.guestCount ) {
		return "Please, type Number of Persons";
	};
	return "";
}

function _ReservationRooms_getText() {
	return 	"Hotel " + 
		this.startDate.toDDMMYYYYString() + "-" + this.endDate.toDDMMYYYYString() + ", " +
		this.hotel + ", " + this.room +  
		", " + this.guestCount + " person(s)" + 
		( this.displacement ? ", " + this.displacement : "" ) +
		( this.earlyIn ? ", Early Check-In" : "" ) +
		( this.lateOut ? ", Late Check-Out" : "" ) +
		( this.comment ? ", with additional info" : "" );
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////

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" ] = "Transfer";
	oData[ "info" ] = new Array();
	add_value_pair( oData.info, "Date", this.eventDate.toLongString());
	add_value_pair( oData.info, "Time", this.eventTime );
	add_value_pair( oData.info, "Train/Flight Number", this.transportInfo );
	add_value_pair( oData.info, "Number of Persons", this.guestCount );
	add_value_pair( oData.info, "Destination", this.transfer );
	add_value_pair( oData.info, "Extra 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 "Invalid Transfer Date";
	};
	if ( ! this.eventTime ) {
		return "Invalid Transfer Time";
	};
	if ( ! this.transfer ) {
		return "Please, select Destination";
	};
	if ( ! this.transportInfo ) {
		return "Please, specify Train or Flight Number";
	};
	if ( ! this.guestCount ) {
		return "Please, specify Number of Persons";
	};
	return "";
}

function _ReservationTransfer_getText() {
	return 	"Transfer " + 
		this.eventDate.toDDMMYYYYString() + " " + this.eventTime + ", " +
		this.transfer + ", Train/Flight " + this.transportInfo + ", " +  
		this.guestCount + " person(s)" + 
		( this.comment ? ", with additional info" : "" );
}
////////////////////////////////////////////////////////////////////////////////////////////////

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" ] = "Conference";
	oData[ "info" ] = new Array();
	add_value_pair( oData.info, "Date", this.eventDate.toLongString());
	add_value_pair( oData.info, "Time", this.eventTime );
	add_value_pair( oData.info, "Duration", this.eventDuration );
	add_value_pair( oData.info, "Number Of Persons", this.guestCount );
	add_value_pair( oData.info, "Facility", this.place );
	add_value_pair( oData.info, "Extra 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 "Invalid Event Date";
	};
	if ( ! this.eventTime ) {
		return "Please, specify Event Time";
	};
	if ( ! this.eventDuration ) {
		return "Please, specify Event Duration";
	};
	if ( ! this.place ) {
		return "Please, select Facility";
	};
	if ( ! this.guestCount ) {
		return "Please, specify Number of Persons";
	};
	return "";
}
function _ReservationService_getText() {
	return	"Conference " + 
		this.eventDate.toDDMMYYYYString() + " " + this.eventTime +"(" + this.eventDuration + "), " +
		this.place + ", " +
		this.guestCount + " person(s)" +
		( this.comment ? ", with additional info" : "" );

}

////////////////////////////////////////////////////////////////////////////////////////////////

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" ] = "Visa support";
	oData[ "info" ] = new Array();
	add_value_pair( oData.info, "Name", this.guestName );
	add_value_pair( oData.info, "Sex", this.sex );
	add_value_pair( oData.info, "Country", this.country );
	add_value_pair( oData.info, "Passport", this.passport );
	add_value_pair( oData.info, "Passport Date", this.passportDate.toLongString());
	add_value_pair( oData.info, "Expiration Date", this.passportEndDate.toLongString() );
	add_value_pair( oData.info, "Extra 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 "Plase, specify name";
	};
	if ( ! this.passport ) {
		return "Please specify passport number";
	};
	if ( ! this.passportDate ) {
		return "Invalid passport date";
	};
	if ( ! this.passportEndDate ) {
		return "Invalid passport expiration date";
	};
	if ( ! this.country ) {
		return "Please, specify coutry";
	};
	return "";
}
function _ReservationVisa_getText() {
	return	"Visa support, " + 
		this.guestName +
		( this.comment ? ", with additional info" : "" );

}

////////////////////////////////////////////////////////////////////////////////////////////////

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" ] = "Restaurant";
	oData[ "info" ] = new Array();
	add_value_pair( oData.info, "Date", this.eventDate.toLongString());
	add_value_pair( oData.info, "Time", this.eventTime );
	add_value_pair( oData.info, "Type", this.eventType );
	add_value_pair( oData.info, "Number of person(s)", this.guestCount );
	add_value_pair( oData.info, "Extra 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 "Invalid Date";
	};
	if ( ! this.eventTime ) {
		return "Please, specify Time";
	};
	if ( ! this.eventType ) {
		return "Please, specify Service Type";
	};
	if ( ! this.guestCount ) {
		return "Please, specify Number of Persons";
	};
	return "";
}
function _ReservationRest_getText() {
	return "Restaurant ," + this.eventType + ", " + 
		this.eventDate.toDDMMYYYYString() + " " + this.eventTime + 
		this.guestCount + " person(s)" + 
		( this.comment ? ", with additional info" : "" );
}

/////////////////////////////////////////////////////////////////////////////////////////////


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 = "Please, specify customer name";
	else if ( ! ( cCustPhone || cCustMail )) sError = "Plase, specify customer phone or e-mail address";
	else sError = "";
	if (sError) window.alert( sError )
	else {
		cMailText = 
			"CUSTOMER:\r\n" + 
			"NAME:" + cCustName + "\r\n" + 
			( cCustOrg ? "Organisation: " + cCustOrg + "\r\n" : "" ) +
			( cCustPhone ? "Phone: " + 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>Customer</H1><P>" +
			"Name:" + cCustName + "<BR>" + 
			( cCustOrg ? "Organisation: " + cCustOrg + "<BR>" : "" ) +
			( cCustPhone ? "Phone: " + cCustPhone + "<BR>" : "" ) +
			( cCustMail ? "E-mail: " + cCustMail + "<BR>" : "" ) +
			"</P>";
		cMailText += "RESERVATION:\r\n";
		cMailHTML += '<H1>Reservation</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();
			

	}
}

/////////////////////////////////////////////////////////////////////////////////////////////

