﻿// JScript 文件
$(function(){
    $("#load").hide();
    $("#template").hide();
    $("#cli").hide();
    bind();           
});
function bind()
{
    $("[@id=ready]").remove();
    $("#load").show();
    $.ajax({
        type: "get",
        dataType: "json",
        url: "include/news.ashx",
        complete :function(){$("#load").hide();},
        success: function(msg){
            var data = msg.table;
            $.each(data, function(i, n){
                var row = $("#template").clone();
                row.find("#time").text(n.addtime.split(" ")[0]);
                row.find("#title").html("<image src=images/gray_point.gif boder=0 /><a href=NewsFiles/"+n.file_path+" target=_bank title="+n.title+">&nbsp;"+curStr(n.title,40)+"</a>");                 
                row.attr("id","ready");
                row.appendTo("#down_center_right");
            });
             $("[@id=ready]").show();   
        }
    });
    $.ajax({
        type: "get",
        dataType: "json",
        url: "include/company.ashx",
        success: function(msg){
            var data = msg.table;
            $.each(data, function(i, n){
                var row = $("#cli").clone();
                row.find("#cname").html("<a href=credit_info/"+n.cid+".html target=_bank title="+n.c_name+">"+n.c_name+"</a> <span class=AAA >"+edit(n.c_leval)+"</span>");       
                row.attr("id","ready");
                row.appendTo("#cul");
            });
            $("[@id=ready]").show();      
        }
    });
}

function edit(a)
{
    if(a=="1")
     return "A";
     else if(a=="2")
     return "AA";
     else if(a=="3")
     return "AAA";
     else
     return "未知";
}
function curStr(str,length)
{
    var position=0;
    var result=[];
    for (var i = 0; i < str.length; i++)
    {
        if(position>=length)
            break;
        if (str.charCodeAt(i) > 255)
        {
            position += 2;
            result.push(str.substr(i,1));
        }
        else
        {
            position++;
            result.push(str.substr(i,1));
        }
    }
    return result.join("");
}
