<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <head>
        <link href="../Content/style.css" rel="stylesheet" type="text/css" />
        <script src="../Scripts/lib/jquery-1.4.4.min.js" type="text/javascript"></script>
        <script src="../Scripts/common.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
                $('#divResutl').hide();
                $('#divBack').hide();
                createKdList();
            });
            //点击快递公司名称时，把代码赋值给查询框
            function setKdgsdm(strKdgsdm, strKdgsmc) {
                $('#kdgsdm').val(strKdgsdm);
                $('#kdgsmc').val(strKdgsmc);

                return false;
            }
            //生成快递公司层内容
            function createKdList() {
                //加载快递信息
                var retKd = ParseData(window.external.DoOptions("TSAMS_Menus", "DoOthers", '{"option":"1"}'));
                var arrKdList = new Array();
                if (0 == retKd.ReturnCode) {
                    var strKdList = '';
                    var strSzm = '';
                    var iCount = 0;
                    for (var i = 0; i < retKd.Records.length; i++) {
                        if (strSzm != retKd.Records[i]['szm'].toUpperCase()) {
                            //非初次加载，加上上一条记录的结束，把该li追加到数组
                            if (strSzm) {
                                strKdList += '</li>';
                                arrKdList.push(strKdList);
                                strKdList = '';
                            }
                            //首字母转大写
                            strSzm = retKd.Records[i]['szm'].toUpperCase();
                            iCount = 0;
                            //新的li记录开始
                            strKdList += '<li';
                            //偶数行加样式：带底色
                            if (arrKdList.length % 2 == 0) {
                                strKdList += ' class="link-bluebg"';
                            }
                            strKdList += '>';
                            strKdList += '<b class="sequence">' + strSzm + '</b>';
                            strKdList += '<a href="#" onclick="setKdgsdm(\'' + retKd.Records[i]['kdgsdm'] + '\', \'' + retKd.Records[i]['kdgsmc'] + '\');return false;">' + retKd.Records[i]['kdgsmc'] + '</a>';
                        }
                        else {
                            iCount++;
                            //该字母记录数超过4条，换到下一行
                            if (iCount % 4 == 0) {
                                strKdList += '</li>';
                                arrKdList.push(strKdList);

                                strKdList = '';
                                strKdList += '<li';
                                //偶数行加样式：带底色
                                if (arrKdList.length % 2 == 0) {
                                    strKdList += ' class="link-bluebg"';
                                }
                                strKdList += '>';
                                strKdList += '<b class="sequence">&nbsp;</b>';
                            }
                            strKdList += '<a href="#" onclick="setKdgsdm(\'' + retKd.Records[i]['kdgsdm'] + '\', \'' + retKd.Records[i]['kdgsmc'] + '\');return false;">' + retKd.Records[i]['kdgsmc'] + '</a>';
                        }
                    }
                }
                strKdList += '</li>';
                arrKdList.push(strKdList);

                strKdList = '';
                var iHalf = parseInt(arrKdList.length / 2) + 1;
                if (iHalf % 2 != 0) {
                    iHalf++;
                }
                strKdList += '<ul>';
                for (var j = 0; j < arrKdList.length; j++) {
                    if (j == iHalf) {
                        strKdList += '</ul>';
                        strKdList += '<ul>';
                    }
                    strKdList += arrKdList[j];
                }
                strKdList += '</ul>';
                $('#divKd').append(strKdList);
            }
            //查询
            function goSearch() {
                $('#divResutl').css("display", "block");
                $('#divBack').css("display", "block");
                $('#divNormal').css("display", "none");
                $('#divKd').css("display", "none");
                //查询数据
                searchData();
                return false;
            }
            //查询数据
            function searchData() {
                $("#divResutl").html('查询中...');
                var expressid = $("#kdgsdm").val();
                var expressno = $("#kddh").val();
                if (!expressid) {
                    $("#divResutl").html("请选择快递公司");
                    return false;
                }
                if (!expressno || "请输入快递单号" == expressno) {
                    $("#divResutl").html("请输入快递单号");
                    return false;
                }
                var strUrl = "http://api.kuaidi100.com/apione?com=" + expressid + "&nu=" + expressno + "&show=0";
                $.getJSON(strUrl, function (data) {
                    //status:1：成功。0：无查询结果。 2：失败
                    if (data['status'] == '1') {
                        var strData = "时间：" + data['data'][0]['time'];
                        strData += "<br>内容：" + data['data'][0]['context'];

                        $("#divResutl").html(strData);
                    }
                    else {
                        $("#divResutl").html(data['message']);
                    }
                });
                //超过一分钟没有返回值，提示用户没有网络连接
                setTimeout(function () {
                    if ($("#divResutl").html() == "查询中...") {
                        $("#divResutl").html("<font color=\"red\">没有查到任何信息，请检查您的网络连接！</font>");
                    }
                }, 1000 * 60);
            }
            //快递单号获得焦点
            function focusKddh() {
                if ($("#kddh").val() == "请输入快递单号") {
                    $("#kddh").val("");
                }
            }
            //快递单号失去焦点
            function blurKddh() {
                if (!$("#kddh").val()) {
                    $("#kddh").val("请输入快递单号");
                }
            }
            //显示快递公司列表层
            function showKdList() {
                $('#divResutl').hide();
                $('#divBack').hide();
                $('#divNormal').show();
                $('#divKd').show();
            }
        </script>
    </head>
    <body>
        <div class="kd_left" style="">
            <div class="number">
                <div style="display: none">
                    <input id="kdgsdm" type="text" value="" /></div>
                <div>
                    <input id="kdgsmc" readonly type="text" value="请选择快递公司" onclick="showKdList()" /></div>
                <div class="single">
                    <input id="kddh" type="text" value="请输入快递单号" onfocus="focusKddh()" onblur="blurKddh()" /></div>
                <div>
                    <a href="#" onclick="goSearch();return false;">查询</a>
                </div>
            </div>
            <div id="divResutl" class="result">
                查询结果</div>
            <div id="divBack" class="divBack">
                <a href="#" onclick="showKdList();return false;"></a>
            </div>
            <div id="divNormal" class="normal">
                <span><strong class="stock">常用:</strong> <strong><a href="#" onclick="setKdgsdm('ems','EMS');return false;">
                    EMS</a></strong> <strong><a href="#" onclick="setKdgsdm('shentong','申通');return false;">
                        申通</a></strong> <strong><a href="#" onclick="setKdgsdm('yuantong','圆通');return false;">
                            圆通</a></strong> <strong><a href="#" onclick="setKdgsdm('zhongtong','中通');return false;">
                                中通</a></strong> <strong><a href="#" onclick="setKdgsdm('huitongkuaidi','汇通');return false;">
                                    汇通</a></strong> <strong><a href="#" onclick="setKdgsdm('ups','UPS');return false;">UPS</a></strong>
                    <strong><a href="#" onclick="setKdgsdm('shunfeng','顺丰');return false;">顺丰</a></strong>
                    <strong><a href="#" onclick="setKdgsdm('yunda','韵达');return false;">韵达</a></strong>
                    <strong><a href="#" onclick="setKdgsdm('tiantian','天天');return false;">天天</a></strong>
                    <strong><a href="#" onclick="setKdgsdm('zhaijisong','宅急送');return false;">宅急送</a></strong>
                </span>
            </div>
            <div id="divKd" class="kd">
            </div>
        </div>
    </body>
</html>
