// JavaScript Document

function Detach()
{
	top.location=self.location;
}

function ClickDay(x, PrefixMonthYear, Open_New_Window)
{
	var FileToShow
	var channel = document.Form1.DateSelect.options[document.Form1.DateSelect.selectedIndex].value;
	if ( x < 10 )
		FileToshow = "0" + x.toString() + PrefixMonthYear + "/" + channel + bet_type + "-c.asp"
	else
		FileToshow = x.toString() + PrefixMonthYear + "/" + channel + bet_type + "-c.asp"		
	document.Form1.FileName.value = FileToshow;
	if (Open_New_Window!="true")	
	{
		document.Form1.submit();
	}
	else
	{
		window.open("ResultHistory.asp?FileName=" + FileToshow);
	}
}

function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11)
{
   this[0] = m0;
   this[1] = m1;
   this[2] = m2;
   this[3] = m3;
   this[4] = m4;
   this[5] = m5;
   this[6] = m6;
   this[7] = m7;
   this[8] = m8;
   this[9] = m9;
   this[10] = m10;
   this[11] = m11;
}

function calendar_actual_month(Open_New_Window)
{
   var monthNames = "JanFebMarAprMayJunJulAugSepOctNovDec";
   var today = new Date();
   var thisDay;
   var monthDays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
   var TodayCellColor="";
   
   	year = today.getFullYear();
	thisDay = today.getDate();
	month = today.getMonth();


	//see if this year is a leap year
	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
	{
      monthDays[1] = 29;
	}
	nDays = monthDays[today.getMonth()];

	firstDay = today;
   	firstDay.setDate(1); // works fine for most systems
   	testMe = firstDay.getDate();
   	if (testMe == 2)
	{
    	firstDay.setDate(0);    
	}
   startDay = firstDay.getDay();
   

	
   document.write("<TABLE align=center cellPadding=5 cellSpacing=0 width=450  BORDER=1 bordercolor=#BECDB0>");
   document.write("<tr bgcolor=#DEEED0>");
   document.write("<td height=34 colspan=7 class=calendartable>");   
   FileName = "-" + monthNames.substring(month * 3,(month + 1) * 3) + "-" + year;	  	
   document.write(monthNames.substring(month * 3,(month + 1) * 3));
   document.write(". " + year);
   document.write("</td></tr>");
   
   document.write("<TR align=center>");
   document.write("<td><img src=images/week_sun.gif width=38 height=38></td>");
   document.write("<td><img src=images/week_mon.gif width=38 height=38></td>");
   document.write("<td><img src=images/week_tue.gif width=38 height=38></td>");
   document.write("<td><img src=images/week_wed.gif width=38 height=38></td>");
   document.write("<td><img src=images/week_thu.gif width=38 height=38></td>");
   document.write("<td><img src=images/week_fri.gif width=38 height=38></td>");
   document.write("<td><img src=images/week_sat.gif width=38 height=38></td>");
   document.write("</TR>");
   



   	column = 0;
	
	for (i=0; i < startDay; i++)
   {
      document.write("<TD>&nbsp;</Td>");
      column++;
   }
	
   for (i=1; i<=nDays; i++)
   {

		if (i == thisDay)
		{
		   TodayCellColor = "bgcolor=gray";
		}
		else
		{
			TodayCellColor="";
		}
	
		document.write("<TD " + TodayCellColor + " >&nbsp;");
		
		if ((DateMonth2[i]==1))
			document.write("<a href=javascript:ClickDay("+i+",'" +  FileName + "','" + Open_New_Window + "')>"+i+"</a></td>");
		else
			document.write(i+"</td> ")				
		column++;
		if (column == 7)
		{
			document.write("</TR><TR>"); 
			column = 0;
		}
   }
   
   for(i=nDays+startDay;i<42;i++)		
   {
		if (column == 7)
		{
			document.write("</Tr><TR>"); 
			column = 0;
		}
		document.write("<TD>&nbsp;</Td>");		
		column++;
   }   
   document.write("</Tr></TABLE>");
}




function calendar_previous_month(Open_New_Window)
{
   var monthNames = "JanFebMarAprMayJunJulAugSepOctNovDec";
   var today = new Date();
   var thisDay;
   var monthDays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
   var prevEndDay=0;
   
   year = today.getFullYear();
   thisDay = today.getDate();

	yearPrev = today.getFullYear();
	monthPrev = today.getMonth();
	if ( monthPrev == 0 )
	{
		yearPrev = yearPrev - 1;
		monthPrev = 11;
	}
	else
		monthPrev = monthPrev - 1;

	//see if this year is a leap year
	if (((yearPrev % 4 == 0) && (yearPrev % 100 != 0)) || (yearPrev % 400 == 0))
	{
      monthDays[1] = 29;
	}
	nDays = monthDays[monthPrev];

	firstDay = today;
   firstDay.setDate(1); // works fine for most systems
   testMe = firstDay.getDate();
   if (testMe == 2)
        firstDay.setDate(0);    
   startDay = firstDay.getDay();
   
   prevEndDay = startDay - 1;
   if ( prevEndDay < 0 )
		prevEndDay = prevEndDay + 7;

	prevEndDay = prevEndDay - nDays % 7;
	if ( prevEndDay < 0 )
		prevEndDay = prevEndDay + 7;
	prevEndDay = prevEndDay + 1;
	
	
   document.write("<TABLE align=center cellPadding=5 cellSpacing=0 width=450  BORDER=1 bordercolor=#BECDB0>");
   document.write("<tr bgcolor=#DEEED0>");
   document.write("<td height=34 colspan=7 class=calendartable>");   
   FileNamePrev = "-" + monthNames.substring(monthPrev * 3,(monthPrev + 1) * 3) + "-" + yearPrev;	  	
   document.write(monthNames.substring(monthPrev * 3,(monthPrev + 1) * 3));
   document.write(". " + yearPrev);
   document.write("</td></tr>");
   
   document.write("<TR align=center>");
   document.write("<td><img src=images/week_sun.gif width=38 height=38></td>");
   document.write("<td><img src=images/week_mon.gif width=38 height=38></td>");
   document.write("<td><img src=images/week_tue.gif width=38 height=38></td>");
   document.write("<td><img src=images/week_wed.gif width=38 height=38></td>");
   document.write("<td><img src=images/week_thu.gif width=38 height=38></td>");
   document.write("<td><img src=images/week_fri.gif width=38 height=38></td>");
   document.write("<td><img src=images/week_sat.gif width=38 height=38></td>");
   document.write("</TR>");
   



   	column = 0;
   
   	if (prevEndDay==7)
   	{
		prevEndDay = 0;
	}
	


	document.write("<TR>");
	
	for (i=0; i < prevEndDay; i++)
   	{
    	document.write("<TD>&nbsp;</Td>");
      	column++;
   	}
	
   for (i=1; i<=nDays; i++)
   {
		document.write("<TD>&nbsp;");
		if ((DateMonth1[i]==1))
			document.write("<a href=javascript:ClickDay("+i+",'" +  FileNamePrev + "','" + Open_New_Window + "')>"+i+"</a></td>");
		else
			document.write(i+"</td> ")				
		column++;
		if (column == 7)
		{
			document.write("</TR><TR>"); 
			column = 0;
		}
   }
   for(i=nDays+prevEndDay;i<42;i++)		
   {
		if (column == 7)
		{
			document.write("</Tr><TR>"); 
			column = 0;
		}
		document.write("<TD>&nbsp;</Td>");		
		column++;
   }   
   document.write("</Tr></TABLE>");
}


function select1_onchange() {
	var channel = document.Form1.DateSelect.options[document.Form1.DateSelect.selectedIndex].value;	
	window.open("race_results.asp?T="+channel, "_self")
}

function in_select1_onchange() {
	var channel = document.Form1.DateSelect.options[document.Form1.DateSelect.selectedIndex].value;	
	window.open("in_race_results.asp?T="+channel, "_self")
}
