/*
 * Author: Badrinath Chebbi
 * Date: 01-04-2002
 */

//Browser detection code
var IE4 = (document.all && !document.getElementById) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE5 = (document.all && document.getElementById) ? true : false;
var N6 = (document.getElementById && !document.all) ? true : false;




var formName = getQueryVariable('formName');
var frameName = getQueryVariable('frameName');
var champ = getQueryVariable('champ');




var aMonthNames = new Array(
	'JANUARY',
	'FEBRUARY',
	'MARCH', 
	'APRIL',
	'MAY',
	'JUNE', 
	'JULY',
	'AUGUST',
	'SEPTEMBER', 
	'OCTOBER',
	'NOVEMBER',
	'DECEMBER'
);
var aMonthDisplay = new Array(
	'01',
	'02',
	'03', 
	'04',
	'05',
	'06', 
	'07',
	'08',
	'09', 
	'10',
	'11',
	'12'
);	
var aMonthDays = new Array(  
	31, /* Jan */
	28, /* Feb */
	31, /* Mar */
	30, /* Apr */
	31, /* May */
	30, /* Jun */
	31, /* Jul */
	31, /* Aug */
	30, /* Sep */
	31, /* Oct */
	30, /* Nov */
	31  /* Dec */
);
var days = new Array(42);




function getQueryVariable (variable)
{
	var query = window.location.search.substring(1);
	var vars = query.split('&');
	for (var i = 0; i < vars.length; i++) {
		var pair = vars[i].split('=');
		if (pair[0] == variable) {
			return pair[1];
		}
	} 
	return false;
}




/*
 * This Function populates the table with the dates for a particular month in a year.
 */
function daylayerdisplay (b, a, c)
{
	/*newwindow = window.open('');
	newwindow.status=b + '' + a + '' + c + '';*/
	/*
	 * b is Year in yyyy format
	 * a is Months in numerical format viz 0=january,1=february etc
	 * c is day in numeric format
	 */
	monthreduction = a;
	monthincrease = a;
	
	if ((b%4 == 0) || (b%100 ==0)) {
		aMonthDays[1] = 29;
	} else {
		aMonthDays[1] = 28;
	}
	
	var oDateNow = new Date();	
	var oDate = new Date(aMonthNames[a] +  1 + ',' + b);
	dayofweek = oDate.getDay();
	
	//Input values in td's
	var count = 0;
	var count1;
	var end = aMonthDays[a] + (dayofweek);
	
	for (s = 1; s <= 42; s++) {
		document.getElementById('day' + s).childNodes[0].innerHTML = '';
	}
	
	for (s = (dayofweek + 1); s <= end; s++) {
		count = count + 1;
		document.getElementById('day' + s).childNodes[0].innerHTML = count;
		if (count <= 9) {
			count1 = 0 + '' + count;
		} else {
			count1 = count;
		}
		document.getElementById('day' + s).childNodes[0].id = count1;
	}
}



/*
 * This function sends the value back to the form object of the window
 * which called it
 */
function sendvalue (y, m, d)
{
	if (y == 1) {
		todayobj = new Date();
		today = todayobj.getYear() + todayobj.getMonth() + todayobj.getDate();
		if (N6) {
			year = todayobj.getYear() + 1900;
		} else {
			year = todayobj.getYear();
		}					
		
		if (todayobj.getDate() <= 9) {
			var todayday = 0 + '' + todayobj.getDate();
		} else {
			var todayday = todayobj.getDate();
		}
		
		eval('parent.document.' + formName + '.' + champ + '.value = todayday + "/" + aMonthDisplay[todayobj.getMonth()] + "/" + year;');
		//parent.document.callingform.receivedate.value=aMonthDisplay[todayobj.getMonth()]+ "-" + todayday + "-" + year;
		//parent.document.getElementById('calendarframe').style.display='none'
		parent.document.getElementById(frameName).style.display = 'none';
	} else {
		eval('parent.document.' + formName + '.' + champ + '.value = d + "/" + aMonthDisplay[m] + "/" + y; //y + m + d;');
		//parent.document.callingform.receivedate.value= aMonthDisplay[m]+"-"+d+"-"+y;//y + m + d;
		//parent.document.getElementById('calendarframe').style.display='none'
		parent.document.getElementById(frameName).style.display = 'none';
	}
}




/*
 * This function reduces the month by one everytime prev.gif is clicked
 */
function reducemonths ()
{ 
	monthreduction = +monthreduction - 1;
	
	if (monthreduction == -1) {
		monthreduction = 11;
		document.calendarform.year.value = parseFloat(document.calendarform.year.value) - 1;
	}
	
	document.calendarform.month[monthreduction].selected = '1';
	daylayerdisplay(document.calendarform.year.value, monthreduction, 101);
}




/*
 * This function Increases the month by one everytime next.gif is clicked
 */
function increasemonths ()
{ 
	monthincrease= +monthincrease + 1;
	
	if (monthincrease == 12) {
		monthincrease = 0;
		document.calendarform.year.value = parseFloat(document.calendarform.year.value) + 1;
	}
	
	document.calendarform.month[monthincrease].selected = '1';
	daylayerdisplay(document.calendarform.year.value, monthincrease, 101);
}