// Avinash Chopde, http://www.acoom.com/
// Some parts of code here are from:
//    The JavaScript Source!! http://javascript.internet.com
//    and http://www.pangea.ca/~kolar/javascript/clock.html
// -----------------------------------------------------------------------

function GetDateTimeStr(inttimemsec, yesnoaddtime){
  var mydate = new Date(inttimemsec);
  var myday = mydate.getDay();
  var mymonth = mydate.getMonth();
  var myweekday= mydate.getDate();
  var myyear= mydate.getYear();
  var year = myyear;

  if (year < 2000) year = year + 1900;

  myhours = mydate.getHours();
  if (myhours >= 12) {
    myhours = (myhours == 12) ? 12 : myhours - 12;
    mm = " PM";
  } else {
    myhours = (myhours == 0) ? 12 : myhours;
    mm = " AM";
  }

  myminutes = mydate.getMinutes();
  mytime = (myminutes < 10) ? ":0" + myminutes : ":" + myminutes;

  arday = new Array("Sunday","Monday","Tuesday","Wednesday",
		    "Thursday","Friday","Saturday");
  armonth = new Array("January ","February ","March ","April ",
		      "May ","June ","July ","August ","September ",
		      "October ","November ","December ");

  var tstr;
  if (yesnoaddtime != 0) {
      tstr =  "" + myhours + mytime + mm + ", " + arday[myday] +", " +
		 armonth[mymonth] +" "+myweekday + ", " + year;
  } else {
      tstr =  "" + arday[myday] + " " + myweekday + " " +
              armonth[mymonth] + " " + year;
  }
  return tstr;
}

// -----------------------------------------------------------------------
function GetBostonTime() {
  var newdate = new Date();
  var gmtmsec = newdate.getTime();

  var TimezoneOffset = 5;  // adjust for time zone, EST
  //var localTime = new Date('April 2, 2000 2:01:00'); // GMT

  var TZL = newdate.getTimezoneOffset(); // = what browser thinks is TZ; but
      // MS IE version 3 gives wrong sign of TZ
      // MSIE 4.0b2 shifts TZ by -1 hour
      // Any other problems?
      // from http://www.pangea.ca/~kolar/javascript/clock.html
  var msie = navigator.userAgent.indexOf("MSIE")
  if(msie > -1) {
    if(navigator.userAgent.substring(msie+5,msie+6) <= 3) TZL *= -1;
    else if(navigator.userAgent.indexOf("4.0b2") > -1) TZL += 60;
  }
  var stdmsec = newdate.getTime() + (TZL - TimezoneOffset*60) * 60000;
  var stddate = new Date(stdmsec);
  var M = stddate.getMonth();
  var D = stddate.getDay();
  var d = stddate.getDate();
  var H = stddate.getHours();

//    var str = "<P>Day: " + D + ", Date: " + d + ", Hours: " +
//	       H + ", Min: " + m + ", minSince: " +
//	       "<BR>" + "TZL " + TZL 
//	       + "<BR>";
//    document.write(str);//DEBUG

  var zone = -5;  // references your time zone, EST in Boston
  var dst = "Eastern Standard Time";
    // Daylight Saving starts first Sunday, April, 1AM EST
    // Daylight Saving ends last Sunday, October, 2AM EDT (1AM EST)
  if((M>3 && M<9) ||
     (M==3 && (d>7 || D==0 && H>0 || D>0 && d>D)) ||
     (M==9 && (d<25 || D==0 && d>24 && H<2 || D>0 && d<(D+25)))
    ) {
    zone = zone + 1 ;
    dst = "Eastern Daylight Saving Time";
  }

  var newtime = gmtmsec + (TZL + zone*60)*60*1000;

  return GetDateTimeStr(newtime, 1) + " (" + dst + " USA)";
} // GetBostonTime

// -----------------------------------------------------------------------
function GetIndiaTime() {
  var newdate = new Date();
  var localzone = newdate.getTimezoneOffset();
  var gmtmsec = newdate.getTime();

  var istzone = 330;  // references your time zone, IST is 5.5 hours ahead 

  istmsec = gmtmsec + (localzone + istzone)*60*1000;
  return GetDateTimeStr(istmsec, 1) + " (Indian Standard Time)";
} // GetIndiaTime
// -----------------------------------------------------------------------
function GetLocalTime() {
  var newdate = new Date();
  var gmtmsec = newdate.getTime();
  return GetDateTimeStr(gmtmsec, 1);
} // GetLocalTime
// -----------------------------------------------------------------------
function GetBostonDate() {
  var newdate = new Date();
  var gmtmsec = newdate.getTime();

  var TimezoneOffset = 5;  // adjust for time zone, EST
  //var localTime = new Date('April 2, 2000 2:01:00'); // GMT

  var TZL = newdate.getTimezoneOffset(); // = what browser thinks is TZ; but
      // MS IE version 3 gives wrong sign of TZ
      // MSIE 4.0b2 shifts TZ by -1 hour
      // Any other problems?
      // from http://www.pangea.ca/~kolar/javascript/clock.html
  var msie = navigator.userAgent.indexOf("MSIE")
  if(msie > -1) {
    if(navigator.userAgent.substring(msie+5,msie+6) <= 3) TZL *= -1;
    else if(navigator.userAgent.indexOf("4.0b2") > -1) TZL += 60;
  }
  var stdmsec = newdate.getTime() + (TZL - TimezoneOffset*60) * 60000;
  var stddate = new Date(stdmsec);
  var M = stddate.getMonth();
  var D = stddate.getDay();
  var d = stddate.getDate();
  var H = stddate.getHours();

//    var str = "<P>Day: " + D + ", Date: " + d + ", Hours: " +
//	       H + ", Min: " + m + ", minSince: " +
//	       "<BR>" + "TZL " + TZL 
//	       + "<BR>";
//    document.write(str);//DEBUG

  var zone = -5;  // references your time zone, EST in Boston
  var dst = "Eastern Standard Time";
    // Daylight Saving starts first Sunday, April, 1AM EST
    // Daylight Saving ends last Sunday, October, 2AM EDT (1AM EST)
  if((M>3 && M<9) ||
     (M==3 && (d>7 || D==0 && H>0 || D>0 && d>D)) ||
     (M==9 && (d<25 || D==0 && d>24 && H<2 || D>0 && d<(D+25)))
    ) {
    zone = zone + 1 ;
    dst = "Eastern Daylight Saving Time";
  }

  var newtime = gmtmsec + (TZL + zone*60)*60*1000;

  return GetDateTimeStr(newtime, 0);
} // GetBostonDate
// -----------------------------------------------------------------------
