var commonGridObj_paysettlement;
var comboCustomer;//委托单位

function $(id){
    return document.getElementById(id);
}

function createGrid(){
    //header
    $("hdNAMES").value = "结算单号\t结算单状态\t结算类别\t结算单位\t结算方式\tRMB支票号\tUSD支票号\tUSD\tRMB\t结算人\t结算日期\t备注";
    var headerArgs_paysettlement = new Array("<input type=\"checkbox\" id=\"ck_all\" onclick=\"checkAll('ck_all')\" />", "结算单号", "结算单状态", "结算类别", "结算单位", "结算方式", "RMB支票号", "USD支票号", "USD", "RMB", "实付支", "结算人", "结算日期", "申请单号", "备注");
    //width
    var widthArgs_paysettlement = new Array("40", "120", "70", "70", "100", "70", "100", "100", "80", "80", "80", "150", "150", "150", "200");
    //column align                       
    var colAlignArgs_paysettlement = new Array("center", "center", "center", "center", "center", "center", "center", "center", "center", "center", "center", "center", "center", "center", "center");
    //column sort               
    var colSortArgs_paysettlement = new Array("na", "str", "str", "str", "str", "str", "str", "str", "str", "str", "str", "str", "str", "str", "str");
    //column type
    var colTypeArgs_paysettlement = new Array("ch", "ro", "ro", "ro", "ro", "ro", "ro", "ro", "ro", "ro", "ro", "ro", "ro", "ro", "ro");
 
    
    commonGridObj_paysettlement = new TGridCommon("mygrid_container_paysettlement","form1",headerArgs_paysettlement,widthArgs_paysettlement,colAlignArgs_paysettlement,colSortArgs_paysettlement,colTypeArgs_paysettlement);
    
    commonGridObj_paysettlement.setResponseUrl("PaySettlementGridSource.aspx");
    
    if($("sel_type").value == 2){
        $("btn_cancelsettle").onclick = cancelSettle;
        $("btn_cancelsettle").disabled = false;
        $("btn_createcheque").onclick = createCheque;
        $("btn_createcheque").disabled = false;
        $("btn_delete").disabled = true;
        $("btn_delete").onclick = clickNull;
        $("btn_postsettle").disabled = true;
        $("btn_postsettle").onclick = clickNull;
        commonGridObj_paysettlement.setRequest("PaySettlementGridSource.aspx?handle=paysettlelist&show_page=15&cur_page=1&uid="+commonGridObj_paysettlement.newGuid());
    }else{
        $("btn_createcheque").onclick = clickNull;
        $("btn_delete").onclick = clickNull;
        $("btn_delete").disabled = true;
        $("btn_cancelsettle").onclick = clickNull;
        $("btn_cancelsettle").disabled = true;
        $("btn_createcheque").onclick = clickNull;
        $("btn_createcheque").disabled = true;
        $("btn_delete").disabled = false;
        $("btn_delete").onclick = deleteUnSettle;
        $("btn_postsettle").disabled = false;
        $("btn_postsettle").onclick = postSettle;
        commonGridObj_paysettlement.setRequest("PaySettlementGridSource.aspx?handle=paysettlesavedlist&show_page=15&cur_page=1&uid="+commonGridObj_paysettlement.newGuid());
    }
    commonGridObj_paysettlement.setSourceType("json");
    commonGridObj_paysettlement.setSkin("xp");
    commonGridObj_paysettlement.setImageUrl("../images/");
    commonGridObj_paysettlement.initGrid();
    commonGridObj_paysettlement.bind();

    if ($("sel_type").value == 2) {
        commonGridObj_paysettlement.initPageByHandle("paysettlelist");
    }
    else {
        commonGridObj_paysettlement.initPageByHandle("paysettlesavedlist");
    }
    
    commonGridObj_paysettlement.isDBClickEvent = true;

    commonGridObj_paysettlement.getGridObj().attachEvent("onRowDblClicked", function (rId, cInd) {
        if ($("sel_type").value == 2) {
            var openSet = "height=750, width=1100, toolbar=no, menubar=no,scrollbars=no, resizable=no,location=no, status=no,Top=10px,Left=100px";
            var openType = "_blank";

            var openUrl = "PaySettlementEdit.aspx?handle=edit&id=" + rId + "&checktype=" + $("sel_type").value;
            window.open(openUrl, openType, openSet);
        } else {
            var openSet = "height=750, width=1100, toolbar=no, menubar=no,scrollbars=no, resizable=no,location=no, status=no,Top=10px,Left=100px";
            var openType = "_blank";

            var openUrl = "PaySettlementEdit.aspx?handle=edit&runsettleid=" + rId + "&checktype=" + $("sel_type").value;
            window.open(openUrl, openType, openSet);
        }
    });
    
    commonGridObj_paysettlement.dbclickEvent = function(){
        commonGridObj_paysettlement.getGridObj().attachEvent("onRowDblClicked", function(rId,cInd){  
            if($("sel_type").value == 2){
                var openSet = "height=750, width=1100, toolbar=no, menubar=no,scrollbars=no, resizable=no,location=no, status=no,Top=10px,Left=100px";
                var openType = "_blank";
                    
                var openUrl = "PaySettlementEdit.aspx?handle=edit&id="+rId+"&checktype="+$("sel_type").value;
                window.open (openUrl,openType,openSet);
            }else{
                var openSet = "height=750, width=1100, toolbar=no, menubar=no,scrollbars=no, resizable=no,location=no, status=no,Top=10px,Left=100px";
                var openType = "_blank";
                    
                var openUrl = "PaySettlementEdit.aspx?handle=edit&runsettleid="+rId+"&checktype="+$("sel_type").value;
                window.open (openUrl,openType,openSet);
            }
        });
    }
}

function settleAction(){
    //异步执行操作
    var url = "PaySettlementGridSource.aspx?handle=validatepaysettlement&uid="+commonGridObj_paysettlement.newGuid();
    var loader = dhtmlxAjax.getSync(url);
    var postStatus = loader.xmlDoc.responseText;
    
    var status = parseInt(postStatus);
    
    if(status > 0){
        var openSet = "height=580, width=970, toolbar=no, menubar=no,scrollbars=no, resizable=no,location=no, status=no,Top= " +(screen.height-580)/2 + ",Left= "+(screen.width-970)/2
        var openType = "_blank";
        var moduleName = "";
        if(commonGridObj_paysettlement.$("h_mod").value != ""){
            moduleName = "?mod="+commonGridObj_paysettlement.$("h_mod").value;
        }
        var openUrl = "CommonPaySettlement.aspx" + moduleName;
        window.open (openUrl,openType,openSet); 
    }else{
        alert("没有权限操作付费结算");
    }
}

function refreshList(){
    createGrid();
}

function payfeeapplsettle(){//付费申请结算
     //异步执行操作
    var url = "PaySettlementGridSource.aspx?handle=validatepaysettlement&uid="+commonGridObj_paysettlement.newGuid();
    var loader = dhtmlxAjax.getSync(url);
    var postStatus = loader.xmlDoc.responseText;
    
    var status = parseInt(postStatus);
    
    if(status > 0){
        var openSet = "height=680, width=1050, toolbar=no, menubar=no,scrollbars=no, resizable=1,location=no, status=no,Top= " +(screen.height-650)/2 + ",Left= "+(screen.width-1200)/2
        var openType = "_blank";
        var openUrl = "PayApplicationSettlement.aspx";
        window.open (openUrl,openType,openSet); 
    }else{
        alert("没有权限操作付费申请结算");
    }
}

function createCheque(){
     //异步执行操作
    var url = "PaySettlementGridSource.aspx?handle=validatepaysettlement&uid="+commonGridObj_paysettlement.newGuid();
    var loader = dhtmlxAjax.getSync(url);
    var postStatus = loader.xmlDoc.responseText;
    
    var status = parseInt(postStatus);
    
    if(status > 0){
        var selectedId = commonGridObj_paysettlement.getGridObj().getSelectedRowId();
        var rowIndex = commonGridObj_paysettlement.getGridObj().getRowIndex(selectedId);
        var billNO = commonGridObj_paysettlement.getGridObj().cellByIndex(rowIndex,0).getValue().trim();
        
        if(billNO != null){
            var openSet = "height=680, width=1050, toolbar=no, menubar=no,scrollbars=no, resizable=1,location=no, status=no,Top= " +(screen.height-650)/2 + ",Left= "+(screen.width-1200)/2
            var openType = "_blank";
            
            var openUrl = "../cheque/ChCheckInfo.aspx?handle=add&paysettlebillno="+billNO;
            window.open (openUrl,openType,openSet);
        }
    }else{
        alert("没有权限生成支票");
    }
}

function initCombo(){
    CustomerCombo();//结算单位
}


//根据条件查询付费申请信息
function search(){
    var _begintime = $("txt_beginDate").value.trim();
    
    if(_begintime.trim() != ""){
        if(!validateDateTime(_begintime)){
            alert("起始时间格式错误");
            return;
        }
    }
    var _endtime = $("txt_endDate").value.trim();
    if(_endtime.trim() != ""){
        if(!validateDateTime(_endtime)){
            alert("结束时间格式错误");
            return;
        }
    }
    
    
    var _customer = $("h_customer").value.trim();
    var _checkno = $("txt_billno").value.trim();
    var _mblno = $("txt_mblno").value.trim();
    var _other = $("txt_other").value.trim();
    
    var searchJson = "";
    //begin
    searchJson +="{";
    searchJson += "[";
    
    //如果查询条件设置了起始时间和结束时间则判断结束时间是否大于起始时间
    if(_begintime != "" && _endtime != ""){
        if(_begintime.length > 9 && _endtime.length > 9){
            var status = DateTimeEqual(_begintime,_endtime);
            if(status == 0){
                searchJson += "\"btime\":\""+_begintime+"\","
                searchJson += "\"etime\":\""+_endtime+"\","
            }else if(status == -1){
                alert("时间设置错误,起始时间不能大于结束时间,请修改!");
                return;
            }
//            else if(status == -2){
//                alert("时间设置错误,起始时间不能等于结束时间,请修改!");
//                return;
//            }
        }
        else{
            alert("时间格式有问题,长度应大于9个字符,请修改!");
            return;
        }
    }else{
        searchJson += "\"btime\":\""+_begintime+"\","
        searchJson += "\"etime\":\""+_endtime+"\","
    }
    
    searchJson += "\"cus\":\""+_customer+"\",";
    searchJson += "\"no\":\"" + _checkno + "\",";
    searchJson += "\"mblno\":\"" + _mblno + "\",";
    searchJson += "\"other\":\"" + _other + "\",";
    searchJson += "\"amount1\":\"" + $("txt_amount1").value.trim() + "\",";
    searchJson += "\"amount2\":\"" + $("txt_amount2").value.trim() + "\"";
    searchJson += "]";
    searchJson +="}";//alert(searchJson);
    $("hdSearch").value = searchJson;
    
    commonGridObj_paysettlement.initGrid();
    commonGridObj_paysettlement.setRequest("PaySettlementGridSource.aspx?handle=paysettlelist&show_page=15&cur_page=1&search="+escape(searchJson)+"&uid="+commonGridObj_paysettlement.newGuid());
    
    if($("sel_type").value == 2){
        $("btn_cancelsettle").onclick = cancelSettle;
        $("btn_cancelsettle").disabled = false;
        $("btn_createcheque").onclick = createCheque;
        $("btn_createcheque").disabled = false;
        $("btn_delete").disabled = true;
        $("btn_delete").onclick = clickNull;
        $("btn_postsettle").disabled = true;
        $("btn_postsettle").onclick = clickNull;
        commonGridObj_paysettlement.setRequest("PaySettlementGridSource.aspx?handle=paysettlelist&show_page=15&cur_page=1&search="+escape(searchJson)+"&uid="+commonGridObj_paysettlement.newGuid());
    }else{
        $("btn_createcheque").onclick = clickNull;
        $("btn_delete").onclick = clickNull;
        $("btn_delete").disabled = true;
        $("btn_cancelsettle").onclick = clickNull;
        $("btn_cancelsettle").disabled = true;
        $("btn_createcheque").onclick = clickNull;
        $("btn_createcheque").disabled = true;
        $("btn_delete").disabled = false;
        $("btn_delete").onclick = deleteUnSettle;
        $("btn_postsettle").disabled = false;
        $("btn_postsettle").onclick = postSettle;
        commonGridObj_paysettlement.setRequest("PaySettlementGridSource.aspx?handle=paysettlesavedlist&show_page=15&cur_page=1&search="+escape(searchJson)+"&uid="+commonGridObj_paysettlement.newGuid());
    }
    commonGridObj_paysettlement.bind();
    
    commonGridObj_paysettlement.setSearch(searchJson);
    
    commonGridObj_paysettlement.initPageByHandle("paysettlelist");
    commonGridObj_paysettlement.isDBClickEvent = true;
    
    commonGridObj_paysettlement.getGridObj().attachEvent("onRowDblClicked", function(rId,cInd){ 
            if($("sel_type").value == 2){
                var openSet = "height=750, width=1100, toolbar=no, menubar=no,scrollbars=no, resizable=no,location=no, status=no,Top=10px,Left=100px";
                var openType = "_blank";
                    
                var openUrl = "PaySettlementEdit.aspx?handle=edit&id="+rId+"&checktype="+$("sel_type").value;
                window.open (openUrl,openType,openSet);
            }else{
                var openSet = "height=750, width=1100, toolbar=no, menubar=no,scrollbars=no, resizable=no,location=no, status=no,Top=10px,Left=100px";
                var openType = "_blank";
                    
                var openUrl = "PaySettlementEdit.aspx?handle=edit&runsettleid="+rId+"&checktype="+$("sel_type").value;
                window.open (openUrl,openType,openSet);
            }
    });
    
    commonGridObj_paysettlement.dbclickEvent = function(){
        commonGridObj_paysettlement.getGridObj().attachEvent("onRowDblClicked", function(rId,cInd){  
            if($("sel_type").value == 2){
                var openSet = "height=750, width=1100, toolbar=no, menubar=no,scrollbars=no, resizable=no,location=no, status=no,Top=10px,Left=100px";
                var openType = "_blank";
                    
                var openUrl = "PaySettlementEdit.aspx?handle=edit&id="+rId+"&checktype="+$("sel_type").value;
                window.open (openUrl,openType,openSet);
            }else{
                var openSet = "height=750, width=1100, toolbar=no, menubar=no,scrollbars=no, resizable=no,location=no, status=no,Top=10px,Left=100px";
                var openType = "_blank";
                    
                var openUrl = "PaySettlementEdit.aspx?handle=edit&runsettleid="+rId+"&checktype="+$("sel_type").value;
                window.open (openUrl,openType,openSet);
            }
        });
    }
}
//校验时间格式
function validateDateTime(dateTimeObj){
    var isValid = false;
    
    var parseToObj = new Date(dateTimeObj.replace(/-/g, "/"));
    if(!isNaN(parseToObj)){
        isValid = true;
    }
    
    return isValid;
}

function DateTimeEqual(beginObj,endObj){
    var isEqual = 0;
    var begin = new Date(beginObj.replace(/-/g, "/"));
    var end = new Date(endObj.replace(/-/g, "/"));
    
    if(Date.parse(begin) - Date.parse(end) > 0){
        isEqual = -1;//起始时间大于结束时间
    }else if(Date.parse(begin) - Date.parse(end) == 0){
        isEqual = -2;//起始时间与结束时间相等
    }
    return isEqual;
}

String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g,""); }

function CustomerCombo(){//委托单位
    comboCustomer = new TCombo("sel_customer","../FeeCodes/WebCrmClientAdapter.aspx?mask=0&pos=0",true,true,false,true,"h_customer");//&strIS=ISCONTROLLER
    comboCustomer.initComboEvent();
    comboCustomer.bind();
}


//初始化界面
function initGrid(){
     $("h_customer").value = "";
    comboCustomer.setText($("h_customer").value);
    $("txt_beginDate").value = "";
    $("txt_endDate").value = "";
    $("txt_billno").value = "";
    $("hdSearch").value = "";
    $("txt_amount1").value = "";
    $("txt_amount2").value = "";
    $("txt_mblno").value = "";
    $("txt_other").value = "";
    createGrid();
}

function checkAll(id){
    if($(id).checked){
        for(var i=0;i<commonGridObj_paysettlement.getGridObj().getRowsNum();i++){
            commonGridObj_paysettlement.getGridObj().cellByIndex(i,0).setValue(1);
        }
    }else{
        for(var i=0;i<commonGridObj_paysettlement.getGridObj().getRowsNum();i++){
            commonGridObj_paysettlement.getGridObj().cellByIndex(i,0).setValue(0);
        }
    }
}

function checkList(val){
    createGrid();
}

function clickNull(){
    
}

//撤销结算
function cancelSettle(){
    if($("sel_type").value == 2){
        var postArg = new Array();
    
        var stateArg = new Array();
        var success = 0;
        var failure = 0;
        var feeError = 0;
        var isVounoError = 0;
        for(var i=0;i<commonGridObj_paysettlement.getGridObj().getRowsNum();i++){
            var rId = commonGridObj_paysettlement.getGridObj().getRowId(i);
            var checkState = commonGridObj_paysettlement.getGridObj().cellByIndex(i,0).getValue();
            
            if(checkState == 1){
                postArg.push(rId);
            }
        }
        
        if(postArg.length > 0){
            if(window.confirm("您确定要撤销付费结算,取消结算后结算信息会被删除 继续请按 (确定)  取消请按(取消) ")){
                for(var j=0;j<postArg.length;j++){
                    var url = "PaySettlementGridSource.aspx?handle=cancelpaysettle&paysettleid="+postArg[j]+"&uid="+commonGridObj_paysettlement.newGuid();
                    var loader = dhtmlxAjax.getSync(url);
                    var stateVal = loader.xmlDoc.responseText;
                    
                    if(stateVal == 1){
                        success++;
                    }else{
                        if(stateVal == -3){
                            feeError++;
                        }
                        else if(stateVal == -4){
                            isVounoError++;
                        }else{
                            failure++;
                        }
                    }
                    stateArg.push(stateVal);
                }
                createGrid();
                //
                var strError = "";
                if (feeError != 0)
                {
                    strError += "\n另:" + feeError + "条“预付支资料”已使用,不允许操作!请先删除已使用的“预付支取用资料”!";
                }
                if (isVounoError != 0)
                {
                    strError += "\n另:" + isVounoError + "条已生成结算凭证,不允许操作!请先删除已生成的“结算凭证”!";
                }
                alert("撤销付费结算完成 共 " + postArg.length + " 条 成功 " + success + " 条 失败 " + failure + " 条。" + strError);
            }
        }else{
            alert("没有要选中的要操作的项");
        }
    }else{
        alert("只能撤销已经结算的付费信息");
    }
}

//删除未结算付费
function deleteUnSettle(){
    if($("sel_type").value == 1){
        var postArg = new Array();
    
        var stateArg = new Array();
        var success = 0;
        var failure = 0;
        //var feeError = 0;
        for(var i=0;i<commonGridObj_paysettlement.getGridObj().getRowsNum();i++){
            var rId = commonGridObj_paysettlement.getGridObj().getRowId(i);
            var checkState = commonGridObj_paysettlement.getGridObj().cellByIndex(i,0).getValue();
            
            if(checkState == 1){
                postArg.push(rId);
            }
        }
        
        if(postArg.length > 0){
            for(var j=0;j<postArg.length;j++){
                var url = "PaySettlementGridSource.aspx?handle=deleteunsavedpaysettle&runsettleid="+postArg[j]+"&uid="+commonGridObj_paysettlement.newGuid();
                var loader = dhtmlxAjax.getSync(url);
                var stateVal = loader.xmlDoc.responseText;
                
                if(stateVal == 1){
                    success++;
                }else{
                    if(stateVal == -3){
                        feeError++;
                    }else{
                        failure++;
                    }
                }
                stateArg.push(stateVal);
            }
            createGrid();
            alert("删除未结算付费完成 共 "+postArg.length+" 条 成功 "+success+" 条 失败 "+failure+" 条");
        }
    }else{
        alert("不能直接删除已结算付费,只能撤销已经结算的付费");
    }
    
}
//提交未已保存为结算付费
function postSettle(){    
    if($("sel_type").value == 1){
        var postArg = new Array();
    
        var stateArg = new Array();
        var success = 0;
        var failure = 0;
        var feeError = 0;

        for(var i=0;i<commonGridObj_paysettlement.getGridObj().getRowsNum();i++){
            var rId = commonGridObj_paysettlement.getGridObj().getRowId(i);
            var checkState = commonGridObj_paysettlement.getGridObj().cellByIndex(i,0).getValue();
            
            if(checkState == 1){
                postArg.push(rId);
            }
        }
        
        if(postArg.length > 0){
            for(var j=0;j<postArg.length;j++){
                var url = "PaySettlementGridSource.aspx?handle=postunsavedpaysettle&runsettleid="+postArg[j]+"&uid="+commonGridObj_paysettlement.newGuid();
                var loader = dhtmlxAjax.getSync(url);
                var stateVal = loader.xmlDoc.responseText;
                
                if(stateVal == 1){
                    success++;
                }else{
                    if(stateVal == -3){
                        feeError++;
                    }else{
                        failure++;
                    }
                }
                stateArg.push(stateVal);
            }
            createGrid();
            alert("提交未结算付费完成 共 "+postArg.length+" 条 成功 "+success+" 条 失败 "+failure+" 条");
        }
    }else{
        alert("已结算付费不能重提提交结算");
    }
}


function setExcel() {
    if (confirm('确定要导出报表吗?')) {
        //
        var loader = "";
        //"ProfitReportGridSource.aspx?handle=excel&tbNO=" + $("tbNO").value + "&ddlCUSTOMERNAME=" + escape($("hd_comboCUSTOMERNAME").value) + "&ddlSALE=" + escape($("hd_comboSALE").value) + "&ddlVESSEL=" + escape($("hd_comboVESSEL").value) + "&ddlVOYNO=" + escape($("hd_comboVOYNO").value) + "&tbETD=" + $("tbETD").value + "&tbETD2=" + $("tbETD2").value + "&hidsel=" + $("hid_sel").value + "&cntr=" + s0 + "&uid=" + newGuid() + "&ddlBSTYPE=" + escape($("ddlBSTYPE").value));
        var searchJson = $("hdSearch").value.trim();
        if ($("sel_type").value == 2) {
            loader = dhtmlxAjax.getSync("PaySettlementGridSource.aspx?handle=paysettlelistexcel&search=" + escape(searchJson) + "&uid=" + newGuid());
        } else {
            loader = dhtmlxAjax.getSync("PaySettlementGridSource.aspx?handle=paysettlesavedlistexcel&search=" + escape(searchJson) + "&uid=" + newGuid());
        }  
        $("hdSQL").value = loader.xmlDoc.responseText;
        //
        document.getElementById("ibExcel").click();               
    }
}    

    //获取GUID
    function newGuid()
    {
        var guid = "";
        for (var i = 1; i <= 32; i++){
          var n = Math.floor(Math.random()*16.0).toString(16);
           guid +=    n;
          if((i==8)||(i==12)||(i==16)||(i==20))
             guid += "-";
         }
        return guid.toUpperCase();
    }
    //是否为数字,且数值格式是否正确
    function IsNumFormat(val) {
        var re = /^[-\+]?\d+(\.\d+)?$/;
        if (!re.test(val)) {
            return false;
        }
        else {
            if (val.toString().indexOf(".") > 0) {
                val.toString().replace("-", "");
                val.toString().replace("+", "");
                if (val.toString().substr(0, 1) == "0" && val.toString().substr(0, 2) != "0.") {
                    return false;
                }
            }
            else {
                var re1 = /^[-\+]+[1-9]+[0-9]*]*$/;
                if (!re1.test(val)) {
                    re1 = /^[1-9]+[0-9]*]*$/;
                    if (!re1.test(val)) {
                        return false;
                    }
                }
            }
            return true;
        }
    }
    //
    function getIsNum(x) {
        var str = x.value.trim();
        if (str == "0") {
            return;
        }
        else if (str == "") {
            return;
//            str = 0;
//            x.value = 0;
        }
        else {
            var bl = IsNumFormat(str);
            if (!bl) {
                alert("数值格式错误!");
                x.focus();
                x.select();
            }
        }
    }

    function printSettlement() {
        var searchJson = $("hdSearch").value.trim();
        if ($("sel_type").value == 1) {
            return;
        }
        var strBillNO = commonGridObj_paysettlement.getGridObj().getCheckedRows(0); //所有选中的grid的id编号 
        //
        var _begintime = $("txt_beginDate").value.trim();

        if (_begintime.trim() != "") {
            if (!validateDateTime(_begintime)) {
                alert("起始时间格式错误");
                return;
            }
        }
        var _endtime = $("txt_endDate").value.trim();
        if (_endtime.trim() != "") {
            if (!validateDateTime(_endtime)) {
                alert("结束时间格式错误");
                return;
            }
        }


        var _customer = $("h_customer").value.trim();
        var _checkno = $("txt_billno").value.trim();
        var _mblno = $("txt_mblno").value.trim();
        var _other = $("txt_other").value.trim();

        var searchJson = "";
        //begin
        searchJson += "{";
        searchJson += "[";

        //如果查询条件设置了起始时间和结束时间则判断结束时间是否大于起始时间
        if (_begintime != "" && _endtime != "") {
            if (_begintime.length > 9 && _endtime.length > 9) {
                var status = DateTimeEqual(_begintime, _endtime);
                if (status == 0) {
                    searchJson += "\"btime\":\"" + _begintime + "\","
                    searchJson += "\"etime\":\"" + _endtime + "\","
                } else if (status == -1) {
                    alert("时间设置错误,起始时间不能大于结束时间,请修改!");
                    return;
                } 
//                else if (status == -2) {
//                    alert("时间设置错误,起始时间不能等于结束时间,请修改!");
//                    return;
//                }
            }
            else {
                alert("时间格式有问题,长度应大于9个字符,请修改!");
                return;
            }
        } else {
            searchJson += "\"btime\":\"" + _begintime + "\","
            searchJson += "\"etime\":\"" + _endtime + "\","
        }

        searchJson += "\"cus\":\"" + _customer + "\",";
        searchJson += "\"no\":\"" + _checkno + "\",";
        searchJson += "\"mblno\":\"" + _mblno + "\",";
        searchJson += "\"other\":\"" + _other + "\",";
        searchJson += "\"amount1\":\"" + $("txt_amount1").value.trim() + "\",";
        searchJson += "\"amount2\":\"" + $("txt_amount2").value.trim() + "\"";
        searchJson += "]";
        searchJson += "}"; 
        $("hdSearch").value = searchJson;
        //
        var printUrl = "";
        var companyID = "";
        var typeName = "PAYSETTLELIST";
        var dbSourceID = "";
        var userID = "";
        var url = "";

        url = "../Reports/ReportService.aspx?handle=printpaysettlelist&billno=" + strBillNO + "&search=" + escape(searchJson) + "&uid=" + commonGridObj_paysettlement.newGuid();
        var loader = dhtmlxAjax.getSync(url);
        var reportVal = loader.xmlDoc.responseText;
        var reportObj = null;

        if (reportVal != "") {
            reportObj = eval('(' + reportVal + ')');
            if (reportObj.reports.length > 0) {
                if (reportObj.reports[0].compid != "") {
                    companyID = reportObj.reports[0].compid;
                }
                if (reportObj.reports[0].sourceid != "") {
                    dbSourceID = reportObj.reports[0].sourceid;
                }
                if (reportObj.reports[0].compid != "") {
                    userID = reportObj.reports[0].userid;
                }
                printUrl = "print://?comp=" + companyID + "&type=" + typeName + "&dbid=" + dbSourceID + "&uid=" + userID; //alert(printUrl);
                window.location.href = window.location.href;
                location.href = printUrl;
            }
        } else {
            alert("没有要打印的报表");
            return;
        }
    }