

function isTime( InString)
    {
    //Returns true if value is in time format or is NULL
    //otherwise returns false   

    if ( InString.length == 0)
        return false;

    //Returns true if value is a date in the mm/dd/yyyy format
        isplit =  InString.indexOf(':');

        if (isplit == -1 || isplit ==  InString.length)
                return false;

    sHour =  InString.substring(0, isplit);
        iminute =  InString.indexOf(':', isplit + 1);

        if (iminute == -1 || iminute ==  InString.length)
                sMin =  InString.substring((sHour.length + 1));
        else
                sMin =  InString.substring((sHour.length + 1), iminute);

    if (!isInteger(sHour)) //check hour
                return false;
    else
    if (!isWithinRange(sHour, 0, 23)) //check hour
                return false;

        if (!isInteger(sMin)) //check minutes
                return false;
        else
        if (!isWithinRange(sMin, 0, 59)) // check minutes
                return false;

        // did they specify seconds
    if (iminute != -1)
        {
                sSec =  InString.substring(iminute + 1);

                if (!isInteger(sSec)) //check seconds
                        return false;
                else
                if (!isWithinRange(sSec, 0, 59)) //check seconds
                        return false;   
        }
    
    return true;
    }
    
    
function isDate(Date1)
    {
    //Returns true if value is a date format 
    //otherwise returns false  
     
    if (Date1.length == 0)
        return false;

   DELIMITER="/"    
   for (var i = 1; i <  Date1.length; i++)
     if (!isNumOrChar(Date1.charAt(i)))
      {
    	DELIMITER=Date1.charAt(i);
    	break;
      }

    //Returns true if value is a date in the mm/dd/yyyy format
        isplit = Date1.indexOf(DELIMITER);
     
        if (isplit == -1 || isplit == Date1.length)
                return false;

    if (isplit == 4)
    {
      // 1999/10/25
      sYear = Date1.substring(0, isplit);
      isplit = Date1.indexOf(DELIMITER, isplit + 1);
      if (isplit == -1 || (isplit + 1 ) == Date1.length)
                return false;

      sMonth = Date1.substring((sYear.length + 1), isplit);
      sDay = Date1.substring(isplit + 1);
    } else {
      // 10/25/1999
      sMonth = Date1.substring(0, isplit);
      isplit = Date1.indexOf(DELIMITER, isplit + 1);
      if (isplit == -1 || (isplit + 1 ) == Date1.length)
                return false;

      sDay = Date1.substring((sMonth.length + 1), isplit);
      sYear = Date1.substring(isplit + 1);
    }	
    
        if (!isInteger(sMonth)) //check month
                return false;
        else
        if (!isWithinRange(sMonth, 1, 12)) //check month
                return false;
        else
        if (!isInteger(sYear)) //check year
                return false;
        else
        if (!isWithinRange(sYear, 1900, 9999)) //check year
                return false;
        else
        if (!isInteger(sDay)) //check day
                return false;
        else
        if (!isDay(sYear, sMonth, sDay)) // check day
                return false;
        else
                return true;
    }
    
    
function isDay(checkYear, checkMonth, checkDay)
    {
       
       
        maxDay = 31;
        checkMonth = checkMonth - 0
        if (checkMonth == 4 || checkMonth == 6 ||
                        checkMonth == 9 || checkMonth == 11)
                maxDay = 30;
        else
        if (checkMonth == 2)
        {
                if (checkYear % 4 > 0)
                        maxDay =28;
                else
                if (checkYear % 100 == 0 && checkYear % 400 > 0)
                        maxDay = 28;
                else
                        maxDay = 29;
        }

        return isWithinRange(checkDay, 1, maxDay); //check day
    }
    
function DateDiff(Date1,Date2)
{

oDate1 = new Date(Date1)
oDate2 = new Date(Date2)

diff = oDate1.getTime() - oDate2.getTime()
var days = Math.floor(diff / (1000 * 60 * 60 * 24));

return diff
}

function GetDate( ShiftDay,Style )
{


nDate= new Date()
theYear = nDate.getYear()
theYear += (theYear < 1900) ? 1900: 0
if (ShiftDate !=0)
{
var oneMinute = 60 * 1000
var oneHour = oneMinute * 60
var oneDay = oneHour * 24
//var oneWeek = oneDay * 7
var TargetDate= oneDay * ShiftDay
  dateInMs = nDate.getTime()
  dateInMs += TargetDate
  nDate.setTime( dateInMs)
}
if (Style == 2)
  return theYear + "/" + (nDate.getMonth()+1) + "/" + nDate.getDate()
else
  return (nDate.getMonth()+1) + "/" + nDate.getDate() + "/" + theYear
}

function GetTime(ShiftMin,Style) {

var now = new Date();
if (ShiftMin !=0)
{
  var oneMinute = 60 * 1000
  var TargetMin= oneMinute * ShiftMin
  dateInMs = now.getTime()
  dateInMs += TargetMin
  now.setTime( dateInMs)
}

var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
if (Style == 2)
{
  var timeValue = "" + ((hours >12) ? hours -12 :hours)
  if (timeValue == "0") timeValue = 12;
} else
  var timeValue = "" + hours

timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
if (Style == 2)
   timeValue += (hours >= 12) ? " P.M." : " A.M."

return timeValue;

}

function MakeArray(n) {
	this.length = n
	return this
}

monthNames = new MakeArray(12)
monthNames[1] = "January"
monthNames[2] = "February"
monthNames[3] = "March"
monthNames[4] = "April"
monthNames[5] = "May"
monthNames[6] = "June"
monthNames[7] = "July"
monthNames[8] = "August"
monthNames[9] = "September"
monthNames[10] = "October"
monthNames[11] = "November"
monthNames[12] = "December"

dayNames = new MakeArray(7)
dayNames[1] = "Sunday"
dayNames[2] = "Monday"
dayNames[3] = "Tuesday"
dayNames[4] = "Wednesday"
dayNames[5] = "Thursday"
dayNames[6] = "Friday"
dayNames[7] = "Saturday"

function customDateString(oneDate) {
	var theDay = dayNames[oneDate.getDay() + 1]
	var theMonth = monthNames[oneDate.getMonth() + 1]
        var theYear = oneDate.getYear()
        theYear += (theYear < 1900) ? 1900: 0
	return theDay + ", " + theMonth + " " + oneDate.getDate() + ", " + theYear
}

function dayPart(oneDate) {
	var theHour = oneDate.getHours()
	if (theHour <6 )
		return "wee hours"
	if (theHour < 12)
		return "morning"
	if (theHour < 18)
		return "afternoon"
	return "evening"
}