var IsHidden = true;               // 日历是否可见
// type                            // 返回值的类型 1 - 2001-04-18-00.00.00.00; 2 - 2001-04-18; 3 - 2001年4月18日
var calLeft = 0;                   // 日历Left坐标值
var calTop = 0;                    // 日历Top坐标值
var stepLevel = 50;                // 日历坐标搜索深度
var eventTimer = null;             // 定时器id
var ptype;

function displayCalendar(focus, type) // 显示和隐藏日历
{
ptype=type;
   if ( IsHidden )
   {
      if(eventTimer != null)
	    window.clearInterval(eventTimer);		//清除定时器
      eventTimer = window.setInterval("setCloseCalendarEvent(top)", 500);	//启动事件定时器

	  calLeft = 0;
	  calTop = 0;
      getCalPos(focus, 0);
	  Calendar.calendarFocus = focus;
	  Calendar.calDateType = type;
      document.all("Calendar").style.pixelTop = calTop + 20;
	  document.all("Calendar").style.pixelLeft = calLeft;
	  if (calLeft + 168 > document.body.clientWidth + document.body.scrollLeft)
	  {
	     left = document.body.clientWidth + document.body.scrollLeft - 172;
	     document.all("Calendar").style.pixelLeft = left>0?left:0;
	  }
	  if (calTop + 152 > document.body.clientHeight + document.body.scrollTop)
	  {
	     bottom = document.body.clientHeight + document.body.scrollTop - 152;
	     document.all("Calendar").style.pixelTop = bottom>0?bottom:0;
	  }
      document.all("Calendar").style.visibility = "visible";
      IsHidden = false;
   }
   else
   {
      if(eventTimer != null)
	    window.clearInterval(eventTimer);		//清除定时器

	  document.all("Calendar").style.pixelTop = 0;
	  document.all("Calendar").style.pixelLeft = 0;
      document.all("Calendar").style.visibility = "hidden";
      IsHidden = true;
   }
}

function hideCalendar()
{
   if(eventTimer != null)
     window.clearInterval(eventTimer);		//清除定时器

   document.all("Calendar").style.pixelTop = 0;
   document.all("Calendar").style.pixelLeft = 0;
   document.all("Calendar").style.visibility="hidden";
   IsHidden = true;
}

function getCalPos(focus, level)
{
  var name = focus.offsetParent.tagName;
  if (!(name == "body" || name == "BODY") && level < stepLevel)
  {
    getCalPos(focus.offsetParent, level + 1);
  }
  calLeft += focus.offsetLeft;
  calTop += focus.offsetTop;
}

function setCloseCalendarEvent(handel)
{
	var targetId = document.all("Calendar");

	if(handel.document && (handel.document.body == targetId.document.body))
	{
		handel.document.body.onmousedown = hideCalendar; 
	}

	for(var i=0; i<handel.frames.length; i++)
	{
		setCloseCalendarEvent(handel.frames[i]);
	}
}

function add()
{
if (check()==true){
   window.open('','projectDetailwin','left=100 width=318 height=260 toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=auto,resizable=0');
   document.form1.submit();
}
}
function check(){
var d1=document.all.notereceivetime.value;
var d2=document.all.schemestarttime.value;
var d3=document.all.schemefinishtime.value;
var d4=document.all.projectno.value;
var d5=document.all.projectname.value;
if ((d1.length=="")||(d2.length=="")||(d3.length=="")||(d4.length=="")||(d5.length=="")){
  window.alert("请填写完整的资料信息");
  return false;
}else{
  return true;
}
}

document.write("<iframe id='Calendar' name='Calendar' src='calendar.html' style='position:absolute; width:170; height:135; left:0px; top:0px; visibility: hidden; background-color: #CCEECC; border: 2px outset #BBDDBB'>");
document.write("</iframe>");

