function doajax(method, dataurl, data, sucessCallBack, errorCallBack) {
    var user_key = undefined;
    var user = $.zui.store.get("user")
    if (typeof(user) == "undefined" || user == null) {

    } else {
        user_key = "XinTong " + (user.token);
    }
    if (typeof(user_key) == "undefined" || user_key == null) {
        $.ajax({
            type: method,
            url: dataurl,
            contentType: "application/json",
            dataType: "json",
            async: true,
            data: JSON.stringify(data),
            success: sucessCallBack,
            error: function(error) {
                if (HandleError(error)) return;
                errorCallBack(error);
            }
        })
    } else {

        $.ajax({
            type: method,
            url: dataurl,
            contentType: "application/json",
            dataType: "json",
            beforeSend: function(xhr) {
                xhr.setRequestHeader("token", user_key);
            },
            headers: {
                'token': user_key
            },
            async: true,
            data: JSON.stringify(data),
            success: sucessCallBack,
            error: function(error) {
                if (HandleError(error)) return;
                errorCallBack(error);
            }
        })
    }

}

function ajaxGet(dataurl, data, sucessCallBack, errorCallBack) {

    doajax("GET", dataurl, data, sucessCallBack, errorCallBack)
}

function ajaxPost(dataurl, data, sucessCallBack, errorCallBack) {

    doajax("POST", dataurl, data, sucessCallBack, errorCallBack)

}

function ajaxPut(dataurl, data, sucessCallBack, errorCallBack) {

    doajax("PUT", dataurl, data, sucessCallBack, errorCallBack)
}

function ajaxDelete(dataurl, data, sucessCallBack, errorCallBack) {

    doajax("DELETE", dataurl, data, sucessCallBack, errorCallBack)

}


function HandleError(error) {
    if (typeof(error) != "undefined" && error != null) {
        if (typeof(error.status) != "undefined" && error.status != null) {
            if (error.status == 403) {
                //未登录退出

                layer.msg('登陆已经过期，将重新登陆！', {
                    time: 2000, //20s后自动关闭
                }, function() {
                    self.location = base_ui_url + UI_USER_LOGIN
                })


                return true;
            }
        }
    }
    return false;
}


function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);

    if (r != null) {
        return unescape(r[2]);
    }
    return null;
}
function getItemByIdFromArr(id,curDatas){
    var rowData;
    for(var i=0;i<curDatas.length;i++){
        if(id==curDatas[i].id){
            rowData = curDatas[i];
            break;            
        }
    }
    return rowData;
}

function showPopup4Common(title,callback,area,divId){
    if(!area) area='auto';
    if(!divId) divId='#form-div';
    //添加常量页面
    return layer.open({
        type: 1,
        area: area,
        title: title,
        closeBtn: 1,
        shadeClose: true,
        offset: 'r',
        skin: 'layui-layer-lan',
        content: $(divId),
        btn: '保存',
        btnAlign: 'c', //按钮居中
        shade: 0 ,//不显示遮罩
        yes: function(index){
            if(callback!=false){
               callback();
            }
            layer.close(index);
        }
    });
}


function deleteItem4Common(id,url,okCb){
    //询问框
    layer.confirm('确定删除记录？', {
        btn: ['删除','取消'] //按钮
    }, function(){
        var param ={"id":id};
        no_return_common_service(url, param, function(data) {
            okCb();//重新加载表格数据
            layer.msg(data, {
                time: 2000//20s后自动关闭
            });
        }, function(error) {
            alert(error);
        });
    }, function(index){
        layer.close(index);
    });
}

function addOrUpdateItem4Common(param,url,okCb){
    no_return_common_service(url, param, function(data) {
        if(okCb) okCb();//重新加载表格数据
        layer.msg(data, {
            time: 2000//20s后自动关闭
        });
    }, function(error) {
        alert(error);
    });
}
function setFeSelect(div,selectId){
    get_common_service("/dept/getAllFs",null,function(data){
        var optStr = '<option value="">全部</option>';
        for(var i in data) {
            if(data[i].deptid==selectId)
                optStr += '<option value="'+data[i].deptid+'" selected="selected">'+data[i].name+'</option>';
            else
                optStr += '<option value="'+data[i].deptid+'">'+data[i].name+'</option>';
        }
        $(div).html('');
        $(div).html(optStr);
    });
}

function setLaneSelect(div,selectId){
    var optStr = '';
    var data =[];
    for(var i =0;i<=8;i++) {
        if(i==0)
            data.push({id:i,name:'值机室'});
        else
            data.push({id:i,name:i+'车道'});
    }
    for(var i in data) {
        if(i==selectId)
            optStr += '<option value="'+data[i].id+'" selected="selected">'+data[i].name+'</option>';
        else
            optStr += '<option value="'+data[i].id+'">'+data[i].name+'</option>';
    }
    $(div).html('');
    $(div).html(optStr);
}

// var ViewMap = new HashMap()
// ViewMap.set("/view/mytask/unchecked.html", __inline('/view/mytask/unchecked.html'));
// ViewMap.set("/view/mytask/unexamined.html", __inline('/view/mytask/unexamined.html'));
// ViewMap.set("/view/mytask/undispatched.html", __inline('/view/mytask/undispatched.html'));
// ViewMap.set("/view/mytask/dispatched.html", __inline('/view/mytask/dispatched.html'));
// ViewMap.set("/view/constant/constant.html", __inline('/view/constant/constant.html'));

/**
 * @Func 处理长整形时间格式化
 * @time long
 * @format string 有默认值
 */
function timeStamp2String(time,format){
    if(time == "" || time == null)
        return ;
    if(format==undefined || format == "")
        format = "yyyy/MM/dd hh:mm:ss";
    var datetime = new Date();
    datetime.setTime(time);
    return datetime.Format(format);
};

/**
 * @Func 时间格式化
 * @FuncName Format
 * (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 
 */
Date.prototype.Format = function (fmt) { 
	 var o = {
	     "M+": this.getMonth() + 1, 
	     "d+": this.getDate(), 
	     "h+": this.getHours(), 
	     "m+": this.getMinutes(), 
	     "s+": this.getSeconds(), 
	     "q+": Math.floor((this.getMonth() + 3) / 3), 
	     "S": this.getMilliseconds()
	 };
	 if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	 for (var k in o)
		 if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	 return fmt;
};

/**
 * 提示框
 */
function tip(data,timeout){
    if(data==undefined || data=='')
        return ;
    layer.msg(data, {
            time: (timeout!=null)?timeout:2000 //20s后自动关闭
        });
}

function showPopup4CommonBtns(title,area,divId,btns,callback1,callback2){
    if(!area) area='auto';
    if(!divId) divId='#form-div';
    //添加常量页面
    return layer.open({
        type: 1,
        area: area,
        title: title,
        closeBtn: 1,
        shadeClose: true,
        skin: 'layui-layer-lan',
        content: $(divId),
        btn: btns,
        btnAlign: 'c', //按钮居中
        shade: 0 ,//不显示遮罩
        yes: function(index){
            if(callback!=false){
               callback();
            }
            layer.close(index);
        }
    });
}