var currentDate = new Date();
var currDate = parseInt(currentDate.getDate());
var currMonth = parseInt(currentDate.getMonth());
var currYear = parseInt(currentDate.getYear());

var preventPreviousDate = false;
var preventFutureDate = false;
var minDate, minMonth, minYear,maxDate, maxMonth, maxYear;


var scToday = false;
var scFutureDate = false;
var scPastDate = false;
var currentfield;
var allowWeekend = false;

var datePickerDivID = "datepicker";
var iFrameDivID = "datepickeriframe";

var dayArrayShort = new Array('Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa');
var dayArrayMed = new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
var dayArrayLong = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
var monthArrayShort = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
var monthArrayMed = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec');
var monthArrayLong = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
  

var defaultDateSeparator = "/";		// common values would be "/" or "."
var defaultDateFormat = "dmy"	// valid values are "mdy", "dmy", and "ymd"
var dateSeparator = defaultDateSeparator;
var dateFormat = defaultDateFormat;

/********************* STATIC HTML TO BE WRITTEN ********************************/

// the calendar will be drawn as a table
  // you can customize the table elements with a global CSS style sheet,
  // or by hardcoding style and formatting elements below
  var crlf = "\r\n";

  var TABLE = "<table cols=7 class='dpTable'>" + crlf;
  var xTABLE = "</table>" + crlf;

  var TR = "<tr class='dpTR'>";
  var TR_title = "<tr class='dpTitleTR'>";
  var TR_days = "<tr class='dpDayTR'>";
  var TR_todaybutton = "<tr class='dpTodayButtonTR'>";
  var xTR = "</tr>" + crlf;
  var TD = "<td class='dpTD'";	// leave this tag open, because we'll be adding an onClick event
  var TD_title = "<td colspan=5 class='dpTitleText'>";
  var TD_buttons = "<td >";
  var TD_todaybutton = "<td colspan=7 class='dpTodayButtonTD'>";
  var TD_days = "<td class='dpDayTD'>";
  var TD_selected = "<td class='dpDayHighlightTD'";	// leave this tag open, because we'll be adding an onClick event
  var xTD = "</td>" + crlf;
  var DIV_title = "<div class='dpTitleText'>";
  var DIV_selected = "<div class='dpDayHighlight'>";
  var xDIV = "</div>";

  var TD_notavail = "<td class='dpTD_notavail'>";
  var TD_holiday = "<td class='dpHoliday'>";
  var TD_EnHoliday = "<td class='dpTD_EnHoliday'";
  var TD_closecal = "<td class='dpTD_closecal' onclick=\"hideDatePicker();\">";

  var topCloseButton = TR_days + TD_notavail + "&nbsp;" + xTD + TD_notavail + "&nbsp;" + xTD + TD_notavail + "&nbsp;" + xTD + TD_notavail + "&nbsp;" + xTD + TD_notavail + "&nbsp;" + xTD + TD_notavail + "&nbsp;" + xTD + TD_closecal + "X" + xTD + xTR;



  var TD_Today = "<td class='dpTD_today' ";
  var TD_DisToday = "<td class='dpTD_disToday'>";


  



/********************* STATIC HTML TO BE WRITTEN ********************************/



function displayDatePicker(dateFieldName)
{	
	var minDt,maxDt;
	var targetDateField = document.getElementById(dateFieldName);
	if(targetDateField.stDate != "")
	{
		minDt = targetDateField.stDate
	}
	if(targetDateField.enDate != "")
	{
		maxDt = targetDateField.enDate
	}
	if(minDt)
	{
		var arrMinDt  = splitDateString(minDt);
		minDate = arrMinDt[0];
		minMonth  = parseInt(arrMinDt[1] - 1);
		minYear = arrMinDt[2];		
		preventPreviousDate = true;
	}
	
	if(maxDt)
	{		
		var arrMaxDt =  splitDateString(maxDt);
		maxDate = arrMaxDt[0];
		maxMonth  = parseInt(arrMaxDt[1] - 1);
		maxYear = arrMaxDt[2];
		preventFutureDate = true;
	}
	if(targetDateField.allowWeekend == "Y")
		allowWeekend = true;
	else
		allowWeekend = false;
   
	currentfield = dateFieldName;
	

  var x = targetDateField.offsetLeft;
  var y = targetDateField.offsetTop + targetDateField.offsetHeight;
  
  
  var parent = targetDateField;
  while (parent.offsetParent) {
  parent = parent.offsetParent;
  x += parent.offsetLeft;
  y += parent.offsetTop;
  }


  drawDatePicker(targetDateField, x, y);
}

function drawDatePicker(targetDateField, x, y)
{ 
  var dt = new Date();

  if (!document.getElementById(datePickerDivID)) {
    // don't use innerHTML to update the body, because it can cause global variables
    // that are currently pointing to objects on the page to have bad references    
    var newNode = document.createElement("div");
    newNode.setAttribute("id", datePickerDivID);
    newNode.setAttribute("class", "dpDiv");
    newNode.setAttribute("style", "visibility: hidden;");
    document.body.appendChild(newNode);
  }
  
  // move the datepicker div to the proper x,y coordinate and toggle the visiblity
  var pickerDiv = document.getElementById(datePickerDivID);
  pickerDiv.style.position = "absolute";
  pickerDiv.style.left = x + "px";
  pickerDiv.style.top = y + "px";
  pickerDiv.style.visibility = (pickerDiv.style.visibility == "visible" ? "hidden" : "visible");
  pickerDiv.style.zIndex = 10000;
  

  if(preventPreviousDate == true)
  {
    checkPastDate(currDate,currMonth,currYear);    
  }
  if(preventFutureDate == true)
  {
    checkFutureDate(currDate,currMonth,currYear);	 
  }
  
  if(scPastDate == true)
  {
		refreshDatePicker(currentfield, minDate, minMonth,minYear);
  }
  else if(scFutureDate == true)
  {
	  if(preventPreviousDate == true)
		refreshDatePicker(currentfield, minDate, minMonth,minYear);
	  else
		refreshDatePicker(currentfield, maxDate, maxMonth,maxYear);
  }
  else
  {
		refreshDatePicker(currentfield, currDate, currMonth,currYear);
  }

 // refreshDatePicker(currentfield, currDate, currMonth,currYear);  
}

//function refreshDatePicker(dateFieldName, year, month, day)
function refreshDatePicker(dateFieldName,cDate, cMonth,cYear)
{  
  var thisDay = new Date();
  
  if ((cMonth >= 0) && (cYear > 0)) {
    thisDay = new Date(cYear, cMonth, 1);
	var day = parseInt(cDate);
  } 
 
  // start generating the code for the calendar table
  var html = TABLE;

  html += topCloseButton; //row for close button on top right corner added


  // this is the title bar, which displays the month and the buttons to
  // go back to a previous month or forward to the next month
  html += TR_title;

  if((preventPreviousDate == true) && (thisDay.getMonth() == minMonth) && (thisDay.getYear() == minYear))
  {
		html += TD_buttons + "&nbsp;" + xTD;
  }
  else
  {
	  html += TD_buttons + getButtonCode(dateFieldName, thisDay, -1, "<B>&lt;</B>") + xTD;
  } 
  html += TD_title + DIV_title + monthArrayLong[thisDay.getMonth()] + " " + thisDay.getFullYear() + xDIV + xTD;

  if((preventFutureDate == true) && (thisDay.getMonth() == maxMonth) && (thisDay.getYear() == maxYear))
  {
		html += TD_buttons + "&nbsp;" + xTD;
  }
  else
  {
	  html += TD_buttons + getButtonCode(dateFieldName, thisDay, 1, "<B>&gt;</B>") + xTD;
  }

  html += xTR;
  
  
  // this is the row that indicates which day of the week we're on
  html += TR_days;
  for(i = 0; i < dayArrayShort.length; i++)
    html += TD_days + dayArrayShort[i] + xTD;
  html += xTR;
  
  // now we'll start populating the table with days of the month
  html += TR;
  
  // first, the leading blanks
  for (i = 0; i < thisDay.getDay(); i++)
    html += TD_notavail + "&nbsp;" + xTD; 	

	var daySeq;
  // now, the days of the month
  do {
		  dayNum = thisDay.getDate();
		  dayNum = parseInt(dayNum);
		  cMonth = parseInt(cMonth);
		  cYear = parseInt(cYear);	  

		//For saturday Sunday marking START
		daySeq = thisDay.getDay();
		//For saturday Sunday marking END

		  checkPastDate(dayNum,cMonth,cYear);		  
		  checkToday(dayNum,cMonth,cYear);
		  checkFutureDate(dayNum,cMonth,cYear)
		  
		  TD_onclick = " onclick=\"updateDateField('" + dateFieldName + "', '" + getDateString(thisDay) + "');\">";
    
		 /* if(daySeq == 0 || daySeq == 6)
		  {
			if(allowWeekend)
				html += TD_EnHoliday + TD_onclick + dayNum + xTD;
			else
				html += TD_holiday + dayNum + xTD;
		  }
		  else*/ if((preventPreviousDate == true) && (preventFutureDate == true))
		  {
			if((scPastDate == true) && (scToday == true))
			{	
				if(daySeq == 0 || daySeq == 6)
				{			
					html += TD_holiday + dayNum + xTD;
				}
				else
				{
				  html += TD_DisToday + dayNum + xTD;
				}
			}
			else if((scPastDate == true) && (scToday == false))
			{	
				if(daySeq == 0 || daySeq == 6)
				{			
					html += TD_holiday + dayNum + xTD;
				}
				else
				{
    				html += TD_notavail + dayNum + xTD;
				}
			} 
			else if((scPastDate == false) && (scToday == true))
			{				
				 if(daySeq == 0 || daySeq == 6)
				 {
					if(allowWeekend)
						html += TD_EnHoliday + TD_onclick + dayNum + xTD;
					else
						html += TD_holiday + dayNum + xTD;
				 }
				 else
					  html += TD_Today + TD_onclick + dayNum + xTD;
			}
			else if((scFutureDate == true) && (scToday == true))
			{			  
				// html += TD_DisToday + dayNum + xTD;
				if(daySeq == 0 || daySeq == 6)
				{			
					html += TD_holiday + dayNum + xTD;
				}
				else
				{
				  html += TD_DisToday + dayNum + xTD;
				}
			}
			else if((scFutureDate == true) && (scToday == false))
			{			  
				//html += TD_notavail + dayNum + xTD;
				if(daySeq == 0 || daySeq == 6)
				{			
					html += TD_holiday + dayNum + xTD;
				}
				else
				{
    				html += TD_notavail + dayNum + xTD;
				}
			}
			else if((scFutureDate == false) && (scToday == true))
			{		 
				//html += TD_Today + TD_onclick + dayNum + xTD;
				 if(daySeq == 0 || daySeq == 6)
				 {
					if(allowWeekend)
						html += TD_EnHoliday + TD_onclick + dayNum + xTD;
					else
						html += TD_holiday + dayNum + xTD;
				 }
				 else
					  html += TD_Today + TD_onclick + dayNum + xTD;
			}
			else
			{
				if(daySeq == 0 || daySeq == 6)
		        {
					if(allowWeekend)
						html += TD_EnHoliday + TD_onclick + dayNum + xTD;
					else
						html += TD_holiday + dayNum + xTD;
				}
				else
						html += TD + TD_onclick + dayNum + xTD;
			}	
		  }
		  else if((preventPreviousDate == true) && (preventFutureDate == false))
		  {	  
			  /*if((scPastDate == true) && (scToday == true))
			  {			  
				  html += TD_DisToday + dayNum + xTD;
			  }
			  else if((scPastDate == true) && (scToday == false))
			  {		
				  html += TD_notavail + dayNum + xTD;
			  }
			  else if((scPastDate == false) && (scToday == true))
			  {		 
				  html += TD_Today + TD_onclick + dayNum + xTD;
			  }*/	
			    if((scPastDate == true) && (scToday == true))
				{	
					if(daySeq == 0 || daySeq == 6)
					{			
						html += TD_holiday + dayNum + xTD;
					}
					else
					{
					  html += TD_DisToday + dayNum + xTD;
					}
				}
				else if((scPastDate == true) && (scToday == false))
				{	
					if(daySeq == 0 || daySeq == 6)
					{			
						html += TD_holiday + dayNum + xTD;
					}
					else
					{
						html += TD_notavail + dayNum + xTD;
					}
				} 
				else if((scPastDate == false) && (scToday == true))
				{				
					 if(daySeq == 0 || daySeq == 6)
					 {
						if(allowWeekend)
							html += TD_EnHoliday + TD_onclick + dayNum + xTD;
						else
							html += TD_holiday + dayNum + xTD;
					 }
					 else
						  html += TD_Today + TD_onclick + dayNum + xTD;
				}	
				else
			    {
					if(daySeq == 0 || daySeq == 6)
					 {
						if(allowWeekend)
							html += TD_EnHoliday + TD_onclick + dayNum + xTD;
						else
							html += TD_holiday + dayNum + xTD;
					 }
					 else
						html += TD + TD_onclick + dayNum + xTD;
			    } 	
		  }
		  else if((preventPreviousDate == false) && (preventFutureDate == true))
		  {	  
			  
			 /* if((scFutureDate == true) && (scToday == true))
			  {			  
				  html += TD_DisToday + dayNum + xTD;
			  }
			  else if((scFutureDate == true) && (scToday == false))
			  {		
				  html += TD_notavail + dayNum + xTD;
			  }
			  else if((scFutureDate == false) && (scToday == true))
			  {		 
				  html += TD_Today + TD_onclick + dayNum + xTD;
			  }*/
				if((scFutureDate == true) && (scToday == true))
				{			  
					// html += TD_DisToday + dayNum + xTD;
					if(daySeq == 0 || daySeq == 6)
					{			
						html += TD_holiday + dayNum + xTD;
					}
					else
					{
					  html += TD_DisToday + dayNum + xTD;
					}
				}
				else if((scFutureDate == true) && (scToday == false))
				{			  
					//html += TD_notavail + dayNum + xTD;
					if(daySeq == 0 || daySeq == 6)
					{			
						html += TD_holiday + dayNum + xTD;
					}
					else
					{
						html += TD_notavail + dayNum + xTD;
					}
				}
				else if((scFutureDate == false) && (scToday == true))
				{		 
					//html += TD_Today + TD_onclick + dayNum + xTD;
					 if(daySeq == 0 || daySeq == 6)
					 {
						if(allowWeekend)
							html += TD_EnHoliday + TD_onclick + dayNum + xTD;
						else
							html += TD_holiday + dayNum + xTD;
					 }
					 else
						  html += TD_Today + TD_onclick + dayNum + xTD;
				}
			    else
			    {
					if(daySeq == 0 || daySeq == 6)
					 {
						if(allowWeekend)
							html += TD_EnHoliday + TD_onclick + dayNum + xTD;
						else
							html += TD_holiday + dayNum + xTD;
					 }
					 else
						html += TD + TD_onclick + dayNum + xTD;
			    }	  
		  }
		  else
		  {	  
			  if(scToday == true)
			  {
					html += TD_Today + TD_onclick + dayNum + xTD;
			  }
			  else
			  {
					html += TD + TD_onclick + dayNum + xTD;
			  }
		  }
		  
		  // if this is a Saturday, start a new row
		  if (thisDay.getDay() == 6)
			 html += xTR + TR;

		  // increment the day
		  thisDay.setDate(thisDay.getDate() + 1);
	
  } while (thisDay.getDate() > 1)

  // fill in any trailing blanks
  if (thisDay.getDay() > 0) {
    for (i = 6; i > thisDay.getDay(); i--)
     html += TD_notavail + "&nbsp;" + xTD;	 
  }
  html += xTR;
 
  // and finally, close the table
  html += xTABLE;
  
  document.getElementById(datePickerDivID).innerHTML = html;
  // add an "iFrame shim" to allow the datepicker to display above selection lists
  adjustiFrame();
}

function adjustiFrame(pickerDiv, iFrameDiv)
{
  if (!document.getElementById(iFrameDivID)) {
    // don't use innerHTML to update the body, because it can cause global variables
    // that are currently pointing to objects on the page to have bad references
    //document.body.innerHTML += "<iframe id='" + iFrameDivID + "' src='javascript:false;' scrolling='no' frameborder='0'>";
    var newNode = document.createElement("iFrame");
    newNode.setAttribute("id", iFrameDivID);
    newNode.setAttribute("src", "javascript:false;");
    newNode.setAttribute("scrolling", "no");
    newNode.setAttribute("frameborder", "0");
    document.body.appendChild(newNode);
  }
  
  if (!pickerDiv)
    pickerDiv = document.getElementById(datePickerDivID);
  if (!iFrameDiv)
    iFrameDiv = document.getElementById(iFrameDivID);
  
  try {
    iFrameDiv.style.position = "absolute";
    iFrameDiv.style.width = pickerDiv.offsetWidth;
    iFrameDiv.style.height = pickerDiv.offsetHeight;
    iFrameDiv.style.top = pickerDiv.style.top;
    iFrameDiv.style.left = pickerDiv.style.left;
    iFrameDiv.style.zIndex = pickerDiv.style.zIndex - 1;
    iFrameDiv.style.visibility = pickerDiv.style.visibility;
  } catch(e) {
  }
}


function getButtonCode(dateFieldName, dateVal, adjust, label)
{
  var newMonth = (dateVal.getMonth() + adjust) % 12;
  var newYear = dateVal.getFullYear() + parseInt((dateVal.getMonth() + adjust) / 12);
  if (newMonth < 0) {
    newMonth += 12;
    newYear += -1;
  }
  return "<button class='dpButton' onClick='refreshDatePicker(\"" + dateFieldName + "\",  1 , " + newMonth + ", " + newYear + ");'><B>" + label + "</B></button>";
}

function getDateString(dateVal)
{
	
  var dayString = "00" + dateVal.getDate();
  var monthString = "00" + (dateVal.getMonth()+1);
  dayString = dayString.substring(dayString.length - 2);
  monthString = monthString.substring(monthString.length - 2);
  
  switch (dateFormat) {
    case "dmy" :
      //return dayString + dateSeparator + monthString + dateSeparator + dateVal.getFullYear();
      return dayString + dateSeparator + monthArrayShort[monthString - 1] + dateSeparator + dateVal.getFullYear();
    case "ymd" :
     // return dateVal.getFullYear() + dateSeparator + monthString + dateSeparator + dayString;
      return dateVal.getFullYear() + dateSeparator + monthArrayShort[monthString - 1] + dateSeparator + dayString;
    case "mdy" :
    default :
      //return monthString + dateSeparator + dayString + dateSeparator + dateVal.getFullYear();
      return monthArrayShort[monthString - 1] + dateSeparator + dayString + dateSeparator + dateVal.getFullYear();
  }
}

function splitDateString(dateString)
{
	
  var dArray;
  if (dateString.indexOf("/") >= 0)
    dArray = dateString.split("/");
  else if (dateString.indexOf(".") >= 0)
    dArray = dateString.split(".");
  else if (dateString.indexOf("-") >= 0)
    dArray = dateString.split("-");
  else if (dateString.indexOf("\\") >= 0)
    dArray = dateString.split("\\");
  else
    dArray = false;
  
  return dArray;
}


function hideDatePicker()
{		
	var newNode = document.getElementById(datePickerDivID);	
	var newNode1 = document.getElementById(iFrameDivID);
	if(newNode1)
	{				
		document.body.removeChild(newNode);
		document.body.removeChild(newNode1);
	}	
	try{
		doDateDependentChanges();
	}
		catch (err){
		//return false;
		}
}



function checkToday(chDate,chMonth,chYear)
{
	if((chDate == currDate) && (chMonth == currMonth) && (chYear == currYear))
	{
		scToday =  true;		
	}
	else
	{
		scToday =  false;
	}
	return scToday;
}

function checkFutureDate(chDate,chMonth,chYear)
{	
	scFutureDate = false;
	var fdate,fmonth,fyear;
	if(chDate < maxDate)
		fdate = -1;
	else if(chDate == maxDate)
		fdate = 0;
	else
		fdate = 1;

	if(chMonth < maxMonth)
		fmonth = -1;
	else if(chMonth == maxMonth)
		fmonth = 0;
	else
		fmonth = 1;

	if(chYear < maxYear)
		fyear = -1;
	else if(chYear == maxYear)
		fyear = 0;
	else
		fyear = 1;

	var cmpString = fdate.toString() + fmonth.toString() + fyear.toString();

	switch (cmpString)
	{
		case "-1-11":
		  scFutureDate = true;
		  break
		case "-101":
		  scFutureDate = true;
		  break
		case "-110":
		  scFutureDate = true;
		  break
		case "-111":
		  scFutureDate = true;
		  break
		case "0-11":
		  scFutureDate = true;
		  break
		case "001":
		  scFutureDate = true;
		  break
		case "010":
		  scFutureDate = true;
		  break
		case "011":
		  scFutureDate = true;
		  break
		case "1-11":
		  scFutureDate = true;
		  break
		case "100":
		  scFutureDate = true;
		  break
		case "101":
		  scFutureDate = true;
		  break
		case "110":
		  scFutureDate = true;
		  break
		case "111":
		  scFutureDate = true;
		  break
		default:
		  scFutureDate = false;
	}	
	return scFutureDate;
}

function checkPastDate(chDate,chMonth,chYear)
{	
	minDate = parseInt(minDate);
	minMonth = parseInt(minMonth);
	minYear = parseInt(minYear);

	scPastDate = false;
	var pdate = -2;
	var pmonth = -2;
	var pyear = -2;

	if(chDate < minDate)
		pdate = -1;
	else if(chDate == minDate)
		pdate = 0;
	else
		pdate = 1;

	if(chMonth < minMonth)
		pmonth = -1;
	else if(chMonth == minMonth)
		pmonth = 0;
	else
		pmonth = 1;

	if(chYear < minYear)
		pyear = -1;
	else if(chYear == minYear)
		pyear = 0;
	else
		pyear = 1;

	var cmpString = pdate.toString() + pmonth.toString() + pyear.toString();		
	switch (cmpString)
	{
		case "-1-1-1":
		  scPastDate = true;
		  break
		case "-1-10":
		  scPastDate = true;
		  break
		case "-10-1":
		  scPastDate = true;
		  break
		case "-100":
		  scPastDate = true;
		  break
		case "-11-1":
		  scPastDate = true;
		  break
		case "0-1-1":
		  scPastDate = true;
		  break
		case "0-10":
		  scPastDate = true;
		  break
		case "00-1":
		  scPastDate = true;
		  break
		case "01-1":
		  scPastDate = true;
		  break
		case "1-1-1":
		  scPastDate = true;
		  break
		case "1-10":
		  scPastDate = true;
		  break
		case "10-1":
		  scPastDate = true;
		  break
		case "11-1":
		  scPastDate = true;
		  break
		default:
		  scPastDate = false;
	}	
	return scPastDate;
}



function updateDateField(dateFieldName, dateString)
{
  var targetDateField = document.getElementById(dateFieldName);
  if (dateString)
    targetDateField.value = dateString;
  document.getElementById(datePickerDivID).style.visibility = "hidden";
  adjustiFrame();
  targetDateField.focus();
  
  // after the datepicker has closed, optionally run a user-defined function called
  // datePickerClosed, passing the field that was just updated as a parameter
  // (note that this will only run if the user actually selected a date from the datepicker)
  if ((dateString) && (typeof(datePickerClosed) == "function"))
    datePickerClosed(targetDateField);


  try{
		doDateDependentChanges();
	}
		catch (err){
		//return false;
		}
}

//function to get maximum number of days in current month
function getMaxDaysMonth()
{
	var returnvalue;
	switch (currMonth)
	{
		case 2:
			if((currYear % 4) == 0)
			{
				returnvalue = 29;
			}
			else
			{
				returnvalue = 28;
			}
		  break			 
		case 4:
			returnvalue = 30;
		  break
		case 6:
			returnvalue = 30;
		  break
        case 9:
			returnvalue = 30;
		  break
	    case 11:
			returnvalue = 30;
		  break
		case 1:
			returnvalue = 31;
		  break
	    case 3:
			returnvalue = 31;
		  break
	    case 5:
			returnvalue = 31;
		  break
		case 7:
			returnvalue = 31;
		  break
		case 8:
			returnvalue = 31;
		  break
		case 10:
			returnvalue = 31;
		  break
		case 12:
			returnvalue = 31;
		  break
		
		default:
		  alert("Error month value not proper " + currMonth);
		  return false;
	}
		return returnvalue;
}

// function to set the date to be used as starting date or the current date
function setUseDate(daySpan)
{	
	if((daySpan) && (!isNaN(daySpan)) && (daySpan > 0))
	{
		preventPreviousDate = true;
		var datespansum = parseInt(currDate + daySpan);
		if (datespansum > getMaxDaysMonth())
		{
			useDate =  datespansum - getMaxDaysMonth();
			if(currMonth == 12)
			{
				useMonth =  1;			
				useYear = currYear + 1;
			}
			else
			{
				useMonth =  currMonth + 1;			
				useYear = currYear;
			}			
		}
		else
		{
			useDate =  datespansum;
			useMonth =  currMonth;
			useYear = currYear;	
		}		
	}
	else
	{
		useDate =  currDate;
		useMonth =  currMonth;
		useYear = currYear;
	}	
}





