// JavaScript Document

var i =0;
var startDate;
var endDate;
var fiscalYear;

function curQuarter()
{
	var date = new Date();
	var day = date.getDate();
	var month = date.getMonth() + 1;
	var yy = date.getYear();
	var year = (yy < 1000) ? yy + 1900 : yy;
		
	if ((month == 10)||(month == 11)||(month == 12)){
		quarter = 1;
		startDate="10/01/"+ year;
		endDate="12/31/"+ year;
		fiscalYear += year + 1;
	}
	
	if ((month == 1)||(month == 2)||(month == 3)){
		quarter = 2;
		startDate="01/01/"+ year;
		endDate="03/31/"+ year;
		fiscalYear = year;
	}
	
	if ((month == 4)||(month == 5)||(month == 6)){
		quarter = 3;
		startDate="04/01/" + year;
		endDate = "06/30/" + year;
		fiscalYear = year;
	}
	
	if ((month == 7)||(month == 8)||(month == 9)){
		quarter = 4;
		startDate="07/01/"+ year;
		endDate="09/30/"+ year;
		fiscalYear = year;
	}	
}

function nextQuarter(zdate) {
	
	var zArr = zdate.split("/");
	var zMonth = parseInt(zArr[0]);
	var zYear = parseInt(zArr[2]);
		
	if ((zMonth == 10)||(zMonth == 11)||(zMonth == 12)){
		zYear = zYear + 1;
		startDate = "01/01/" + zYear;
		endDate = "03/31/" + zYear;
	}
	if ((zMonth == 1)||(zMonth == 2)||(zMonth == 3)){
		startDate = "04/01/" + zYear;
		endDate = "06/30/" + zYear;
	}
	if ((zMonth == 4)||(zMonth == 5)||(zMonth == 6)){
		startDate = "07/01/" + zYear;
		endDate = "09/30/" + zYear;
	}
	if ((zMonth == 7)||(zMonth == 8)||(zMonth == 9)){
		startDate = "10/01/" + zYear;
		endDate = "12/31/" + zYear;
	}
}

function prevQuarter(zdate) {
	
	var zArr = zdate.split("/");
	var zMonth = parseInt(zArr[0]);
	var zYear = parseInt(zArr[2]);
		
	if ((zMonth == 10)||(zMonth == 11)||(zMonth == 12)){
		startDate = "07/01/" + zYear;
		endDate = "09/30/" + zYear;
	}
	if ((zMonth == 1)||(zMonth == 2)||(zMonth == 3)){
		zYear = zYear - 1;
		startDate = "10/01/" + zYear;
		endDate = "12/31/" + zYear;
	}
	if ((zMonth == 4)||(zMonth == 5)||(zMonth == 6)){
		startDate = "01/01/" + zYear;
		endDate = "03/31/" + zYear;
	}
	if ((zMonth == 7)||(zMonth == 8)||(zMonth == 9)){
		startDate = "04/01/" + zYear;
		endDate = "06/30/" + zYear;
	}
}

function jumpUp(zone) {
	
	var zArr = startDate.split("/");
	var zYear = parseInt(zArr[2]);
	
	if ((parseInt(zArr[0]) == 10)||(parseInt(zArr[0]) == 11)||(parseInt(zArr[0]) == 12)){
		zYear = zYear + 1;
	}
		
	if (zone == 1) {
		startDate = "10/01/" + zYear;
		endDate = "12/31/" + zYear;
	}
	if (zone == 2) {
		startDate = "01/01/" + zYear;
		endDate = "03/31/" + zYear;
	}
	if (zone == 3) {
		startDate = "04/01/" + zYear;
		endDate = "06/30/" + zYear;
	}
	if (zone == 4) {
		startDate = "07/01/" + zYear;
		endDate = "09/30/" + zYear;
	}
}

function jumpDown(zone) {
	
	var zArr = startDate.split("/");
	var zYear = parseInt(zArr[2]);
		
	if (zone == 1) {
		zYear = zYear - 1
		startDate = "10/01/" + zYear;
		endDate = "12/31/" + zYear;
	}
	if (zone == 2) {
		startDate = "01/01/" + zYear;
		endDate = "03/31/" + zYear;
	}
	if (zone == 3) {
		startDate = "04/01/" + zYear;
		endDate = "06/30/" + zYear;
	}
	if (zone == 4) {
		startDate = "07/01/" + zYear;
		endDate = "09/30/" + zYear;
	}
}


/* Rollover calendar button functions */

function showQ1(){
	MM_swapImage('Q1','','images/quarter1-on.gif',1);
}
function showQ2(){
	MM_swapImage('Q2','','images/quarter2-on.gif',1);
}
function showQ3(){
	MM_swapImage('Q3','','images/quarter3-on.gif',1);
}
function showQ4(){
	MM_swapImage('Q4','','images/quarter4-on.gif',1);
}
function hideQ1(){
	MM_swapImage('Q1','','images/quarter1-off.gif',1);
}
function hideQ2(){
	MM_swapImage('Q2','','images/quarter2-off.gif',1);
}
function hideQ3(){
	MM_swapImage('Q3','','images/quarter3-off.gif',1);
}
function hideQ4(){
	MM_swapImage('Q4','','images/quarter4-off.gif',1);
}

/* Updates the calendar view */

function changeQ(thisone) {
	
	var xArr = thisone.split("/");
	var xQ;
	var xY = parseInt(xArr[2]);
	
	var pMo = parseInt(xArr[0]) + '';
	var pDay = parseInt(xArr[1]) + '';
	var pYr = parseInt(xArr[2]) + '';
	pDate = pMo + '/' + pDay + '/' + pYr;
	
	var date = new Date();
	var day = date.getDate();
	var month = date.getMonth() + 1;
	var yy = date.getYear();
	var BacktoCurr = 'Y';
	
	if ((parseInt(xArr[0]) == 10)||(parseInt(xArr[0]) == 11)||(parseInt(xArr[0]) == 12)){
		xQ = "1st Quarter";
		xCal = "<img src='images/quarter1-on.gif' alt='First Quarter' name='Q1' width='126' height='79' border='0' id='Q1' /><a href='#' onmouseout='hideQ2()' onmouseover='showQ2()' onclick='jumpUp(2);thisShow();changeQ(startDate)'><img src='images/quarter2-off.gif' alt='Quarter 2' name='Q2' width='135' height='79' border='0' id='Q2' /></a><a href='#' onmouseout='hideQ3()' onmouseover='showQ3()' onclick='jumpUp(3);thisShow();changeQ(startDate)'><img src='images/quarter3-off.gif' alt='Quarter 3' name='Q3' width='134' height='79' border='0' id='Q3' /></a><a href='#' onmouseout='hideQ4()' onmouseover='showQ4()' onclick='jumpUp(4);thisShow();changeQ(startDate)'><img src='images/quarter4-off.gif' alt='Quarter 4' name='Q4' width='127' height='79' border='0' id='Q4' /></a>"
		xY = xY + 1;
		if((month==10) || (month==11) || (month==12))
		{
			if(yy+1 == xY)
			{
				BacktoCurr = 'Y';
			}
			else
			{
				BacktoCurr = 'N';
			}
		}
		else
		{
			BacktoCurr = 'N';
		}
	}
	if ((parseInt(xArr[0]) == 1)||(parseInt(xArr[0]) == 2)||(parseInt(xArr[0]) == 3)){
		xQ = "2nd Quarter";
		xCal = "<a href='#' onmouseout='hideQ1()' onmouseover='showQ1()' onclick='jumpDown(1);changeQ(startDate);thisShow()'><img src='images/quarter1-off.gif' alt='First Quarter' name='Q1' width='126' height='79' border='0' id='Q1' /></a><img src='images/quarter2-on.gif' alt='Quarter 2' name='Q2' width='135' height='79' border='0' id='Q2' /><a href='#' onmouseout='hideQ3()' onmouseover='showQ3()' onclick='jumpUp(3);changeQ(startDate);thisShow()'><img src='images/quarter3-off.gif' alt='Quarter 3' name='Q3' width='134' height='79' border='0' id='Q3' /></a><a href='#' onmouseout='hideQ4()' onmouseover='showQ4()' onclick='jumpUp(4);changeQ(startDate);thisShow()'><img src='images/quarter4-off.gif' alt='Quarter 4' name='Q4' width='127' height='79' border='0' id='Q4' /></a>"
		if((month==1) || (month==2) || (month==3))
		{
			if(yy == xY)
			{
				BacktoCurr = 'Y';
			}
			else
			{
				BacktoCurr = 'N';
			}
		}
		else
		{
			BacktoCurr = 'N';
		}
	}
	if ((parseInt(xArr[0]) == 4)||(parseInt(xArr[0]) == 5)||(parseInt(xArr[0]) == 6)){
		xQ = "3rd Quarter";
		xCal = "<a href='#' onmouseout='hideQ1()' onmouseover='showQ1()' onclick='jumpDown(1);changeQ(startDate);thisShow()'><img src='images/quarter1-off.gif' alt='First Quarter' name='Q1' width='126' height='79' border='0' id='Q1' /></a><a href='#' onmouseout='hideQ2()' onmouseover='showQ2()' onclick='jumpDown(2);changeQ(startDate);thisShow()'><img src='images/quarter2-off.gif' alt='Quarter 2' name='Q2' width='135' height='79' border='0' id='Q2' /></a><img src='images/quarter3-on.gif' alt='Quarter 3' name='Q3' width='134' height='79' border='0' id='Q3' /><a href='#' onmouseout='hideQ4()' onmouseover='showQ4()' onclick='jumpUp(4);changeQ(startDate);thisShow()'><img src='images/quarter4-off.gif' alt='Quarter 4' name='Q4' width='127' height='79' border='0' id='Q4' /></a>"
		if((month==4) || (month==5) || (month==6))
		{
			if(yy == xY)
			{
				BacktoCurr = 'Y';
			}
			else
			{
				BacktoCurr = 'N';
			}
		}
		else
		{
			BacktoCurr = 'N';
		}
	}
	if ((parseInt(xArr[0]) == 7)||(parseInt(xArr[0]) == 8)||(parseInt(xArr[0]) == 9)){
		xQ = "4th Quarter";
		xCal = "<a href='#' onmouseout='hideQ1()' onmouseover='showQ1()' onclick='jumpDown(1);changeQ(startDate);thisShow()'><img src='images/quarter1-off.gif' alt='First Quarter' name='Q1' width='126' height='79' border='0' id='Q1' /></a><a href='#' onmouseout='hideQ2()' onmouseover='showQ2()' onclick='jumpDown(2);changeQ(startDate);thisShow()'><img src='images/quarter2-off.gif' alt='Quarter 2' name='Q2' width='135' height='79' border='0' id='Q2' /></a><a href='#' onmouseout='hideQ3()' onmouseover='showQ3()'  onclick='jumpDown(3);changeQ(startDate);thisShow()'><img src='images/quarter3-off.gif' alt='Quarter 3' name='Q3' width='134' height='79' border='0' id='Q3' /></a><img src='images/quarter4-on.gif' alt='Quarter 4' name='Q4' width='127' height='79' border='0' id='Q4' />"
		if((month==7) || (month==8) || (month==9))
		{
			if(yy == xY)
			{
				BacktoCurr = 'Y';
			}
			else
			{
				BacktoCurr = 'N';
			}
		}
		else
		{
			BacktoCurr = 'N';
		}
	}
	
/* Updates the fiscal year, quarter, and calendar view */

var thisID = Math.random();
var newEmail = '<a href=http://ncrr.palladianpartners.com/timeline/index.asp?setStart=' + pDate + '&setEnd=' + pDate + '&setQ=All&setID=' + thisID + '><strong>E-mail this page as a link</strong></a></p>';
	
	document.getElementById("divFY").innerHTML = "FY " + xY;
	document.getElementById("divCal").innerHTML = xCal;
	if(BacktoCurr == 'N'){
	document.getElementById("divQ").innerHTML = xQ;
	document.getElementById("divC").innerHTML = "<a href='index.asp'>&#60;&#60; Back to current quarter</a>";
	}
	else
	{
		document.getElementById("divQ").innerHTML = xQ;
		document.getElementById("divC").innerHTML = "&nbsp;";
	}
}

function thisShow(){
	showme(document.getElementById('themes').value,startDate,endDate);
}

var xmlHttp;

function showme(str,stdate,endate)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="test2.asp";
url=url+"?q="+str;
url=url+"&Sdate="+stdate;
url=url+"&Edate="+endate;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("divThemes").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}