function $(fctId){
        return document.getElementById(fctId);
}

//取得某对象，若提供ID下的对象不存在则自动创建
function c$(fctId,fctClassName){
        var varTempDivObj=$(fctId);
        if(!varTempDivObj){
                GetPyzyIframe("ifm"+fctId);
                varTempDivObj=document.createElement("div");
                varTempDivObj.id=fctId;
                if(fctClassName && fctClassName!="")varTempDivObj.className=fctClassName;
                document.body.appendChild(varTempDivObj);
        }
        return varTempDivObj;
}

//取得某ID的iframe对象，若不存在该ID的对象则自动创建
function GetPyzyIframe(fctIfmId,fctVisibility,fctTop,fctLeft,fctWidth,fctHeight){
        var varTempIfmObj=$(fctIfmId);
        if(!varTempIfmObj){
                varTempIfmObj=document.createElement("iframe");
                varTempIfmObj.id=fctIfmId;
                varTempIfmObj.style.position="absolute";
                varTempIfmObj.style.zIndex="1";
                varTempIfmObj.style.visibility="hidden";
                document.body.appendChild(varTempIfmObj);
        }
       if(fctTop)varTempIfmObj.style.top=fctTop+"px";
        if(fctLeft)varTempIfmObj.style.left=fctLeft+"px";
        if(fctWidth)varTempIfmObj.style.width=fctWidth+"px";
        if(fctHeight)varTempIfmObj.style.height=fctHeight+"px";
        if(fctVisibility)varTempIfmObj.style.visibility=(document.all?fctVisibility:"hidden        ");
        return varTempIfmObj;
}

//取得某对象的坐标位置、宽、高
function getPosition(obj){
        var top=0;
        var left=0;
        var width=obj.offsetWidth;
        var height=obj.offsetHeight;
        while(obj.offsetParent){
                top+=obj.offsetTop;
                left+=obj.offsetLeft;
                obj=obj.offsetParent;
        }
        return{"top":top,"left":left,"width":width,"height":height};
}

//取得编码存储框对象
function GetValueToInputObj(fctThisObj){
        if(!fctThisObj)return null;
        var varThisObjAutoInput=(fctThisObj.getAttributeNode("value_to_input")?fctThisObj.getAttributeNode("value_to_input").value:"");
        if(varThisObjAutoInput=="")return null;
        return $(varThisObjAutoInput);
}

//自动触发下一个对象的Act事件
function AutoNextInputAct(fctThisObj,fctAct){
        var varNextInput=fctThisObj.getAttributeNode("nextinput");
        if(varNextInput && varNextInput!=""){
                if(document.all){
                        eval("$('"+varNextInput.value+"')."+fctAct+"()");
                }else{
                        var evt = document.createEvent("MouseEvents");
                        evt.initEvent(fctAct,true,true);
                        $(varNextInput.value).dispatchEvent(evt);
                }
                $(varNextInput.value).focus();
        }
}
//隐藏城市列表
function _Hidden(e){
        e=e?e:event;
        var varMenuObj=c$("divAddressMenu");
        var varThisObj=varMenuObj.obj;
        if(varMenuObj.style.visibility!="hidden"){
                if(e){
                        var EventOBJ=(e.srcElement?e.srcElement:e.target);
                        if(EventOBJ.id=="menuPageS" && EventOBJ.style.color==""){ //如果点的是“上一页”则向上翻页
                                varPageId=varPageId-1;
                                GetCityList(EventOBJ);
                        }
                        if(EventOBJ.id=="menuPageE" && EventOBJ.style.color==""){ //如果点的是“下一页”则向下翻页
                                varPageId=varPageId+1;
                                GetCityList(EventOBJ);
                        }
                        if(varThisObj==EventOBJ || EventOBJ.id.indexOf("menuPage")==0 || EventOBJ.id.indexOf("divAddressMenu")==0) return false;
                }
                
                var varThisObjAutoInput=GetValueToInputObj(varThisObj); //取得城市编码值存储对象
                if($("menuA1")){ //如果下拉菜单中存在第一个城市
                        if(!varThisObjAutoInput)varThisObjAutoInput=varThisObj;
                        if(varThisObjAutoInput.value=="" || varThisObjAutoInput==varThisObj){ //编码框中无值
                                WriteCity("1");
                        }
                }else if(EventOBJ.id.indexOf("menuA")<0){ //如果下拉菜单中不存在满足条件的城市
                        if(varThisObj)varThisObj.value="";
                }
                varMenuObj.style.visibility="hidden";
                GetPyzyIframe("ifm"+varMenuObj.id,"hidden");
        }
}
/**********城市列表功能 End huzj 2008-4-14*************/

/**********日历选择功能 End huzj 2008-4-14*************/
//输出日历样式表 huzj 2008-4-12
document.write('\
        <style type="text/css">\
                .DateListBox{float:left;border:solid #FC7A7D 1px;width:147px !important;width:142px;height:168px !important;height:176px;font-size:12px;text-align:center;}\
                .DateListBox h1{width:100%;background-color:#FFF4F4;color:#B42929;font-size:12px;height:20px;font-weight:bold;line-height:20px;vertical-align:middle;margin:0px;}\
                .DateListBox div{float:left;border:solid #EB696C 1px;background-color:#EB696C;color:#FFFFFF;width:19px !important;width:20px;height:20px;font-size:12px;font-weight:bold;line-height:20px;vertical-align:middle;}\
                .DateListBox a{float:left;color:#990000;border:solid #ffffff 1px;background-color:#ffffff;width:19px !important;width:20px;height:19px !important;height:22px;font-size:12px;line-height:20px;vertical-align:middle;}\
                .DateListBox a:hover{border:solid #F2C2BD 1px;background-color:#FBEDEC;}\
                .DateListBox .aSelect{cursor:pointer;border:solid #DEB4B4 1px;background-color:#FAE0CF;color:#FF0000;}\
                .PyzyDateBox{position:absolute;z-index:1;visibility:hidden;background-color:#FFFFFF;border:solid #EBcccC 1px;width:298px !important;width:286px;}\
        </style>\
');

//取得日历列表，该函数输出的内容需要根据需求放置到特定的容器中，如浮动层、固定DIV…
function GetMonthHTML(fctStaDate,fctDate){
        if(!fctDate)fctDate=new Date(); //默认为当前日期
        var varYear=fctDate.getFullYear();
        var varMonth=fctDate.getMonth();
        var varNextMonth=new Date(varYear,varMonth+1,1);
        var varThisMonthButDay = new Date(varNextMonth-86400000); //本月最后一天

        var varThisDate,varThisWeekDay,varThisMonthHTML="";
        varThisMonthHTML+="<h1>"+varYear+"年"+(varMonth+1)+"月</h1>"
        varThisMonthHTML+="<div>日</div><div>一</div><div>二</div><div>三</div><div>四</div><div>五</div><div>六</div>"
        for(var DayI=1;DayI<=varThisMonthButDay.getDate();DayI++){
                varThisDate=new Date(varYear,varMonth,DayI);
                varThisWeekDay=varThisDate.getDay();
                if(DayI==1){
                        for(var spcI=0;spcI<varThisWeekDay;spcI++){
                                varThisMonthHTML+="<a></a>"
                        }
                }
                varThisMonthHTML+="<a "+((fctStaDate && fctStaDate!="")?(varThisDate<fctStaDate?"old":""):"")+" href=javascript:; onclick='SelectDate(this)' title='"+varYear+"-"+(varMonth+1)+"-"+DayI+"'>"+DayI+"</a>";
        }
        return '<div class="DateListBox">'+varThisMonthHTML+'</div>';
}
//选择日期
function SelectDate(fctAObj){
        if(fctAObj.href||fctAObj.className=="aSelect"){
                var varValueObj=$("divPyzyDateBox").Obj;
                var varValueToObj=GetValueToInputObj(varValueObj);
                if(varValueToObj)varValueObj=varValueToObj;
                if(varValueObj.value==fctAObj.title){
                        varValueObj.value=varValueObj.value;
                }else{
                        varValueObj.value=fctAObj.title;
                }
                $("divPyzyDateBox").style.visibility="hidden";
                $("divPyzyDateBox").bodyclick="";
                GetPyzyIframe("ifmdivPyzyDateBox","hidden");
                AutoNextInputAct($("divPyzyDateBox").Obj,"click");
        }
}
//隐藏日历
function HiddenDateBox(){
        if($("divPyzyDateBox")){
                if($("divPyzyDateBox").style.visibility!="hidden" && $("divPyzyDateBox").bodyclick=="1"){
                        $("divPyzyDateBox").style.visibility="hidden";
                        $("divPyzyDateBox").bodyclick="";
                        GetPyzyIframe("ifmdivPyzyDateBox","hidden");
                }else{
                        $("divPyzyDateBox").bodyclick="1";
                }
        }
}
//显示日历
function ShowTwoMonthList(fctThisObj,fctJNum,fctStaDate){
        if(!fctJNum)fctJNum=0;
        if(!fctThisObj)fctThisObj="";
        var varStaDate=null,varTheDate=new Date();
        if(fctStaDate||fctStaDate==""){
                varStaDate=new Date(new Date()-86400000); //如果没有定义具体可使用的开始时间则自定义为今天
                var varStaDateSplit=fctStaDate.split("-");
                if(varStaDateSplit.length==3){
                        varStaDate=new Date(varStaDateSplit[0],parseInt(varStaDateSplit[1],10)-1,varStaDateSplit[2]);//fctStaDate=new Date();
                }
                varTheDate=varStaDate;
                if(fctStaDate=="")fctStaDate=varStaDate.getFullYear()+"-"+(varStaDate.getMonth()+1)+"-"+varStaDate.getDate();
        }
        var varShowTwoMonthHTML="";
        for(var i=0+fctJNum;i<2+fctJNum;i++){
                varShowTwoMonthHTML+=GetMonthHTML((varStaDate?varStaDate:""),new Date(varTheDate.getFullYear(),varTheDate.getMonth()+i,1));
        }
        if(varStaDate)varShowTwoMonthHTML=varShowTwoMonthHTML.replace(/old href/g,"style=color:#999 old");
        if(fctThisObj.value!=""){ //对已选日期样式进行改变
                if(/^((\d{4})|(\d{2}))-(\d{1,2})-(\d{1,2})$/g.test(fctThisObj.value))varShowTwoMonthHTML=varShowTwoMonthHTML.replace(fctThisObj.value,fctThisObj.value+"' class='aSelect");
        }
        var varDateBoxObj = c$("divPyzyDateBox","PyzyDateBox");
        varDateBoxObj.bodyclick="";
        if(fctThisObj!=""){ //调整坐标到合适位置
                var varThisObjPosition=getPosition(fctThisObj);
                varDateBoxObj.style.top=(varThisObjPosition.top+varThisObjPosition.height)+"px";
                varDateBoxObj.style.left=varThisObjPosition.left+"px";
                varDateBoxObj.style.visibility="visible"; //hidden
                varDateBoxObj.Obj=fctThisObj;
        }
        varDateBoxObj.innerHTML=varShowTwoMonthHTML+'<div style="margin-top:'+(document.all?'-177':'-1')+'px;color:#B42929;font-size:12px;font-weight:bold;line-height:24px;vertical-align:bottom;"> <span style="padding-right:'+(document.all?'220':'232')+'px;cursor:pointer;" onclick="ShowTwoMonthList(null,'+(fctJNum-1)+(fctStaDate?',\''+fctStaDate+'\'':'')+')" title="上月"><--</span><span style="cursor:pointer;" onclick="ShowTwoMonthList(null,'+(fctJNum+1)+(fctStaDate?',\''+fctStaDate+'\'':'')+')" title="下月">--></span></div>';
        GetPyzyIframe("ifmdivPyzyDateBox","visible",(varThisObjPosition.top+varThisObjPosition.height),varThisObjPosition.left,varDateBoxObj.offsetWidth,varDateBoxObj.offsetHeight); //取Iframe
}
/**********日历选择功能 End huzj 2008-4-14*************/

//为window.onload增加一个为document增加onclick处理函数的函数(^_^)huzj 2008-4-14
//AddFunToObj(window,"onload","AddFunToObj(document,'onclick','_Hidden("+(document.all?"":"e")+");HiddenDateBox();');");