// JavaScript Document

function SubmitReservationLoginForm(e) {

	if(CheckReservationLoginForm()) {

		document.reservationForm.action = __LatLang__URL_ReservationWizardPage + '?step=1';

		document.reservationForm.subaction.value = 'login';

		document.reservationForm.submit();

	}

	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();

	return false;

}

function CheckReservationLoginForm() {

	if(blankStringRegExp.test(document.reservationForm.username.value)) {
		alert(__lang_enter_your_username_email);
		document.reservationForm.username.focus();
		return false;
	}

	if(!emailAddressRegExp.test(document.reservationForm.username.value)) {
		alert(__lang_username_email_not_formated);
		document.reservationForm.username.focus();
		return false;
	}

	return true;

}

function ForceReservationStepForm(Step, e) {

	document.reservationForm.action = _site_url + __LatLang__URL_ReservationWizardPage + "?step=" + Step;

	document.reservationForm.submit();

	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();

	return false;

}

function SubmitReservationStepForm(e) {

	if(CheckReservationStepForm())

		document.reservationForm.submit();

	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();

	return false;

}

	function CheckReservationStepForm() {

		// This is for Step 1
		if(document.reservationForm.current_step.value == 1) {

			if(!document.reservationForm.confirm.checked) {
				alert(__lang_agree_to_terms_and_conditions);
				document.reservationForm.confirm.focus();
				return false;
			}
	
		}

		// This is for Step 2
		if(document.reservationForm.current_step.value == 2) {

			if(document.reservationForm.new_account.value == "1") {

				if(blankStringRegExp.test(document.reservationForm.email.value)) {
					alert(__lang_enter_your_username_email);
					document.reservationForm.email.focus();
					return false;
				}

				if(!emailAddressRegExp.test(document.reservationForm.email.value)) {
					alert(__lang_username_email_not_formated);
					document.reservationForm.email.focus();
					return false;
				}

				if(document.reservationForm.choose_password && document.reservationForm.choose_password.checked) {

					if(document.reservationForm.new_password.value == "") {
						alert(__lang_enter_password_for_account);
						document.reservationForm.new_password.focus();
						return false;
					}

					if(document.reservationForm.new_password.value != document.reservationForm.confirm_password.value) {
						alert(__lang_confirm_your_password);
						document.reservationForm.confirm_password.focus();
						return false;
					}

				}

			}

			if(document.reservationForm.detailed_form.value == '0') {

				if(blankStringRegExp.test(document.reservationForm.first_name.value)) {
					alert(__lang_enter_your_first_name);
					document.reservationForm.first_name.focus();
					return false;
				}

				if(blankStringRegExp.test(document.reservationForm.last_name.value)) {
					alert(__lang_enter_your_last_name);
					document.reservationForm.last_name.focus();
					return false;
				}
			}

			if(document.reservationForm.payment_method.value == 'RECEPTION')
				if(!CheckCreditCardInfo(document.reservationForm))
					return false;

		   	if(document.reservationForm.detailed_form.value == '1')
				if(document.reservationForm.editprofile.value == '1')
					if(!CheckFullProfileForm(document.reservationForm))
						return false;

		}

		return true;

	}

	function cancel_reservation_action (reservationId, pageSource) {
		//if (confirm(__lang_confirm_cancel_reservation)) {
			window.location = _site_url + __LatLang__URL_CancelReservationPage + "?page="+pageSource+"&id="+reservationId+"&r=" + new Date().getTime();
		//}
	}

	function cancel_reservation_perform (reservationId) {
		var answer=confirm(__lang_confirm_cancel_reservation);
		if (answer) {
			document.getElementById("cancelForm").submit();
		}
	}
	
