var timeout;
var gformfield;
var mindate;

if (browser.ie4 || browser.ie5){document.write('<span id="spCal" class="contact" name="spCal" STYLE="visibility: hidden; position:absolute; top:260; left:100; width:175; height:85; z-index:4"></span>');}
if (browser.ns6){document.write('<span id="spCal" class="contact" name="spCal" STYLE="visibility: hidden; position:absolute; top:260; left:100; width:175; height:90; z-index:4"></span>');}


//--------------------------------------------------------------------------------

function timeron() 
{
	 window.clearTimeout(timeout);
	 temp_Obj = attach('spCal');
     timeout = window.setTimeout('hide_obj(temp_Obj)', 5000);
}



//--------------------------------------------------------------------------------

function timeroff(timer){window.clearTimeout(timer)}


//--------------------------------------------------------------------------------


function generatecalendar(d)
{
	//set up variables
	var col	= 0;
	var i;
	var DayName = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
	var MonthName = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var text;
	
	var d = new Date(d);

	var dCurrent = new Date();
	
	var b=new Date();
	b.setDate(b.getDate());
	
	prev=new Date(d);
	next=new Date(d);
	prev.setMonth(prev.getMonth()-1)
	next.setMonth(next.getMonth()+1)
    
    text="";

	text=text+'<table class="calendertable" cellpadding="0" cellspacing="0" border="0">';
	
	if(d.getMonth()==dCurrent.getMonth() && d.getFullYear()==dCurrent.getFullYear())
		text=text+'<tr><td colspan="2" align="center"></td><td class="small" colspan="3" align="center">'+MonthName[d.getMonth()]+' '+d.getFullYear()+'</td><td colspan="2" align="center"><a style="font-size: 7pt" href="Javascript:generatecalendar(\''+next+'\');" onmouseover="timeron()">Next <img src="../../images/calender/right.gif" style="border-width: 0" align="center" width="5" height="9"></a></td></tr>';
	else
		text=text+'<tr><td colspan="2" align="center"><a style="font-size: 7pt" href="Javascript:generatecalendar(\''+prev+'\');" onmouseover="timeron()"><img src="../../images/calender/left.gif" style="border-width: 0" align="center" width="5" height="9"> Prev</a></td><td class="small" colspan="3" align="center">'+MonthName[d.getMonth()]+' '+d.getFullYear()+'</td><td colspan="2" align="center"><a style="font-size: 7pt" href="Javascript:generatecalendar(\''+next+'\');" onmouseover="timeron()">Next <img src="../../images/calender/right.gif" style="border-width: 0" align="center" width="5" height="9"></a></td></tr>';
	
	
	//write out day titles
	text=text+'<tr>';
	for(i = 0; i < 7; i++)
		text=text+'<td class="small" align="center" width="25">'+DayName[i]+'</td>';
	text=text+'</tr>';

	// Write out first week
	text=text+'<tr>';
	for(i = 0; i < d.getDay(); i++)
	{
		text=text+'<td class="small" width="25"> </td>';
		col++
	}


	while(d<next) 
	{
		
		if (d < mindate)
			text=text+'<td class="small" width="25" align="center">'+d.getDate()+'</td>';
		else
	    	text=text+'<td class="small" width="25" align="center"><a style="font-size: 7pt;" href="Javascript:writedate(\''+d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear()+'\')" onmouseover="timeron()">'+d.getDate()+'</a></td>';
		
		col++; 
		if((col % 7) == 0) 
		{
			text=text+'</tr>';
			col=0
			if(d.getDate() < (next.getDate() - 1))
				text=text+'<tr>';
			
		}
		d.setDate(d.getDate()+1);
	}
	if (col!=0)
	 	text+='<td colspan="'+(7-col)+'"></td></tr>';

	text=text+'</table>';
	temp_Obj = attach("spCal");
	temp_Obj.innerHTML=text;
}


//--------------------------------------------------------------------------------


function writedate(m) 
{
	gformfield.value=m;
 	temp_Obj = attach('spCal');
	hide_obj(temp_Obj);
}


//--------------------------------------------------------------------------------


function setupform(formfield)
{
	gformfield = formfield;
	var d = new Date(); 
	mindate = new Date(); 
	
	if (browser.ie4 || browser.ie5 || browser.ns6)
	{
		d.setDate(1);
		generatecalendar(d);
	}
}

