
var iCalendarWidth,iCalendarHeight;
var iCounter,iCountID;
var bCloseIt;
var oMyField;


iCounter=0;
iCountID=0;

bCloseIt=true;

// calendar dimensions for IE
if(navigator.appName=="Microsoft Internet Explorer")
{
	iCalendarWidth=200;
	iCalendarHeight=200;
}
// calendar dimensions for Netscape
else if(navigator.appName=="Netscape")
{
	iCalendarWidth=205;
	iCalendarHeight=200;
}

/*function checks which object is supported by the browser
*/
function checkMe()
{
	if(document.all) // usually Microsoft Internet Explorer
		return(document.all("oCalendarDIV"))
	else if(document.getElementById) // usually Netscape
		return(document.getElementById("oCalendarDIV"));
}

/* function is useful only for Ms IE 5
because there is a bug which first time when is clicked on a
object returned value of offsetTop and offsetLeft is zero.
To solve the problem I use this function that do very similar thing as showCalendar
but it doesn't show it.
*/
function prepareCalendar(oField)
{
	var oCalendar;
	oCalendar=checkMe();

	if(oCalendar!=null)
	{
		if(oCalendar.style.display!="block")
		{
			oField.style.position="absolute";
			oCalendar.style.top=oField.offsetTop-10;
			oCalendar.style.left=oField.offsetLeft+50;
				
			oField.style.position="relative";
		}
	}
}

/*function that do all needed things to show calendar
*/
function showCalendar(oField,dMinDate,dMaxDate,cDateSep)
{
	
	if(document.getElementById || document.all)
	{
		var oCalendar;
		var iYear,iMonth,iDate,iMinYear,iMinMonth,iMinDate,iMaxYear,iMaxMonth,iMaxDate;

		oMyField=oField;

		oCalendar=checkMe();
		
		bCloseIt=false;
		
		if(oCalendar!=null)
		{
				
			if(oCalendar.style.display!="block")
				showHideSelects();
				
			/* get date (if is specified) from field 
			*/
			iYear=oField.value.substring(oField.value.indexOf(cDateSep,oField.value.indexOf(cDateSep,0)+1)+1,oField.value.length);
			iMonth=oField.value.substring(oField.value.indexOf(cDateSep,0)+1,oField.value.indexOf(cDateSep,oField.value.indexOf(cDateSep,0)+1));
			iDate=oField.value.substring(0,oField.value.indexOf(cDateSep,0));
			
			/* get min date (if is specified)
			*/
			iMinYear=dMinDate.substring(dMinDate.indexOf(cDateSep,dMinDate.indexOf(cDateSep,0)+1)+1,dMinDate.length);
			iMinMonth=dMinDate.substring(dMinDate.indexOf(cDateSep,0)+1,dMinDate.indexOf(cDateSep,dMinDate.indexOf(cDateSep,0)+1));
			iMinDate=dMinDate.substring(0,dMinDate.indexOf(cDateSep,0));
			
			/* get max date (if is specified)
			*/
			iMaxYear=dMaxDate.substring(dMaxDate.indexOf(cDateSep,dMaxDate.indexOf(cDateSep,0)+1)+1,dMaxDate.length);
			iMaxMonth=dMaxDate.substring(dMaxDate.indexOf(cDateSep,0)+1,dMaxDate.indexOf(cDateSep,dMaxDate.indexOf(cDateSep,0)+1));
			iMaxDate=dMaxDate.substring(0,dMaxDate.indexOf(cDateSep,0));
		
			/* set date (if is specified) from field 
			*/		
			document.forms["oCalendar"].txtYear.value="";
			document.forms["oCalendar"].hdnYear.value=iYear;
			document.forms["oCalendar"].hdnMonth.value=iMonth;
			document.forms["oCalendar"].hdnDate.value=iDate;
	
			/* set min date (if there is) 
			*/
			document.forms["oCalendar"].hdnMinYear.value=iMinYear;
			document.forms["oCalendar"].hdnMinMonth.value=iMinMonth;
			document.forms["oCalendar"].hdnMinDate.value=iMinDate;
			
			/* set max date (if there is) 
			*/		
			document.forms["oCalendar"].hdnMaxYear.value=iMaxYear;
			document.forms["oCalendar"].hdnMaxMonth.value=iMaxMonth;
			document.forms["oCalendar"].hdnMaxDate.value=iMaxDate;
		
			/* set a date separator
			*/
			document.forms["oCalendar"].hdnDateSep.value=cDateSep;
			
			oField.style.position="absolute";
			oCalendar.style.top=oField.offsetTop-10;
			oCalendar.style.left=oField.offsetLeft+50;
			
			oCalendar.style.zIndex=10000;
			
			oField.style.position="relative";		
			
			oCalendar.style.width=iCalendarWidth +"px";
			oCalendar.style.height=iCalendarHeight +"px";
			
			iCounter=0;
	
			// show calendar
			oCalendar.style.display="block";
			
			loadCalendar();
		}
	}

	
}
/* hides calendar
*/
function hideFrame(whoCloses)
{
	var oCalendar;
	
	oCalendar=checkMe();
	if(whoCloses=="body" && bCloseIt)
	{
		if(oCalendar!=null)
		{
			if(oCalendar.style.display=="block")
			{	
				showHideSelects();
				oCalendar.style.display="none";
			}
		}
	}
	
	bCloseIt=true;	
}


function showHideSelects()
{
	var oSelect,oSelectOne;

	if(document.all) // usually Microsoft Internet Explorer
		oSelect=document.all.tags('select');
	else if(document.getElementsByTagName) // usually Netscape 6
		oSelect=document.getElementsByTagName('select');
	
	for(iCounter=0; iCounter<oSelect.length; iCounter++)
	{
		
		// sets object for current browser
		if(document.all) // usually Microsoft Internet Explorer
			oSelectOne=oSelect(iCounter)
		else if(document.getElementsByTagName) // usually Netscape 6
			oSelectOne=oSelect.item(iCounter)
		
		
		if(oSelectOne.name!="cboMonth")
		{
			if(oSelectOne.style.visibility=="hidden")
				oSelectOne.style.visibility="visible";
			else
				oSelectOne.style.visibility="hidden";
		}
	}
}

document.onclick=new Function("hideFrame('body')");

//
//
//
//