/****************************************************************************   
Java Scripts used for formatting and displaying the dates according to user's
local system format. This file is included in the branding jsp files so this 
file would be available throughout the portal.
***************************************************************************/


/* Function to display time in local format. */
function displayLocalTime(milliSecs, includeTime, onlyTime) {
	var dateStr;
	dateStr = formatDateInStr(milliSecs, includeTime, onlyTime);
	document.write(dateStr); 
} 
	 
/* Function to format date in local format. This function calculates the timezone offset
	and adjust the same with the acutal date. This ensures that dates would be displayed 
	same all acorss the globe. */	 
function formatDateInStr(milliSecs, includeTime, onlyTime) {
	 var displayDate = new Date();
	 var convertedTime; 
	 var dateLocaleStr; 
		 var offset = displayDate.getTimezoneOffset() * 60 * 1000; 
		 convertedTime = eval(milliSecs) + eval(offset); 
		 displayDate.setTime(convertedTime); 
		 if(!onlyTime){ 
		 	if(includeTime){ 
				 dateLocaleStr = displayDate.toLocaleString(); 
			 }else{ 
	 			 dateLocaleStr = displayDate.toLocaleDateString(); 
		 	 } 
		 }else{ 
	 		dateLocaleStr = displayDate.toLocaleTimeString(); 
		 } 
	 var index = dateLocaleStr.lastIndexOf(":"); 
	 if(index > 0) { 
	 	var subStr = dateLocaleStr.substring(index).substring(3); 
	 	dateLocaleStr = dateLocaleStr.substring(0,index)+subStr; 
	 } 
	 return dateLocaleStr;
}	 