﻿// Javascript by Joel Grossman

function convertToWords(value) {
	var tempStore = parseInt(value);
	var weeks = tempStore;
	var years = tempStore;
	
	var one_day = 1000*60*60*24;
	var one_week = one_day * 7;
	var one_year = one_day * 365;
	var years_string = "";
	var weeks_string = "";
	var days_string = "";
	var hours_string = "";
	var minutes_string = "";
	var seconds_string = "";


	years = Math.floor(tempStore/one_year);
	if (years = 1) {
		years_string = years.toString() + " year, ";
		tempStore = tempStore - years*one_year;
	} else if (years >= 2) {
		years_string = years.toString() + " years, ";
		tempStore = tempStore - years*one_year;
	}

	weeks = Math.floor(tempStore/one_week);
	if (weeks >= 2) {
		weeks_string = weeks.toString() + " weeks, ";
		tempStore = tempStore - weeks*one_week;
	}
	
	var days = Math.floor(tempStore/one_day);
	if (days == 1) {
		days_string = days.toString() + " day, ";
		tempStore = tempStore - days*one_day;
		} else {
		days_string = days.toString() + " days, ";
		tempStore = tempStore - days*one_day;
		}
		
	var	hours = Math.floor(tempStore/(1000*60*60));
	if (hours == 1 ) {
		hours_string = hours.toString() + " hour, ";
		tempStore = tempStore - hours*(1000*60*60);
		} else {
		hours_string = hours.toString() + " hours, ";
		tempStore = tempStore - hours*(1000*60*60);
		}
		
	var minutes = Math.floor(tempStore/(1000*60));
	if (minutes == 1) {
	minutes_string = minutes.toString() + " minute, ";
	tempStore = tempStore - minutes*(1000*60);
	} else {
	minutes_string = minutes.toString() + " minutes, ";
	tempStore = tempStore - minutes*(1000*60);
	}
	
	var seconds = Math.floor(tempStore/(1000));
	if (seconds == 1) {
	seconds_string = seconds.toString() + " second";
	} else {
	seconds_string = seconds.toString() + " seconds";
	}

//	var inWords = weeks_string + days_string + hours_string + minutes_string + seconds_string;
//	alert("convert_milliseconds_to_string has run");
	return years_string + weeks_string + days_string + hours_string + minutes_string + seconds_string;
;
}