// JavaScript Document
var g_SentenceDate;
var g_OtherDate;
var DaysMonthsYears;
var Days;
var MonthsDays;
var YearsMonthsDays;
var count;

function PreLoadVariables()
{
	g_SentenceDate = new Array(3); // month, day, year
	g_OtherDate = new Date();
	DaysMonthsYears = new Array(3);
	Days = 0;
	MonthsDays = new Array(2);
	YearsMonthsDays = new Array(3);
	count = 2;
	
	document.getElementById('dateOfActionB').checked = true;
	document.getElementById('dateOfActionO').checked = false;
	
	document.getElementById('otherMonth').disabled = true;
	document.getElementById('otherDay').disabled = true;
	document.getElementById('otherYear').disabled = true;
	
	document.getElementById('state').checked = true;
	document.getElementById('elpaso').checked = false;
	document.getElementById('teller').checked = false;
	document.getElementById('any').checked = false;
	document.getElementById('federal').checked = false;
	
	document.getElementById('misd').checked = true;
	document.getElementById('felony').checked = false;
	document.getElementById('felonyFirst').checked = false;
}

function TurnOthersOff(excluded)
{
	if(excluded < 5)
	{
		if(excluded != 0) document.getElementById('state').checked = false;
		if(excluded != 1) document.getElementById('elpaso').checked = false;
		if(excluded != 2) document.getElementById('teller').checked = false;
		if(excluded != 3) document.getElementById('any').checked = false;
		if(excluded != 4) document.getElementById('federal').checked = false;
	}
	else
	{
		if(excluded != 5) document.getElementById('misd').checked = false;
		if(excluded != 6) document.getElementById('felony').checked = false;
		if(excluded != 7) document.getElementById('felonyFirst').checked = false;
	}
}

function SwitchSelected(id, value)
{
	// 0: state; 1: elpaso; 2: teller; 3: any; 4: federal; 5: misd; 6: felony; 7: felonyFirst
	if(id == 0) document.getElementById('state').checked = value;
	if(id == 1) document.getElementById('elpaso').checked = value;
	if(id == 2) document.getElementById('teller').checked = value;
	if(id == 3) document.getElementById('any').checked = value;
	if(id == 4) document.getElementById('federal').checked = value;
	if(id == 5) document.getElementById('misd').checked = value;
	if(id == 6) document.getElementById('felony').checked = value;
	if(id == 7) document.getElementById('felonyFirst').checked = value;
	
	TurnOthersOff(id);
}

function GetItemSelectedQ1()
{
	var g_State = document.getElementById('state').checked;
	var g_Elpaso = document.getElementById('elpaso').checked;
	var g_Teller = document.getElementById('teller').checked;
	var g_Any = document.getElementById('any').checked;
	var g_Federal = document.getElementById('federal').checked;
	
	if(g_State == true) return 'state';
	if(g_Elpaso == true) return 'elpaso';
	if(g_Teller == true) return 'teller';
	if(g_Any == true) return 'any';
	if(g_Federal == true) return 'federal';
}

function GetItemSelectedQ2()
{
	var g_Misd = document.getElementById('misd').checked;
	var g_Felony = document.getElementById('felony').checked;
	var g_FelonyFirst = document.getElementById('felonyFirst').checked;
	
	if(g_Misd == true) return 'misd';
	if(g_Felony == true) return 'felony';
	if(g_FelonyFirst == true) return 'felonyFirst';
}

function CalculateResults()
{
	var q1Answer = GetItemSelectedQ1();
	var q2Answer = GetItemSelectedQ2();
	
	var g_DaysElapsed = document.getElementById('daysElapsed').value;
	var g_MonthsElapsed = document.getElementById('monthsElapsed').value;
	var g_YearsElapsed = document.getElementById('yearsElapsed').value;
	
	var results = "";
	
	if(q1Answer == 'any') results = "<ul><li>This list will not apply to your case.</ul>";
	
	else if(g_DaysElapsed <= 30 && (q1Answer == 'elpaso' || q1Answer == 'teller')) results = "<ul><li>Here's what you can do:<li>Appeal the Conviction to the District Court or Supreme Court<li>Request Sentence Reconsideration<li>Attack the conviction in the trial court<ul><li>for constitutional error<li>for an illegal sentence</ul><li>Modify your Deferred Sentence<li>Modify your Probation<li>Transfer Probation to another state</ul>";
	
	else if(g_DaysElapsed <= 45 && q1Answer == 'state') results = "<ul><li>Appeal the Conviction to the Court of Appeals or the Supreme Court<li>Appeal the Sentence to the Court of Appeals or the Supreme Court<li>Request Sentence Reconsideration<li>Attack the conviction in the trial court<ul><li>for constitutional error<li>for an illegal sentence</ul><li>Modify your Deferred Sentence<li>Modify your Probation<li>Transfer Probation to another state</ul>";
	
	else if(g_DaysElapsed <= 120) results = "<ul><li>Request Sentence Reconsideration<li>Attack the conviction in the trial court<ul><li>for constitutional error<li>for an illegal sentence</ul><li>Modify your Deferred Sentence<li>Modify your Probation<li>Transfer Probation to another state</ul>";
	
	else if(g_MonthsElapsed <= 18 && q2Answer == 'misd') results = "<ul><li>Attack the conviction in the trial court<ul><li>for constitutional error<li>for an illegal sentence</ul><li>Modify your Deferred Sentence<li>Modify your Probation<li>Transfer Probation to another state</ul>";
	
	else if(g_YearsElapsed <= 3 && q2Answer == 'felony') results = "<ul><li>Attack the conviction in the trial court<ul><li>for constitutional error<li>for an illegal sentence</ul><li>Modify your Deferred Sentence<li>Modify your Probation<li>Transfer Probation to another state</ul>";
	
	else if(g_YearsElapsed > 3 && q2Answer == 'felonyFirst') results = "<ul><li>Attack the conviction in the trial court<ul><li>for constitutional error<li>for an illegal sentence</ul></ul>";
	
	else if(g_YearsElapsed > 3 && (q2Answer == 'misd' || q2Answer == 'felony')) results = "<ul><li>Some Relief is available without a time limit:<li>Attack the conviction in the trial court<ul><li>for an illegal sentence<li>Motion for other relief out-of-time</ul></ul>";
	
	document.getElementById('title').innerHTML = 'Results Page';
	document.getElementById('divPage').innerHTML = 'This list includes many of the actions I can take on your behalf.  The list is likely not complete.  Once in a long while, I learn of a new or different approach.  I then add it to my arsenal.  Here is what the information you provided suggests is possible:<br><br>' + results + 'If you have already taken the "case posture" test, go to the contact page, or call us. If you have not taken the "case posture" test, go there now.<br><br><table cellpadding="0" cellspacing="0" border="2" bgcolor="#999999"><tr><td>The results are not definite and only an indicator of likely options available to you.<br><ul><li>Some actions, including a motion for a new trial, must be filed days after the <b>verdict</b> or finding of guilt.  That is often before sentencing and you should discuss that with your trial counsel.<li>If any of the deadlines are past, you can still take some action.<li>But, you should call me as soon as possible.<li>There may be a way around, over, or through the rules that are blocking you.</ul></td></tr></table>';	
}

function DisplayTime()
{
	document.getElementById('space').innerHTML = "<b>Time Elapsed:</b><br>" + Days + " Days<br>" + MonthsDays[0] + " Months, " + MonthsDays[1] + " Days<br>" + YearsMonthsDays[0] + " Years, " + YearsMonthsDays[1] + " Months, " + YearsMonthsDays[2] + " Days";
	//document.getElementById('space').innerHTML = "Months: " + DaysMonthsYears[1] + "<br>Days: " + DaysMonthsYears[0] + "<br>Years: " + DaysMonthsYears[2];	
}

function SetOtherAvailability(disabled)
{
	if(disabled == true)
	{
		document.getElementById('otherMonth').disabled = true;
		document.getElementById('otherDay').disabled = true;
		document.getElementById('otherYear').disabled = true;
	}
	else
	{
		document.getElementById('otherMonth').disabled = false;
		document.getElementById('otherDay').disabled = false;
		document.getElementById('otherYear').disabled = false;
	}
}

function GetSentencingDate(useOtherDate)
{
	g_SentenceDate[0] = document.getElementById('sentenceMonth').value;
	g_SentenceDate[1] = document.getElementById('sentenceDay').value;
	g_SentenceDate[2] = document.getElementById('sentenceYear').value;

	if(useOtherDate == true)
	{
		var g_OtherMonth = document.getElementById('otherMonth').value;
		var g_OtherDay = document.getElementById('otherDay').value;
		var g_OtherYear = document.getElementById('otherYear').value;

		g_OtherDate.setFullYear(g_OtherYear, g_OtherMonth - 1, g_OtherDay);
		g_OtherDate.setMilliseconds(0);
		g_OtherDate.setSeconds(0);
		g_OtherDate.setMinutes(0);
		g_OtherDate.setHours(0);
	}
}
	
function CalculateOtherDate()
{
	var gSD = new Date();
	gSD.setFullYear(g_SentenceDate[2], g_SentenceDate[0]-1, g_SentenceDate[1]);
	var timeElapsed = g_OtherDate.getTime() - gSD.getTime();
	var newDateTime = new Date();
	newDateTime.setTime(timeElapsed);
	var tmpTime = newDateTime;
	var secTime = gSD;
	var daysElapsed = 0;
	var monthsElapsed = 0;
	var yearsElapsed = 0;
		
	var dayOfMonth = tmpTime.getDate();
	var month = tmpTime.getMonth();
	var year = tmpTime.getFullYear() - 1970;
			
	if(year == 0)
	{
		yearsElapsed = 0;
		daysElapsed = GetDayOfYear(tmpTime)[0];
		monthsElapsed = GetDayOfYear(tmpTime)[1];
	}
	else
	{
		yearsElapsed = year;
		for(var i = -1; i < year; i++)
		{
			if(i == -1)
			{
				daysElapsed += GetDayOfYear(tmpTime)[0];
				monthsElapsed += GetDayOfYear(tmpTime)[1];
			}
			else
			{
				if(secTime.getFullYear() % 4 == 0)
				{
					daysElapsed += 366;
				}
				else
				{
					daysElapsed += 365;
				}
				monthsElapsed += 12;
			}
			tmpTime.setFullYear(tmpTime.getFullYear()-1, month, dayOfMonth);
			secTime.setFullYear(secTime.getFullYear()+1, secTime.getMonth(), secTime.getDate());
		}
	}
		
	DaysMonthsYears[0] = daysElapsed;
	DaysMonthsYears[1] = monthsElapsed;
	DaysMonthsYears[2] = yearsElapsed;
}

function _CalculateOtherDate(otherTime)
{
	var gSD = new Date();
	gSD.setFullYear(g_SentenceDate[2], g_SentenceDate[0]-1, g_SentenceDate[1]);
	var timeElapsed = otherTime.getTime() - gSD;
	var newDateTime = new Date();
	newDateTime.setTime(timeElapsed);
	var tmpTime = newDateTime;
	var secTime = gSD;
	var daysElapsed = 0;
	var monthsElapsed = 0;
	var yearsElapsed = 0;
		
	var dayOfMonth = tmpTime.getDate();
	var month = tmpTime.getMonth();
	var year = tmpTime.getFullYear() - 1970;
			
	if(year == 0)
	{
		yearsElapsed = 0;
		daysElapsed = GetDayOfYear(tmpTime)[0];
		monthsElapsed = GetDayOfYear(tmpTime)[1];
	}
	else
	{
		yearsElapsed = year;
		for(var i = -1; i < year; i++)
		{
			if(i == -1)
			{
				daysElapsed += GetDayOfYear(tmpTime)[0];
				monthsElapsed += GetDayOfYear(tmpTime)[1];
			}
			else
			{
				if(secTime.getFullYear() % 4 == 0)
				{
					daysElapsed += 366;
				}
				else
				{
					daysElapsed += 365;
				}
				monthsElapsed += 12;
			}
			tmpTime.setFullYear(tmpTime.getFullYear()-1, month, dayOfMonth);
			secTime.setFullYear(secTime.getFullYear()+1, secTime.getMonth(), secTime.getDate());
		}
	}
	
	var dmy = new Array(3);
	dmy[0] = daysElapsed;
	dmy[1] = monthsElapsed;
	dmy[2] = yearsElapsed;
	
	return dmy;
}

function CalculateNextBusinessDay()
{
	var dayOfWeek = new Date();
	dayOfWeek.setMilliseconds(0);
	dayOfWeek.setHours(0);
	dayOfWeek.setMinutes(0);
	dayOfWeek.setSeconds(0);
	var arrayOfTime = _CalculateOtherDate(dayOfWeek);
	
	DaysMonthsYears[0] = arrayOfTime[0];
	DaysMonthsYears[1] = arrayOfTime[1];
	DaysMonthsYears[2] = arrayOfTime[2];
	g_OtherDate = dayOfWeek;
}

function _GetDayOfYear(month, day, year)
{
	var month = month-1;
	var dayOfMonth = day;
	var isLeapYear = (year % 4 == 0);
	var dayOfYear = new Array(2);
	dayOfYear[0] = 0;
	dayOfYear[1] = 0;
		
	if(month == 0)
	{
		dayOfYear[0] = dayOfMonth;
		dayOfYear[1] = 0;
	}
	else if(month == 1)
	{
		dayOfYear[0] += 31; // Count days in January
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 1;
	}
	else if(month == 2)
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 2;
	}
	else if(month == 3)
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] +=  31; // Count for days in March
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 3;
	}
	else if(month == 4)
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] +=  31; // Count for days in March
		dayOfYear[0] += 30; // Count for days in April
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 4;
	}
	else if(month == 5)
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] +=  31; // Count for days in March
		dayOfYear[0] += 30; // Count for days in April
		dayOfYear[0] += 31; // Count for days in May
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 5;
	}
	else if(month == 6)
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] +=  31; // Count for days in March
		dayOfYear[0] += 30; // Count for days in April
		dayOfYear[0] += 31; // Count for days in May
		dayOfYear[0] += 30; // Count for days in June
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 6;
	}
	else if(month == 7)
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] +=  31; // Count for days in March
		dayOfYear[0] += 30; // Count for days in April
		dayOfYear[0] += 31; // Count for days in May
		dayOfYear[0] += 30; // Count for days in June
		dayOfYear[0] += 31; // Count for days in July
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 7;
	}
	else if(month == 8)
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] +=  31; // Count for days in March
		dayOfYear[0] += 30; // Count for days in April
		dayOfYear[0] += 31; // Count for days in May
		dayOfYear[0] += 30; // Count for days in June
		dayOfYear[0] += 31; // Count for days in July
		dayOfYear[0] += 31; // Count for days in August
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 8;
	}
	else if(month == 9)
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] +=  31; // Count for days in March
		dayOfYear[0] += 30; // Count for days in April
		dayOfYear[0] += 31; // Count for days in May
		dayOfYear[0] += 30; // Count for days in June
		dayOfYear[0] += 31; // Count for days in July
		dayOfYear[0] += 31; // Count for days in August
		dayOfYear[0] += 30; // Count for days in September
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 9;
	}
	else if(month == 10)
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] +=  31; // Count for days in March
		dayOfYear[0] += 30; // Count for days in April
		dayOfYear[0] += 31; // Count for days in May
		dayOfYear[0] += 30; // Count for days in June
		dayOfYear[0] += 31; // Count for days in July
		dayOfYear[0] += 31; // Count for days in August
		dayOfYear[0] += 30; // Count for days in September
		dayOfYear[0] += 31; // Count for days in October
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 10;
	}
	else
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] +=  31; // Count for days in March
		dayOfYear[0] += 30; // Count for days in April
		dayOfYear[0] += 31; // Count for days in May
		dayOfYear[0] += 30; // Count for days in June
		dayOfYear[0] += 31; // Count for days in July
		dayOfYear[0] += 31; // Count for days in August
		dayOfYear[0] += 30; // Count for days in September
		dayOfYear[0] += 31; // Count for days in October
		dayOfYear[0] += 30; // Count for days in November
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 11;
	}
		
	return dayOfYear;
}

function GetDayOfYear(DateObject)
{
	var month = DateObject.getMonth();
	var dayOfMonth = DateObject.getDate();
	var isLeapYear = (DateObject.getFullYear() % 4 == 0);
	var dayOfYear = new Array(2);
	dayOfYear[0] = 0;
	dayOfYear[1] = 0;
		
	if(month == 0)
	{
		dayOfYear[0] = dayOfMonth;
		dayOfYear[1] = 0;
	}
	else if(month == 1)
	{
		dayOfYear[0] += 31; // Count days in January
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 1;
	}
	else if(month == 2)
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 2;
	}
	else if(month == 3)
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] +=  31; // Count for days in March
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 3;
	}
	else if(month == 4)
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] +=  31; // Count for days in March
		dayOfYear[0] += 30; // Count for days in April
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 4;
	}
	else if(month == 5)
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] +=  31; // Count for days in March
		dayOfYear[0] += 30; // Count for days in April
		dayOfYear[0] += 31; // Count for days in May
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 5;
	}
	else if(month == 6)
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] +=  31; // Count for days in March
		dayOfYear[0] += 30; // Count for days in April
		dayOfYear[0] += 31; // Count for days in May
		dayOfYear[0] += 30; // Count for days in June
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 6;
	}
	else if(month == 7)
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] +=  31; // Count for days in March
		dayOfYear[0] += 30; // Count for days in April
		dayOfYear[0] += 31; // Count for days in May
		dayOfYear[0] += 30; // Count for days in June
		dayOfYear[0] += 31; // Count for days in July
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 7;
	}
	else if(month == 8)
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] +=  31; // Count for days in March
		dayOfYear[0] += 30; // Count for days in April
		dayOfYear[0] += 31; // Count for days in May
		dayOfYear[0] += 30; // Count for days in June
		dayOfYear[0] += 31; // Count for days in July
		dayOfYear[0] += 31; // Count for days in August
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 8;
	}
	else if(month == 9)
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] +=  31; // Count for days in March
		dayOfYear[0] += 30; // Count for days in April
		dayOfYear[0] += 31; // Count for days in May
		dayOfYear[0] += 30; // Count for days in June
		dayOfYear[0] += 31; // Count for days in July
		dayOfYear[0] += 31; // Count for days in August
		dayOfYear[0] += 30; // Count for days in September
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 9;
	}
	else if(month == 10)
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] +=  31; // Count for days in March
		dayOfYear[0] += 30; // Count for days in April
		dayOfYear[0] += 31; // Count for days in May
		dayOfYear[0] += 30; // Count for days in June
		dayOfYear[0] += 31; // Count for days in July
		dayOfYear[0] += 31; // Count for days in August
		dayOfYear[0] += 30; // Count for days in September
		dayOfYear[0] += 31; // Count for days in October
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 10;
	}
	else
	{
		dayOfYear[0] += 31; // Count days in January
		// Count for February
		if(isLeapYear == true)
		{
			dayOfYear[0] += 29;
		}
		else
		{
			dayOfYear[0] += 28;
		}
		dayOfYear[0] +=  31; // Count for days in March
		dayOfYear[0] += 30; // Count for days in April
		dayOfYear[0] += 31; // Count for days in May
		dayOfYear[0] += 30; // Count for days in June
		dayOfYear[0] += 31; // Count for days in July
		dayOfYear[0] += 31; // Count for days in August
		dayOfYear[0] += 30; // Count for days in September
		dayOfYear[0] += 31; // Count for days in October
		dayOfYear[0] += 30; // Count for days in November
		dayOfYear[0] += dayOfMonth;
		dayOfYear[1] = 11;
	}
		
	return dayOfYear;
}

function GenerateProperTime(type)
{
	if(type == 'businessDay')
		CalculateNextBusinessDay();
	else if(type == 'otherDate')
		CalculateOtherDate();
	
	var totalDaysElapsed = DaysMonthsYears[0];
	var totalMonthsElapsed = DaysMonthsYears[1];
	var totalYearsElapsed = DaysMonthsYears[2];
	
	/*// Calculate Months, Days	
	for(var i = 0; i < totalMonthsElapsed; i++)
	{
		var nMonth = monthDayDate.getMonth()+i+1;
		var nYear = monthDayDate.getFullYear();
		var nDay = monthDayDate.getDate();
		if(nMonth > 12)
		{
			nMonth = 1;
			nYear++;
		}
		
		monthDayDate.setFullYear(nYear, nMonth-1, nDay);
	}
	var newDay = monthDayDate.getDate() - g_OtherDate.getDate();
	if(newDay < 0) newDay = g_OtherDate.getDate() - monthDayDate.getDate();
	// Validate the newDay variable
	if(monthDayDate.getMonth() == 0 && newDay > 31) // January
	{
		monthDayDate.setMonth(1);
		monthDayDate.setDate(newDay - 31);
		totalMonthsElapsed++;
	}
	else if(monthDayDate.getMonth() == 1 && monthDayDate.getFullYear() % 4 == 0 && newDay > 29) // February Leap Year
	{
		monthDayDate.setMonth(2);
		monthDayDate.setDate(newDay - 29);
		totalMonthsElapsed++;
	}
	else if(monthDayDate.getMonth() == 1 && newDay > 28) // Regular February
	{
		monthDayDate.setMonth(2);
		monthDayDate.setDate(newDay - 28);
		totalMonthsElapsed++;
	}
	else if(monthDayDate.getMonth() == 2 && newDay > 31) // March
	{
		monthDayDate.setMonth(3);
		monthDayDate.setDate(newDay - 31);
		totalMonthsElapsed++;
	}
	else if(monthDayDate.getMonth() == 3 && newDay > 30) // April
	{
		monthDayDate.setMonth(4);
		monthDayDate.setDate(newDay - 30);
		totalMonthsElapsed++;
	}
	else if(monthDayDate.getMonth() == 4 && newDay > 31) // May
	{
		monthDayDate.setMonth(5);
		monthDayDate.setDate(newDay - 31);
		totalMonthsElapsed++;
	}
	else if(monthDayDate.getMonth() == 5 && newDay > 30) // June
	{
		monthDayDate.setMonth(6);
		monthDayDate.setDate(newDay - 30);
		totalMonthsElapsed++;
	}
	else if(monthDayDate.getMonth() == 6 && newDay > 31) // July
	{
		monthDayDate.setMonth(7);
		monthDayDate.setDate(newDay - 31);
		totalMonthsElapsed++;
	}
	else if(monthDayDate.getMonth() == 7 && newDay > 31) // August
	{
		monthDayDate.setMonth(8);
		monthDayDate.setDate(newDay - 31);
		totalMonthsElapsed++;
	}
	else if(monthDayDate.getMonth() == 8 && newDay > 30) // September
	{
		monthDayDate.setMonth(9);
		monthDayDate.setDate(newDay - 30);
		totalMonthsElapsed++;
	}
	else if(monthDayDate.getMonth() == 9 && newDay > 31) // October
	{
		monthDayDate.setMonth(10);
		monthDayDate.setDate(newDay - 31);
		totalMonthsElapsed++;
	}
	else if(monthDayDate.getMonth() == 10 && newDay > 30) // November
	{
		monthDayDate.setMonth(11);
		monthDayDate.setDate(newDay - 30);
		totalMonthsElapsed++;
	}
	else if(monthDayDate.getMonth() == 11 && newDay > 31) // December
	{
		monthDayDate.setFullYear(monthDayDate.getFullYear()+1, 0, newDay - 31);
		totalMonthsElapsed++;
		totalYearsElapsed++;
	}
	else
	{
		monthDayDate.setDate(newDay);	
	}	
	
	//if(monthDayDate.getDate() == 31) totalMonthsElapsed--;
	
	// Set Time Variables*/
	Days = totalDaysElapsed+1;
	/*MonthsDays[0] = totalMonthsElapsed;
	if(newDay == 0) { MonthsDays[1] = 0; }
	else { MonthsDays[1] = monthDayDate.getDate(); }*/
	
	GetTimeAfterDate(g_OtherDate);
}

function GetTimeAfterDate(dateObj)
{
	// [0]->Years, [1]->Months, [2]->Days
	var gSD = new Date();
	var oMonth = document.getElementById('sentenceMonth').value;
	var oDay = document.getElementById('sentenceDay').value;
	var oYear = document.getElementById('sentenceYear').value;
	gSD.setFullYear(oYear, oMonth-1, oDay);
	gSD.setMilliseconds(0);
	gSD.setSeconds(0);
	gSD.setMinutes(0);
	gSD.setHours(0);
	
	var numMS = dateObj.getTime() - gSD.getTime();
	var newDay = new Date(numMS);

	MonthsDays[0] = ((newDay.getFullYear()-1970)*12) + newDay.getMonth();
	
	MonthsDays[1] = CalculateCorrection(newDay, gSD, dateObj);
	
	if(Days >= 365 && dateObj.getFullYear() % 4 != 0)
		YearsMonthsDays[0] = dateObj.getFullYear() - oYear;
	else if(Days >= 366 && dateObj.getFullYear() % 4 == 0)
		YearsMonthsDays[0] = dateObj.getFullYear() - oYear;
	else
		YearsMonthsDays[0] = 0;
	
	YearsMonthsDays[1] = newDay.getMonth();
	YearsMonthsDays[2] = CalculateCorrection(newDay, gSD, dateObj);
}

function CalculateCorrection(newDay, sentence, other)
{
	var extra = 0;
	if(sentence.getDate() <= other.getDate() && sentence.getFullYear() < other.getFullYear())
		extra = 1;
		
	if(newDay.getMonth() == 0)
		return newDay.getDate()-1;
	else if(newDay.getMonth() == 1)
		return newDay.getDate()+2;
	else if(newDay.getMonth() == 2)
	{
		return newDay.getDate()-1;
	}
	else if(newDay.getMonth() == 3)
		return newDay.getDate()-1+(other.getFullYear()-sentence.getFullYear());
	else if(newDay.getMonth() == 4)
		return newDay.getDate()-1;
	else if(newDay.getMonth() == 5)
		return newDay.getDate()-1;
	else if(newDay.getMonth() == 6)
		return newDay.getDate()-1;
	else if(newDay.getMonth() == 7)
		return newDay.getDate()-1;
	else if(newDay.getMonth() == 8)
		return newDay.getDate()-1;
	else if(newDay.getMonth() == 9)
		return newDay.getDate()-1;
	else if(newDay.getMonth() == 10)
		return newDay.getDate()-1;
	else if(newDay.getMonth() == 11)
		return newDay.getDate()-1;
}