document.write('<iframe id=CalFrame name=CalFrame frameborder=0 src="/js/date.htm" style=display:none;position:absolute;z-index:100></iframe>');

function addListener_1(element,e,fn){
     if(element.addEventListener){
          element.addEventListener(e,fn,false);
     } else {
          element.attachEvent("on" + e,fn);
     }
}
addListener_1(document,"click",hideCalendar);
//WGY  2007-04-17  
//参数顺序： 最早乘机时间 、 最晚乘机时间、 提前出票天数、 预定截止时间
//用于验证“最早乘机时间”、“最晚乘机时间”、“预定截止日期”的有效性。
//规则为：最早乘机时间 <= 最晚乘机时间;  预定截止日期 <= 最晚乘机时间 - 提前出票天数
//函数返回boolean值，若通过验证返回TRUE，反之弹出提示，将焦点移至应修改处，并返回FALSE
function checkDate(earliestDate,latestDate,preDays,toDate){
  	if(latestDate < earliestDate){
  		alert("最晚乘机时间不得早于最早乘机时间！");
  		return false;
  	}

  	var dates;//临时变量，存放将日期拆分后的数组
  	var rightDate;//最晚有效预定截止时间

  	dates = latestDate.split("-");
  	latestDate = new Date(dates[0], dates[1]-1, dates[2]);

  	dates = toDate.split("-");
	toDate = new Date(dates[0], dates[1]-1, dates[2]); 

	if(preDays > (latestDate.getTime() - toDate.getTime())/3600/24/1000){
		rightDate = latestDate;
		rightDate.setTime(latestDate.getTime()-preDays*3600*24*1000);
		alert("预定截止时间不能晚于"+rightDate.getYear()+"-"+(rightDate.getMonth()+1)+"-"+rightDate.getDate());
		return false;
	}else
		return true;
}
//章磊:计算一个日期减/相加一个天数,如果减用aiDay=-7
function   getDateByInterval(asDate,aiDay){   
        var   liDate   =   Date.parse(asDate.replace(/\-/g,   '/'));   
        var   liDay   =   3600*1000*24*aiDay;   
        var   loDate   =   new   Date(liDate+liDay);  
        month =  (loDate.getMonth()+1) <10 ? "0"+(loDate.getMonth()+1) : (loDate.getMonth()+1)
        day = loDate.getDate() <10 ? "0"+loDate.getDate() : loDate.getDate()
        return   loDate.getYear()   +   "-"   +   month   +   "-"   +   day;   
}
//获得2个日期间相隔的天数
function getTwoDate(date1,date2){
	    var   liDate1   =   Date.parse(date1.replace(/\-/g,   '/')); 
	    var   liDate2  =    Date.parse(date2.replace(/\-/g,   '/')); 
	     return (liDate1-liDate2)/(3600*1000*24);
}
   
//WGY 2007-04-06 处理数据库中的各种时间格式，将其转换为 MM-DD HHMI 的格式。对于长度不足14位的日期 转化为MM-DD的格式
function transDate(date){
date=trim(date);

	if(date == null||date == "")
		return;
	var values = date.split("-");
	var yyyy = values[0];
	var mm = values[1];
	var dd = values[2].substr(0,2);
	var temp = values[2].substr(3,values[2].length-2);

	if(temp.length < 4){
		document.write(mm+"-"+dd);
		return;
	}
	if(temp.length == 4){
		document.write(mm+"-"+dd+" "+temp);
		return;	
	}
	if(temp.length > 4){
		var hhmi = temp.split(":")[0]+temp.split(":")[1]
		document.write(mm+"-"+dd+" "+hhmi);
		return;	
	}
}

function showCalendar(sImg,bOpenBound,sFld1,sFld2,sCallback)
{
	var fld1,fld2;
	var cf=document.getElementById("CalFrame");
	var wcf=window.frames.CalFrame;
	var oImg=document.getElementById(sImg);
	if(!oImg){alert("控制对象不存在！");return;}
	if(!sFld1){alert("输入控件未指定！");return;}
	fld1=document.getElementById(sFld1);
	if(!fld1){alert("输入控件不存在！");return;}
	if(fld1.tagName!="INPUT"||fld1.type!="text"){alert("输入控件类型错误！");return;}
	if(sFld2)
	{
		fld2=document.getElementById(sFld2);
		if(!fld2){alert("参考控件不存在！");return;}
		if(fld2.tagName!="INPUT"||fld2.type!="text"){alert("参考控件类型错误！");return;}
	}
	if(!wcf.bCalLoaded){alert("日历未成功装载！请刷新页面！");return;}
	if(cf.style.display=="block"){cf.style.display="none";return;}
	
	var eT=0,eL=0,p=oImg;
	var sT=document.body.scrollTop,sL=document.body.scrollLeft;
	var eH=oImg.height+25,eW=oImg.width;
	while(p&&p.tagName!="BODY"){eT+=p.offsetTop;eL+=p.offsetLeft;p=p.offsetParent;}
	cf.style.top=(document.body.clientHeight-(eT-sT)-eH>=cf.height)?eT+eH:eT-cf.height;
	cf.style.left=(document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width;
	cf.style.display="block";
	wcf.openbound=bOpenBound;
	wcf.fld1=fld1;
	wcf.fld2=fld2;
	wcf.callback=sCallback;
	wcf.initCalendar();
	fld = fld1
}
function hideCalendar()
{
	var cf=document.getElementById("CalFrame");
	cf.style.display="none";
}

function trim(obj){
trim_str=obj.split(/^\s+|\s+$/)[0];
//alert(/^\s*$/.test(obj)?'文本框里为空':'文本框里有字符');
//alert("去掉两边空格后的字符串为"+trim_str);
if(trim_str=="undefined"){
return "";
}
return trim_str;
}
