﻿function setImgSize(img, width, height) {
    var MaxWidth = width; //设置图片宽度界限
    var MaxHeight = height; //设置图片高度界限
    var HeightWidth = img.offsetHeight / img.offsetWidth; //设置高宽比
    var WidthHeight = img.offsetWidth / img.offsetHeight; //设置宽高比
    if (img.offsetWidth > MaxWidth) {
        img.width = MaxWidth;
        img.height = MaxWidth * HeightWidth;
    }
    if (img.offsetHeight > MaxHeight) {
        img.height = MaxHeight;
        img.width = MaxHeight * WidthHeight;
    }
}

function vod() { }

//encodeURIComponent可以还处理utf-8编码
function EncodeURL(str) {
    return encodeURIComponent(str).replace(/\+/g, "%2b");
}
function escape2(str) {
    return escape(str).replace(/\+/g, "%2b");
}

function preview(obj) {
    window.clipboardData.setData("Text", $(obj).html());
    try {
        var ExApp = new ActiveXObject("Excel.Application")
        var ExWBk = ExApp.workbooks.add()
        var ExWSh = ExWBk.worksheets(1)
        ExApp.DisplayAlerts = false
        ExApp.visible = true
    }
    catch (e) {
        alert("您的电脑没有安装Microsoft Excel软件！")
        return false
    }
    ExWBk.worksheets(1).Paste;
}


var idTmr;


function method1(tableid) {//整个表格拷贝到EXCEL中    

    var curTbl = document.getElementById(tableid);
    var oXL = new ActiveXObject("Excel.Application");
    //创建AX对象excel    
    var oWB = oXL.Workbooks.Add();
    //获取workbook对象    
    var xlsheet = oWB.Worksheets(1);
    //激活当前sheet    
    var sel = document.body.createTextRange();
    sel.moveToElementText(curTbl);
    //把表格中的内容移到TextRange中    
    sel.select();
    //全选TextRange中内容    
    sel.execCommand("Copy");
    //复制TextRange中内容     
    xlsheet.Paste();
    //粘贴到活动的EXCEL中          
    oXL.Visible = true;
    //设置excel可见属性    

    try {
        var fname = oXL.Application.GetSaveAsFilename("save.xls", "Excel Spreadsheets (*.xls), *.xls");
        if (fname) {
            oWB.SaveAs(fname);
        }


    } catch (e) {
        print("Nested catch caught " + e);
    } finally {

        oWB.Close(savechanges = false);
        oXL.Quit();
        oXL = null;
        //结束excel进程，退出完成   
        idTmr = window.setInterval("Cleanup();", 1);


    }
}
function Cleanup() {
    window.clearInterval(idTmr);

    CollectGarbage();
}

//添加收藏夹
//onclick="AddFavorite(window.location,document.title)"
function AddFavorite(sURL, sTitle) {
    try {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e) {
        try {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

//设为首页
//onclick="SetHome(this,window.location)"
function SetHome(obj, vrl) {
    try {
        obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vrl);
    }
    catch (e) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("此操作被浏览器拒绝!请在浏览器地址栏输入\"about:config\"并回车然后将[signed.applets.codebase_principal_support]设置为\"true\"");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', vrl);
        }
    }
}

// 字体大小
function setFontSize(size) {
    //document.body.style.fontSize=size;
    var a = document.getElementById("Info_Content");
    //var b = a.childNodes;
    var b = a.getElementsByTagName("p");
    a.style.fontSize = size;
    for (var i = 0; i < b.length; i++) {
        b[i].style.fontSize = size;
    }
}

function ShowTime() {
    var date = new Date(); //日期对象
    var now = "";
    now = date.getFullYear() + "年"; //读英文就行了
    now = now + (date.getMonth() + 1) + "月"; //取月的时候取的是当前月-1如果想取当前月+1就可以了
    now = now + date.getDate() + "日";
    now = now + date.getHours() + "时";
    now = now + date.getMinutes() + "分";
    now = now + date.getSeconds() + "秒";
    $("#ShowTime").html(now); //div的html是now这个字符串 
    setTimeout("ShowTime()", 1000); //设置过1000毫秒就是1秒，调用show方法
}

function GetAjax(codeID,time){
    $('#Code'+codeID).html("数据加载中......");
    $.ajax({
        url: 'http://61.154.11.185:8088/getlotnum.php?lottype=10&period='+codeID,
        dataType: "jsonp",
        jsonp: "jsonpcallback",
        success: function (json) {
            var string = "";
            var strs = new Array(); //定义一数组
            strs = json[0].src.split("+"); //字符分割      
            for (i = 0; i < strs.length; i++) {
                string = string + "<span>" + strs[i] + "</span>";    //分割后的字符输出
            }
            $('#Code'+codeID).html(string);  //调用用来显示内容的div
        }
    },time);
}
