function buildCal(selecteddate, m, y)
{ /*This is design exclusively foe the Chang Ad Run or Length page when posting/editing an ad.
	It takes the following parameters:
	selecteddate, the date to be selected, which is highlighted in red once the calendar get written out.
				NOTE that Today's date is BOLDED... and then the selected date has a background
	m: the month of the calendar to be displayed.
	y: the year of the calendar to be displayed.
	
	By: Gustavo Vasconcelos 11/20/2003 (base of code gotten from Brian)
  */
	var mn=['January','February','March','April','May','June','July','August','September','October','November','December'];
	var dim=[31,0,31,30,31,30,31,31,30,31,30,31];
	var myDay='0';

	var oD = new Date(y, m-1, 1); //DD replaced line to fix date bug when current day is 31st
	oD.od=oD.getDay()+1; //DD replaced line to fix date bug when current day is 31st	
	
	var todaydate = new Date(); //DD added
	var scanfortoday=((y==todaydate.getFullYear()) && (m==todaydate.getMonth()+1))? todaydate.getDate():0;
	
	dim[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28;
	
	var t='<div class="calmain"><table class="calmain" cols="7" cellpadding="0" border="0" cellspacing="0"><tr align="center">';
	
	t+='<td colspan="7" align="center" class="calmonth">'+mn[m-1]+' - '+y+'</td></tr><tr align="center">';
	
	for(s=0;s<7;s++)
		t+='<td class="caldaysofweek">'+"SMTWTFS".substr(s,1)+'</td>';
		
	t+='</tr><tr align="center">';
	for(i=1;i<=42;i++)
	{
		var x=((i-oD.od>=0)&&(i-oD.od<dim[m-1]))? i-oD.od+1 : '&nbsp;';
		switch(x){
		case 1:		
			myDay = (m+'/01/'+y);
			break;
		case 2:		
			myDay = (m+'/02/'+y);
			break;
		case 3:		
			myDay = (m+'/03/'+y);
			break;
		case 4:		
			myDay = (m+'/04/'+y);
			break;
		case 5:		
			myDay = (m+'/05/'+y);
			break;
		case 6:		
			myDay = (m+'/06/'+y);
			break;
		case 7:		
			myDay = (m+'/07/'+y);
			break;
		case 8:		
			myDay = (m+'/08/'+y);
			break;
		case 9:		
			myDay = (m+'/09/'+y);
			break;
		default:
			myDay = (m+'/'+x+'/'+y)
			break;
			}
			
			
		if (x==scanfortoday)
		{
			if (selecteddate==myDay) //(m+'/'+x+'/'+y)) //==scanforselday) 
				t+='<td class="selecteddate"><A href="javascript:SubmitMyForm('+"'ADRUNLENGTH'"+', '+"'"+m+'/'+x+'/'+y+"'"+')" class="selecteddate" onclick="linkClicked= true">'+x+'</A></td>';
			else
				t+='<td class="caldays"><A href="javascript:SubmitMyForm('+"'ADRUNLENGTH'"+', '+"'"+m+'/'+x+'/'+y+"'"+')" class="caldays" onclick="linkClicked= true"><span id="today">'+x+'</span></A></TD>';//'+x+'</span>'; //DD added
		}
		else
		{			
			if (x>scanfortoday)
			{
				if (selecteddate==myDay) //(m+'/'+x+'/'+y))																										
					t+='<td class="selecteddate"><A href="javascript:SubmitMyForm('+"'ADRUNLENGTH'"+', '+"'"+m+'/'+x+'/'+y+"'"+')" class="selecteddate" onclick="linkClicked= true">'+x+'</A></td>';
				else
					t+='<td class="caldays"><A href="javascript:SubmitMyForm('+"'ADRUNLENGTH'"+', '+"'"+m+'/'+x+'/'+y+"'"+')" class="caldays" onclick="linkClicked= true">'+x+'</A></td>';
			}
			else
				t+='<td class="caldays">'+x+'</td>';
		}
			
		if(((i)%7==0)&&(i<36))
			t+='</tr><tr align="center">';
	}
return t+='</tr></table></div>';
}

