/***
 * date_modified.js
 * Checks current date and compares it to article last modified date.
 * If the difference is <= 5 hours, returns red date text, otherwise
 * it returns normal formatted modified date.
 **/

function writeModDate(mod_date) {
	/*
	// get uploaded day and time
	var uploaded_date = new Array();
	uploaded_date = up_date.split(" ");
	var uploaded_date_month = findMonth(uploaded_date[0]);
	var uploaded_date_day = parseInt(uploaded_date[1].substring(0,uploaded_date[1].indexOf(",")));
	var uploaded_date_year = parseInt(uploaded_date[2]);
	var uploaded_date_hour = parseInt(uploaded_date[3].substring(0,uploaded_date[3].indexOf(":")));
	if ((uploaded_date[4] == "p.m.") && (uploaded_date_hour != 12)) {
		uploaded_date_hour += 12;
	}
	var uploaded_date_minutes = parseInt(uploaded_date[3].substring(uploaded_date[3].indexOf(":")+1));
	var uploaded_date_time = new Date(uploaded_date_year, uploaded_date_month, uploaded_date_day, uploaded_date_hour, uploaded_date_minutes, 0);
	uploaded_date_time.setFullYear(uploaded_date_year, uploaded_date_month, uploaded_date_day);
	uploaded_date_time.setHours(uploaded_date_hour);
	uploaded_date_time.setMinutes(uploaded_date_minutes);
	uploaded_date_time.setSeconds(0);
	var uploaded_date_time_total = uploaded_date_time.getTime();
	// alert("uploaded_date_time_total = "+uploaded_date_time_total);
	*/
	
	var current_date = new Date();
	var current_date_time = current_date.getTime();
	
	// now we will parse the inputted modified date
	var modified_date = new Array();
	modified_date = mod_date.split(" ");
	var modified_date_month = findMonth(modified_date[0]);
	var modified_date_day = parseInt(modified_date[1].substring(0,modified_date[1].indexOf(",")));
	var modified_date_year = parseInt(modified_date[2]);
	if (modified_date[3].indexOf(":") == -1) {
		if (modified_date[3] == "midnight")
			var modified_date_hour = 0;
		else if (modified_date[3] == "noon")
			var modified_date_hour = 12;
		else
			var modified_date_hour = parseInt(modified_date[3]);

		var modified_date_minutes = 0;
	}
	else {
		var modified_date_hour = parseInt(modified_date[3].substring(0,modified_date[3].indexOf(":")));
		var modified_date_minutes = parseInt(modified_date[3].substring(modified_date[3].indexOf(":")+1));
	}
	if ((modified_date[4] == "p.m.") && (modified_date_hour != 12)) {
		modified_date_hour += 12;
	}
	
	if ((modified_date[4] == "a.m.") && (modified_date_hour == 12)) {
		modified_date_hour = 0;
	}

	var modified_date_time = new Date(modified_date_year, modified_date_month, modified_date_day, modified_date_hour, modified_date_minutes, 0);
	modified_date_time.setFullYear(modified_date_year, modified_date_month, modified_date_day);
	modified_date_time.setHours(modified_date_hour);
	modified_date_time.setMinutes(modified_date_minutes);
	modified_date_time.setSeconds(0);
	var modified_date_time_total = modified_date_time.getTime();
	
	// alert("modified_date_time_total = "+modified_date_time_total);
	
	// now we will compare the current date vars
	// with the modified date array (passed into array
	// so we can parse the ints)
	// alert(modified_date_time_total - uploaded_date_time_total);
	if (current_date_time - modified_date_time_total <= 18000000) {
		return '<span style="color:#cc0000;">Updated: '+mod_date+'</span>';
	}
	else {
		return 'Updated: ' + mod_date;
	}
}

function findMonth(s) {
	switch (s) {
		case "Jan.": return 0;  break;
		case "Feb.": return 1;  break;
		case "March": return 2;  break;
		case "April": return 3;  break;
		case "May":  return 4;  break;
		case "June": return 5;  break;
		case "July": return 6;  break;
		case "Aug.": return 7;  break;
		case "Sept.": return 8;  break;
		case "Oct.": return 9;  break;
		case "Nov.": return 10; break;
		case "Dec.": return 11; break;
		default:     return 0;  break;
	}
}