var calendar = new Class({
	options: {
		date: new Date(),
		minDate: new Date(),
		maxDate: new Date(9999,11,1),
		disableDays: [],
		format: "d/m/y",
		mondayFirst: false,
		showTransDays: false,
		selectBirthDay: false,
		days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
		fulldays: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
		months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
		assignTo: "",
		onChange: Class.empty,
		onSelect: Class.empty,
		onReleaseOutSide: Class.empty,
		
		// class variables
		activeDate: Class.empty,
		activeWeek: Class.empty,
		activeControl: Class.empty,
		calYear: 0
	},

	// init calendar
	initialize: function(id, options){
		// generate holder
		this.holder = $(id);		
		this.holderIframe = $(id+'iframe');
		if(!this.holderIframe) {
			this.holderIframe = new Element("iframe" ).setProperties({
				frameborder: "no",
				"id" : id+'iframe'	
			}).setStyles({
				filter:'alpha(opacity=0)',
				overflow: "hidden",
				position: "absolute", 
				top: "-1000px", 
				left: "-1000px",
				"z-index": "998"
			});
			this.holderIframe.injectInside($$('body')[0]);
		}		
		if (!this.holder) {
			this.holder = new Element("div", {
				"id": id
			}).inject(document.body);
		}
		this.holder.addClass("calendar");
		//
		this.setOptions(options);
		this.generateCalendar();
	},
	
	generateCalendar: function(){
		// empty holder
		this.holder.empty();
		
		// set holder 
		this.setHolder();
		
		// create calendar title
		this.generateTitle();
		
		// create table
		this.generateTable();
		
		// set month selector
		this.setMonthSelector();
		
		// create popup calendar
		if (this.options.assignTo != "") {
			this.assignPopup();
		}
	},
	
	setHolder: function(){
		var fn = this;
		//
		document.addEvent("mouseup", function(e){
			var evt = new Event(e);
			try {
				if (!$(evt.target).isChildOf(fn.holder)) {
					fn.fireEvent("onReleaseOutSide", fn.holder);
				}
			} catch (err) {}
		});
	},
	
	generateTitle: function(){
		var fn = this;
		var ul = new Element("ul", {
			"class": "calendarTitle"
		}).inject(this.holder);
		var li = new Array();
		
		// create list
		for (var i = 0; i<5; i++) {
			li[i] = new Element("li").addClass("title"+i).inject(ul);
		}
		
		// set buttons
		var scrollYearLeft = new Element("a", {
			"href": "javascript:;",
			"class": "scrollYearLeft",
			"html": "<span>&laquo;</span>",
			"events": {
				"click": function(e){
					e.stop();
					fn.previousYear();
				}
			}
		}).inject(li[0]);
		
		var scrollMonthLeft = new Element("a", {
			"href": "javascript:;",
			"class": "scrollMonthLeft",
			"html": "<span>&lt;</span>",
			"events": {
				"click": function(e){
					e.stop();
					fn.previousMonth();
				}
			}
		}).inject(li[1]);
		
		var scrollYearRight = new Element("a", {
			"href": "javascript:;",
			"class": "scrollYearRight",
			"html": "<span>&raquo;</span>",
			"events": {
				"click": function(e){
					e.stop();
					fn.nextYear();
				}
			}
		}).inject(li[4]);
		
		var scrollMonthRight = new Element("a", {
			"href": "javascript:;",
			"class": "scrollMonthRight",
			"html": "<span>&gt;</span>",
			"events": {
				"click": function(e){
					e.stop();
					fn.nextMonth();
				}
			}
		}).inject(li[3]);
		
		var arrMonth = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
		// set month control
		if(this.options.assignTo == "calDateMyPlanNew") {
			var _MONTH = arrMonth[this.options.date.getMonth()];			
		} else if(this.options.assignTo == "calDateInitiative") {
			var _MONTH = arrMonth[this.options.date.getMonth()];			
		} else {
			var _MONTH = arrMonth[this.options.months[this.options.date.getMonth()].toInt()-1];
		}
		
		var currentMonth = new Element("a", {
			"href": "javascript:;",
			"class": "currentDate",
			//"html": arrMonth[this.options.months[this.options.date.getMonth()].toInt()-1],
			"html": _MONTH,
			"events": {
				"click": function(e){
					e.stop();
					fn.hideDateSelector();
					fn.showMonthSelector();
				}
			}
		}).inject(li[2]);

		// set year control
		/*new Element("span", {
			"html": ", "
		}).inject(li[2]);*/
		var currentYear = new Element("a", {
			"href": "javascript:;",
			"class": "currentDate",
			"html": this.options.date.getFullYear(),
			"events": {
				"click": function(e){
					e.stop();
					fn.options.calYear = fn.options.date.getFullYear();
					fn.hideDateSelector();
					fn.showYearSelector();
				}
			}
		}).inject(li[2]);
	},
	
	generateTable: function(){
		var table = new Element("table", {
			"class": "calendarData",
			"cellspacing": 0,
			"cellpadding": 0
		}).inject(this.holder);
		
		// create header
		var thead = new Element("thead").inject(table);
		var headTr = new Element("tr").inject(thead);
		for (var i = 0; i<7; i++) {
			new Element("th", {
				"scope": "col",
				"html": (this.options.mondayFirst == false) ? this.options.days[i] : (i != 6) ? this.options.days[i+1] : this.options.days[0]
			}).inject(headTr);
		}
		
		// create calendar data
		var fn = this;
		var tbody = new Element("tbody").inject(table);
		for (i = 0; i<this.getTotalRow(); i++) {
			var bodyTr = new Element("tr", {
				"events": {
					"mouseenter": function(e) {
						$(this).addClass("weekHover");
					},
					"mouseleave": function(e) {
						$(this).removeClass("weekHover");
					}
				}
			}).inject(tbody);
			for (var j = 0; j<7; j++) {
				
				// calculate date value
				var dateValue = i*7+j-this.getFirstDayIndex()+1;
				var cellValue = (dateValue <= 0) ? (this.getPreviousTotalDays()+dateValue) : (dateValue > this.getTotalDays()) ? (dateValue - this.getTotalDays()) : dateValue;		
				var cellDate = new Date(this.options.date.getFullYear(), (dateValue <= 0) ? this.options.date.getMonth() - 1 : (dateValue > this.getTotalDays()) ? this.options.date.getMonth() + 1 : this.options.date.getMonth(), cellValue);
				var cell = new Element("td").inject(bodyTr);
				var cellLink = new Element("a", {
					"href": "javascript:;",
					"text": cellValue,
					"events": {
						"click": function(e){
							e.stop();
							fn.onSelect(this);
						}
					}
				}).inject(cell);
				cellLink.store("date", cellDate);
				
				// today
				if (this.isToday(cellDate)) {
					cellLink.addClass("today");
					this.activeWeek = bodyTr.addClass("currentWeek");
				}
				
				// sunday & saturday
				if (cellDate.getDay() == 0) {
					cellLink.addClass("sunday");
				} else if (cellDate.getDay() == 6) {
					cellLink.addClass("saturday");
				}
				
				
				
				// add class to transdays
				if (dateValue <= 0 || dateValue > this.getTotalDays()) {
					cellLink.addClass("transdays");
				}
				
				// remove if not want to show transdays
				if (this.options.showTransDays == false && (dateValue <= 0 || dateValue > this.getTotalDays())) {
					cellLink.removeEvents();
					cellLink.dispose();
				}
				// if not active date
				if (!this.isActiveDate(cellDate)) {
					cellLink.addClass("disabled");
					cellLink.removeEvents();
					cellLink.removeProperty("href");					
				}
				// store week
				bodyTr.store("week", this.getWeek(cellDate));
			}
		}
		
		// call event
		this.fireEvent("onChange", this.holder);
	},
	
	setMonthSelector: function(){
		var fn = this;
		var h = new Element("h3", {
			"html": "<span>"+this.options.date.getFullYear()+"</span>",
			"class": "currentYearTitle",
			"styles": {
				"display": "none"
			}
		}).inject(this.holder);
		var a = new Element("a", {
			"href": "javascript:;",
			"text": "x",
			"events": {
				"click": function(e) {
					e.stop();
					fn.hideMonthSelector();
					fn.hideYearSelector();
					fn.showDateSelector();
				}
			}
		}).inject(h, "top");
		var ul = new Element("ul", {
			"class": "calendarSelector monthSelector",
			"styles": {
				"display": "none"
			}
		}).inject(this.holder);
		
		// add montb
		for (var i = 0; i<12; i++){
			var li = new Element("li").inject(ul);
			var a = new Element("a", {
				"href": "javascript:;",
				"text": this.options.months[i],
				"class": "monthBtn",
				"events": {
					"click": function(e) {
						e.stop();
						fn.setMonth(this.month);
					}
				}
			}).inject(li);
			a.month = i;
		}
	},
	
	showDateSelector: function(){
		this.holder.getElement("ul.calendarTitle").set("styles", {"display": ""});
		this.holder.getElement("table.calendarData").set("styles", {"display": ""});
	},
	
	hideDateSelector: function(){
		this.holder.getElement("ul.calendarTitle").set("styles", {"display": "none"});
		this.holder.getElement("table.calendarData").set("styles", {"display": "none"});
	},
	
	showMonthSelector: function(){
		this.holder.getElement("ul.monthSelector").set("styles", {"display": "block"});
		this.holder.getElement("h3.currentYearTitle").set("styles", {"display": "block"});
		this.holder.getElement("h3.currentYearTitle span").set("text", this.options.date.getFullYear());
	},
	
	hideMonthSelector: function(){
		this.holder.getElement("ul.monthSelector").set("styles", {"display": "none"});
		this.holder.getElement("h3.currentYearTitle").set("styles", {"display": "none"});
	},
	
	showYearSelector: function(){
		var fn = this;
		
		this.holder.getElement("h3.currentYearTitle").set("styles", {"display": "block"});
		this.holder.getElement("h3.currentYearTitle span").set("text", this.options.date.getFullYear());
		this.holder.getElements("ul.yearSelector").dispose();
		
		var ul = new Element("ul", {
			"class": "calendarSelector yearSelector"
		}).inject(this.holder);
		
		var range = 14;
		var minYear = this.options.calYear - range/2;
		var maxYear = this.options.calYear + range/2;
		
		// add years
		for (var i = minYear; i<maxYear; i++) {
			var li = new Element("li").inject(ul);
			var a = new Element("a", {
				"href": "javascript:;",
				"text": i,
				"class": "yearBtn",
				"events": {
					"click": function(e) {
						e.stop();
						fn.setYear($(this).get("text"));
					}
				}
			}).inject(li);
		}
		
		// previous year
		var li = new Element("li").inject(ul, "top");
		var a = new Element("a", {
			"href": "javascript:;",
			"html": "<span>&lt;</span>",
			"class": "yearBtn",
			"events": {
				"click": function(e) {
					e.stop();
					fn.options.calYear -= range;
					fn.showYearSelector();
				}
			}
		}).inject(li);
		
		// next year
		var li = new Element("li").inject(ul);
		var a = new Element("a", {
			"href": "javascript:;",
			"html": "<span>&gt;</span>",
			"class": "yearBtn",
			"events": {
				"click": function(e) {
					e.stop();
					fn.options.calYear += range;
					fn.showYearSelector();
				}
			}
		}).inject(li);
	},
	
	hideYearSelector: function(){
		this.holder.getElements("ul.yearSelector").dispose();
		this.holder.getElement("h3.currentYearTitle").set("styles", {"display": "none"});
	},
	
	setMonth: function(month){
		this.options.date = new Date(this.options.date.getFullYear(), month, this.options.date.getDate());
		this.hideMonthSelector();
		this.reGenerateCalendar();
		this.showDateSelector();
	},
	
	setYear: function(year){
		this.options.date = new Date(year, this.options.date.getMonth(), this.options.date.getDate());
		
		// select birthday
		if (this.options.selectBirthDay) {
			this.hideYearSelector();
			this.showMonthSelector();
		} else {
			this.hideYearSelector();
			this.reGenerateCalendar();
			this.showDateSelector();
		}
	},
	
	reGenerateCalendar: function(){
		var fn = this;
		// change title
		var arrMonth = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
		//print(fn.options.date.getMonth() + " :::: " + arrMonth[fn.options.date.getMonth()]);
		if(this.options.assignTo == "calDateMyPlanNew") {
			var _MONTH = arrMonth[fn.options.date.getMonth()];		
		} else {
			var _MONTH = arrMonth[fn.options.months[fn.options.date.getMonth()].toInt()-1];			
		}
		this.holder.getElements("a.currentDate").each(function(el, i){
			//el.set("html", (i == 0) ? arrMonth[fn.options.months[fn.options.date.getMonth()].toInt()-1] : fn.options.date.getFullYear());
			el.set("html", (i == 0) ? _MONTH : fn.options.date.getFullYear());
		});
		
		// dispose old table
		this.holder.getElements("table").dispose();
		
		// re-generate
		this.generateTable();
	},
	
	getFirstDayIndex: function(){
		var index = new Date(this.options.date.getFullYear(), this.options.date.getMonth(), 1).getDay() + (this.options.mondayFirst == false ? 0 : -1);
		return index >= 0 ? index : 7 + index;
	},
	
	getTotalDays: function(){
		return this.getTotalDaysInMonth(this.options.date.getMonth());
	},
	
	getPreviousTotalDays: function(){
		var month = this.options.date.getMonth()-1;		
		if (month == -1) {
			month = 11;
		}
		return this.getTotalDaysInMonth(month);
	},
	
	getTotalDaysInMonth: function(month){
		var dayCount = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
		return (month != 1) ? dayCount[month] : this.isLeafYear() ? 29 : 28;
	},
	
	isLeafYear: function() {
		return (new Date(this.options.date.getFullYear(), 1, 29).getMonth() == 1);
	},
	
	isToday: function(date) {
		if($('frmIniatiative') || $('frmMyLan')){
			if(!d){
				var today = new Date();	
			} else {
				var today = new Date(y,m,d);
			}
			
		} else {
			var today = new Date();
		}
		return (date.getDate() == today.getDate() && date.getMonth() == today.getMonth() && date.getFullYear() == today.getFullYear());
	},
	
	getWeek: function(date){
		var startDate = new Date(date.getFullYear(), 0, 1);
		var time = date - startDate;
		var days = time / 1000 / 60 / 60 / 24 + startDate.getDay() + 1;
		return Math.ceil(days / 7);
	},
	
	isActiveDate: function(date) {
		// check for limit date
		/*
		var thedate = this.options.minDate.getDate();
		var themonth = this.options.minDate.getMonth()-1;
		var theyear = this.options.minDate.getFullYear();
		
		var _thedate = this.options.date.getDate();
		var _themonth = this.options.date.getMonth()-1;
		var _theyear = this.options.date.getFullYear();
		
		if(thedate == _thedate && themonth == _themonth && theyear == _theyear) {
			
			return true;
		}
		*/
		if (date < this.options.minDate) {
			return false;
		}
		if (date > this.options.maxDate) {
			return false;
		}
		
		// check for disable dates
		for (var i = 0; i<this.options.disableDays.length; i++) {
			if (date.getDay() == this.options.disableDays[i]) {
				return false;
			}
		}
		
		// if pass
		return true;
	},
	
	getTotalRow: function() {
		return Math.ceil((this.getFirstDayIndex() + this.getTotalDays())/7);
	},
	
	previousYear: function() {
		this.options.date = new Date(this.options.date.getFullYear()-1, this.options.date.getMonth(), this.options.date.getDate());
		this.reGenerateCalendar();
	},
	
	previousMonth: function() {
		var date = this.options.date.getDate();
		var month = this.options.date.getMonth()-1;		
		var year = this.options.date.getFullYear();
		
		if (month == -1) {
			month = 11;
			year--;
		}
		this.options.date = new Date(year, month, date);
		this.reGenerateCalendar();
	},
	
	nextYear: function() {
		this.options.date = new Date(this.options.date.getFullYear()+1, this.options.date.getMonth(), this.options.date.getDate());
		this.reGenerateCalendar();
	},
	
	nextMonth: function() {
		var date = this.options.date.getDate();
		var month = this.options.date.getMonth()+1;
		var year = this.options.date.getFullYear();
		
		if (month == 12) {
			month = 0;
			year++;
		}
		this.options.date = new Date(year, month , date);
		this.reGenerateCalendar();
	},
	
	assignPopup: function(){
		var fn = this;		
		this.holder.addClass("pcalendar");
		if($('frmIniatiative') || $('frmMyLan')){
				if(this.options.assignTo == 'calDate02') {
					$$("."+this.options.assignTo).each(function(el){			
						el.addEvent("click", function(e){
							fn.showCalendar(el);
						});
					});
				} else {
					el = imgClick;
					fn.showCalendar(el);
				}
		} else {
			$$("."+this.options.assignTo).each(function(el){
				
				el.addEvent("click", function(e){
					fn.showCalendar(el);
				});
			});
		}
		// modify onSelect
		this.addEvent("onSelect", function(obj){
			this.setSelectedValue(obj.retrieve("date"));
			this.hideCalendar();
		});
		this.addEvent("onReleaseOutSide", function(e) {
			this.hideMonthSelector();
			this.hideYearSelector();
			this.showDateSelector();
			this.hideCalendar();
		});
	},
	
	showCalendar: function(el) {
		this.options.activeControl = el;
		var input = this.getInputControl();		
		var _top = input.getCoordinates().top+input.getCoordinates().height;
		if(input.getParent("form#frmIniatiative") && Browser.Engine.trident) {
			_top = _top + 57.5;
		}
		
		this.holder.set("styles", {
			"visibility": "visible",
			"display": "block",
			"top": _top + "px",
			"left": (input.getCoordinates().left>900)?input.getCoordinates().left - 80+'px' : input.getCoordinates().left+"px"
		});
		
		this.holderIframe.set('styles' , {
			"visibility": "visible",
			"display": "block",
			"top": $('myCalendar').getCoordinates().top +"px",
			"left": $('myCalendar').getCoordinates().left +"px",
			"width" : $('myCalendar').getCoordinates().width +"px",
			"height" : $('myCalendar').getCoordinates().height +"px"
		});
		// select birthday
		if (this.options.selectBirthDay) {
			this.options.calYear = this.options.date.getFullYear();
			this.hideDateSelector();
			this.showYearSelector();
		}
		
		// ie fix overlay
		//this.holder.ieFixLayerShow();
	},
	
	hideCalendar: function() {
		this.holder.set("styles", {
			"visibility": "hidden"
		});
		this.holderIframe.set("styles", {
			"visibility": "hidden"
		});
		// ie fix overlay
		//this.holder.ieFixLayerHide();
	},
	
	setSelectedValue: function(date) {		
		if($('frmIniatiative') || $('frmListAlert')) {
			var label = this.getInputControl();
			var str=this.parseDate(date);
			var strArr = str.split(" ");
			var year = strArr[2].toString();
			year = year.substring(2);
			var str1 = strArr[1]+'.'+strArr[0]+'.'+year;	
			if(label.tagName.toLowerCase() == "input"){
				if($('frmListAlert')) {
					label.value = str1;
				} else {
					label.value = strArr[1]+'.'+strArr[0]+'.'+strArr[2];
				}
				
			} else {
				valueCalendar = strArr[1]+'.'+strArr[0]+'.'+strArr[2];
				if(label.getParent('tr.headerIniatiative')) {
					changDataCalendar(label , valueCalendar);
				}
				if(label.getParent('tr.showHideTr')) {
					changDataCalendar(label , valueCalendar, 1);
				}
				if(label.id.contains('status')) {
					label.innerHTML = 'Due ' + str1;
				} else {
					label.innerHTML = str1;
				}
			}	
		} else {
			var input = this.getInputControl();
			if (input) {
				if( $$('.profilesBlock')[0] && $$('.profilesBlock')[0].getElement('form[class=editFrm]') || $('frmOfficeSetup')){
					var str=this.parseDate(date);
					var strArr=str.split(" ");
					if (this.options.assignTo == 'calDateMyPlanNew') {
						var str1 = strArr[1]+' '+strArr[0]+', '+strArr[2];					
					} else {
						var str1 = strArr[1]+'.'+strArr[0]+'.'+strArr[2];					
					}
					
					input.value = str1;
				} else {
					
					input.value = this.parseDate(date);
				}	
			}
		}
	},
	
	parseDate: function(date) {
		var spliter = (this.options.format.indexOf("-") != -1) ? "-" : (this.options.format.indexOf(".") != -1) ? "." : (this.options.format.indexOf("/") != -1) ? "/" : " ";
		var format = this.options.format.replace(new RegExp("["+spliter+"]", "g"), "");
		var dateArr = new Array();
		dateArr[format.indexOf("d")] = this.formatNumber(date.getDate());
		dateArr[format.indexOf("D")] = this.options.fulldays[date.getDay()] + ", "+this.formatNumber(date.getDate());
		dateArr[format.indexOf("m")] = this.formatNumber(date.getMonth()+1);
		dateArr[format.indexOf("M")] = this.options.months[date.getMonth()];
		dateArr[format.indexOf("y")] = this.formatNumber(date.getFullYear());
		return dateArr[0]+spliter+dateArr[1]+spliter+dateArr[2];
	},
	
	getInputControl: function() {
		var el = this.options.activeControl;		
		//calDateNewAction
		if(el.hasClass('calDateNewAction')){
			while (el && el.tagName.toLowerCase() != "input") {
				el = el.getPrevious();
			}
			if (el.tagName.toLowerCase() == "input") {
				return el;
			}
		}
		else if($('frmIniatiative')) {
			if(el.tagName.toLowerCase() == "img") {
				return el.getPrevious();
			}
		} else {
			while (el && el.tagName.toLowerCase() != "input") {
				el = el.getPrevious();
			}
			if (el.tagName.toLowerCase() == "input") {
				return el;
			}
		}	
		return false;
	},
	
	formatNumber: function(num) {
		return (parseInt(num) < 10) ? "0" + parseInt(num) : parseInt(num);
	},
	
	onSelect: function(obj) {
		if (this.activeDate) {
			this.activeDate.removeClass("selected");
		}
		this.activeDate = obj;
		this.activeDate.addClass("selected");
		
		//
		if (this.activeWeek) {
			this.activeWeek.removeClass("currentWeek");
		}
		this.activeWeek = obj.getParent().getParent();
		this.activeWeek.addClass("currentWeek");
		
		//
		this.fireEvent("onSelect", obj);
	}
	
});

calendar.implement(new Chain, new Events, new Options);

// create calendar
var DAYS = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
var FULLDAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var MONTHS = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
var FULLMONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
		
var y , m ,d;
var imgClick;
window.addEvent("load", function() {
	loadCalenda();
	loadCalendaMyPhanNew();
});

function loadStartCalendaFrequency(){
	alert(0);
	new calendar("myCalendar", {
		date: new Date(),
		minDate: new Date(1990,11,1),
		maxDate: new Date(2999,11,1),		
		format: "d M y",
		mondayFirst: false,
		showTransDays: false,
		selectBirthDay: false,
		days: DAYS,
		fulldays: FULLDAYS,
		months: MONTHS,
		assignTo: "calDate",
		onSelect: function(obj){
			//
			
		},
		onChange: function(holder){
			//
		},
		onReleaseOutSide: function(holder) {
			//holder.setStyle("display", "none");
		}
	});
}

function loadCalendaFrequency(){
	new calendar("myCalendar", {
		date: new Date(),
		minDate: new Date(1990,11,1),
		maxDate: new Date(2999,11,1),
		// disableDays: [],
		format: "d M y",
		mondayFirst: false,
		showTransDays: false,
		selectBirthDay: false,
		days: DAYS,
		fulldays: FULLDAYS,
		months: MONTHS,
		assignTo: "calDate02",
		onSelect: function(obj){
			//
		},
		onChange: function(holder){
			//
		},
		onReleaseOutSide: function(holder) {
			//holder.setStyle("display", "none");
		}
	});
	
}
function loadCalenda() {
	if($("txtFName") || $("txtLName")) {
		return true;
	}
	if($('frmIniatiative') || $('frmMyLan')) {
		var arr = $$('.calDate ');
		arr.each(function(el) {
			el.removeEvents().addEvent('click' , function() {
				imgClick = this;
				if($('myCalendariframe')) $('myCalendariframe').dispose();
				if($('myCalendar')) $('myCalendar').dispose();
				if($('frmMyLan')){
					var label = this.getPrevious().value;
				} else {
					var label = this.getPrevious().innerHTML;
					label = label.toLowerCase();
				}
				if((label).contains('due')) {
					label = label.substring(3);
				}
				var arrDate = label.split(".");
				var y, m, d;
				if($$('.editFrm').length > 0 && arrDate[2] && arrDate[2].length == 4 ){
					y = arrDate[2];
				} else {
					y = "20"+arrDate[2];
				}
				m = arrDate[0] - 1 ;
				d = arrDate[1];
				if(!d){
					var theDay = new Date();	
				} else {
					var theDay = new Date(y,m,d);
				}
				var theMinDate = new Date();
				var thedate = theMinDate.getDate();
				var themonth = theMinDate.getMonth();
				var theyear = theMinDate.getFullYear(); 				
				var monthType = MONTHS;
				
				var mooCalendar = new calendar("myCalendar", {
					date: theDay,
					minDate: new Date(theyear,themonth,thedate),
					//minDate: new Date(),
					maxDate: new Date(2999,11,1),
					disableDays: [],
					format: "d M y",
					mondayFirst: false,
					showTransDays: false,
					selectBirthDay: false,
					days: DAYS,
					fulldays: FULLDAYS,
					months: monthType,
					assignTo: "calDate",
					onSelect: function(obj){
						//
					},
					onChange: function(holder){
						//
					},
					onReleaseOutSide: function(holder) {
						//holder.setStyle("display", "none");
					}
				});				
			});
		});
		var arrNewAction = $$('.calDateNewAction');
		arrNewAction.each(function(el) {
			el.removeEvents().addEvent('click' , function() {
				imgClick = this;
				if($('myCalendariframe')) $('myCalendariframe').dispose();
				if($('myCalendar')) $('myCalendar').dispose();
				var label = this.getPrevious().value;
				var arrDate = label.split(".");
				y = "20"+arrDate[2];
				m = arrDate[0] - 1 ;
				d = arrDate[1];
				if(!d){
					var theDay = new Date();	
				} else {
					var theDay = new Date(y,m,d);
				}
				var theMinDate = new Date();
				
				var thedate = theMinDate.getDate();
				var themonth = theMinDate.getMonth();
				var theyear = theMinDate.getFullYear();
				
				var mooCalendar = new calendar("myCalendar", {
					date: new Date(),
					minDate: new Date(theyear,themonth,thedate),
					//minDate: new Date(),
					maxDate: new Date(2999,11,1),
					disableDays: [],
					format: "d M y",
					mondayFirst: false,
					showTransDays: false,
					selectBirthDay: false,
					days: DAYS,
					fulldays: FULLDAYS,
					months: MONTHS,
					assignTo: "calDate",
					onSelect: function(obj){
						//
					},
					onChange: function(holder){
						//
					},
					onReleaseOutSide: function(holder) {
						//holder.setStyle("display", "none");
					}
				});
				 
			});
		});
	} else {
		if($('frmOfficeSetup') || $('frmListAlert') || $('frequencyLayer')) {
			_thedateMindate = new Date(1099,11,1);
		} else {
			var theMinDate = new Date();
			var thedate = theMinDate.getDate();
			var themonth = theMinDate.getMonth();
			var theyear = theMinDate.getFullYear();
			var _thedateMindate = new Date(theyear,themonth,thedate)
		}
		var mooCalendar = new calendar("myCalendar", {
			date: new Date(),
			minDate: _thedateMindate,
			//minDate: new Date(),
			maxDate: new Date(2999,11,1),
			disableDays: [],
			format: "d M y",
			mondayFirst: false,
			showTransDays: false,
			selectBirthDay: false,
			days: DAYS,
			fulldays: FULLDAYS,
			months: MONTHS,
			assignTo: "calDate",
			onSelect: function(obj){
				//
			},
			onChange: function(holder){
				//
			},
			onReleaseOutSide: function(holder) {
				//holder.setStyle("display", "none");
			}
		});
	}
}


function loadCalendaMyPhanNew() {
	var frmMyLanNew = $('frmMyLanNew');
	if(frmMyLanNew) {
		var arr = $$('.calDateMyPlanNew');
		arr.each(function(el) {
			el.removeEvents().addEvent('click' , function() {
				imgClick = this;
				if($('myCalendariframe')) $('myCalendariframe').dispose();
				if($('myCalendar')) $('myCalendar').dispose();
				var currDate = this.getPrevious().value;
				var _minDate = frmMyLanNew.getElement('input[name=start_date]').value;
				var _maxDate = frmMyLanNew.getElement('input[name=end_date]').value;
				if(currDate) {
					var arrDate = currDate.split(" ");
					var y, m, d;
					
					y = arrDate[2];
					m = MONTHS[FULLMONTHS.indexOf(arrDate[0])].toInt() - 1;					
					d = arrDate[1].toInt();
					var theDay = new Date(y,m,d);
				} else {
					var theDay = new Date();
				}
				//////////////////////////
				if(_minDate) {
					var arrMinDate = _minDate.split(".");
					var yMin, mMin, dMin;
					
					yMin = arrMinDate[2];
					mMin = arrMinDate[0] - 1;					
					dMin = arrMinDate[1];
					var theMinDay = new Date(yMin,mMin,dMin);					
				} else {
					var theMinDay = new Date(2000,11,1);
				}
				////////////////////
				if(_maxDate) {
					var arrMaxDate = _maxDate.split(".");
					var yMax, mMax, dMax;
					
					yMax = arrMaxDate[2];
					mMax = arrMaxDate[0] - 1;					
					dMax = arrMaxDate[1];
					var theMaxDay = new Date(yMax,mMax,dMax);
					
				} else {
					var theMaxDay = new Date(2000,11,1);
				}
				var mooCalendar = new calendar("myCalendar", {
					date: theDay,					
					minDate: theMinDay,
					maxDate: theMaxDay,
					disableDays: [],
					format: "d M y",
					mondayFirst: false,
					showTransDays: false,
					selectBirthDay: false,
					days: DAYS,
					fulldays: FULLDAYS,
					months: FULLMONTHS,
					assignTo: "calDateMyPlanNew",
					onSelect: function(obj){
						//
					},
					onChange: function(holder){
						//
					},
					onReleaseOutSide: function(holder) {
						//holder.setStyle("display", "none");
					}
				});				
			});
		});
		
	}
}

function loadCalenda_disabledate() {
	var arr = $$('.calDate');
		arr.each(function(el) {
			el.removeEvents().addEvent('click' , function() {
				imgClick = this;
				if($('myCalendariframe')) $('myCalendariframe').dispose();
				if($('myCalendar')) $('myCalendar').dispose();
				if($('frmMyLan')){
					var label = this.getPrevious().value;
				} else {
					var label = this.getPrevious().innerHTML;
				}	
				var arrDate = label.split(".");
				if($$('.editFrm').length > 0 && arrDate[2] && arrDate[2].length == 4 ){
					y = arrDate[2];
				} else {
					y = "20"+arrDate[2];
				}
				m = arrDate[0] - 1 ;
				d = arrDate[1];
				if(!d){
					var theDay = new Date();	
				} else {
					var theDay = new Date(y,m,d);
				}				
				var mooCalendar = new calendar("myCalendar", {
					date: theDay,
					minDate: new Date(1099,11,1),
					maxDate: new Date(2999,11,1),
					disableDays: [],
					format: "d M y",
					mondayFirst: false,
					showTransDays: false,
					selectBirthDay: false,
					days: DAYS,
					fulldays: FULLDAYS,
					months: MONTHS,
					assignTo: "calDate",
					onSelect: function(obj){
						//
					},
					onChange: function(holder){
						//
					},
					onReleaseOutSide: function(holder) {
						//holder.setStyle("display", "none");
					}
				});				
			});
		});
}