﻿function getObject(objectId) {
    if (document.getElementById && document.getElementById(objectId)) {
        // W3C DOM
        return document.getElementById(objectId);
    }
    else if (document.all && document.all(objectId)) {
        // MSIE 4 DOM
        return document.all(objectId);
    }
    else if (document.layers && document.layers[objectId]) {
        // NN 4 DOM.. note: this won't find nested layers
        return document.layers[objectId];
    }
    else {
        return false;
    }
}
function $(objectId) {
    if (document.getElementById && document.getElementById(objectId)) {
        // W3C DOM
        return document.getElementById(objectId);
    }
    else if (document.all && document.all(objectId)) {
        // MSIE 4 DOM
        return document.all(objectId);
    }
    else if (document.layers && document.layers[objectId]) {
        // NN 4 DOM.. note: this won't find nested layers
        return document.layers[objectId];
    }
    else {
        return false;
    }
}
function trim(str) {
    return str.replace(/(^\s*)|(\s*$)/g, "");
}

/*获取url中的keywords值*/
function getquery(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = location.href.substr(location.href.indexOf("\?") + 1).match(reg);
    if (r != null) return r[2]; return null;
} 


function LoadAjax(url) {
    var objxml;
    if (window.ActiveXObject) {
        objxml = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        objxml = new XMLHttpRequest();
    }

    objxml.open("GET", url, false);
    objxml.send(null);
    
    var sResult=objxml.responseText;
    if(objxml.status=="200")
    {
        return sResult;
    }
    return "";
}

function CheckAll(form)
{
       if (form.checkbox.length==null){
		        form.checkbox.checked=form.chkall.checked;
		        CheckSingle(form.checkbox);
        }else{
		        for (var i=0;i<form.checkbox.length;i++){
		        form.checkbox[i].checked=form.chkall.checked;
		        CheckSingle(form.checkbox[i]);
		        }
	        }
 }

function CheckSingle(s)
{
    var e=s;
    while (e.tagName != "TR")
	    e = e.parentElement.parentElement;	
    if(s.checked)
	    e.style.backgroundColor="#F1F1F1";
    else
	    e.style.backgroundColor="#F1F5FA";
}


function OpenClose(id)
{
    var obj = getObject(id);
    if(obj.style.display == "none")
    {
        obj.style.display = "";
    }
    else
    {
        obj.style.display = "none";
    }
}

function search()
{
    var skey =trim(getObject("r_key").value);
    if(skey == "")
    {
        alert("请输入要搜索的内容");
        return;
    }
    var rs = document.getElementsByName("r_s");
    for(var i =0; i < rs.length; i++)
    {
        if(rs[i].checked)
        {
            goUrl(rs[i].value, skey);
            break;
        }
    }
}

function goUrl(s, v) 
{
    switch(s)
    {
        case "s":
            window.location.href = "http://www.simiao.net/SiMiaoList.aspx?key=" + encodeURI(v);
            break;
        case "z":
            document.location.href = "http://www.simiao.net/news/NewsList.aspx?nn=" + encodeURI(v);
            break;
    }
}

function DrawImage(ImgD)
{ 
    var image=new Image(); 
    image.src=ImgD.src; 
    if(image.width>0 && image.height>0)
    { 
        if(image.width/image.height>= 1)
        { 
            if(image.width>100)
            { 
                ImgD.width=100 
                ImgD.height=(image.height*100)/image.width; 
            }
            else
            { 
                ImgD.width=image.width; 
                ImgD.height=image.height; 
            } 
        } 
        else
        { 
            if(image.height>100)
            { 
                ImgD.height=100; 
                ImgD.width=(image.width*100)/image.height; 
            }
            else
            { 
                ImgD.width=image.width; 
                ImgD.height=image.height; 
            } 
        } 
    }
} 

function DrawImageSize(ImgD, w, h)
{ 
    var image=new Image(); 
    image.src=ImgD.src; 
    if(image.width>0 && image.height>0)
    { 
        if(image.width/image.height>= 1)
        { 
            if(image.width>w)
            { 
                ImgD.width=w 
                ImgD.height=(image.height*w)/image.width; 
            }
            else
            { 
                ImgD.width=image.width; 
                ImgD.height=image.height; 
            } 
        } 
        else
        { 
            if(image.height>h)
            { 
                ImgD.height=h; 
                ImgD.width=(image.width*h)/image.height; 
            }
            else
            { 
                ImgD.width=image.width; 
                ImgD.height=image.height; 
            } 
        } 
    }
} 

function showcount()
{
    document.write ('<script language="javascript" type="text/javascript" src="http://js.users.51.la/3306767.js"></script>');
}

// Copyright: hc360.com
// Author: Dakular
// Useage: HCmarquee(滚动对象id, 可见范围宽度, 可见范围高度, 滚动条数, 可见条数, 滚动速度, 停留时间, 方向); 方向有left和up两种
function HCmarquee(id, mw, mh, mr, sr, ms, pause) {

    var obj = document.getElementById(id);
    obj.ss = false; //stop tag
    obj.mr = mr; //marquee rows
    obj.sr = sr; //marquee display rows
    obj.mw = mw; //marquee width
    obj.mh = mh; //marquee height
    obj.ms = ms; //marquee speed
    obj.pause = pause; //pause time
    obj.pt = 0; //pre top
    obj.st = 0; //stop time
    obj.mul = 1;
    obj.con = "";
    with (obj) {
        style.width = mw + "px";
        style.height = mh + "px";
        noWrap = false;
        onmouseover = stopm;
        onmouseout = startm;
        scrollTop = 0 + "px";
        scrollLeft = 0 + "px";
    }

    if (obj.mr != 1) {
        obj.tt = mh * mr / sr;
        obj.ct = mh; //current top
        obj.innerHTML += obj.innerHTML;
        setInterval(scrollUp, obj.ms);
    }
    function scrollUp() {
        if (obj.ss == true) return;
        obj.ct += 1;
        if (obj.ct == obj.mh + 1) {
            obj.st += 1; obj.ct -= 1;
            if (obj.st == (obj.pause * obj.mul)) {
                obj.ct = 0; obj.st = 0;
                if (obj.mul == 1) obj.mul = 1;
                else obj.mul = 1;
            }
        } else {
            obj.pt = (++obj.scrollTop);
            if (obj.pt == obj.tt) { obj.scrollTop = 0; }
        }
    }

    function stopm() { obj.ss = true; }
    function startm() { obj.ss = false; }

}
//]]>
// Copyright: hc360.com
// Author: Dakular
// Useage: HCmarquee(滚动对象id, 可见范围宽度, 可见范围高度, 滚动条数, 可见条数, 滚动速度, 停留时间, 方向); 方向有left和up两种
function HCmarquee(id, mw, mh, mr, sr, ms, pause) {

    var obj = document.getElementById(id);
    obj.ss = false; //stop tag
    obj.mr = mr; //marquee rows
    obj.sr = sr; //marquee display rows
    obj.mw = mw; //marquee width
    obj.mh = mh; //marquee height
    obj.ms = ms; //marquee speed
    obj.pause = pause; //pause time
    obj.pt = 0; //pre top
    obj.st = 0; //stop time
    obj.mul = 1;
    obj.con = "";
    with (obj) {
        style.width = mw + "px";
        style.height = mh + "px";
        noWrap = false;
        onmouseover = stopm;
        onmouseout = startm;
        scrollTop = 0 + "px";
        scrollLeft = 0 + "px";
    }

    if (obj.mr != 1) {
        obj.tt = mh * mr / sr;
        obj.ct = mh; //current top
        obj.innerHTML += obj.innerHTML;
        setInterval(scrollUp, obj.ms);
    }
    function scrollUp() {
        if (obj.ss == true) return;
        obj.ct += 1;
        if (obj.ct == obj.mh + 1) {
            obj.st += 1; obj.ct -= 1;
            if (obj.st == (obj.pause * obj.mul)) {
                obj.ct = 0; obj.st = 0;
                if (obj.mul == 1) obj.mul = 1;
                else obj.mul = 1;
            }
        } else {
            obj.pt = (++obj.scrollTop);
            if (obj.pt == obj.tt) { obj.scrollTop = 0; }
        }
    }

    function stopm() { obj.ss = true; }
    function startm() { obj.ss = false; }

} //]]>