/*comment1 starts
Author: Badrinath Chebbi
Date: 01-04-2002
comment1 ends*/
	//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;
   //Browser detection code ends here
var enterday=0;
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(  
	/* Jan */ 31,     /* Feb */ 28, /* Mar */ 31,     /* Apr */ 30, 
	/* May */ 31,     /* Jun */ 30, /* Jul */ 31,     /* Aug */ 31, 
	/* Sep */ 30,     /* Oct */ 31, /* Nov */ 30,     /* Dec */ 31 
	);
var days = new Array(42);
		
		/*Comment2 starts
		  This Function populates the table with the dates for a particular month in a year.
		  comment2 ends*/
		function daylayerdisplay(b,a,c)
		{
		/*newwindow=window.open("");
		newwindow.status=b + "" + a + "" + c + "";*/
		/*Comment3 starts
		  b is Year in yyyy format
		  a is Months in numerical format viz 0=january,1=february etc
		  c is day in numeric format
		  Comment3 ends
		*/
		monthreduction=a;
		monthincrease=a;
		            if (b%4 == 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="";
					}
						
					begin = dayofweek + 2;	
					if(begin == 8)
					{	
						begin=1;
						end -=7;
					}
					for (s=begin;s<=end+1;s++){
					count=count+1;
					
				    var d=oDateNow.getDate();  //Today with color.
				   	
					if(count==getenterday() & a==getentermonth() & b==getenteryear())
						document.getElementById("day"+s).childNodes[0].innerHTML='<span class=selectedStyle>'+count+'</span>';
					else if(count==d & oDateNow.getMonth()==a & oDateNow.getFullYear()==b)
							document.getElementById("day"+s).childNodes[0].innerHTML='<span class=todayStyle>'+count+'</span>';
					else if(getcolor())
						document.getElementById("day"+s).childNodes[0].innerHTML='<span class=dayStyle>'+count+'</span>';
					else
						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;
					}
					
					for(s=1;s<=42;s++)
					{
					if(document.getElementById("day"+s).childNodes[0].innerHTML=="")
					  document.getElementById("day"+s).childNodes[0].style.display = 'none';
					else
					  document.getElementById("day"+s).childNodes[0].style.display = '';
					}
					
			}
				
				/*Comment4 starts
				This function sends the value back to the form object of the window
				which called it*/
				function sendvalue(y,m,d)
				{	
				try{
					textenter=location.search.split("&")[1].split("=")[1];	
					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();
					}
					window.opener.document.all(textenter).value= todayday+"-"+aMonthDisplay[todayobj.getMonth()] +"-" + year;
					//window.opener.document.getElementById('calendarframe').style.display='none';
					window.close();
					}
					else{					
					window.opener.document.all(textenter).value = d+"-"+aMonthDisplay[m]+"-"+y; //y + m + d;
					//window.opener.document.getElementById('calendarframe').style.display='none';
					window.close();
					}
					}
					catch(a)
					{
						window.close();
					}	
				 }
				 /*Comment4 ends here*/
				 
				 /*Comment5 starts
				 This function reduces the month by one everytime prev.gif is clicked*/
				 function reducemonths()
				 { 
				  monthreduction= +monthreduction - 1;
				 if (monthreduction==-1)
				 {
				 monthreduction=11;
				 document.all("year").value=
				 parseFloat(document.all("year").value)-1;
				 }
				 document.calendarform.month.selectedIndex =monthreduction; 
				 //document.allmonth[monthreduction]).selected = "1";
				 daylayerdisplay(document.all("year").value,monthreduction,101);
				 }
				 /*Comment5 ends here*/
				 
				 /*Comment6 starts
				 This function Increases the month by one everytime next.gif is clicked*/
				 function increasemonths()
				 { 
				 monthincrease= +monthincrease + 1;
				 if (monthincrease==12)
				 {
				 monthincrease=0;
				 document.all("year").value=
				 parseFloat(document.all("year").value)+1;
				 }
				 document.calendarform.month[monthincrease].selected = "1";
				 daylayerdisplay(document.all("year").value,monthincrease,101);
				 }
				 /*Comment6 ends here*/	

				/*comment7 start heres
					this function test the date			 
				comment7 start here*/
				
				function appear(textenter)
				{					
					if(!document.all(textenter).disabled)
					{
						Requestdate=document.all(textenter).value.split("-");
						if(Requestdate.length!=3 || document.all(textenter).value=="" || document.all(textenter).value=="00-00-0000" || !test(getenteryear(),getentermonth(),getenterday()))
						Requestdate='';
						window.open('calendar/Calendar.html?Requestdate='+ Requestdate+'&textenter='+textenter,'tt','dependent=1,directories=0, height=250, width=190, location=0, top = ' + (screen.availHeight - 250)/2 + ', left = ' + (screen.availWidth-190)/2 + ' , menubar=0, resizable=0, scrollbars=0, status=0, titlebar=0, title=0')
					}
				}
								
function getcolor()
{
n=7;
while(n>7)
  n=n-7;
line=0;
	d=7-n;
	if(s>7)
	{	ss=s;
	while(ss>7)
	{
	line+=1;
	ss-=7;
	}
	}	
	yes=0;
	for(num=0;num<=line;num++)
	{
		if(s==n*(num+1)+num*d)				
		yes=1;
	}
	if(yes==1)
			return true; 
	else 
			return false;	
}

var Requestdate;
var textenter;

function getenterday()
{
	return Requestdate[0];
}

function  getentermonth()
{
	mm=Requestdate[1];
	mm = mm-1;
	return mm;
}

function getenteryear()
{
	return Requestdate[2];
}

function test(y,m,d)
{
	var mr=m.toString().substring(2,1);
	var ml=m.toString().substring(1,0);
	if (y%4 == 0){
					aMonthDays[1]=29;
					}
					else{
					aMonthDays[1]=28;
					}
	if(ml==0)
		monthdays=aMonthDays[mr];
	else
		monthdays=aMonthDays[m];
	if((m<=12)&& (y.length==4)&&(m+1!=0))
		return true;
	else 
		return false;
}


function testcontrol(myobj)
{
	o=document.all(myobj);
	if(o!=null)
	{
		s=o.value;
	}
	else
	{
		o=myobj.value;
		if(o!=null)		
			s=myobj.value;
		else
			s=myobj;
	}
	return testdate(s);
}

function testdate(textenter)
{
Requestdate=textenter.split("-");
y=getenteryear();
m=getentermonth();
d=getenterday();
if(m==null || d==null || y==null || Requestdate.length!=3 || textenter=="" || d==0 || y.length>4 || m>11 || m<0)
return false ;

var mr=m.toString().substring(2,1);
var ml=m.toString().substring(1,0);
 if (y%4 == 0){
				aMonthDays[1]=29;
			  }
			  else{
			    aMonthDays[1]=28;
			  }
			  
if(ml==0 && mr!="")
	monthdays=aMonthDays[mr];
else
	monthdays=aMonthDays[m];

m +=1;	
if( d>monthdays )
	return false;
	
return true;
}







