$(document).ready(function() {
$('body').addClass('js-activated');
$('form#rsvp1').on('change', function(event) {
formRefresh(this);
});
formRefresh('form#rsvp1');
});
function copyFromID(id) {
e = document.getElementById(id);
navigator.clipboard.writeText(e.innerHTML);
$("#copyHint").show().delay(2000).fadeOut();
}
function formRefresh(form) {
locale = 'de-DE';
total_mxn = $('input#total_mxn1');
total_eur = $('input#total_eur1');
total_mxn.val(0);
total_eur.val(0);
$(form).find('select.room').each(function() {
quantity = Number($(this).val());
price_mxn = Number($(this).parent().parent().find('span.price_mxn').text()) * 1000;
price_eur = Number($(this).parent().parent().find('span.price_eur').text());
console.log("Quantity: " + quantity + ", price_mxn: " + price_mxn + ", price_eur: " + price_eur);
total_mxn.val(Number(total_mxn.val()) + price_mxn * quantity);
total_eur.val(Number(total_eur.val()) + price_eur * quantity);
});
total_mxn.val(new Intl.NumberFormat(locale).format(total_mxn.val()));
total_eur.val(new Intl.NumberFormat(locale).format(total_eur.val()));
}
function formSubmit(form) {
var error = {
en: {
title: "Confirmation",
html: "There was an error submitting the form.
Please try again later, or contact us directly.
Sorry!"
}, es: {
title: "Error",
html: "Se ha producido un error al enviar el formulario.
Por favor, inténtalo de nuevo más tarde o ponte en contacto con nosotros directamente.
¡Lo sentimos!"
}, fr: {
title: "Erreur",
html: "Le formulaire n'a pas pu être envoyé.
Désolé !"
}
};
var success = {
en: {
title: "Confirmation",
html: "The form was submitted successfully.
We will be in touch with you soon.
Thank you!"
}, es: {
title: "Confirmación",
html: "El formulario se ha enviado correctamente.
En breve nos pondremos en contacto con usted.
¡Muchas gracias!"
}, fr: {
title: "Confirmation",
html: "Le formulaire a été envoyé avec succès.
Nous allons vous contacter aussi vite que possible.
Merci !"
}
};
formRefresh(form);
lang = document.documentElement.getAttribute('lang');
if(!error.hasOwnProperty(lang) || !success.hasOwnProperty(lang))
lang = "en";
values = {};
$(form).find("[name]").each(function() {
values[$(this).attr("name")] = $(this).val();
});
$.ajax({
type: form.method,
url: form.action,
data: values,
success: function(response) { $("#dialog").html(response).dialog({
title: success[lang].title,
modal: true,
buttons: {
Close: function() {
$(this).dialog("close");
}
}
});},
error: function(response) { $("#dialog").html(error[lang].html).dialog({
title: error[lang].title,
modal: true,
buttons: {
Close: function() {
$(this).dialog("close");
}
}
});},
});
return false;
}