var theCurrentDate = new Date(); 
var theDueDate;  


function My_CreateCalendar(parmDueDate) {
	var thisHTML = '';
	var thisCode = '';

	if (parmDueDate == 'init') {
		<!--	document.getElementById("My_CalInst").style.display='block';-->
		theDueDate = new Date(theCurrentDate);
		theDueDate.setMonth(theDueDate.getMonth() - 12);
	} else {
		<!--document.getElementById("My_CalInst").style.display='none';-->
		document.getElementById("My_CalRDV").style.display='block';
		theDueDate = new Date(parmDueDate);
		var conceptionDate=new Date(theDueDate.getUTCFullYear(),theDueDate.getMonth(),theDueDate.getDate()-266);
		var currDate=new Date();
		var diffDate = currDate-conceptionDate;
	    var dayInMsecs = 24 * 60 * 60 * 1000;
	    var diffWeeks = Math.round(diffDate / (dayInMsecs*7));
	    
	    diffWeeks=diffWeeks+1;
	    document.getElementById("spanPregWeek").innerHTML=message2+diffWeeks+message;
	}

	thisHTML = '';
	for (idxRow = 0; idxRow < 3; idxRow++) {
		thisHTML += '<div class="My_CalRow">';
		for (idxCol = 1; idxCol < 4; idxCol++) {
			thisHTML += '<div class="My_CalCol' + idxCol + '">' + My_CreateMonth(idxRow * 3 + idxCol) + '</div>';
		}
		thisHTML += '</div>';
	}
	document.getElementById("My_Calendar").innerHTML = thisHTML;
	
}

function My_CreateMonth(parmMonthNum) {
	var thisHTML = '';
	var thisFullDate = new Date(theCurrentDate);
	var tempFullDate;
	var thisYear;
	var thisMonth = thisFullDate.getMonth() + parmMonthNum - 1;
	var thisDate;
	var thisWeekDay;
	thisFullDate.setDate(1);
	thisFullDate.setMonth(thisMonth);
	thisMonth = thisFullDate.getMonth();
	thisYear = thisFullDate.getFullYear();
	thisHTML = '<table border="0" cellspacing="0" cellpadding="0" class="My_CalMonth">';
	thisHTML += '<tr"><td height="16" align="center" colspan="7" class="My_CalMonthTitle">' + theMonths[thisMonth]  + '&nbsp;&nbsp;' + thisYear + '</td></tr>';
	thisHTML += '<tr>';
	for (idxWeekday=0; idxWeekday < 7; idxWeekday++) {
		thisHTML += '<td height="16" align="center" class="My_CalDayHdg">' + theDays[idxWeekday] + '</td>';
	}
	thisHTML += '</tr>';
	thisWeekday = thisFullDate.getDay();
	if (thisWeekday > 0) {
		thisHTML += '<tr class="My_CalDateRow">';
		for (idxWeekday=0; idxWeekday < thisWeekday; idxWeekday++) {
			thisHTML += '<td height="16" align="center" class="My_CalDateBlank">&nbsp;</td>';
		}
	}
	tempFullDate = new Date(thisFullDate);
	tempFullDate.setMonth(tempFullDate.getMonth() + 1);
	tempFullDate.setDate(0);
	thisDaysInMonth = tempFullDate.getDate();
	for (idxDate=0; idxDate < thisDaysInMonth; idxDate++) {
		thisDate = thisFullDate.getDate();
		thisWeekday = thisFullDate.getDay();
		if (thisWeekday == 0) {
			thisHTML += '<tr class="My_CalDateRow">';
		}
		thisHTML += "<td align='center' class='My_CalDate" + My_SetStyle(thisFullDate, theDueDate) + "' onclick='My_CreateCalendar(\"" + thisFullDate + "\");'";
		if (parmMonthNum == 1 & thisFullDate.toDateString() == theCurrentDate.toDateString()) { // Ignore time differences
			thisHTML += " id='My_CalDateToday'";
		}
		thisHTML += ">" + thisDate + "</td>";
		if (thisWeekday == 6) {
			thisHTML += '</tr>';
		}
		thisFullDate.setDate(thisDate+1);
	}
	thisWeekday = thisFullDate.getDay();
	if (thisWeekday > 0) {
		for (idxWeekday=thisWeekday; idxWeekday < 7; idxWeekday++) {
			thisHTML += '<td align="center" class="My_CalDateBlank">&nbsp;</td>';
		}
		thisHTML += '</tr>';
	}
	thisHTML += '</table>';
	return thisHTML;
}
function My_SetStyle(parmFullDate, parmDueDate) {
	var styleSuffix = '';
	var conceptionDate=new Date(parmDueDate.getUTCFullYear(),parmDueDate.getMonth(),parmDueDate.getDate()-265);
	var diffDate = parmFullDate-conceptionDate;
	var dayInMsecs = 24 * 60 * 60 * 1000;
	var diffDays = Math.round(diffDate / dayInMsecs);
	if (diffDays < 0) {
		return styleSuffix;
	}
	if (diffDays == 266) {
		styleSuffix = 'Due';
		return styleSuffix;
	}
	if(diffDays>=112 && diffDays<=147)
		styleSuffix = 'Gender';
	else if(diffDays>=169 && diffDays<=202)
	    styleSuffix = 'Best';
	else if(diffDays>=148 && diffDays<=217)
	    styleSuffix = 'Good';
	else if(diffDays>=218 && diffDays<=245)
	    styleSuffix = 'Poor';
	
	return styleSuffix;
}