function BlurMe()
{

document.getElementById("ChoiceDate1").blur();
document.getElementById("ChoiceDate2").blur();
}

function show_calendar2(str_target, str_datetime,strdates,selectedDate)
{
	//alert("Selected Date:"+selectedDate)
	var strLen=str_datetime.length;
	var str_datetime=str_datetime;
	if (strLen >11)
	{
		var str_datetime1=str_datetime.substring(4,str_datetime.length);
		var str_datetimeMonth=str_datetime1.substring(0,3);
		str_datetime1=str_datetime1.substring(4,str_datetime1.length);
		var str_datetimeDay=str_datetime1.substring(0,str_datetime1.indexOf("-"));
		var strdatetimeYear=(str_datetime1.substring(str_datetime1.indexOf("-")+1,str_datetime1.length));
		str_datetime=str_datetimeDay + "-" + str_datetimeMonth + "-" + strdatetimeYear;
		//alert(str_datetime);
	} 
	
	strLen=selectedDate.length;
	var selectedDate=selectedDate;
	if (strLen >11)
	{
		var selectedDate1=selectedDate.substring(4,selectedDate.length);
		var selectedDateMonth=selectedDate1.substring(0,3);
		selectedDate1=selectedDate1.substring(4,selectedDate1.length);
		var selectedDateDay=selectedDate1.substring(0,selectedDate1.indexOf("-"));
		var selectedDateYear=(selectedDate1.substring(selectedDate1.indexOf("-")+1,selectedDate1.length));
		selectedDate=selectedDateDay + "-" + selectedDateMonth + "-" + selectedDateYear;
		//alert("Selected Date:"+selectedDate);
	} 
	
	var arr_months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
	var week_days = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
	var n_weekstart = 0; // day week starts from (normally 0 or 1)
	
	var dt_selectedDate = (selectedDate == null || selectedDate =="" ? new Date() : str2dt2(selectedDate));
	var dt_datetime = (str_datetime == null || str_datetime =="" ?  new Date() : str2dt2(str_datetime));
	var dt_prev_month = new Date(dt_datetime);
	dt_prev_month.setMonth(dt_datetime.getMonth()-1);
	if (dt_datetime.getMonth()%12 != (dt_prev_month.getMonth()+1)%12) {
		dt_prev_month.setMonth(dt_datetime.getMonth());
		dt_prev_month.setDate(0);
	}
	var dt_next_month = new Date(dt_datetime);
	dt_next_month.setMonth(dt_datetime.getMonth()+1);
	if ((dt_datetime.getMonth() + 1)%12 != dt_next_month.getMonth()%12)
		dt_next_month.setDate(0);
	
	var dt_firstday = new Date(dt_datetime);
	dt_firstday.setDate(1);
	dt_firstday.setDate(1-(7+dt_firstday.getDay()-n_weekstart)%7);
	var dt_lastday = new Date(dt_next_month);
	dt_lastday.setDate(0);
	
	// html generation (feel free to tune it for your particular application)
	// print calendar header
	var str_buffer = new String (
		"<html>\n"+
		"<head>\n"+
		"	<title>Calendar</title>\n <link rel=\"stylesheet\" href=\"css/cssCAL.css\"></link>"+
		"</head>\n"+
		"<body bgcolor=\"White\">\n"+
		"<table class=\"clsOTable\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"+
		"<tr><td bgcolor=\"#\">\n"+
		"<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"100%\">\n"+
		"<tr>\n	<td bgcolor=\"Black\">");
	var today	=	new Date();
	if (dt_prev_month.getMonth()< today.getMonth() && dt_prev_month.getFullYear()<=today.getFullYear())
		str_buffer +="<font color=\"white\" face=\"Georgia, Times New Roman, Times, serif\" size=\"1\"><strong><<</strong></font>"+
		"</td>\n";
	else
		str_buffer +="<a href=\"javascript:window.opener.show_calendar2('"+
		str_target+"', '"+ dt2dtstr2(dt_prev_month)+"','"+strdates+"','"+selectedDate+"');\">"+
		"<font color=\"white\" face=\"Georgia, Times New Roman, Times, serif\" size=\"1\"><strong><<</strong></font>"+
		"</a></td>\n";
	str_buffer +="	<td bgcolor=\"Black\" colspan=\"5\" align=\"center\">"+
		"<font color=\"white\" face=\"Georgia, Times New Roman, Times, serif\" size=\"2\"><strong>"
		+arr_months[dt_datetime.getMonth()]+" "+dt_datetime.getFullYear()+"</font></strong></td>\n"+
		"	<td bgcolor=\"Black\" align=\"right\"><a href=\"javascript:window.opener.show_calendar2('"
		+str_target+"', '"+dt2dtstr2(dt_next_month)+"','"+strdates+"','"+selectedDate+"');\">"+
		"<font color=\"white\" face=\"Georgia, Times New Roman, Times, serif\" size=\"1\"><strong>>></strong></font>"+
		"</a></td>\n</tr>\n"
	

	var dt_current_day = new Date(dt_firstday);
	var dt_today		=new Date()
	// print weekdays titles
	str_buffer += "<tr>\n";
	for (var n=0; n<7; n++)
		str_buffer += "	<td bgcolor=\"#d3d3d3\">"+
		"<font color=\"Black\" face=\"Georgia, Times New Roman, Times, serif\" size=\"2\"><strong>"+
		week_days[(n_weekstart+n)%7]+"</strong></font></td>\n";
	// print calendar table
	str_buffer += "</tr>\n";
	while (dt_current_day.getMonth() == dt_datetime.getMonth() ||
		dt_current_day.getMonth() == dt_firstday.getMonth()) {
		// print row heder
		str_buffer += "<tr>\n";
		for (var n_current_wday=0; n_current_wday<7; n_current_wday++) {
				if(check_blackOutDate(dt_current_day,strdates))
					str_buffer += "	<td bgcolor=\"#AAAAAA\" align=\"right\"";
				else if(selectedDate !="" && selectedDate != null && (dt_current_day.getDate() == dt_selectedDate.getDate() &&
					dt_current_day.getMonth() == dt_selectedDate.getMonth() && dt_current_day.getFullYear()==dt_selectedDate.getFullYear()))
					// print selected date
					str_buffer += "	<td bgcolor=\"#dbc0b9\" align=\"right\"";  
				else if (dt_current_day.getDate() == dt_today.getDate() && 
					dt_current_day.getMonth() == dt_today.getMonth() && dt_current_day.getFullYear()==dt_today.getFullYear())
					// print current date
					str_buffer += "	<td bgcolor=\"white\" align=\"right\"";  
				else if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6)
					// weekend days
					str_buffer += "	<td bgcolor=\"#eee9e9\" align=\"right\" ";   
				else
					// print working days of current month
					str_buffer += "	<td bgcolor=\"white\" align=\"right\" ";        
				//  To disable blackout dates given in config file
				if(check_blackOutDate(dt_current_day,strdates)==false)
				
					str_buffer += " class=\"textCal\" onclick=\"javascript:window.opener."+str_target+
						".value='"+dt2dtstr2NEW(dt_current_day)+"';window.opener."+str_target+".focus();window.close();\">";
				else
					str_buffer += ">";
					
					
				if (dt_current_day.getMonth() == dt_datetime.getMonth())  {
					// print days of current month
					
					//alert('hello IF--'+dt2dtstr2(dt_current_day));
					if(check_blackOutDate(dt_current_day,strdates)==false)
						str_buffer += "<a class=\"WeekEnd\" href=\"javascript:window.opener."+str_target+
						".value='"+dt2dtstr2NEW(dt_current_day)+"';window.opener."+str_target+".focus();window.close();\">"+
						"<font color=\"#5B041A\" face=\"Georgia, Times New Roman, Times, serif\" size=\"2\"  >";
					else if (dt_current_day.getDate() == dt_today.getDate() && dt_current_day.getMonth() == dt_today.getMonth() && dt_current_day.getFullYear()==dt_today.getFullYear())
						str_buffer += "<font color=\"#5B041A \" face=\"Georgia, Times New Roman, Times, serif\"  size=\"2\">";																		  
					else
						str_buffer += "<font color=\"#333333\" face=\"Georgia, Times New Roman, Times, serif\"  size=\"2\">";
					
					}
				else {
					// print days of other months
					
					if(check_blackOutDate(dt_current_day,strdates)==false)
						str_buffer += "<a href=\"javascript:window.opener."+str_target+
						".value='"+dt2dtstr2NEW(dt_current_day)+"';window.opener."+str_target+".focus();window.close();\">"+
						"<font color=\"#5B041A\" face=\"Georgia, Times New Roman, Times, serif\" size=\"2\">";
					else
						str_buffer += "<font color=\"#333333\" face=\"Georgia, Times New Roman, Times, serif\" Text-Decoration=\"Underlined\" size=\"2\">";
					
				}
				str_buffer += dt_current_day.getDate()+"</font></a></td>\n";
				dt_current_day.setDate(dt_current_day.getDate()+1);
		}
		// print row footer
		str_buffer += "</tr>\n";
	}
	// print calendar footer
	str_buffer +=
		"</table>\n" +
		"</tr>\n</td>\n</table>\n" +
		"</body>\n" +
		"</html>\n";

	var vWinCal = window.open("", "Calendar", 
		"width=200,height=250,status=no,resizable=no,top=600,left=850");
	vWinCal.opener = self;
	vWinCal.focus();
	var calc_doc = vWinCal.document;
	calc_doc.write (str_buffer);
	calc_doc.close();
}
// datetime parsing and formatting routimes. modify them if you wish other datetime format
function str2dt2 (str_datetime) {
	var arr_months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
	//var re_date = /^(\d+)\/(\d+)\/(\d+)$/;
	var re_date = /^(\d+)\-([a-zA-Z]+)\-(\d+)$/;
	if (!re_date.exec(str_datetime))
		return alert("Invalid Datetime format: "+ str_datetime);
	//return (new Date (RegExp.$3, RegExp.$2-1, RegExp.$1));
	
	for (var i= 0; i < 12; i++){
		if (arr_months[i] == RegExp.$2){
			return (new Date(RegExp.$3, i, RegExp.$1));
		}
	}
	return alert("Invalid Datetime format: "+ str_datetime);
}
function dt2dtstr2 (dt_datetime) {
	var arr_months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
		
	return (new String (
			dt_datetime.getDate() + "-"+ arr_months[dt_datetime.getMonth()] + "-"+dt_datetime.getFullYear()));
}

function dt2dtstr2NEW (dt_datetime) {
	var arr_months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
	var arr_days = ["Sun","Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
				
	return (new String (
			arr_days[dt_datetime.getDay()] + "-"+ arr_months[dt_datetime.getMonth()] + "-"+ dt_datetime.getDate() + "-" + dt_datetime.getFullYear()));
}

// check for blackout date
function check_blackOutDate(seldate,blackoutDates)
{
	
	var intDay=seldate.getDay();
	var seldate=dt2dtstr2(seldate);
	var arrblackoutDates=new Array()
	arrblackoutDates=blackoutDates.split(',');
	var i=0; 
	for (i=0;i<arrblackoutDates.length; i++)
	{
		if ((arrblackoutDates[i].toString().toLowerCase())==(seldate.toLowerCase()) )
			return true;
		else if ((blackoutDates.toLowerCase()).indexOf('false')>=0 && (intDay==6 || intDay==0))
			return true;
		
	}
	return false;
	
}
