function suycDateDiff( start, end, interval, rounding ) {

    var iOut = 0;
    
    // Create 2 error messages, 1 for each argument. 
    var startMsg = "Check the Start Date and End Date\n"
        startMsg += "must be a valid date format.\n\n"
        startMsg += "Please try again." ;
		
    var intervalMsg = "Sorry the dateAdd function only accepts\n"
        intervalMsg += "d, h, m OR s intervals.\n\n"
        intervalMsg += "Please try again." ;

    var bufferA = Date.parse( start ) ;
    var bufferB = Date.parse( end ) ;
    	
    // check that the start parameter is a valid Date. 
    if ( isNaN (bufferA) || isNaN (bufferB) ) {
        alert( startMsg ) ;
        return null ;
    }
	
    // check that an interval parameter was not numeric. 
    if ( interval.charAt == 'undefined' ) {
        // the user specified an incorrect interval, handle the error. 
        alert( intervalMsg ) ;
        return null ;
    }
    
    var number = bufferB-bufferA ;
    
    // what kind of add to do? 
    switch (interval.charAt(0))
    {
        case 'd': case 'D': 
            iOut = parseInt(number / 86400000) ;
            if(rounding) iOut += parseInt((number % 86400000)/43200001) ;
            break ;
        case 'h': case 'H':
            iOut = parseInt(number / 3600000 ) ;
            if(rounding) iOut += parseInt((number % 3600000)/1800001) ;
            break ;
        case 'm': case 'M':
            iOut = parseInt(number / 60000 ) ;
            if(rounding) iOut += parseInt((number % 60000)/30001) ;
            break ;
        case 's': case 'S':
            iOut = parseInt(number / 1000 ) ;
            if(rounding) iOut += parseInt((number % 1000)/501) ;
            break ;
        default:
        // If we get to here then the interval parameter
        // didn't meet the d,h,m,s criteria.  Handle
        // the error. 		
        alert(intervalMsg) ;
        return null ;
    }
    
    return iOut ;
}

function nowStr() {
var now=new Date()
var hours=now.getHours()
var minutes=now.getMinutes()
timeStr=""+((hours > 12) ? hours - 12 : hours)
timeStr+=((minutes < 10) ? ":0" : ":") + minutes
timeStr+=(hours >= 12) ? " PM" : " AM"
return timeStr
} 

function GetMonth(intMonth){
    var MonthArray = new Array("January", "February", "March",
                               "April", "May", "June",
                               "July", "August", "September",
                               "October", "November", "December") 
    return MonthArray[intMonth] 	  	 
    }


function todayStr() {
var today=new Date()

todayFix = today.getYear()
if(todayFix < 1000){
todayFix = todayFix + 1900
}
return today.getDate() + " " + GetMonth(today.getMonth()) + " " + (todayFix)
}

function presentDate1(dateToCheck,timeToCheck) {

origdateToCheck = dateToCheck;
origtimeToCheck = timeToCheck;
dateToCheckArray = dateToCheck.split("/")
dateToCheckMonth = GetMonth(parseInt(dateToCheckArray[0] - 1))
dateToCheckDay = dateToCheckArray[1]
dateToYear = dateToCheckArray[2]

var colPos = timeToCheck.indexOf(":");
 if (colPos == -1) {
 	timeToCheckArray = timeToCheck.split(" ")
 	timeToCheckTime = timeToCheckArray[0];
 	timeToCheckAMPM = timeToCheckArray[1];
 
	 timeToCheck = timeToCheckTime + ":00" + " " + timeToCheckAMPM;
 }

dateToCheck = dateToCheckArray[1] + " " + dateToCheckMonth + " " + dateToYear + " " + timeToCheck;

    var ierr = 1 ;
    
    todaysDate = todayStr()+ " " + nowStr()

	//alert(todaysDate)
	
   // Verify whether the user wants to return only whole
   // intervals or intervals rounded to the nearest number 
   // of interval.
   var roundDays = true; //f.chkWholeDays.checked ;
   
   // Verify that the user entered something in the
   // Start Date input box.
    if(todaysDate != '') {
        if(!isNaN(Date.parse(todaysDate))) {
            var s = new Date(Date.parse(todaysDate)) ;
            ierr = 0 ;
        }
    }
    
    // Verify that the user entered something in the
   // Ending Date input box.
    if(dateToCheck != '' && ierr != 1) {
        if(!isNaN(Date.parse(dateToCheck))) {
            var e = new Date(Date.parse(dateToCheck)) ;
            
            // call the dateDiff function.
            var temp = suycDateDiff(s,e,"h",roundDays) ;
        }else{
            ierr = 1;
        }
    }else{
        ierr = 1;
    }
    
    // update the tellTime field with our new value.
    if ( temp != null && ierr != 1 ){

    	if(temp > 36) {
		if (dateToCheckMonth == "January") {
		    window.location.href="appt-january.html?d=" + origdateToCheck + "&t=" + origtimeToCheck
	 	} else if (dateToCheckMonth == "February") {
		    window.location.href="appt-february.html?d=" + origdateToCheck + "&t=" + origtimeToCheck
		} else {
			window.location.href="book-appt.html?d=" + origdateToCheck + "&t=" + origtimeToCheck
		}
    	}else{
    		alert("Sessions must be booked 36 hours in advance.\n\nBookings for the session you have chosen are now closed.\n\nPlease choose a later date.")
    	}
    }
}

function presentDate(dateToCheck) {

//origdateToCheck = dateToCheck;
//origtimeToCheck = timeToCheck;

origdateToCheckArray = dateToCheck.split(",");
origdateToCheck = origdateToCheckArray[0];
origtimeToCheck = origdateToCheckArray[1];

dateToCheckArray = origdateToCheckArray[0].split("/")
dateToCheckMonth = GetMonth(parseInt(dateToCheckArray[0] - 1))
dateToCheckDay = dateToCheckArray[1]
dateToYear = dateToCheckArray[2]

var colPos = origtimeToCheck.indexOf(":");
 if (colPos == -1) {
 	timeToCheckArray = origtimeToCheck.split(" ")
 	timeToCheckTime = timeToCheckArray[0];
 	timeToCheckAMPM = timeToCheckArray[1];

	 timeToCheck = timeToCheckTime + ":00" + " " + timeToCheckAMPM;
 }

dateToCheck = dateToCheckArray[1] + " " + dateToCheckMonth + " " + dateToYear + " " + timeToCheck;

    var ierr = 1 ;
    
    todaysDate = todayStr()+ " " + nowStr()

	//alert(todaysDate)
	
   // Verify whether the user wants to return only whole
   // intervals or intervals rounded to the nearest number 
   // of interval.
   var roundDays = true; //f.chkWholeDays.checked ;
   
   // Verify that the user entered something in the
   // Start Date input box.
    if(todaysDate != '') {
        if(!isNaN(Date.parse(todaysDate))) {
            var s = new Date(Date.parse(todaysDate)) ;
            ierr = 0 ;
        }
    }

    // Verify that the user entered something in the
   // Ending Date input box.
    if(dateToCheck != '' && ierr != 1) {
        if(!isNaN(Date.parse(dateToCheck))) {
            var e = new Date(Date.parse(dateToCheck)) ;
            
            // call the dateDiff function.
            var temp = suycDateDiff(s,e,"h",roundDays) ;
        }else{
            ierr = 1;
        }
    }else{
        ierr = 1;
    }

    // update the tellTime field with our new value.
    if ( temp != null && ierr != 1 ){

    	if(temp > 36) {
		if (dateToCheckMonth == "January") {
		    window.location.href="appt-january.html?d=" + origdateToCheck + "&t=" + origtimeToCheck
	 		} else if (dateToCheckMonth == "February") {
		    window.location.href="appt-february.html?d=" + origdateToCheck + "&t=" + origtimeToCheck
			} else {
				window.location.href="book-appt.html?d=" + origdateToCheck + "," + origtimeToCheck
			}
    	}else{
    		alert("Sessions must be booked 36 hours in advance.\n\nBookings for the session you have chosen are now closed.\n\nPlease choose a later date.")
    	}
    }
}

