function DateSelector(InstanceName) {
    //对象名称
    this.instanceName = InstanceName;
    //保存结果的表单域
    this.oResultField = null;

    //选择器的标题
    this.strTitle = "日期选择";

    //放置选择器的div的id
    this.divId = InstanceName + "Div";

    //点击的按钮
    this.but = null;

    //函数
    this.Init = dateSelectorInit;
    this.checkedBox = dateCheckedBox;
    this.setTitle = dateSetTitle
    this.showSelector = showDateSelector;
    this.initResult = initDateResult;

    //this.chooseType=chooseType;//用于点击父类：当子类隐藏时，父类选中并添加到结果中，当子类显示父类设为没选中

}

function dateSetTitle(strTitle) {
    this.strTitle = strTitle;
}

//建立selector的各个层次的容器（div，span等）
function dateSelectorInit() {

    var objJobType = document.getElementById(this.divId);
    if (objJobType != null) {
        return;
    }

    var divHtml = "<DIV id=\"" + this.divId + "\" style=\'width:450px;DISPLAY:none; Z-INDEX:999; POSITION:absolute;  BACKGROUND-COLOR:#ffffff; bordercolor:#ffffff'';>";
    divHtml += "<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">";
    divHtml += "<tr>";
    divHtml += "<td width=\"5\" height=\"5\"><img src=\"/images/typeselector/div_01.gif\"></td><td background=\"/images/typeselector/div_02.gif\"></td>";
    divHtml += "<td><img src=\"/images/typeselector/div_03.gif\"></td></tr>";
    divHtml += "<tr>";
    divHtml += "<td background=\"/images/typeselector/div_04.gif\"></td>";
    divHtml += "<td valign=\"top\" bgcolor=\"#FFFFFF\">";
    divHtml += "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" id=\"divtt\">";
    divHtml += "<tr>";
    divHtml += "<td class=\"tt\">" + this.strTitle + "</td>";
    divHtml += "<td align=\"right\"><a href=\"javascript:showSelect('" + this.divId + "');divClose('" + this.divId + "');\">[确定]</a> <a href=\"javascript:showSelect('" + this.divId + "');divClose('" + this.divId + "');\">[关闭]</a></td>";
    divHtml += "</tr>";
    divHtml += "</table>";
    divHtml += "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">";
    divHtml += "<tr><td align=\"center\" onclick=\"dateClick(1,'近一天'," + this.instanceName + ")\" style='cursor:hand'>近一天</td><td align=\"center\" onclick=\"dateClick(2,'近两天'," + this.instanceName + ")\" style='cursor:hand'>近两天</td><td align=\"center\" onclick=\"dateClick(3,'近三天'," + this.instanceName + ")\" style='cursor:hand'>近三天</td></tr>";
    divHtml += "<tr><td align=\"center\" onclick=\"dateClick(7,'近一周'," + this.instanceName + ")\" style='cursor:hand'>近一周</td><td align=\"center\" onclick=\"dateClick(15,'近半月'," + this.instanceName + ")\" style='cursor:hand'>近半月</td><td align=\"center\" onclick=\"dateClick(30,'近一月'," + this.instanceName + ")\" style='cursor:hand'>近一月</td></tr>";
    divHtml += "<tr><td align=\"center\" onclick=\"dateClick(60,'近两月'," + this.instanceName + ")\" style='cursor:hand'>近两月</td><td align=\"center\" onclick=\"dateClick(90,'近三月'," + this.instanceName + ")\" style='cursor:hand'>近三月</td><td align=\"center\"></td></tr>";
    divHtml += "</table>";
    divHtml += "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" id=\"divtt\">";
    divHtml += "<tr>";
    divHtml += "<td align=\"right\"><a href=\"javascript:showSelect('" + this.divId + "');divClose('" + this.divId + "');\">[确定]</a> <a href=\"javascript:showSelect('" + this.divId + "');divClose('" + this.divId + "');\">[关闭]</a></td>";
    divHtml += "</tr>";
    divHtml += "</table>";
    divHtml += "</td>";
    divHtml += "<td background=\"/images/typeselector/div_06.gif\">";
    divHtml += "</td></tr>";
    divHtml += "<tr><td>";
    divHtml += "<img src=\"/images/typeselector/div_07.gif\"></td>";
    divHtml += "<td background=\"/images/typeselector/div_08.gif\"></td>";
    divHtml += "<td width=\"1\" height=\"1\">";
    divHtml += "<img src=\"/images/typeselector/div_09.gif\"></td>";
    divHtml += "</tr></table>";
    divHtml += "</div>"
    document.write(divHtml);

}

/**显示选择器，如果选择器的第一层还没有创建则要创建
@param oInstance 选择器对象
*/

function showDateSelector(objBut, resultField) {
    this.but = objBut;
    this.oResultField = resultField;

    setDivInCenter(this.divId);

    objJobType = document.getElementById(this.divId);
    objJobType.style.display = "";
    hiddenSelect(this.divId);

    return;
}

/**选中某一类型后显示下一级所有类型或没有下级时更改选择结果
@param cityId 选中的类型
@param level 选中的类型所处的级别的下一级别。级别从1开始
*/
function dateCheckedBox(days, strName) {
    this.oResultField.value = days;
    this.but.value = strName;
    showSelect(this.divId);
    divClose(this.divId);
}



function dateClick(days, strName, oInstance) {
    oInstance.checkedBox(days, strName);
}

/*显示默认结果
oResultField:保存结果的隐藏域对象
objBut触发选择器的按钮对象
*/
function initDateResult(oResultField, objBut) {
    this.oResultField = oResultField;
    this.but = objBut;
    if (this.oResultField.value == 1) {
        this.but.value = "近一天";
    } else if (this.oResultField.value == 2) {
        this.but.value = "近两天";
    } else if (this.oResultField.value == 3) {
        this.but.value = "近三天";
    } else if (this.oResultField.value == 7) {
        this.but.value = "近一周";
    } else if (this.oResultField.value == 14) {
        this.but.value = "近半月";
    } else if (this.oResultField.value == 30) {
        this.but.value = "近一月";
    } else if (this.oResultField.value == 60) {
        this.but.value = "近两月";
    } else if (this.oResultField.value == 90) {
        this.but.value = "近三月";
    }
}