BigNumber.config({ROUNDING_MODE: 4});
function doLoadCot() {
var prdcodes = document.getElementById('prdcodes').value;
var prdcodesHEB = document.getElementById('prdcodesHEB').value;
prdcodes = prdcodes.split(',');
var MTHTT1_Total = new BigNumber("0.0");
var MTTVAT1_Total = new BigNumber("0.0");
var MTHTT2_Total = new BigNumber("0.0");
var MTTVAT2_Total = new BigNumber("0.0");
//http://u-project2.umanis.com/view.php?id=36186 produits à cotisation variable - plafonnement
for(i=0; i < prdcodes.length; i++){
if(document.getElementById('qu_'+prdcodes[i])){
var qt = new BigNumber(document.getElementById('qu_'+prdcodes[i]).value);
var qt2 = new BigNumber(document.getElementById('max_qu_'+prdcodes[i]).value);
if(parseInt(qt.toString()) > parseInt(qt2.toString()) && (prdcodesHEB.indexOf("="+prdcodes[i]+"=") > -1))
qt = new BigNumber(qt2.toString());
var pr = new BigNumber(document.getElementById('pr_'+prdcodes[i]).value);
var rem = new BigNumber(document.getElementById('REM_tofil_'+ prdcodes[i]).value);
var tvam = new BigNumber(document.getElementById('TVA_tofil_'+ prdcodes[i]).value);
var ProUnitHTT1_ = new BigNumber(document.getElementById('ProUnitHTT1_'+ prdcodes[i]).value);
var TVAT1_ = new BigNumber(document.getElementById('TVAT1_'+ prdcodes[i]).value);
var pr2 = pr.minus(rem);
pr = pr.plus(tvam).minus(rem);
var to = qt.mul(pr);
var to2 = new BigNumber(qt.mul(pr2).toFixed(2));
MTHTT1_Total = MTHTT1_Total.plus(to2);
var to3 = ProUnitHTT1_.mul(qt).mul(TVAT1_).div(new BigNumber("100")).toFixed(2); // verif
var to = new BigNumber(to2.plus(to3).toFixed(2));
MTTVAT1_Total = MTTVAT1_Total.plus(to3);//verif
document.getElementById('tofil_'+ prdcodes[i]).value = to.toString();
document.getElementById('MTHTT1_'+ prdcodes[i]).innerHTML = ''+to2.toString()+' €';
document.getElementById('MTTVAT1_'+ prdcodes[i]).innerHTML = ''+to3.toString()+' €';
}
if(document.getElementById('2qu_'+prdcodes[i])){
var qt = new BigNumber(document.getElementById('2qu_'+prdcodes[i]).value);
var qt2 = new BigNumber(document.getElementById('max_2qu_'+prdcodes[i]).value);
if(parseInt(qt.toString()) > parseInt(qt2.toString()) && (prdcodesHEB.indexOf("="+prdcodes[i]+"=") > -1))
qt = new BigNumber(qt2.toString());
var pr = new BigNumber(document.getElementById('2pr_'+prdcodes[i]).value);
var rem = new BigNumber(document.getElementById('REM_todep_'+ prdcodes[i]).value);
var tvam = new BigNumber(document.getElementById('TVA_todep_'+ prdcodes[i]).value);
var tvam2 = new BigNumber(document.getElementById('TVAT2_'+ prdcodes[i]).value);
var ProUnitHTT2_ = new BigNumber(document.getElementById('ProUnitHTT2_'+ prdcodes[i]).value);
var TVAT2_ = new BigNumber(document.getElementById('TVAT2_'+ prdcodes[i]).value);
var pr2 = pr.minus(rem);
tvam = pr2.div("100").mul(tvam2);
pr = pr.plus(tvam).minus(rem);
var to = qt.mul(pr);
var to2 = new BigNumber(qt.mul(pr2).toFixed(2));
MTHTT2_Total = MTHTT2_Total.plus(to2);
var to3 = new BigNumber(ProUnitHTT2_.mul(qt).mul(TVAT2_).div(new BigNumber("100")).toFixed(2));
to = new BigNumber(to2.plus(to3).toFixed(2));
MTTVAT2_Total = MTTVAT2_Total.plus(to3);
document.getElementById('todep_'+ prdcodes[i]).value = to.toString();
//document.getElementById('MTHTT2_'+ prdcodes[i]).innerHTML = ''+to2.toString()+' €';
//document.getElementById('MTTVAT2_'+ prdcodes[i]).innerHTML = ''+to3.toString()+' €';
}
}
document.getElementById('MTHTT1_Total').innerHTML = ''+MTHTT1_Total.toFixed(2).toString()+' €';
document.getElementById('MTTVAT1_Total').innerHTML = ''+MTTVAT1_Total.toFixed(2).toString()+' €';
//document.getElementById('MTHTT2_Total').innerHTML = ''+MTHTT2_Total.toFixed(2).toString()+' €';
//document.getElementById('MTTVAT2_Total').innerHTML = ''+MTTVAT2_Total.toFixed(2).toString()+' €';
calculToto();
}
function calculToto(){
var tofil = 0;
//var todep = 0;
var prdcodes = document.getElementById('prdcodes').value;
prdcodes = prdcodes.split(',');
for(i=0; i < prdcodes.length; i++){
if(document.getElementById('tofil_'+prdcodes[i])){
var t = document.getElementById('tofil_'+prdcodes[i]).value;
tofil = parseFloat(tofil) + parseFloat(t);
}
//if(document.getElementById('todep_'+prdcodes[i])){
//var t = document.getElementById('todep_'+prdcodes[i]).value;
//todep = parseFloat(todep) + parseFloat(t);
//}
}
//todep = todep.toFixed(2);
tofil = tofil.toFixed(2);
document.getElementById('tofil').value = tofil;
//document.getElementById('todep').value = todep;
}
function getElementsByIdStartsWith(container, selectorTag, prefix) {
var items = [];
var myPosts = document.getElementById(container).getElementsByTagName(selectorTag);
for (var i = 0; i < myPosts.length; i++) {
//omitting undefined null check for brevity
if (myPosts[i].id.lastIndexOf(prefix, 0) === 0) {
items.push(myPosts[i]);
}
}
return items;
}
function doSaveCotValues(){
var prdcodes = document.getElementById('prdcodes').value;
prdcodes = prdcodes.split(',');
for(i=0; i < prdcodes.length; i++){
if(document.getElementById('qu_'+prdcodes[i])){
var qt = document.getElementById('qu_'+prdcodes[i]).value;
document.getElementById(prdcodes[i]).value = qt;
}
}
}
$(document).ready(function(){
$('input[type="file"]').ajaxfileupload({
'action': '/upload_custom_ajax.fl',
'onComplete': function(response) {
response = response.replace("", "");
response = response.substr(response.length-16,response.length);
document.getElementById('photoAttID').value = response;
document.getElementById('photo').src= '/download?id=' + response;
$('#upload').hide();
},
'onStart': function() {
$('#upload').show();
}
});
$("ul.ul_w95ofh input[type=radio]").live('click', function() {
$("ul.ul_w95ofh").find("input[type=radio]").each(function(){
if(this.checked){
$("#div3_w50fl input[name='490_ResponseInt']").attr('disabled','disabled');
$("#div3_w50fl input[name='490_ResponseInt']").val("");
}else{
$("#div3_w50fl input[name='490_ResponseInt']").removeAttr('disabled');
}
});
});
// Afficher ou non les exemples de plats si case cochée ou pas
//$(".div1_w50fl input[name='R_5630_ResponseTxt']").hide();
//$(".div1_w50fl input[name='R_5640_ResponseTxt']").hide();
//$(".div1_w50fl input[name='R_5650_ResponseTxt']").hide();
//$("#div1_w172fl").hide();
//$("#div1_w173fl").hide();
//$("#div1_w174fl").hide();
if($(".div1_w50fl input[name='R_5630_ResponseTxt']").val()|| $(".div1_w50fl input[name='R_5640_ResponseTxt']").val() || $(".div1_w50fl input[name='R_5650_ResponseTxt']").val()){
$("#R_PARA5").find(".webform_label.div1_w95fl").find("input[type=checkbox][name^='R']").prop( "checked", true );
$(".div1_w50fl input[name='R_5630_ResponseTxt']").show();
$(".div1_w50fl input[name='R_5640_ResponseTxt']").show();
$(".div1_w50fl input[name='R_5650_ResponseTxt']").show();
$(".div1_w50fl input[name='R_5630_ResponseTxt']").parent().prev().show();
$(".div1_w50fl input[name='R_5640_ResponseTxt']").parent().prev().show();
$(".div1_w50fl input[name='R_5650_ResponseTxt']").parent().prev().show();
}else{
$("#R_PARA5").find(".webform_label.div1_w95fl").find("input[type=checkbox][name^='R']").prop( "checked", false );
$(".div1_w50fl input[name='R_5630_ResponseTxt']").hide();
$(".div1_w50fl input[name='R_5640_ResponseTxt']").hide();
$(".div1_w50fl input[name='R_5650_ResponseTxt']").hide();
$(".div1_w50fl input[name='R_5630_ResponseTxt']").parent().prev().hide();
$(".div1_w50fl input[name='R_5640_ResponseTxt']").parent().prev().hide();
$(".div1_w50fl input[name='R_5650_ResponseTxt']").parent().prev().hide();
}
$("#R_PARA5").find(".webform_label.div1_w95fl").find("input[type=checkbox][name^='R']").click(function() {
if($(this).is(":checked")) {
$(".div1_w50fl input[name='R_5630_ResponseTxt']").show();
$(".div1_w50fl input[name='R_5640_ResponseTxt']").show();
$(".div1_w50fl input[name='R_5650_ResponseTxt']").show();
$(".div1_w50fl input[name='R_5630_ResponseTxt']").parent().prev().show();
$(".div1_w50fl input[name='R_5640_ResponseTxt']").parent().prev().show();
$(".div1_w50fl input[name='R_5650_ResponseTxt']").parent().prev().show();
}else{
$(".div1_w50fl input[name='R_5630_ResponseTxt']").hide();
$(".div1_w50fl input[name='R_5640_ResponseTxt']").hide();
$(".div1_w50fl input[name='R_5650_ResponseTxt']").hide();
$(".div1_w50fl input[name='R_5630_ResponseTxt']").val("");
$(".div1_w50fl input[name='R_5640_ResponseTxt']").val("");
$(".div1_w50fl input[name='R_5650_ResponseTxt']").val("");
$(".div1_w50fl input[name='R_5630_ResponseTxt']").parent().prev().hide();
$(".div1_w50fl input[name='R_5640_ResponseTxt']").parent().prev().hide();
$(".div1_w50fl input[name='R_5650_ResponseTxt']").parent().prev().hide();
}
});
$("#div1_w50fl input[name='56_ResponseTxt']").live('keyup change', function() {
var checker = $.trim($(this).val()).length === 0;
$("#div3_w50fl input[name='57_ResponseInt']").attr('disabled', !checker);
});
$("#div3_w50fl input[name='57_ResponseInt']").live('keyup change', function() {
var checker = $.trim($(this).val()).length === 0;
$("#div1_w50fl input[name='56_ResponseTxt']").attr('disabled', !checker);
});
formatSiret($("#div1_w50fl input[name='270_ResponseTxt']").get(0));
$('textarea.input_textarea').each(function(index){
var trimmed = $.trim($(this).val()).replace(/\s*[\r\n]+\s*/g, '\n')
.replace(/(<[^\/][^>]*>)\s*/g, '$1')
.replace(/\s*(<\/[^>]+>)/g, '$1');
$(this).val(trimmed);
$(this).html(trimmed);
$(this).text(trimmed);
});
$("input[name='M_5300_ResponseRefID']").each(function(){
if(this.checked){
handleBreakfastPrice(this);
}
});
calculateIndice('T' , '3800');
loadHandleBreakfast();
});
function isTime(txtTime){
regexp = /^(2[0-3]|[01]?[0-9])h([0-5][0-9])$/;
if(!regexp.test(txtTime)) alert("Time n'est pas correcte");
}
function isDate(txtDate)
{
var currVal = txtDate;
if(currVal == '')
return false;
var rxDatePattern = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/; //Declare Regex
var dtArray = currVal.match(rxDatePattern); // is format OK?
if (dtArray == null)
return false;
//Checks for dd/mm/yyyy format.
dtMonth = dtArray[3];
dtDay= dtArray[1];
dtYear = dtArray[5];
if (dtMonth < 1 || dtMonth > 12)
return false;
else if (dtDay < 1 || dtDay> 31)
return false;
else if ((dtMonth==4 || dtMonth==6 || dtMonth==9 || dtMonth==11) && dtDay ==31)
return false;
else if (dtMonth == 2)
{
var isleap = (dtYear % 4 == 0 && (dtYear % 100 != 0 || dtYear % 400 == 0));
if (dtDay> 29 || (dtDay ==29 && !isleap))
return false;
}
return true;
}
function getDatefromString(str1){
// str1 format should be dd/mm/yyyy. Separator can be anything e.g. / or -. It wont effect
var from = str1.split("/");
var date1 = new Date(from[2], from[1] - 1, from[0]);
return date1;
}
function trim1(str) {
return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
function areTheyValid(type,element){
var element1 = document.getElementsByName(element.name)[0];
var element2 = document.getElementsByName(element.name)[1];
element1.value = trim1(element1.value);
element2.value = trim1(element2.value);
if(!element1.value && !element2.value)
return true;
if(isItValid(type,element1))
if(!element2.value){
if(type == 'java.util.Date|java.util.Date'){
element2.focus();
}
}else{
if(isItValid(type,element2))
return isIntervalValid(type,element);
}
return false;
}
function checkSemaineLivraison(element){
var rrr = isItValid('java.lang.Integer',element);
if(rrr){
return isIntervalValid('7to23',element);
}
}
function clearDates(elementName){
document.getElementsByName(elementName)[0].value = '';
document.getElementsByName(elementName)[1].value = '';
}
function _tempSave(endPos) {
var f = document.forms[0];
f.action = '/save_partial_web_form.fl?fromToSave=0&toToSave=' + endPos;
f.submit();
}
function _save() {
var f = document.forms[0];
f.action = '/save_web_form.fl';
f.submit();
}
function sortNum(a, b) {
return 1 * $(a).find('.sort').text() < 1 * $(b).find('.sort').text() ? 0 : 1;
}
function sortTheTable(idtbl){
$(function() {
var elems = $.makeArray($('tr:has(.sort)').remove())
elems.sort(sortNum)
$('table#'+idtbl).append($(elems));
});
}
function sortNum2(a, b) {
return 1 * $(a).find('.sort2').text() < 1 * $(b).find('.sort2').text() ? 0 : 1;
}
function sortTheTable2(idtbl){
$(function() {
var elems = $.makeArray($('tr:has(.sort2)').remove())
elems.sort(sortNum2)
$('table#'+idtbl).append($(elems));
});
}
function openTiersTab(elem, tabName,scroll) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
var elt = document.getElementById(tabName);
if(elt != null && elt != undefined){
elt.style.display = "block";
}
elem.className += " active";
if(scroll == null || scroll == true){
$("html, body").animate({scrollTop : 0});
}
}
window.onscroll = function() {myFunction()};
//Get the header
//var header = document.getElementById("myHeader");
//Get the offset position of the navbar
//var sticky = document.getElementById("myHeader").offsetTop;
//Add the sticky class to the header when you reach its scroll position. Remove "sticky" when you leave the scroll position
function myFunction() {
if (window.pageYOffset > document.getElementById("myHeader").offsetTop) {
document.getElementById("myHeader").classList.add("sticky");
} else {
document.getElementById("myHeader").classList.remove("sticky");
}
}
function topForm(){
$("html, body").animate({scrollTop : 0});
}
function bottomForm(){
$("html, body").animate({scrollTop : document.body.scrollHeight});
}
function loadingPopUp(){
document.getElementById('light').style.display='block';
document.getElementById('fade').style.display='block';
document.getElementById('webform').style.display='none';
setTimeout(function(){return;}, 3000000);
}
function doSubmit(navigation) {
f=document.forms[0];
if (navigation) {
f.action+= '&' + navigation;
}
$("*[disabled]").css("visibility", "hidden");
$("*[disabled]").removeAttr("disabled");
// popup pour chargement
loadingPopUp();
f.submit();
}
function doSubmitAjax(navigation) {
$("*[disabled]").css("visibility", "hidden");
$("*[disabled]").removeAttr("disabled");
for (var index = document.forms.length - 2; index >= 0; index--) {
var form = document.forms[index];
var formID = form.getAttribute("id");
if(index == 0){
$('#T_Covid_Form :input').not(':submit').clone().hide().appendTo('#' + formID);
}
// popup pour chargement
//handle the Opening inputs
var prefix = formID[0];
if(document.forms.length - 1 != index){
for(var i = 6400; i <= 7000 ; i+=100){
var k = prefix + "_" + i + "_ResponseRefID";
var elt = form.elements[k][0];
if(elt != null && elt != undefined && elt.checked){
for(var j = 0; j < 2 ; j++){
var eltInput = form.elements[prefix + "_" + i + "_ResponseInt"][j];
if(eltInput != null && eltInput != undefined){
eltInput.value = '00:00';
}
}
}
if(prefix != "R"){
elt = form.elements[k][1];
if(elt != null && elt != undefined && elt.checked){
var eltInput = form.elements[prefix + "_" + i + "_ResponseInt"][0];
if(eltInput != null && eltInput != undefined){
eltInput.value = '00:01';
}
eltInput = form.elements[prefix + "_" + i + "_ResponseInt"][1];
if(eltInput != null && eltInput != undefined){
eltInput.value = '23:59';
}
}
}
}
}
if (navigation) {
form.action+= '&' + navigation;
}
loadingPopUp();
if(index == 0){
form.submit();
}else{
var frm = $('#'+formID);
$.ajax({
type: frm.attr('method'),
url: frm.attr('action'),
contentType: "application/x-www-form-urlencoded",
data: frm.serialize(),
async: false,
success: function (data) {
console.log('Submission was successful.');
console.log(data);
},
error: function (data) {
console.log('An error occurred.');
console.log(data);
},
});
}
}//for
}//function
//function checkLimits(id){
// /* onKeyUp="checkLimits();"
// onPaste="checkLimits();"
// onCut="checkLimits();"
// onBlur="checkLimits()*/
// var textarea = document.getElementById("T_3126_ResponseTxt");
// var limit = textarea.getAttribute("rows");
//
// var lines = textarea.value.split("\n");
//
// if(lines.length>limit)
// {
// textarea.style.color = 'red';
// setTimeout(function(){
// textarea.style.color = '';
// },500);
// }
// textarea.value = lines.slice(0, limit).join("\n");
//}
//
function disableOpening(element, id){
if(element.checked){
var inputElt = document.getElementsByName(id + "_ResponseInt");
for(var i = 0 ; i < inputElt.length ; i++){
inputElt[i].value = '';
inputElt[i].disabled = true;
}
}
}
function enableOpening(element, id ){
if(element.checked){
var inputElt = document.getElementsByName(id + "_ResponseInt");
for(var i = 0 ; i < inputElt.length ; i++)
inputElt[i].disabled = false;
}
}
function changeLabelColor(elt){
elt.parentNode.style.color = elt.checked ? "green" : "black";
}
function doInInputTime(elt, id){
if( elt != undefined && elt.value && elt.value != ""){
// radioElt.checked = true;
if(elt.parentElement.parentElement.firstElementChild.firstElementChild.firstElementChild != null )
elt.parentElement.parentElement.firstElementChild.firstElementChild.firstElementChild.checked = true;
}
// else{
// radioElt.checked = false;
// if(elt.parentElement.parentElement.firstElementChild.firstElementChild.firstElementChild != null )
// elt.parentElement.parentElement.firstElementChild.firstElementChild.firstElementChild.checked = false;
// }
answerTime(elt);
checkIsAfter(elt, id);
}
function answerTime(elt){
if(elt.value){
if(elt.value.startsWith(':')){
elt.value = '00' + elt.value;
}else if(elt.value.endsWith(':')){
elt.value += '00';
}
}
}
function checkIsAfter(elt, eltName){
var elts = document.getElementsByName(eltName + '_ResponseInt');
var startTime = new Date();
var endTime = new Date();
if (elts[1].value) {
if(elts[0].value){
startTime.setHours(elts[0].value.split(':')[0]);
startTime.setMinutes(elts[0].value.split(':')[1]);
startTime.setSeconds(0);
endTime.setHours(elts[1].value.split(':')[0]);
endTime.setMinutes(elts[1].value.split(':')[1]);
endTime.setSeconds(0);
if(startTime > endTime){
elts[1].value = '';
}
}
else {
elts[1].value = '';
}
}
if(elts.length > 2){
var startTime1 = new Date();
var endTime1 = new Date();
if (elts[3].value) {
if(elts[2].value){
startTime1.setHours(elts[2].value.split(':')[0]);
startTime1.setMinutes(elts[2].value.split(':')[1]);
startTime1.setSeconds(0);
endTime1.setHours(elts[3].value.split(':')[0]);
endTime1.setMinutes(elts[3].value.split(':')[1]);
endTime1.setSeconds(0);
if(startTime1 > endTime1){
elts[3].value = '';
}
}else if(elts[0].value && !elts[1].value){
startTime1.setHours(elts[0].value.split(':')[0]);
startTime1.setMinutes(elts[0].value.split(':')[1]);
startTime1.setSeconds(0);
endTime1.setHours(elts[3].value.split(':')[0]);
endTime1.setMinutes(elts[3].value.split(':')[1]);
endTime1.setSeconds(0);
if(startTime1 > endTime1){
elts[3].value = '';
}
}else{
elts[3].value = '';
}
}
}
}
function handleBreakfastPrice(elt,prefix='M'){
var isYes = undefined;
if(elt.nextElementSibling != null && elt.nextElementSibling != undefined){
isYes = elt.nextElementSibling.textContent.includes('O');
} else{
isYes = elt.nextSibling.textContent.includes('O')
}
if(isYes != undefined && isYes){
document.getElementsByName(prefix.substring(0, 1)+'_5400_ResponseInt')[0].parentNode.parentNode.style.display = 'none';
document.getElementsByName(prefix.substring(0, 1)+'_5400_ResponseInt')[0].value='';
document.getElementsByName(prefix.substring(0, 1)+'_5400_ResponseInt')[1].value='';
} else{
try {
document.getElementsByName(prefix.substring(0, 1)+'_5400_ResponseInt')[0].parentNode.parentNode.style.display = 'block';
} catch (e) {
console.log(e);
}
}
}
function loadHandleBreakfast(){
for (var index = document.forms.length - 2; index >= 0; index--) {
var form = document.forms[index];
var formID = form.getAttribute("id");
var prefix = formID[0];
var input = Array.from(document.getElementsByName(prefix + '_5300_ResponseRefID')).filter(val => val.checked);
if(input.length > 0){
handleBreakfastPrice(input[0], prefix);
}
}
}
function showHidePriceEquipement(prefix, field, id){
if ($("#"+ prefix + "_" + id + "_price").length == 0)
return;
if (Array.from(document.getElementsByName(field)).filter(val => val.checked).reduce((val, current) => current.value == id || val, false)){
$("#"+ prefix + "_" + id + "_price").show();
}else{
$("#"+ prefix + "_" + id + "_price").hide();
}
}
function doCivResuired(prefix, position){
if(prefix && position){
var elt = document.getElementsByName(prefix + "_" + position +'_ResponseTxt')[0];
if(elt != null && elt != undefined && elt.value.length > 0 && elt.value != ''){
var civPos = position - 5;
var civElt = document.getElementsByName(prefix + "_" + civPos +'_ResponseRefID')[0];
if(civElt.selectedIndex == 0){
civElt.style.backgroundColor = '#FDCBCC';
}
}else{
var civElt = document.getElementsByName(prefix + "_" + civPos +'_ResponseRefID')[0];
civElt.style.backgroundColor = '';
}
}
}