// текущая дата
let date = new Date();
function changeDeliveryChbox(){
let chbox1 = document.querySelector('#DELIVERY_TYPE_1')
let chbox2 = document.querySelector('#DELIVERY_TYPE_2')
let inputDate = document.querySelector('#delivery_date')
let inputHours = document.querySelector('#delivery_time')
let inputFastDate = document.querySelector('#delivery_date_fast')
let inputFastHours = document.querySelector('#delivery_time_fast')
let deliveryBoxSimple = document.querySelector('.delivery-box-simple')
let deliveryBoxFast = document.querySelector('.delivery-box-fast')
let calculateButton = document.querySelector('#calculate-button')
if (chbox1.checked) {
chbox1.setAttribute('value', 'simple')
deliveryBoxSimple.setAttribute('style', 'display: block')
deliveryBoxFast.setAttribute('style', 'display: none')
calculateButton.setAttribute('style', 'display: block')
chbox2.checked = false;
chbox1.setAttribute('name', 'ORDER_PROP_33')
chbox2.setAttribute('name', '')
inputDate.setAttribute('name', 'ORDER_PROP_32')
inputFastDate.setAttribute('name', '')
inputHours.setAttribute('name', 'ORDER_PROP_25')
inputFastHours.setAttribute('name', '')
inputDate.innerHTML = getSimpleDateOptions();
inputHours.innerHTML = getSimpleHoursOptions();
}
else {
chbox1.checked = true;
}
if (chbox2.checked) {
chbox2.setAttribute('value', 'fast')
deliveryBoxSimple.setAttribute('style', 'display: none')
deliveryBoxFast.setAttribute('style', 'display: block')
chbox1.checked = false;
}
else {
chbox2.setAttribute('value', '')
deliveryBoxFast.setAttribute('style', 'display: none')
}
}
function changeDeliveryChboxFast(){
let chbox1 = document.querySelector('#DELIVERY_TYPE_1')
let chbox2 = document.querySelector('#DELIVERY_TYPE_2')
let inputDate = document.querySelector('#delivery_date')
let inputHours = document.querySelector('#delivery_time')
let inputFastDate = document.querySelector('#delivery_date_fast')
let inputFastHours = document.querySelector('#delivery_time_fast')
let deliveryBoxSimple = document.querySelector('.delivery-box-simple')
let deliveryBoxFast = document.querySelector('.delivery-box-fast')
let calculateButton = document.querySelector('#calculate-button')
if (chbox2.checked) {
chbox2.setAttribute('value', 'fast')
deliveryBoxSimple.setAttribute('style', 'display: none')
deliveryBoxFast.setAttribute('style', 'display: block')
calculateButton.setAttribute('style', 'display: block')
chbox1.checked = false;
chbox2.setAttribute('name', 'ORDER_PROP_33')
chbox1.setAttribute('name', '')
inputFastDate.setAttribute('name', 'ORDER_PROP_32')
inputDate.setAttribute('name', '')
inputFastHours.setAttribute('name', 'ORDER_PROP_25')
inputHours.setAttribute('name', '')
inputFastDate.innerHTML = getFastDateOptions();
inputFastHours.innerHTML = getFastHoursOptions();
}
else {
chbox2.checked = true;
}
}
function getSimpleDateOptions(){
// текущая дата
let date = new Date();
let arDate = [];
let strOptions = ''
let inputDate = document.querySelector('#delivery_date')
let valueDate = inputDate.getAttribute('data-value')
let inputLang = inputDate.getAttribute('lang')
if(date.getHours() < 19){ arDate.push('today')}
for(let i = 0; i < 7; i++){
date.setDate(date.getDate()+1);
arDate.push(date.getDate() + '.' + (date.getMonth()+1))
}
arDate.forEach(function(item, i, arr) {
selected = ''
if (valueDate == item) {selected = 'selected = ""'}
if (inputLang = 'ru'){
strOptions = strOptions + '<option ' + selected + ' value="' + item + '">' + 'Сегодня' + '</option>\n'
}else{
strOptions = strOptions + '<option ' + selected + ' value="' + item + '">' + 'Today' + '</option>\n'}
});
return strOptions
}
function getSimpleHoursOptions($fullday){
// текущая дата
let date = new Date()
let arDate = []
let strOptions = ''
let hours
let inputDate = document.querySelector('#delivery_time')
inputDate = inputDate.getAttribute('data-value')
if ($fullday == true){hours = 0}else{hours = date.getHours() + 3}
while(hours < 22) {
arDate.push(hours)
hours++;
}
arDate.forEach(function(item, i, arr) {
selected = ''
if (inputDate == (item + ':00 - ' + (item + 3) + ':00')) {selected = 'selected = ""'}
strOptions = strOptions + '<option ' + selected + ' value="' + item + ':00 - ' + (item + 3) + ':00" >' + item + ':00 - ' + (item + 3) + ':00' + '</option>\n'
});
return strOptions
}
function getFastDateOptions(){
// текущая дата
let date = new Date();
let arDate = [];
let strOptions = ''
let inputDate = document.querySelector('#delivery_date_fast')
let valueDate = inputDate.getAttribute('data-value')
let inputLang = inputDate.getAttribute('lang')
if(date.getHours() < 19){ arDate.push('today')}
for(let i = 0; i < 7; i++){
date.setDate(date.getDate()+1);
arDate.push(date.getDate() + '.' + (date.getMonth()+1))
}
arDate.forEach(function(item, i, arr) {
selected = ''
if (valueDate == item) {selected = 'selected = ""'}
if (inputLang = 'ru'){
strOptions = strOptions + '<option ' + selected + ' value="' + item + '">' + 'Сегодня' + '</option>\n'
}else{
strOptions = strOptions + '<option ' + selected + ' value="' + item + '">' + 'Today' + '</option>\n'}
});
return strOptions
}
function getFastHoursOptions($fullday){
// текущая дата
let date = new Date()
let arDate = []
let strOptions = ''
let hours
let inputDate = document.querySelector('#delivery_time_fast')
inputDate = inputDate.getAttribute('data-value')
if ($fullday == true){hours = 0}else{hours = date.getHours() + 3}
while(hours < 24) {
arDate.push(hours)
hours++;
}
arDate.forEach(function(item, i, arr) {
selected = ''
if (inputDate == (item + ':00 - ' + item + ':15')) {selected = 'selected = ""'}
strOptions = strOptions + '<option ' + selected + ' value="' + item + ':00 - ' + item + ':15" >' + item + ':00 - ' + item + ':15' + '</option>\n'
if (inputDate == (item + ':15 - ' + item + ':30')) {selected = 'selected = ""'}
strOptions = strOptions + '<option ' + selected + ' value="' + item + ':15 - ' + item + ':30" >' + item + ':15 - ' + item + ':30' + '</option>\n'
if (inputDate == (item + ':30 - ' + item + ':45')) {selected = 'selected = ""'}
strOptions = strOptions + '<option ' + selected + ' value="' + item + ':30 - ' + item + ':45" >' + item + ':30 - ' + item + ':45' + '</option>\n'
if (inputDate == (item + ':45 - ' + (item + 1) +':00')) {selected = 'selected = ""'}
strOptions = strOptions + '<option ' + selected + ' value="' + item + ':45 - ' + (item + 1) +':00" >' + item + ':45 - ' + (item + 1) + ':00' + '</option>\n'
});
return strOptions
}
function delivery_day_change_date(input) {
input.setAttribute('data-value', input.value)
let inputHours = document.querySelector('#delivery_time')
let calculateButton = document.querySelector('#calculate-button')
calculateButton.setAttribute('style', 'display: block')
if (input.value == 'today'){
inputHours.innerHTML = getSimpleHoursOptions()
}
else{
inputHours.innerHTML = getSimpleHoursOptions(true)
}
}
function delivery_day_change_date_fast(input) {
input.setAttribute('data-value', input.value)
let inputHours = document.querySelector('#delivery_time_fast')
let calculateButton = document.querySelector('#calculate-button')
calculateButton.setAttribute('style', 'display: block')
if (input.value == 'today'){
inputHours.innerHTML = getFastHoursOptions()
}
else{
inputHours.innerHTML = getFastHoursOptions(true)
}
}
function delivery_time_change_date(input) {
let calculateButton = document.querySelector('#calculate-button')
calculateButton.setAttribute('style', 'display: block')
input.setAttribute('data-value', input.value)
}