﻿// JScript File
var strDefaultOrderMessage = "Order right now and we will ship your package on or before";
var exceptiondateyear = new Date();
//******************************************************************
//Exception days list. To alter simple change the month and day, the year
//is automatically figured out based on this year
//******************************************************************
var exceptiondates = new Array(13);
   exceptiondates[0]  = "1/1/" + exceptiondateyear.getFullYear(); //new years day
   exceptiondates[1]  = "1/26/" + exceptiondateyear.getFullYear(); //Chinese new years eve
   exceptiondates[2]  = "5/31/" + exceptiondateyear.getFullYear(); //memorial day
   exceptiondates[3]  = "7/5/" + exceptiondateyear.getFullYear(); //july 6th
   exceptiondates[4]  = "9/7/" + exceptiondateyear.getFullYear(); //labor day
   exceptiondates[5]  = "11/26/" + exceptiondateyear.getFullYear(); //thanksgiving day
   exceptiondates[6]  = "11/27/" + exceptiondateyear.getFullYear(); //day after thanksgiving
   exceptiondates[7]  = "12/25/" + exceptiondateyear.getFullYear(); //christmas eve
   exceptiondates[8]  = "12/26/" + exceptiondateyear.getFullYear(); //christmas day
   exceptiondates[9]  = "2/9/"; //
   exceptiondates[10] = "2/15/"; //
   exceptiondates[11] = ""; //
   exceptiondates[12] = "";
   
function GetOrderMessage(){
//******************************************************************
//this function writes out the sale date message to the screen based on the current
//day, time of the day, and any exception days to take into consideration
//example call : GetOrderMessage();

//> If it is before 2 PM EST, XYZ is the current day If it is after 2 PM, 
//> XYZ is the next valid business day Valid business days are MTWThF 
//> Script will also look at an exception list for dates that we are 
//> closed.  The exception list needs to be editable.
//******************************************************************
    var dtOrderMessageDate = new Date();
   
    if(dtOrderMessageDate.getUTCHours() >= 18){ //18 GMT = 14 eastern time or 2:00 pm
        //it's after 2 PM so it ships out tomorrow
        dtOrderMessageDate.setDate(dtOrderMessageDate.getDate() + 1);
    }    
    //check the day and if it is a weekday then the shipping date is the monday
    while(IsExceptionDate(dtOrderMessageDate.toLocaleDateString())==true){
        dtOrderMessageDate.setDate(dtOrderMessageDate.getDate() + 1);
    }  
    document.write(strDefaultOrderMessage + ' ' + dtOrderMessageDate.toLocaleDateString());
};
function IsExceptionDate(dtDate){
//checks the exception date list and returns true or false if the date is an exception date
    var lenexceptiondates = exceptiondates.length -1;
    for(var y=0;y<lenexceptiondates;y++){
		//grab the exception dates
		if(exceptiondates[y].toString() != ''){
		    //cast the dates and compare them
		    if(new Date(dtDate).toLocaleDateString() == new Date(exceptiondates[y]).toLocaleDateString()){
			    return true;
			}
		}
	}
	//check to see if the date is a none business day 0=sunday,6=saturday if it is then its an exception
	if(new Date(dtDate).getDay()==6 || new Date(dtDate).getDay()==0){
	    return true;
	}
    return false;
};



