var commonGridObj_orderlist;
var comboVESSEL;//船名
var comboVOYNO;//航次
var comboCUSTOMERNAME;//委托单位 
var comboOP;//操作人员
var s0="";
var sortName = "";
var sortIndex = "";
var newHeaderArgs;
var newWidthArgs;
var newColAlignArgs;
var newColSortArgs;
var newColTypeArgs;

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

function createGrid(type)
{
//    //header
//    var headerArgs_orderlist = new Array("<input type=\"checkbox\" id=\"ck_all\" onclick=\"checkAll('ck_all')\" />","业务状态","费用状态","委托方式","录入人","录入日期",
//                                   "船名","航次","主提单号","开船日期","发货人","委托单位","集装箱","订舱代理","揽货人","操作","单证","客服","航线","装货港","卸货港","交货地","目的地",
//                                   "会计期间","分提单号","委托编号","运单号","装运方式","场站","截港日期","预抵日期",
//                                   "运输条款","品名","货物毛重","货物尺码","件数","包装","箱TEU","船公司","报关行","承运车队",
//                                   "发票号","业务来源","来源明细","订舱类型","订舱编号","装箱类型","仓库","截单日期","集港日期","其他箱型");  
//    //width                            
//    var widthArgs_orderlist = new Array("40","70","70","70","70","120",
//                                        "150","70","150","120","120","120","120","120","70","70","70","70","120","150","150","150","150","70","150","150","100","100","100","120","120",
//                                        "100","100","100","100","100","100","100","120","120","120",
//                                        "100","100","100","100","150","100","120","120","120","60");  
//                                  
//    //column align                            
//    var colAlignArgs_orderlist = new Array("center","center","left","left","left","left",
//                                            "left","left","left","left","left","left","left","left","left","left","left","left","left","left","left","left","left","left","left","left","left","left","left","left","left",
//                                            "left","left","left","left","left","left","left","left","left","left",
//                                            "left","left","left","left","left","left","left","left","left","left");  
//                                    
//    //column sort                                 
//    var colSortArgs_orderlist = new Array("na","bsstatus","feestatus","ordertype","inputby","bsdate",
//                                            "vessel","voyno","mblno","etd","shipperid","customername","cntrtotal","forwarder","sale","op","doc","custservice","lane","portload","portdischarge","placedelivery","destination",
//                                            "accdate","hblno","custno","transno","bltype","yard","closingdate","eta","service","goodsname","kgs","cbm","pkgs","kindpkgs","teu","carrier",
//                                            "customser","trucker","invno","bssource","bssourcedetail","ordtype","orderno","packingtype","warehouse","closedocdate",
//                                            "intoportdate","otcntr");    
//    //column type                              
//    var colTypeArgs_orderlist = new Array("ch","ro","ro","ro","ro","ro",
//                                            "ro","ro","ro","ro","ro","ro","ro","ro","ro","ro","ro","ro","ro","ro","ro","ro","ro","ro","ro","ro","ro","ro","ro","ro","ro",
//                                            "ro","ro","ro","ro","ro","ro","ro","ro","ro","ro",
//                                            "ro","ro","ro","ro","ro","ro","ro","ro","ro","ro");

//    var oldSortArg = new Array("na","bsstatus","feestatus","ordertype","inputby","bsdate",
//                    "vessel","voyno","mblno","etd","shipperid","customername","cntrtotal","forwarder","sale","op","doc","custservice","lane","portload","portdischarge","placedelivery","destination",
//                    "accdate","hblno","custno","transno","bltype","yard","closingdate","eta","service","goodsname","kgs","cbm","pkgs","kindpkgs","teu","carrier",
//                    "customser","trucker","invno","bssource","bssourcedetail","ordtype","orderno","packingtype","warehouse","closedocdate",
//                    "intoportdate","otcntr");    
    //
    //alert(headerArgs_orderlist);alert(widthArgs_orderlist);alert(colAlignArgs_orderlist);alert(colSortArgs_orderlist);alert(colTypeArgs_orderlist);

    //获取自定义列表样式
    //if(document.getElementById("origopseae") == null){
        var url = "../UserSettings/UserGridSource/OrigOpSeaeGrid.js?uid="+newGuid();
        var loader = dhtmlxAjax.getSync(url);
        var jsVal = loader.xmlDoc.responseText;
                
                
        var oHead = document.getElementsByTagName('head').item(0); 
        var oScript = document.createElement( "script" ); 

        oScript.language = "javascript"; 
        oScript.type = "text/javascript"; 
        oScript.id = "origopseae"; 
        oScript.defer = true; 
        oScript.text = jsVal; 

        oHead.appendChild(oScript); 
    //}
    //
    var searchJson = "";
        if(type == 2){
            var _begintime = $("txt_beginetd").value.trim();
            
            if(_begintime.trim() != ""){
                if(!validateDateTime(_begintime)){
                    alert("起始时间格式错误");
                    return;
                }
            }
            var _endtime = $("txt_endetd").value.trim();
            if(_endtime.trim() != ""){
                if(!validateDateTime(_endtime)){
                    alert("结束时间格式错误");
                    return;
                }
            }
            
            
            var _customer = $("h_customer").value.trim();
            var _vessel = $("h_vessel").value.trim();
            var _voyno = $("h_voyno").value.trim();
            var _op = $("h_operator").value.trim();
            var _checkno = $("txt_no").value.trim();
            var _bstype = comboBsType.getSelectedValue();//业务类型
            
            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 += "\"vessel\":\""+_vessel+"\",";
            searchJson += "\"voyno\":\""+_voyno+"\",";
            searchJson += "\"op\":\""+_op+"\",";
            searchJson += "\"bty\":\""+_bstype+"\",";
            searchJson += "\"no\":\""+_checkno+"\"";
            searchJson += "]";
            searchJson +="}";
        }
    s0="";
    var strCNTR = dhtmlxAjax.getSync("../FeeCodes/TopCtnAdapter.aspx?cntr=cntr&val="+newGuid());
    var sCNTR = strCNTR.xmlDoc.responseText;
    var jsonCtnObj = null;
    if(sCNTR.trim() != ""){
        jsonCtnObj = eval('(' + sCNTR + ')');
        
        for(var i=0;i<jsonCtnObj.ctns.length;i++){
            if(jsonCtnObj.ctns[i].ctn != ""){
                s0 +=",CNTR"+(i+1);
                headerArgs_orderlist[headerArgs_orderlist.length] = jsonCtnObj.ctns[i].ctn;
                newHeaderArgs[newHeaderArgs.length] = jsonCtnObj.ctns[i].ctn;
                widthArgs_orderlist[widthArgs_orderlist.length] = "50";
                newWidthArgs[newWidthArgs.length] = "50";
                colAlignArgs_orderlist[colAlignArgs_orderlist.length] = "left";
                newColAlignArgs[newColAlignArgs.length] = "left";
                colSortArgs_orderlist[colSortArgs_orderlist.length] = "na";
                newColSortArgs[newColSortArgs.length] = "na";
                colTypeArgs_orderlist[colTypeArgs_orderlist.length] = "ro";
                newColTypeArgs[newColTypeArgs.length] = "ro";
            }
        }
    }
    
//    if(sCNTR!="")
//    {
//        var arrtmp=sCNTR.split("&&");//将各参数分离形成参数数组
//        for(var i=0;i<arrtmp.length;i++)
//        {
//            if(arrtmp[i]!="0")
//            {
//                s0 +=",CNTR"+(i+1);
//                headerArgs_orderlist[headerArgs_orderlist.length] = arrtmp[i];
//                widthArgs_orderlist[widthArgs_orderlist.length] = "50";
//                colAlignArgs_orderlist[colAlignArgs_orderlist.length] = "left";
//                colSortArgs_orderlist[colSortArgs_orderlist.length] = "str";
//                colTypeArgs_orderlist[colTypeArgs_orderlist.length] = "ro";
//            }
//        }
//    }
                                            
 
    commonGridObj_orderlist = new TGridCommon("mygrid_container_seae","form1",headerArgs_orderlist,widthArgs_orderlist,colAlignArgs_orderlist,colSortArgs_orderlist,colTypeArgs_orderlist);
    commonGridObj_orderlist.setResponseUrl("SeaExportGridSource.aspx");
    commonGridObj_orderlist.setSortValue("etd","desc");
    
    var searchcacheName = $("h_searchcache").value;//alert(searchcacheName);
    if(commonGridObj_orderlist.sortValue.length > 1 && commonGridObj_orderlist.sortType.length > 1){
        if(searchcacheName != ""){
            commonGridObj_orderlist.setRequest("SeaExportGridSource.aspx?handle=list&show_page=15&cur_page=1&uid="+commonGridObj_orderlist.newGuid()+"&sort="+commonGridObj_orderlist.sortValue+"&sortindex="+commonGridObj_orderlist.sortType+"&cntr="+s0+"&searchcachename="+searchcacheName);
        }else{
            if(searchJson.trim() != ""){
                commonGridObj_orderlist.setRequest("SeaExportGridSource.aspx?handle=list&show_page=15&cur_page=1&search="+escape(searchJson)+"&uid="+commonGridObj_orderlist.newGuid()+"&sort="+commonGridObj_orderlist.sortValue+"&sortindex="+commonGridObj_orderlist.sortType+"&cntr="+s0);
            }else{
                commonGridObj_orderlist.setRequest("SeaExportGridSource.aspx?handle=list&show_page=15&cur_page=1&uid="+commonGridObj_orderlist.newGuid()+"&sort="+commonGridObj_orderlist.sortValue+"&sortindex="+commonGridObj_orderlist.sortType+"&cntr="+s0);
            }
        }
        
    }else{ 
        if(searchcacheName != ""){
            commonGridObj_orderlist.setRequest("SeaExportGridSource.aspx?handle=list&show_page=15&cur_page=1&uid="+commonGridObj_orderlist.newGuid()+"&sort=etd&sortindex=desc"+"&cntr="+s0+"&searchcachename="+searchcacheName);
        }else{
            if(searchJson.trim() != ""){
                commonGridObj_orderlist.setRequest("SeaExportGridSource.aspx?handle=list&show_page=15&cur_page=1&search="+escape(searchJson)+"&uid="+commonGridObj_orderlist.newGuid()+"&sort=etd&sortindex=desc"+"&cntr="+s0);
            }else{
                commonGridObj_orderlist.setRequest("SeaExportGridSource.aspx?handle=list&show_page=15&cur_page=1&uid="+commonGridObj_orderlist.newGuid()+"&sort=etd&sortindex=desc"+"&cntr="+s0);
            }
        }
        
    }
    
    if(searchcacheName != ""){
        commonGridObj_orderlist.setMultiple("&searchcachename="+searchcacheName);
    }
    commonGridObj_orderlist.setSourceType("json");
    commonGridObj_orderlist.setSkin("xp");
    commonGridObj_orderlist.setImageUrl("../images/");
    commonGridObj_orderlist.loadafter = true;
    //
    commonGridObj_orderlist.after = function () {
        //提取原始模板
        var url = "../UserSettings/UserGridSource/OrigOpSeaeGrid.js?uid=" + newGuid();
        var loader = dhtmlxAjax.getSync(url);
        var jsVal = loader.xmlDoc.responseText;
        var oHead = document.getElementsByTagName('head').item(0);
        var oScript = document.createElement("script");
        oScript.language = "javascript";
        oScript.type = "text/javascript";
        oScript.id = "origopseae";
        oScript.defer = true;
        oScript.text = jsVal;
        oHead.appendChild(oScript);
        //
        s0 = "";
        var strCNTR = dhtmlxAjax.getSync("../FeeCodes/TopCtnAdapter.aspx?cntr=cntr&val=" + newGuid());
        var sCNTR = strCNTR.xmlDoc.responseText;
        var jsonCtnObj = null;
        if (sCNTR.trim() != "") {
            jsonCtnObj = eval('(' + sCNTR + ')');

            for (var i = 0; i < jsonCtnObj.ctns.length; i++) {
                if (jsonCtnObj.ctns[i].ctn != "") {
                    s0 += ",CNTR" + (i + 1);
                    headerArgs_orderlist[headerArgs_orderlist.length] = jsonCtnObj.ctns[i].ctn;
                    widthArgs_orderlist[widthArgs_orderlist.length] = "50";
                    colAlignArgs_orderlist[colAlignArgs_orderlist.length] = "left";
                    colSortArgs_orderlist[colSortArgs_orderlist.length] = "na";
                    colTypeArgs_orderlist[colTypeArgs_orderlist.length] = "ro";
                }
            }
        }
        //
        var arg = new Array();
        if (newColSortArgs.length == colSortArgs_orderlist.length) {
            for (var i = 0; i < colSortArgs_orderlist.length; i++) {
                var oIndex = i;
                var nIndex = 0;
                var iCount = 0;
                if (colSortArgs_orderlist[i] != newColSortArgs[i]) {
                    for (var k = 0; k < colSortArgs_orderlist.length; k++) {
                        if (colSortArgs_orderlist[k] == newColSortArgs[i]) {
                            nIndex = k;

                            //arg.push(nIndex+"#"+oIndex);
                            //alert(commonGridObj_orderlist.getGridObj().getColumnLabel(nIndex)+"#"+commonGridObj_orderlist.getGridObj().getColumnLabel(oIndex));
                            commonGridObj_orderlist.getGridObj().moveColumn(nIndex, oIndex);

                            var title = headerArgs_orderlist[nIndex];
                            var width = widthArgs_orderlist[nIndex];
                            var sort = colSortArgs_orderlist[nIndex];
                            var colType = colTypeArgs_orderlist[nIndex];
                            var align = colAlignArgs_orderlist[nIndex];
                            //var index = i;

                            headerArgs_orderlist[nIndex] = headerArgs_orderlist[oIndex];
                            widthArgs_orderlist[nIndex] = widthArgs_orderlist[oIndex];
                            colSortArgs_orderlist[nIndex] = colSortArgs_orderlist[oIndex];
                            colTypeArgs_orderlist[nIndex] = colTypeArgs_orderlist[oIndex];
                            colAlignArgs_orderlist[nIndex] = colAlignArgs_orderlist[oIndex];

                            headerArgs_orderlist[oIndex] = title;
                            widthArgs_orderlist[oIndex] = width;
                            colSortArgs_orderlist[oIndex] = sort;
                            colTypeArgs_orderlist[oIndex] = colType;
                            colAlignArgs_orderlist[oIndex] = align;

                            //alert(commonGridObj_orderlist.getGridObj().getColumnLabel(nIndex)+"#"+commonGridObj_orderlist.getGridObj().getColumnLabel(oIndex));
                            commonGridObj_orderlist.getGridObj().moveColumn(oIndex + 1, nIndex + 1);

                            //        					alert(commonGridObj_orderlist.getGridObj().getColumnLabel(oIndex)+"##"+oIndex+"##wd:"+widthArgs_orderlist[oIndex])
                            //Set AllCheckBox 
                            //        					if(headerArgs_orderlist[nIndex] == "checkboxs"){
                            //		                        commonGridObj_orderlist.getGridObj().setColLabel(nIndex,"<input type=\"checkbox\" id=\"ck_all\" onclick=\"checkAll('ck_all')\" />");
                            //		                    }

                            var tempWidth = widthArgs_orderlist[nIndex];
                            commonGridObj_orderlist.getGridObj().setColWidth(nIndex, tempWidth);

                            iCount++; //alert(headerArgs_orderlist);
                            break;
                        }
                    }
                } else {
                    //		            if(headerArgs_orderlist[i] == "checkboxs"){
                    //		                commonGridObj_orderlist.getGridObj().setColLabel(i,"<input type=\"checkbox\" id=\"ck_all\" onclick=\"checkAll('ck_all')\" />");
                    //		            }
                    var tempWidth = newWidthArgs[i];
                    commonGridObj_orderlist.getGridObj().setColWidth(i, tempWidth);
                }
            }
        }

        finishLoading();
    };
    commonGridObj_orderlist.initGrid();
    
    //if(commonGridObj_orderlist.getGridObj().getColumnLabel(0) != null){
    setTimeout(function(){
        initLoading();
        commonGridObj_orderlist.bind();
    },500);  
    //}
    //commonGridObj_orderlist.bind();

    commonGridObj_orderlist.isSort = true;
    commonGridObj_orderlist.setSearch(searchJson);
    commonGridObj_orderlist.initPageByHandle("list");
    commonGridObj_orderlist.isDBClickEvent = true;
    commonGridObj_orderlist.sortEventFun();
    
    commonGridObj_orderlist.getGridObj().attachEvent("onRowDblClicked", function(rId,cInd)
    {
        var openSet = "height=700, width=1024, toolbar=no, menubar=no,scrollbars=no, resizable=1,location=no, status=no,Top= " +(screen.height-750)/2 + ",Left= "+(screen.width-1100)/2
        var openType = "_blank";
        var openUrl = "../shipping/edit.aspx?handle=edit&id="+rId;        
        window.open (openUrl,openType,openSet);
    });
    
    commonGridObj_orderlist.clickEvent = function()
    {
        commonGridObj_orderlist.getGridObj().attachEvent("onRowDblClicked", function(rId,cInd)
        {  
            var openSet = "height=700, width=1024, toolbar=no, menubar=no,scrollbars=no, resizable=1,location=no, status=no,Top= " +(screen.height-750)/2 + ",Left= "+(screen.width-1100)/2
            var openType = "_blank";                
            var openUrl = "../shipping/edit.aspx?handle=edit&id="+rId;   
            window.open (openUrl,openType,openSet); 
        });
    }
    
//    commonGridObj_orderlist.sortEventFun = function(){
//        commonGridObj_orderlist.getGridObj().attachEvent("onBeforeSorting", function(ind,type,direction){
//              if(type == "na" || type == "checkboxs"){
//                return false;
//              }else{
//                //alert(type);alert(direction);alert(ind);
//                commonGridObj_orderlist.setSortValue(type,direction);
//                commonGridObj_orderlist.getGridObj().clearAll();
//                commonGridObj_orderlist.setRequest("SeaExportGridSource.aspx?handle=list&show_page=15&cur_page=1&uid="+commonGridObj_orderlist.newGuid()+"&sort="+type+"&sortindex="+direction+"&cntr="+s0);
//                if(commonGridObj_orderlist.loadafter){
//                    commonGridObj_orderlist.loadafter = false;
//                    commonGridObj_orderlist.after = function(){
//                    }
//                }
//                commonGridObj_orderlist.bind();
//                
//                
//                return true;
//              }
//        });
//    }
//    commonGridObj_orderlist.getGridObj().attachEvent("onBeforeSorting", function(ind,type,direction){
//          if(type == "na" || type == "checkboxs"){
//            return false;
//          }else{
//            //alert(type);alert(direction);alert(ind);
//            commonGridObj_orderlist.setSortValue(type,direction);
//            commonGridObj_orderlist.getGridObj().clearAll();
//            
//            commonGridObj_orderlist.setRequest("SeaExportGridSource.aspx?handle=list&show_page=15&cur_page=1&uid="+commonGridObj_orderlist.newGuid()+"&sort="+type+"&sortindex="+direction+"&cntr="+s0);
//            
//            if(commonGridObj_orderlist.loadafter){
//                commonGridObj_orderlist.loadafter = false;
//                commonGridObj_orderlist.after = function(){
//                }
//            }
//    
//            commonGridObj_orderlist.bind();
//            
//            //alert("SeaExportGridSource.aspx?handle=list&show_page=15&cur_page=1&uid="+commonGridObj_orderlist.newGuid()+"&sort="+type+"&sortindex="+direction+"&cntr="+s0);
//            //createGrid();
//            
//            return true;
//          }
//    });
    //
}

function initCombo(){
    CustomerCombo();
    OperatorCombo();
    VesselCombo();
    VoynoCombo();
    createComboBsType();//业务类型
}
function createComboBsType(){//业务类型
    comboBsType = dhtmlXComboFromSelect("sel_bstype");
}

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

function OperatorCombo(){
    var strUserID = $("h_uid").value.trim();
    comboOperator = new TCombo("sel_op","../FeeCodes/OPAdapter.aspx?mask=0&pos=0&rName=isOperator&userID="+strUserID,true,true,false,true,"h_operator");
    comboOperator.initComboEvent();
    comboOperator.bind();
}

function VesselCombo(){
    comboVessel = new TCombo("sel_vessel","../FeeCodes/TCodeVesselAdapter.aspx?mask=0&pos=0",true,false,false,true,"h_vessel");
    comboVessel.initComboEvent();
    comboVessel.bind();
}

function VoynoCombo(){
    var strVessel = $("h_vessel").value;
    comboVoyno = new TCombo("sel_voyno","../FeeCodes/TCodeVoynoAdapter.aspx?mask=0&pos=0&strVESSEL="+strVessel,true,true,false,true,"h_voyno");
    comboVoyno.initComboEvent();
    
    if(strVessel.trim() != ""){
        comboVoyno.bind();
    }
}

function initSearch(){
    $("h_customer").value = "";
    comboCustomer.setText($("h_customer").value);
    
    $("h_vessel").value = "";
    comboVessel.setText($("h_vessel").value);
    
    $("h_voyno").value = "";
    comboVoyno.setText($("h_voyno").value);
    
    $("h_operator").value = "";
    comboOperator.setText($("h_operator").value);
    
    $("txt_beginetd").value = "";
    $("txt_endetd").value = "";
    $("txt_no").value = "";
    
    if($("h_searchcache").value != ""){
        $("h_searchcache").value = "";
    }
    //清空业务类型
    if(comboBsType != null){
        comboBsType.setComboText("全部");
    }
    createGrid(1);
}

function ShowDetailSelect(){
    createGrid();
}

function GetRange2(strgid) {
    var loader;
    var dates;
    var strR="";
//    var getstrgid = commonGridObj_orderlist.getGridObj();
//    var strgid = getstrgid.getSelectedRowId();
    if ($("hdRangeV").value != $("hdRangeO").value){
        if($("hdRangeO").value=="1"){//分公司
            loader = dhtmlxAjax.getSync("../FeeCodes/RangeAdapter.aspx?RangeID=1&strGID="+strgid+"&RangeName=modOrderManagement&val="+newGuid());//委托管理列表
            dates = loader.xmlDoc.responseText;
            if(dates==""){
                //alert("您没有操作此数据的权限!");
                return "您没有操作业务的权限!"; //0;
            }
        }
        else if ($("hdRangeO").value == "2") {//分公司
            loader = dhtmlxAjax.getSync("../FeeCodes/RangeAdapter.aspx?RangeID=2&strGID=" + strgid + "&RangeName=modOrderManagement&val=" + newGuid()); //委托管理列表
            dates = loader.xmlDoc.responseText;
            if (dates == "") {
                //alert("您没有操作此数据的权限!");
                return "您没有操作数据的权限!"; //0;
            }
        } else if ($("hdRangeO").value == "3") {//个人
            loader = dhtmlxAjax.getSync("../FeeCodes/RangeAdapter.aspx?RangeID=3&strGID=" + strgid + "&RangeName=modOrderManagement&val=" + newGuid()); //委托管理列表
            dates = loader.xmlDoc.responseText;
            if (dates == "") {
                //alert("您没有操作此数据的权限!");
                return "您没有操作数据的权限!"; //0;
            }
        }
    }
    return "";
}
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 deleteOrder() {
    var alt = "";
    var strError1 = "";
    var strError2 = "";
    var strError3 = "";
    var strError4 = "";
    var strError5 = "";
    //
    var orderGridObj = commonGridObj_orderlist.getGridObj();
    var selRowID = orderGridObj.getCheckedRows(0); //所有选中的grid的id编号  
    //var selRowID = orderGridObj.getSelectedRowId();
    var selGroup = new Array(); 
    
    if(selRowID.indexOf(",") > 0){
        selGroup = selRowID.split(",");
    }else{
        if(selRowID != null){
            selGroup.push(selRowID);
        }
    }
    //查看是否有被选中的费用项
    if(selGroup.length > 0){
//        if(selGroup.length > 1){
            var delCount = 0;
            if(window.confirm("您确定删除已选中的委托信息")){
                while(delCount < selGroup.length){
                    var rowIndex = orderGridObj.getRowIndex(selGroup[delCount]);
                
                    var feeName = orderGridObj.cellByIndex(rowIndex,1).getValue();
                    var cusName = orderGridObj.cellByIndex(rowIndex, 2).getValue();

                    //
                    strError1 = GetRange2(selGroup[delCount]);
                    if (strError1.toString().trim() == "") {
                        var urlVal = "SeaExportGridSource.aspx?handle=delete&bsno="+selGroup[delCount]+"&val="+commonGridObj_orderlist.newGuid()+"&tbNO="+escape($("txt_no").value)+"&VESSEL="+escape($("h_vessel").value)+"&VOYNO="+escape($("h_voyno").value)+"&tbETD="+$("txt_beginetd").value+"&tbETD2="+$("txt_endetd").value+"&CUSTOMERNAME="+escape($("h_customer").value)+"&ddlOP="+escape($("h_op").value+"&cntr="+s0);                        
                        var loader = dhtmlxAjax.getSync(urlVal);
                        var loadVal = loader.xmlDoc.responseText;
                    		
                        if(loadVal > 0 )
                        {
                            //alert("删除成功");
                        }
                        else
                        {
                           if(loadVal == -1 || loadVal == -2)
                           {
                               strError2="删除失败!";
                           }
                           if(loadVal == -3)
                           {
                               strError3 = "有业务为锁定状态,不允许删除此类业务!"; //业务封帐
                           }
                           if(loadVal == -4)
                           {
                               strError4 = "您不是某些业务的操作,无删除此类业务的权限!";
                           }
                           if(loadVal == -5)
                           {
                               strError5 = "些业务有与海运出口委托相关联的费用信息,不允许删除!";
                           }
                        }
                    }
                    delCount++;
                }
                alt = strError1 + strError2 + strError3 + strError4 + strError5;
                if (alt.trim() != "") {
                    alert(alt);
                }
                createGrid(1);
            }
//        }else{
//            var delCount = 0;
//            while(delCount < selGroup.length){
//                var rowIndex = orderGridObj.getRowIndex(selGroup[delCount]); 
//            
//                var feeName = orderGridObj.cellByIndex(rowIndex,1).getValue();
//                var cusName = orderGridObj.cellByIndex(rowIndex,2).getValue();
//                
//                if(window.confirm("您确定要将所选委托信息删除")){
//                    
//                    var urlVal = "SeaExportGridSource.aspx?handle=delete&bsno="+selGroup[delCount]+"&val="+commonGridObj_orderlist.newGuid()+"&tbNO="+escape($("txt_no").value)+"&VESSEL="+escape($("h_vessel").value)+"&VOYNO="+escape($("h_voyno").value)+"&tbETD="+$("txt_beginetd").value+"&tbETD2="+$("txt_endetd").value+"&CUSTOMERNAME="+escape($("h_customer").value)+"&ddlOP="+escape($("h_op").value+"&cntr="+s0);
//                    var loader = dhtmlxAjax.getSync(urlVal);
//                    var loadVal = loader.xmlDoc.responseText;

//	                if(loadVal > 0 ){
//	                    //alert("删除成功");
//	                    createGrid(1);
//	                }
//	                else
//	                {
//                       if(loadVal == -1 || loadVal == -2)
//                       {
//                            alert("删除失败!");
//                       }
//                       if(loadVal == -3)
//                       {
//                            alert("当前业务为锁定状态,不允许删除此业务!");//业务封帐
//                       }
//                       //if(loadVal == -4)
//                       //{
//                            //alert("您不是当前业务的操作,无删除此业务的权限!");
//                       //}
//                       if(loadVal == -5)
//                       {
//                            alert("当前业务有与海运出口委托相关联的费用信息,不允许删除!");
//                       }
//	                }
//                }
//                delCount++;
//            }
//            
//        }
    }else{
        alert("请选择您要删除的委托信息");
        
    }
}
    
function refreshOrder(){
    window.location.href = window.location.href;
}
    
function addOrder(){
    var openSet = "height=700, width=1024, toolbar=no, menubar=no,scrollbars=no, resizable=1,location=no, status=no,Top= " +(screen.height-750)/2 + ",Left= "+(screen.width-1100)/2
    var openType = "_blank";
    var openUrl = "../shipping/edit.aspx?handle=add";
    window.open (openUrl,openType,openSet);
//    var tempWin = window.open ("about:blank",openType,openSet);
//    tempWin.location = openUrl; 
}
    
function addFullOrder(){
    var orderGridObj = commonGridObj_orderlist.getGridObj();
    var selRowID = orderGridObj.getSelectedRowId();
    if(selRowID==null || selRowID==""){
        alert("请先选择要操作的数据!");
    }else{
        var openSet = "height=700, width=1024, toolbar=no, menubar=no,scrollbars=no, resizable=1,location=no, status=no,Top= " +(screen.height-750)/2 + ",Left= "+(screen.width-1100)/2
        var openType = "_blank";
        var openUrl = "../shipping/edit.aspx?handle=addfull&id="+selRowID;
        //window.open (openUrl,openType,openSet);
        var tempWin = window.open ("about:blank",openType,openSet);
        tempWin.location = openUrl;
    } 
}
//校验时间格式
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;
}
//根据条件查询付费申请信息
function search(){
    createGrid(2);
//    var _begintime = $("tbETD").value.trim();
//    
//    if(_begintime.trim() != ""){
//        if(!validateDateTime(_begintime)){
//            alert("起始时间格式错误");
//            return;
//        }
//    }
//    var _endtime = $("tbETD2").value.trim();
//    if(_endtime.trim() != ""){
//        if(!validateDateTime(_endtime)){
//            alert("结束时间格式错误");
//            return;
//        }
//    }
//    
//    
//    var _customer = $("hd_comboCUSTOMERNAME").value.trim();
//    var _vessel = $("hd_comboVESSEL").value.trim();
//    var _voyno = $("hd_comboVOYNO").value.trim();
//    var _op = $("hd_comboOP").value.trim();
//    var _checkno = $("tbNO").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 += "\"vessel\":\""+_vessel+"\",";
//    searchJson += "\"voyno\":\""+_voyno+"\",";
//    searchJson += "\"op\":\""+_op+"\",";
//    searchJson += "\"no\":\""+_checkno+"\"";
//    searchJson += "]";
//    searchJson +="}";//alert(searchJson);
//    
//    commonGridObj_orderlist.initGrid();
//    commonGridObj_orderlist.loadafter = true;
//    commonGridObj_orderlist.after = function(){
//        
//        var arg = new Array();
//        
//        if(newColSortArgs.length == colSortArgs_orderlist.length){
//	        for(var i=0;i<colSortArgs_orderlist.length;i++){
//		        var oIndex = i;
//		        var nIndex = 0;
//		        var iCount = 0;
//		        if(colSortArgs_orderlist[i] != newColSortArgs[i]){
//			        for(var k=0;k<colSortArgs_orderlist.length;k++){
//				        if(colSortArgs_orderlist[k] == newColSortArgs[i]){
//					        nIndex = k;
//					        
//					        //arg.push(nIndex+"#"+oIndex);
//					        //alert(commonGridObj_orderlist.getGridObj().getColumnLabel(nIndex)+"#"+commonGridObj_orderlist.getGridObj().getColumnLabel(oIndex));
//	                        commonGridObj_orderlist.getGridObj().moveColumn(nIndex,oIndex);
//	                        
//	                        var title = headerArgs_orderlist[nIndex];
//							var width = widthArgs_orderlist[nIndex];
//							var sort = colSortArgs_orderlist[nIndex];
//							var colType = colTypeArgs_orderlist[nIndex];
//							var align = colAlignArgs_orderlist[nIndex];
//							//var index = i;
//							
//							headerArgs_orderlist[nIndex] = headerArgs_orderlist[oIndex];
//							widthArgs_orderlist[nIndex] = widthArgs_orderlist[oIndex];
//							colSortArgs_orderlist[nIndex] = colSortArgs_orderlist[oIndex];
//							colTypeArgs_orderlist[nIndex] = colTypeArgs_orderlist[oIndex];
//							colAlignArgs_orderlist[nIndex] = colAlignArgs_orderlist[oIndex];
//							
//							headerArgs_orderlist[oIndex] = title;
//							widthArgs_orderlist[oIndex] = width;
//							colSortArgs_orderlist[oIndex] = sort;
//							colTypeArgs_orderlist[oIndex] = colType;
//							colAlignArgs_orderlist[oIndex] = align;
//							
//	                        //alert(commonGridObj_orderlist.getGridObj().getColumnLabel(nIndex)+"#"+commonGridObj_orderlist.getGridObj().getColumnLabel(oIndex));
//	                        commonGridObj_orderlist.getGridObj().moveColumn(oIndex+1,nIndex+1);
//	                        iCount++;//alert(headerArgs_orderlist);
//					        break;
//				        }
//			        }
//		        }
//		        
//		        if(iCount == 1){
//		            //break;
//		        } 
//	        }
//        }
//    };
//    
//    if(commonGridObj_orderlist.sortValue.length > 1 && commonGridObj_orderlist.sortType.length > 1){
//       
//        commonGridObj_orderlist.setRequest("SeaExportGridSource.aspx?handle=list&show_page=15&cur_page=1&search="+escape(searchJson)+"&uid="+commonGridObj_orderlist.newGuid()+"&sort="+commonGridObj_orderlist.sortValue+"&sortindex="+commonGridObj_orderlist.sortType+"&cntr="+s0);
//    }else{
//        commonGridObj_orderlist.setSortValue("etd","desc");
//        commonGridObj_orderlist.setRequest("SeaExportGridSource.aspx?handle=list&show_page=15&cur_page=1&search="+escape(searchJson)+"&uid="+commonGridObj_orderlist.newGuid()+"&sort=etd&sortindex=desc"+"&cntr="+s0);
//    }
//    //commonGridObj_orderlist.setRequest("SeaExportGridSource.aspx?handle=list&show_page=15&cur_page=1&search="+escape(searchJson)+"&uid="+commonGridObj_orderlist.newGuid()+"&cntr="+s0);
//    commonGridObj_orderlist.bind();
//    commonGridObj_orderlist.setSearch(searchJson);
//    
//    commonGridObj_orderlist.initPageByHandle("list");
//    commonGridObj_orderlist.isDBClickEvent = true;
//    
//    commonGridObj_orderlist.isSort = true;
//    
//    commonGridObj_orderlist.getGridObj().attachEvent("onRowDblClicked", function(rId,cInd){ 
//            var openSet = "height=700, width=1024, toolbar=no, menubar=no,scrollbars=no, resizable=1,location=no, status=no,Top= " +(screen.height-750)/2 + ",Left= "+(screen.width-1100)/2
//            var openType = "_blank";
//                
//            var openUrl = "../shipping/edit.aspx?handle=edit&id="+rId;
//            window.open (openUrl,openType,openSet); 
//            //var tempWin = window.open ("about:blank",openType,openSet);
//            //tempWin.location = openUrl;
//    });
//    
//    commonGridObj_orderlist.clickEvent = function(){
//        commonGridObj_orderlist.getGridObj().attachEvent("onRowDblClicked", function(rId,cInd){  
//            var openSet = "height=700, width=1024, toolbar=no, menubar=no,scrollbars=no, resizable=1,location=no, status=no,Top= " +(screen.height-750)/2 + ",Left= "+(screen.width-1100)/2
//            var openType = "_blank";
//                
//            var openUrl = "../shipping/edit.aspx?handle=edit&id="+rId;
//            window.open (openUrl,openType,openSet); 
//            //var tempWin = window.open ("about:blank",openType,openSet);
//            //tempWin.location = openUrl;
//        });
//    }
//    
//    commonGridObj_orderlist.sortEventFun = function(){
//        commonGridObj_orderlist.getGridObj().attachEvent("onBeforeSorting", function(ind,type,direction){
//              if(type == "na"){
//                return false;
//              }else{
//                //alert(type);alert(direction);alert(commonGridObj_orderlist.getRequest());
//                commonGridObj_orderlist.setSortValue(type,direction);
//                commonGridObj_orderlist.getGridObj().clearAll();
//                if(commonGridObj_orderlist.loadafter){
//                    commonGridObj_orderlist.loadafter = false;
//                    commonGridObj_orderlist.after = function(){
//                    }
//                }
//                commonGridObj_orderlist.setRequest("SeaExportGridSource.aspx?handle=list&show_page=15&cur_page=1&search="+escape(searchJson)+"&uid="+commonGridObj_orderlist.newGuid()+"&sort="+type+"&sortindex="+direction+"&cntr="+s0);
//                commonGridObj_orderlist.bind();
//                return true;
//              }
//        });
//    }
//    
//    commonGridObj_orderlist.getGridObj().attachEvent("onBeforeSorting", function(ind,type,direction){
//          if(type == "na"){
//            return false;
//          }else{
//            //alert(type);alert(direction);alert(commonGridObj_orderlist.getRequest());
//            commonGridObj_orderlist.setSortValue(type,direction);
//            commonGridObj_orderlist.getGridObj().clearAll();
//            if(commonGridObj_orderlist.loadafter){
//                commonGridObj_orderlist.loadafter = false;
//                commonGridObj_orderlist.after = function(){
//                }
//            }
//            commonGridObj_orderlist.setRequest("SeaExportGridSource.aspx?handle=list&show_page=15&cur_page=1&search="+escape(searchJson)+"&uid="+commonGridObj_orderlist.newGuid()+"&sort="+type+"&sortindex="+direction+"&cntr="+s0);
//            commonGridObj_orderlist.bind();
//            //createGrid();
//            return true;
//          }
//    });
}

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


function searchMultiple(){
//    var openSet = "height=280, width=800, toolbar=no, menubar=no,scrollbars=no, resizable=1,location=no, status=no,Top= " +(screen.height-280)/2 + ",Left= "+(screen.width-800)/2
//    var openType = "_blank";
//        
//    var openUrl = "../search/multiplesearch.aspx?handle=opseae";
//    window.open (openUrl,openType,openSet);

    printMessageBox(event);
}

function editOpSeae(){
    var selArg = new Array();
    var iCount = 0;
    for(var i=0;i<commonGridObj_orderlist.getGridObj().getRowsNum();i++){
        var checkState = commonGridObj_orderlist.getGridObj().cellByIndex(i,0).getValue();
        var rId = commonGridObj_orderlist.getGridObj().getRowId(i);
        if(checkState == 1){
            iCount++;
            selArg.push(rId);
        }
    }
    
    if(iCount == 1){
        var openSet = "height=700, width=1024, toolbar=no, menubar=no,scrollbars=no, resizable=1,location=no, status=no,Top= " +(screen.height-750)/2 + ",Left= "+(screen.width-1100)/2
        var openType = "_blank";
            
        var openUrl = "../shipping/edit.aspx?handle=edit&id="+selArg[0];
        window.open (openUrl,openType,openSet);
    }else{
        alert("每次只能编辑一个海运出口委托信息");
    }
    
}

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

function editGridSetting(){
    var openSet = "height=500, width=800, toolbar=no, menubar=no,scrollbars=no, resizable=no,location=no, status=no,Top= " +(screen.height-500)/2 + ",Left= "+(screen.width-800)/2
    var openType = "_blank";
        
    var openUrl = "../UserSettings/UserGridEdit.aspx?handle=usergrid&templatetype=opseae";
    window.open (openUrl,openType,openSet);
}

var isIe=(document.all)?true:false;
//设置select的可见状态
function setSelectState(state){
    var objl=document.getElementsByTagName('select');
    for(var i=0;i<objl.length;i++)
    {
        objl[i].style.visibility=state;
    }
}

function mousePosition(ev){
    if(ev.pageX || ev.pageY)
    {
        return {x:ev.pageX, y:ev.pageY};
    }
    return {
        x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,y:ev.clientY + document.body.scrollTop - document.body.clientTop
    };
}
//弹出方法
function showMessageBox(wTitle,content,pos,wWidth){
    closeWindow();
    var bWidth=parseInt(document.documentElement.scrollWidth);
    var bHeight=parseInt(document.documentElement.scrollHeight);
    if(isIe){
        setSelectState('hidden');}
        var back=document.createElement("div");
        back.id="back";
        var styleStr="top:0px;left:0px;position:absolute;background:#666;width:"+bWidth+"px;height:"+bHeight+"px;";
        styleStr+=(isIe)?"filter:alpha(opacity=0);":"opacity:0;";
        back.style.cssText=styleStr;
        document.body.appendChild(back);
        showBackground(back,50);
        var mesW=document.createElement("div");
        mesW.id="mesWindow";
        mesW.className="mesWindow";
        mesW.innerHTML = "<div class='mesWindowTop'><table width='100%' height='100%'><tr><td>"+wTitle+"</td><td style='width:1px;'>"
                       + "<input type='button' onclick='closeWindow();' title='关闭窗口' class='close' value='关闭' style='width:60px;'/></td></tr></table></div>"
                       + "<div class='mesWindowContent' id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
        var v_top=(document.body.clientHeight-mesW.clientHeight)/2;
        v_top+=document.documentElement.scrollTop;
        styleStr="top:"+(v_top-180)+"px;left:"+(document.body.clientWidth/2-mesW.clientWidth/2)+"px;position:absolute;width:700px;margin-left:-300px;left:50%;z-index:9999;";
        mesW.style.cssText=styleStr;
        document.body.appendChild(mesW);
}
//让背景渐渐变暗
function showBackground(obj,endInt){
    if(isIe){
        obj.filters.alpha.opacity+=5;
        if(obj.filters.alpha.opacity<endInt){
            setTimeout(function(){showBackground(obj,endInt)},5);
        }
    }else{
        var al=parseFloat(obj.style.opacity);al+=0.05;
        obj.style.opacity=al;
    if(al<(endInt/100)){
        setTimeout(function(){showBackground(obj,endInt)},5);}
    }
}
//关闭窗口
function closeWindow(){
    if(document.getElementById('back')!=null){
        document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
    }
    if(document.getElementById('mesWindow')!=null){
        document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
    }
    if(isIe){
        setSelectState('');
    }
}
//测试弹出
function printMessageBox(ev)
{
    
    var messContent = "";
    var objPos = mousePosition(ev);
//    messContent = "<div style=\"padding:20px 0 20px 0;text-align:center\">"
//                +"<div style=\"float:left;width:100%\"><select id=\"reportType\" onchange=\"onReportTypeChange('reportType')\"><option value=\"1\">打印应收费用报表</option><option value=\"2\">打印应付费用报表</option> "
//                +"<option value=\"3\">打印利润报表</option></select></div> "
////                +"<div style=\"float:left;width:100%;text-align:center;display:none;\" id=\"dvGainCheck\"><div style=\"float:left\"><input type=\"radio\" id=\"ra_recv\" name=\"gain\" title=\"打印应收利润\"/>应收利润</div> "
////                +"<div style=\"float:left\"><input type=\"radio\" id=\"ra_recv\" name=\"gain\" title=\"打印应付利润\"/>应付利润</div><div style=\"float:left\"> "
////                +"<input type=\"radio\" id=\"ra_recv\" name=\"gain\" title=\"打印利润\"/>利润</div></div> "
//                +"<div style=\"float:left;width:100%;padding-left:80px;\"> "
//                +"<table style=\"width:350px;\"><tr><td><select id=\"sel_customer\" multiple style=\"width:150px; height:60px;\">"+selectCustomerOptions+"</select></td><td> "
//                +"<table style=\"height:60px; width:20px;\"><tr><td height=\"20px\"><div id=\"dvRemove\"><img src=\"../images/icons/edit_left.gif\" "
//                +"onmouseover=\"mouseMoveImg(this,1)\" onmouseout=\"mouseMoveImg(this,1)\" title=\"移除\" onclick=\"removeCustomer()\"/></div></td> "
//                +"</tr><tr><td height=\"20px\"><div  id=\"dvAdd\"><img src=\"../images/icons/edit_right.gif\" onmouseover=\"mouseMoveImg(this,2)\" " 
//                +"onmouseout=\"mouseMoveImg(this,2)\" title=\"添加\" onclick=\"addCustomer()\"/></div></td> "
//                +"</tr></table></td><td><select id=\"sel_print\" multiple style=\"width:150px; height:60px;\" class=\"select\"></select></td></tr></table></div>"
//                +"<input type=\"button\" id=\"btn_print_report\" value=\"打印\" class=\"btn\" onclick=\"printReport()\"/></div> ";
                
    messContent += "<div style=\"padding:20px 0 20px 0;text-align:center\">"
                +  "<iframe frameborder=\"0\" src=\"../search/multiplesearch.aspx?handle=opseae&opentype=frame\" width=\"100%\" height=\"230px;\" scrolling=\"no\">";
                +  "</div> ";
                
    showMessageBox('综合查询',messContent,objPos,350);
}

function reInitJs(){
//    
//    
//    var opSeaeSrc = $("opseae");
//    var origOpSeaeSrc = $("origopseae");
//    var defaultSource = $("defaultsource");
    if(document.getElementById("origopseae") == null){
        var url = "../UserSettings/UserGridSource/OrigOpSeaeGrid.js?uid="+newGuid();
        var loader = dhtmlxAjax.getSync(url);
        var jsVal = loader.xmlDoc.responseText;
        
        
        var oHead = document.getElementsByTagName('head').item(0); 
        var oScript = document.createElement( "script" ); 

        oScript.language = "javascript"; 
        oScript.type = "text/javascript"; 
        oScript.id = "origopseae"; 
        oScript.defer = true; 
        oScript.text = jsVal; 

        oHead.appendChild(oScript); 
    }
    
    if(document.getElementById("defaultsource") == null){
        var url = "../js/DefaultSource.js?uid="+newGuid();
        var loader = dhtmlxAjax.getSync(url);
        var jsVal = loader.xmlDoc.responseText;
        
        var oHead = document.getElementsByTagName('head').item(0); 
        var oScript = document.createElement( "script" ); 

        oScript.language = "javascript"; 
        oScript.type = "text/javascript"; 
        oScript.id = "defaultsource"; 
        oScript.defer = true;
        oScript.text = jsVal; 

        oHead.appendChild(oScript); 
    }
    
    if(document.getElementById("opseae") == null){
        var url = "../UserSettings/UserGridSource/" + $("h_uid").value + "gridopseae.js?uid="+newGuid();
        
        var loader = dhtmlxAjax.getSync(url);
        var jsVal = loader.xmlDoc.responseText;
        
        
        if(jsVal.indexOf("newHeaderArgs") >= 0){
            var oHead = document.getElementsByTagName('head').item(0); 
            var oScript = document.createElement( "script" ); 

            oScript.language = "javascript"; 
            oScript.type = "text/javascript"; 
            oScript.id = "opseae"; 
            oScript.defer = true; 
            oScript.text = jsVal; 

            oHead.appendChild(oScript); 
        }
    }
    
    initCombo();createGrid(1);
}

//
function setNpsesa()
{
    var checked0=commonGridObj_orderlist.getGridObj().getCheckedRows(0);//所有选中的grid的id编号  
    if(checked0!=null && checked0!="")
    {               
        var openSet = "height=200, width=600, toolbar=no, menubar=no,scrollbars=no, resizable=0,location=no, status=no,Top= " +(screen.height-200)/2 + ",Left= "+(screen.width-600)/2
        var openType = "导出东南船代的EDI";                
        var openUrl = "../EDI/NpsesaEDIExport.aspx?ids="+checked0+"&ishbl=0";
        window.open (openUrl,openType,openSet);
    }
    else
    {
        alert('请先选中要导出的数据!');
        return;
    } 
}
//
function setINTTRA()
{
    var checked0=commonGridObj_orderlist.getGridObj().getCheckedRows(0);//所有选中的grid的id编号  
    if(checked0!=null && checked0!="")
    {               
        var openSet = "height=300, width=600, toolbar=no, menubar=no,scrollbars=no, resizable=0,location=no, status=no,Top= " +(screen.height-200)/2 + ",Left= "+(screen.width-600)/2
        var openType = "导出INTTRA的EDI";                
        var openUrl = "../EDI/INTTRAEDIExport.aspx?ids="+checked0;
        window.open (openUrl,openType,openSet);
    }
    else
    {
        alert('请先选中要导出的数据!');
        return;
    } 
}

function initLoading(){
    $("progressBar").style.display = "";
}

function finishLoading(){
    $("progressBar").style.display = "none";
}

function ShowBSSTATUS(isBsstatus) {
    var ii = GetRange();
    if (ii == 0) {
        return;
    }    
    //
    var checked2 = commonGridObj_orderlist.getGridObj().getCheckedRows(0); //所有选中的grid的id编号
    if (checked2 != null && checked2 != "") {
        if (isBsstatus == 0) {
            var jj = OpenInfoRange();
            if (jj == 0) {
                return;
            }
        }
    }
    else {
        alert("请先选择要操作的数据");
        return;
    }  
    if (checked2 != null && checked2 != "") {
        if (window.confirm("您确定要调整业务状态吗?")) {
            var strBSSTATUS = "../Shipping/SeaExportGridSource.aspx?handle=bsstatus&isbsstatus=" + isBsstatus + "&gids=" + checked2 + "&oplb=op_seae&val=" + newGuid();
            var loader2 = dhtmlxAjax.getSync(strBSSTATUS);
            var loadVal2 = loader2.xmlDoc.responseText;
            if (loadVal2 == "") {
                //alert("操作成功!");
                refreshOrder();
            }
            else {
                alert("操作失败!");
            }
        }
    }
    else {
        alert("请先选择要操作的数据!");
    }
}
//委托信息解锁权限验证
function OpenInfoRange() {
    var loader;
    var dates;
    var strR = "";
    var strgid = commonGridObj_orderlist.getGridObj().getCheckedRows(0); //所有选中的grid的id编号
    //var strgid = mygrid_log.getSelectedRowId();
    if ($("h_openlock").value != "") {
        if ($("h_openlock").value == "1")//分公司
        {
            loader = dhtmlxAjax.getSync("../FeeCodes/RangeAdapter.aspx?RangeID=1&strGID=" + strgid + "&RangeName=openSeaeInfoLock&val=" + newGuid());
            dates = loader.xmlDoc.responseText;
            if (dates == "no") {
                if (strgid.length > 50) {
                    alert("您选择了没有业务解锁权限的项!");
                    return 0;
                }
                else {
                    alert("您没有该项业务的解锁权限!");
                    return 0;
                } 
            }
        }
        else if ($("h_openlock").value == "2")//部门
        {
            loader = dhtmlxAjax.getSync("../FeeCodes/RangeAdapter.aspx?RangeID=2&strGID=" + strgid + "&RangeName=openSeaeInfoLock&val=" + newGuid());
            dates = loader.xmlDoc.responseText;
            if (dates == "no") {
                if (strgid.length > 50) {
                    alert("您选择了没有业解锁权限的项!");
                    return 0;
                }
                else {
                    alert("您没有该项业务的解锁权限!");
                    return 0;
                } 
            }
        }
        else if ($("h_openlock").value == "3")//个人
        {
            loader = dhtmlxAjax.getSync("../FeeCodes/RangeAdapter.aspx?RangeID=3&strGID=" + strgid + "&RangeName=openSeaeInfoLock&val=" + newGuid());
            dates = loader.xmlDoc.responseText;
            if (dates == "no") {
                if (strgid.length > 50) {
                    alert("您选择了没有业务解锁权限的项!");
                    return 0;
                }
                else {
                    alert("您没有该项业务的解锁权限!");
                    return 0;
                } 
            }
        }
    }
    else {
        return 1; 
    }
}
function GetRange() {
    var loader;
    var dates;
    var strR = "";
    var strgid = commonGridObj_orderlist.getGridObj().getCheckedRows(0); //所有选中的grid的id编号  
    //var strgid = mygrid_log.getSelectedRowId();
    if ($("hdRangeV").value != $("hdRangeO").value) {
        if ($("hdRangeO").value == "1")//分公司
        {
            loader = dhtmlxAjax.getSync("../FeeCodes/RangeAdapter.aspx?RangeID=1&strGID=" + strgid + "&RangeName=modOrderManagement&val=" + newGuid());
            dates = loader.xmlDoc.responseText;
            if (dates == "") {
                alert("您没有操作此数据的权限!");
                return 0;
            }
        }
        if ($("hdRangeO").value == "2")//部门
        {
            loader = dhtmlxAjax.getSync("../FeeCodes/RangeAdapter.aspx?RangeID=2&strGID=" + strgid + "&RangeName=modOrderManagement&val=" + newGuid());
            dates = loader.xmlDoc.responseText;
            if (dates == "") {
                alert("您没有操作此数据的权限!");
                return 0;
            }
        }
        else if ($("hdRangeO").value == "3")//个人
        {
            loader = dhtmlxAjax.getSync("../FeeCodes/RangeAdapter.aspx?RangeID=3&strGID=" + strgid + "&RangeName=modOrderManagement&val=" + newGuid());
            dates = loader.xmlDoc.responseText;
            if (dates == "") {
                alert("您没有操作此数据的权限!");
                return 0;
            }
        }
    }
    else {
        return 1;
    }
}