function CalendarProxy(contextPath){
	this.ifm=null;
	this.calendar=null;
  this.calendarPad=null;
  this.selectMonth=null;
  this.prevYear=null;
  this.nextYear=null;
  this.selectYear=null;
  this.goToday=null;
  this.calendarClose=null;
  this.calendarAbout=null;
  this.head=null;
  this.body=null;
  this.today=[];
  this.currentDate=[];
  this.contextPath="";
  if(contextPath)this.contextPath = contextPath;
  this.sltDate;
  this.target;
  this.source;
  this.setup();
}

/************** Add calendar background panel*********************/
CalendarProxy.prototype.addCalendarPad=function(){
 document.write("<div id='divCalendarpad' style='position:absolute;z-index:100;top:100;left:0;width:250;height:193;display:none;'>");
 document.write("<iframe id='calendarframe' name='calendarframe' frameborder=0 height=201 width=251 ></iframe>");
 document.write("</div>");
 this.calendarPad=document.all.divCalendarpad;
 var ifm= window.frames["calendarframe"];
 var href=this.contextPath+"/js/calendar/calendar.jsp";
 ifm.location.href=href;
 this.ifm =ifm;
}
/************** start from here *********************/
CalendarProxy.prototype.setup=function(defaultDate){
 this.addCalendarPad();
 //calendar.setDefaultDate();
}
/****************** cal the location *************************/
CalendarProxy.prototype.getAbsolutePos = function(el) {
 var r = { x: el.offsetLeft, y: el.offsetTop};
 var parent = el.offsetParent;   
 if (parent) {
  var tmp = this.getAbsolutePos(parent);
  r.x += tmp.x;
  r.y += tmp.y;
 }
 return r;
};
/****************** Show Calendar *********************/
CalendarProxy.prototype.show=function(targetObject,defaultDate,sourceObject){
	try{
	if(!this.ifm.selector){
		this.calendar=this.ifm.calendar;
		this.ifm.selector=this;
	}
 if(targetObject==undefined) {
  return false;
 }
 else    this.target=targetObject;
 if(sourceObject==undefined) this.source=this.target;
 else this.source=sourceObject;
 
 this.calendarPad.style.display="";
 this.calendar.show(defaultDate);  

 //****************adjust the location of calendar **************//
 var offsetPos=this.getAbsolutePos(this.source);//cal the location;
 if((document.body.offsetHeight-(offsetPos.y+this.source.offsetHeight-document.body.scrollTop))<this.calendarPad.style.pixelHeight){
  var calTop=offsetPos.y-this.calendarPad.style.pixelHeight;
 }
 else{
  var calTop=offsetPos.y+this.source.offsetHeight;
 }
 if((document.body.offsetWidth-(offsetPos.x+this.source.offsetWidth-document.body.scrollLeft))>this.calendarPad.style.pixelWidth){
  var calLeft=offsetPos.x;
 }
 else{
  var calLeft=offsetPos.x-this.calendarPad.style.pixelWidth;
 }
 this.calendarPad.style.pixelLeft=calLeft;
 this.calendarPad.style.pixelTop=calTop;
}
catch(E){
	alert(E);
}
}

/************** hide the calendar *********************/
CalendarProxy.prototype.hide=function(){
 //this.clearEventKey();
 this.calendarPad.style.display="none";
}
var CalendarWebControl = new CalendarProxy(contextPath);
