//??kr: 2009-02-04
//TODO: move the functions here to the common.js; probably to the Date object 
//the getmonth and getdayofweek are probably available but it is easier to implement it 
//rather than finding/figuring-out/modiyfing existing code in the available time

function gl_getMonth(dateTime){
	var month = "";
	switch(dateTime.getMonth())
	{
		case 0: 
			month="Jan";
			break;
		case 1: 
			month="Feb";
			break;
		case 2: 
			month="Mar";
			break;
		case 3: 
			month="Apr";
			break;
		case 4: 
			month="May";
			break;
		case 5: 
			month="Jun";
			break;
		case 6: 
			month="Jul";
			break;
		case 7: 
			month="Aug";
			break;
		case 8: 
			month="Sep";
			break;
		case 9: 
			month="Oct";
			break;
		case 10: 
			month="Nov";
			break;
		case 11: 
			month="Dec";
	}	
	return month;
}

function gl_getDayOfWeek(dateTime) {
	var day = "";
    switch (dateTime.getDay()) {
        case 0:
            day = "Sun";
            break;
        case 1:
            day = "Mon";
            break;
        case 2:
            day = "Tue";
            break;
        case 3:
            day = "Wed";
            break;
        case 4:
            day = "Thu";
            break;
        case 5:
            day = "Fri";
            break;
        case 6:
            day = "Sat";
            break;
    }
    return day;
}

//gl_getETTime() and gl_getETDate() should be parameterized to accept zone and format so that it can be used 
//as a util fn throughtout the code
//for now returns East coast time in the format "Wed Feb 11 | 1:48 pm ET" without the quotes
function gl_getETDate(serverTime)
{
	//offset for East coast time
    var offset = gl_getETOffset();
    var zone = "ET";
	
	var now = new Date();
	now.setTime(serverTime);

	//utc = current time + offset (the offset is mins so convert to millisec x60x1000)
	//add/sub the timezone to which we want to convert (convert hours to millisec x60x60x1000) 
	var newZoneTimeInMilliSec = now.getTime() + now.getTimezoneOffset() * 60000 + offset * 3600000;
	var newZoneTime = new Date(newZoneTimeInMilliSec);
	
	var dayOfWeek = newZoneTime.getDay();
	
	var dateString = gl_getDayOfWeek(newZoneTime) + ' ' + gl_getMonth(newZoneTime) + ' ' + newZoneTime.getDate();
    return dateString;
}


//gl_getETTime() should be parameterized to accept zone and format so that it can be used 
//as a util fn throughtout the code
//for now returns East coast time in the format "1:48 pm ET" without the quotes
function gl_getETTime(serverTime)
{

	//offset for East coast time
    var offset = gl_getETOffset();
  var zone = "ET";
	
	var now = new Date();
	now.setTime(serverTime);

	//utc = current time + offset (the offset is mins so convert to millisec x60x1000)
	//add/sub the timezone to which we want to convert (convert hours to millisec x60x60x1000) 
	var newZoneTimeInMilliSec = now.getTime() + now.getTimezoneOffset() * 60000 + offset * 3600000;
	var newZoneTime = new Date(newZoneTimeInMilliSec);
	
	var curHour = newZoneTime.getHours();
	var curMin = newZoneTime.getMinutes();
	var amPm = (curHour<12) ? "am" : "pm";
	
	//convert hour to 12hr clock-hour
	curHour = (curHour > 12) ? curHour - 12 : curHour;
	
	//convert 0hr to 12'o clock
	curHour = (curHour == 0) ? 12 : curHour;

	curMin = (curMin < 10) ? '0' + curMin : curMin;
	
	var timeString = curHour + ':' + curMin + ' ' + amPm + ' ' + zone;
	return timeString;
}

var etoffset = -5;
function gl_getETOffset() {
	return etoffset;
	/*
	var offset = -5;
	   var rightNow = new Date();
	   var date1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);
	   var date2 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0);
	   var temp = date1.toGMTString();
	   var date3 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	   var temp = date2.toGMTString();
	   var date4 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	   var hoursDiffStdTime = (date1 - date3) / (1000 * 60 * 60);
	   var hoursDiffDaylightTime = (date2 - date4) / (1000 * 60 * 60);
	   if (hoursDiffDaylightTime != hoursDiffStdTime) {
		   offset = -4;
	   }
	   return offset;
	   */
}