// alert('0') var form = document.form_cart; varDelTime = new Array("Anytime of the day","Morning (10:00 AM - 1:00 PM)","Afternoon (2:00 PM - 5:30 PM)","Evening (5:00 PM - 10:00 PM)"); //okstmtcc 20160125 valentines day //okstmtcc 20140110 valentines day //okstmtcc 20190213 disable valentines //okstmtcc 20210211 enable valentines to 1 slot only // varValTime = new Array("Morning (9:00 AM - 5:30 PM)"); varValTime = new Array("Anytime of the day","Morning (10:00 AM - 1:00 PM)","Afternoon (2:00 PM - 5:30 PM)","Evening (5:00 PM - 10:00 PM)"); if ($(".is_sunday_and_holiday").length > 1) { for (var i=0;i<$(".is_sunday_and_holiday").length;i++){ BuildTime(i,true) } }else{ BuildTime(0,true); } function BuildTime(num,first_time){ var smaller_than_earliest = false; var form = document.form_cart; chkOption($(".is_sunday_and_holiday"),num).value = "No"; // if(form.surcharge) chkOption(form.surcharge,num).value = "5"; if (chkOption($(".dtime"),num)!=null){ if (chkOption($(".dtime"),num).type=="select-one"){ /* var earliest_delivery_date = new Date(2025,2,04); var curdate = new Date(2025,2,03); */ var deldate = new Date(chkOption($(".year1"),num).options[chkOption($(".year1"),num).selectedIndex].value, chkOption($(".month1"),num).options[chkOption($(".month1"),num).selectedIndex].value-1, chkOption($(".day1"),num).options[chkOption($(".day1"),num).selectedIndex].value); chkOption($(".dtime"),num).length = 0; //validate date //validate deldate dayfield = chkOption($(".day1"),num).options[chkOption($(".day1"),num).selectedIndex].value; monthfield = chkOption($(".month1"),num).options[chkOption($(".month1"),num).selectedIndex].value; yearfield = chkOption($(".year1"),num).options[chkOption($(".year1"),num).selectedIndex].value; daydiff = 0; if ((deldate.getMonth()+1!=monthfield)||(deldate.getDate()!=dayfield)||(deldate.getFullYear()!=yearfield)){ alert('Invalid Delivery Date!'); return; } if (earliest_delivery_date.getTime() > deldate.getTime() || dateDiff(curdate,deldate) > 30){ // small than earliest delivery date chkOption($(".is_sunday_and_holiday"),num).value = "N/A" chkOption($(".dtime"),num).options[0] = new Option("No available delivery time",""); console.log('small than earliest delivery date'); //Only check for today whether is Sun or PH if(dateDiff(curdate,deldate)==0){ if (isHoliday(form,num,deldate)){ } // check if sunday else if (chkSunday(form,num)){ chkOption($(".is_sunday_and_holiday"),num).value = "Yes"; } } smaller_than_earliest = true; } else { //Order time just to determine earliest deliver date & session //Chosen delivery date will determine which session is available //if delivery date choosen is 1 day after earliest day, all session should be available; daydiff = Cov2Day(deldate - earliest_delivery_date); if(daydiff > 0){ for (var i=0;i 0){ chkOption($(".dtime"),num).length = 2; chkOption($(".dtime"),num).options[0] = new Option(varDelTime[1],1); chkOption($(".dtime"),num).options[1] = new Option(varDelTime[2],2); }else{ //If is today, mean have only 1 session Afternoon // same day with earliest delivery date; get the earliest session; switch ('Afternoon'){ case 'Morning': chkOption($(".dtime"),num).length = 2; chkOption($(".dtime"),num).options[0] = new Option(varDelTime[1],1); chkOption($(".dtime"),num).options[1] = new Option(varDelTime[2],2); break; case 'Afternoon': chkOption($(".dtime"),num).length = 1; chkOption($(".dtime"),num).options[0] = new Option(varDelTime[2],2); break; } } } //Check if is sunday or PH if ( (isHoliday(form,num,deldate) || chkSunday(form,num)) && daydiff > 0 && !smaller_than_earliest){ chkOption($(".is_sunday_and_holiday"),num).value = "Yes"; chkOption($(".dtime"),num).length = 1; chkOption($(".dtime"),num).options[0] = new Option(varDelTime[1],1); chkOption($(".self_collection"),num).checked = false; } //okstmtcc 20160125 valentines day //okstmtcc 20140110 valentines day //okstmtcc 20210211 enable valentines to 1 slot only if(chkValentinesDay(form,num) && !smaller_than_earliest){ //If bigger than today, mean have 2 sessions Morning & Afternoon if(daydiff > 0){ chkOption($(".dtime"),num).length = 1; chkOption($(".dtime"),num).options[0] = new Option(varValTime[0],0); //chkOption($(".dtime"),num).options[1] = new Option(varValTime[3],5); }else{ //If is today, mean have only 1 session Afternoon // same day with earliest delivery date; get the earliest session; //okstmtcc 20190213 disable valentines //okstmtcc 20210211 enable valentines to 1 slot only switch ('Afternoon'){ case 'Morning':case 'Afternoon': chkOption($(".dtime"),num).length = 1; chkOption($(".dtime"),num).options[0] = new Option(varValTime[0],0); // chkOption($(".dtime"),num).options[1] = new Option(varValTime[3],5); break; case 'Evening': chkOption($(".dtime"),num).length = 1; chkOption($(".dtime"),num).options[0] = new Option(varValTime[3],5); break; } } } //okstmtcc 20140103 redemption (23) var curCategory = chkOption($(".categories_id"),num).value; var daydiff_r = 0; var smaller_than_redemption_earliest = false; if(curCategory=='23'){ daydiff_r = daydiff+1;//add 1 more day for the existing if(redemption_earliest_delivery_date.getTime() > deldate.getTime()){ smaller_than_redemption_earliest = true; } //If bigger or equal to 2 days difference if(daydiff_r >= 2 || daydiff_r==1){ chkOption($(".dtime"),num).length = 1; chkOption($(".dtime"),num).options[0] = new Option(varValTime[0],4); } //Check if is sunday or PH or less than 2 days from order date if ( (isHoliday(form,num,deldate) || chkWeekend(form,num)) || (daydiff_r < 2 && daydiff_r!=1) || smaller_than_redemption_earliest){ if(chkSunday(form,num)){ chkOption($(".is_sunday_and_holiday"),num).value = "Yes"; } chkOption($(".dtime"),num).length = 1; chkOption($(".dtime"),num).options[0] = new Option("No available delivery time",""); } } //okstmtcc 20140407 International Order (29) if(curCategory=='29'){ daydiff_r = daydiff+1;//add 1 more day for the existing if(redemption_earliest_delivery_date.getTime() > deldate.getTime()){ smaller_than_redemption_earliest = true; } //If bigger or equal to 2 days difference if(daydiff_r >= 2 || daydiff_r==1){ chkOption($(".dtime"),num).length = 1; chkOption($(".dtime"),num).options[0] = new Option(varDelTime[0],0); } //Check if is sunday or PH or less than 2 days from order date if ( (isHoliday(form,num,deldate) || chkWeekend(form,num)) || (daydiff_r < 2 && daydiff_r!=1) || smaller_than_redemption_earliest){ if(chkSunday(form,num)){ chkOption($(".is_sunday_and_holiday"),num).value = "Yes"; } chkOption($(".dtime"),num).length = 1; chkOption($(".dtime"),num).options[0] = new Option("No available delivery time",""); } } //Check if self-collection is checked //Schedule for self-collection is Mon-Fri: 10am-5.30pm, Sat: 10am - 1pm if(chkSelfCollection(num) && daydiff >= 0 && !smaller_than_earliest && curCategory!='29'){ var nowDate = new Date(); var cur_hour = nowDate.getHours(); var cur_minute = nowDate.getMinutes(); var cur_second = nowDate.getSeconds(); if(cur_hour<10){ cur_hour = "0"+cur_hour; } if(cur_minute<10){ cur_minute = "0"+cur_minute; } if(cur_second<10){ cur_second = "0"+cur_second; } var cur_time = cur_hour + ":" + cur_minute + ":" + cur_second; // if(cur_time <= "10:00:00"){ // chkOption($(".dtime"),num).length = 2; // chkOption($(".dtime"),num).options[0] = new Option(varDelTime[1],1); // chkOption($(".dtime"),num).options[1] = new Option(varDelTime[2],2); // }else if(cur_time <= '14:00:00'){ // chkOption($(".dtime"),num).length = 1; // chkOption($(".dtime"),num).options[0] = new Option(varDelTime[2],2); // }else{ chkOption($(".dtime"),num).length = 2; chkOption($(".dtime"),num).options[0] = new Option(varDelTime[1],1); chkOption($(".dtime"),num).options[1] = new Option(varDelTime[2],2); // } if (chkSaturday(form,num)){ chkOption($(".dtime"),num).length = 1; chkOption($(".dtime"),num).options[0] = new Option(varDelTime[1],1); } //okstmtcc 20140103 redemption (23) if(curCategory=='23'){ //Check if is sunday or PH or less than 2 days from order date if ( (isHoliday(form,num,deldate) || chkWeekend(form,num)) || (daydiff_r < 2 && daydiff_r!=1) || smaller_than_redemption_earliest){ if(chkSunday(form,num)){ chkOption($(".is_sunday_and_holiday"),num).value = "Yes"; } chkOption($(".dtime"),num).length = 1; chkOption($(".dtime"),num).options[0] = new Option("No available delivery time",""); } } } //okstmtcc 20131227 close for delivery if(isCloseForDelivery(form,num,deldate)){ } //okstmtcc 20140107 special price delivery if(fallInSpecialPriceDeliveryDate(form,num,deldate)){ } //okstmtcc 20131204 //To check if delivery date is changed, reset the delivery session options to default var chkd = chkOption($(".day1"),num); var chkm = chkOption($(".month1"),num); var chky = chkOption($(".year1"),num); var chksc = chkOption($(".self_collection"),num); var day_no_change = chkd.options[chkd.selectedIndex].defaultSelected ; var month_no_change = chkm.options[chkm.selectedIndex].defaultSelected; var year_no_change = chky.options[chky.selectedIndex].defaultSelected; if (day_no_change && month_no_change && year_no_change && chksc.checked == chksc.defaultChecked){ } } function Cov2Day(millisec){ if (!isNaN(millisec)){ return (millisec/1000/60/60/24) } } function chkWeekend(form,num){ var date1 = new Date(chkOption($(".year1"),num).options[chkOption($(".year1"),num).selectedIndex].value, chkOption($(".month1"),num).options[chkOption($(".month1"),num).selectedIndex].value-1, chkOption($(".day1"),num).options[chkOption($(".day1"),num).selectedIndex].value); if (date1.getDay() == 0 || date1.getDay() == 6) return true; else return false; } function chkSunday(form,num){ var date1 = new Date(chkOption($(".year1"),num).options[chkOption($(".year1"),num).selectedIndex].value, chkOption($(".month1"),num).options[chkOption($(".month1"),num).selectedIndex].value-1, chkOption($(".day1"),num).options[chkOption($(".day1"),num).selectedIndex].value); if (date1.getDay() == 0) return true; else return false; } function chkSaturday(form,num){ var date1 = new Date(chkOption($(".year1"),num).options[chkOption($(".year1"),num).selectedIndex].value, chkOption($(".month1"),num).options[chkOption($(".month1"),num).selectedIndex].value-1, chkOption($(".day1"),num).options[chkOption($(".day1"),num).selectedIndex].value); if (date1.getDay() == 6) return true; else return false; } //okstmtcc 20140110 valentines day function chkValentinesDay(form,num){ var date1 = new Date(chkOption($(".year1"),num).options[chkOption($(".year1"),num).selectedIndex].value, chkOption($(".month1"),num).options[chkOption($(".month1"),num).selectedIndex].value-1, chkOption($(".day1"),num).options[chkOption($(".day1"),num).selectedIndex].value); if (date1.getMonth()+1 == 2 && date1.getDate()==14) return true; else return false; } function chkSelfCollection(num){ return chkOption($(".self_collection"),num).checked; } //No self-collection Available on Sunday & PH (for checkbox) function validateSelfCollection(t,num){ var deldate = new Date(chkOption($(".year1"),num).options[chkOption($(".year1"),num).selectedIndex].value, chkOption($(".month1"),num).options[chkOption($(".month1"),num).selectedIndex].value-1, chkOption($(".day1"),num).options[chkOption($(".day1"),num).selectedIndex].value); var earliest_delivery_date = new Date(2025,2,04); //okstmtcc 20140407 international order (29) var curCategory = chkOption($(".categories_id"),num).value; //if delivery date choosen is 1 day after earliest day, all session should be available; daydiff = Cov2Day(deldate - earliest_delivery_date); // if(daydiff > 0){ // if(chkOption($(".is_sunday_and_holiday"),num).value == "Yes"){ // (deldate.getDate()=='14'&&deldate.getMonth()+1=='2') //check valentines if ( (isHoliday(form,num,deldate) || chkSunday(form,num)) && daydiff > 0 || curCategory=='29'){ t.checked = false; //okstmtcc 20140407 international order (29) if(curCategory=='29'){ alert("Self-Collection is not available for International Order."); }else{ alert("Self-Collection is not available for Sunday and public holiday. Please choose other date."); } } // } // } } function isHoliday(form,num,deldate){ // chkOption($(".is_sunday_and_holiday"),num).value = "No"; // if(form.surcharge) chkOption(form.surcharge,num).value = 5; var bln = false; // check if public holiday if(arrHolidays!=null){ for(var i=0; i= begin_date && deldate <= end_date){ bln = true; var spe_notes = arrSpecialPriceDelivery[pid][i].notes; } } } } if (bln){ // $(chkOption($(".default_final_price"),num)).hide(); // $(chkOption($(".special_final_price"),num)).show(); $(chkOption($(".is_special_delivery"),num)).val('1'); $(chkOption($(".cart-del-spec-notes-box"),num)).show(); $(chkOption($("span.inner-notes"),num)).html(spe_notes); }else{ $(chkOption($(".is_special_delivery"),num)).val('0'); } return bln; } function chkOption(obj,num){ if ($(".is_sunday_and_holiday").length > 1) { return obj[num]; }else { return obj[0]; } }