var fmonth = null;
var fday = null;
var tmonth = null;
var tday = null;
var widgetID = 1;


function initDate()
{
	var now = new Date();
	var mth = now.getMonth();
	var dd = now.getDate();
	var yy = now.getFullYear();

	if (mth <10)
	{
		mth == 0 + mth;
	}
	if (dd <10)
	{
		dd == 0 + dd;
	}
	if ((mth==11) && (dd>=29))
	{
			if(widgetID == 1)
			{
				document.resrvForm.doa_mm.selectedIndex = fmonth != null ? fmonth : mth;
				document.resrvForm.doa_dd.selectedIndex = fday != null ? fday : dd - 1;
				document.resrvForm.dod_mm.selectedIndex = tmonth != null ? tmonth : mth-mth;
				document.resrvForm.dod_dd.selectedIndex = tday != null ? tday : dd - dd;
			}
			else if(widgetID == 2)
			{
				document.resrvForm.dateLeavingMonth.selectedIndex = fmonth != null ? fmonth : mth;
				document.resrvForm.dateLeavingDay.selectedIndex = fday != null ? fday : dd - 1;
				document.resrvForm.dateReturningMonth.selectedIndex = tmonth != null ? tmonth : mth-mth;
				document.resrvForm.dateReturningDay.selectedIndex = tday != null ? tday : dd - dd;
			}
			else if(widgetID == 3)
			{
				document.resrvForm.pudate_mo.selectedIndex = fmonth != null ? fmonth : mth;
				document.resrvForm.pudate_dy.selectedIndex = fday != null ? fday : dd - 1;
				document.resrvForm.dodate_mo.selectedIndex = tmonth != null ? tmonth : mth-mth;
				document.resrvForm.dodate_dy.selectedIndex = tday != null ? tday : dd - dd;
			}
			else if(widgetID == 4)
			{
				document.resrvForm.dateLeavingMonth.selectedIndex = fmonth != null ? fmonth : mth;
				document.resrvForm.dateLeavingDay.selectedIndex = fday != null ? fday : dd - 1;
				document.resrvForm.dateReturningMonth.selectedIndex = tmonth != null ? tmonth : mth-mth;
				document.resrvForm.dateReturningDay.selectedIndex = tday != null ? tday : dd - dd;
			}
	}
	else if ((dd>=29 ) || ((dd>=27 ) && (mth==1)))
	{
			if(widgetID == 1)
			{
				document.resrvForm.doa_mm.selectedIndex = fmonth != null ? fmonth : mth+1;
				document.resrvForm.doa_dd.selectedIndex = fday != null ? fday : dd-dd;
				document.resrvForm.dod_mm.selectedIndex = tmonth != null ? tmonth : mth + 1;
				document.resrvForm.dod_dd.selectedIndex = tday != null ? tday : (dd-dd)+1;
			}
			else if(widgetID == 2)
			{
				document.resrvForm.dateLeavingMonth.selectedIndex = fmonth != null ? fmonth : mth+1;
				document.resrvForm.dateLeavingDay.selectedIndex = fday != null ? fday : dd-dd;
				document.resrvForm.dateReturningMonth.selectedIndex = tmonth != null ? tmonth : mth + 1;
				document.resrvForm.dateReturningDay.selectedIndex = tday != null ? tday : (dd-dd)+1;
			}
			else if(widgetID == 3)
			{
					document.resrvForm.pudate_mo.selectedIndex = fmonth != null ? fmonth : mth+1;
					document.resrvForm.pudate_dy.selectedIndex = fday != null ? fday : dd-dd;
					document.resrvForm.dodate_mo.selectedIndex = tmonth != null ? tmonth : mth + 1;
					document.resrvForm.dodate_dy.selectedIndex = tday != null ? tday : (dd-dd)+1;
			}
			else if(widgetID == 4)
			{
					document.resrvForm.dateLeavingMonth.selectedIndex = fmonth != null ? fmonth : mth+1;
					document.resrvForm.dateLeavingDay.selectedIndex = fday != null ? fday : dd-dd;
					document.resrvForm.dateReturningMonth.selectedIndex = tmonth != null ? tmonth : mth + 1;
					document.resrvForm.dateReturningDay.selectedIndex = tday != null ? tday : (dd-dd)+1;
			}
	}
	else
	{
			if(widgetID == 1)
			{
				document.resrvForm.doa_mm.selectedIndex = fmonth != null ? fmonth : mth;
				document.resrvForm.doa_dd.selectedIndex = fday != null ? fday : dd+1;
				document.resrvForm.dod_mm.selectedIndex =  tmonth != null ? tmonth : mth;
				document.resrvForm.dod_dd.selectedIndex = tday != null ? tday : dd+3;
			}
			else if(widgetID == 2)
			{
				document.resrvForm.dateLeavingMonth.selectedIndex = fmonth != null ? fmonth : mth;
				document.resrvForm.dateLeavingDay.selectedIndex = fday != null ? fday : dd+1;
				document.resrvForm.dateReturningMonth.selectedIndex = tmonth != null ? tmonth : mth;
				document.resrvForm.dateReturningDay.selectedIndex = tday != null ? tday : dd+3;
			}
			else if(widgetID == 3)
			{
				document.resrvForm.pudate_mo.selectedIndex = fmonth != null ? fmonth : mth;
				document.resrvForm.pudate_dy.selectedIndex = fday != null ? fday : dd + 1;
				document.resrvForm.dodate_mo.selectedIndex = tmonth != null ? tmonth : mth;
				document.resrvForm.dodate_dy.selectedIndex = tday != null ? tday : dd + 3;
			}
			else if(widgetID == 4)
			{
				document.resrvForm.dateLeavingMonth.selectedIndex = fmonth != null ? fmonth : mth;
				document.resrvForm.dateLeavingDay.selectedIndex = fday != null ? fday : dd + 1;
				document.resrvForm.dateReturningMonth.selectedIndex = tmonth != null ? tmonth : mth;
				document.resrvForm.dateReturningDay.selectedIndex = tday != null ? tday : dd + 3;
			}
	}
}

function calCallBack(calendar) {
    if (calendar.dateClicked) {
      // OK, a date was clicked, redirect to /yyyy/mm/dd/index.php
      var m = calendar.date.getMonth();     // integer, 0..11
      var d = calendar.date.getDate();      // integer, 1..31
		  calendar.params.inputMonth.selectedIndex = m;
		  calendar.params.inputDay.selectedIndex = d-1;
		  calendar.callCloseHandler();
    }
 }





function submitRes()
{
	document.resrvForm.submit();
}