var styleclass = null;
var xmlhttp;

function openScript(url, width, height)  {
    var Win = window.open(url, "openScript", 'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=yes'); //设置被打开网页的数据
}

function addfavorite() {
	if (document.all) {
	    window.external.addFavorite("http://www.zscs.org","中山市计算机学会");
	}
	else if (window.sidebar) {
	    window.sidebar.addPanel("中山市计算机学会", "http://www.zscs.org","");
	}
}

function sethomepage()
{
	if (document.all)
	{
		document.body.style.behavior="url(#default#homepage)";
	   document.body.setHomePage("http://www.zscs.org");
	}
	else if (window.sidebar)
	{
		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","http://www.zscs.org");
	}
}

function createStandardXHR() {
    try {
        return new window.XMLHttpRequest();
    } catch (e) { }
}

function createActiveXHR() {
    try {
        return new window.ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) { }
}

// 创建XMLHTTP对象
function getXMLObj() {
    var xhr = createStandardXHR() || createActiveXHR(); 
	return xhr;
}

xmlhttp = getXMLObj();

function addquerynum()
{
	var querynum = document.getElementById("querynum"); 
	if (querynum != null)
	{
		querynum.innerHTML++; 
	}
}
// 加载左栏
function loadindexleft1() {
    try {
        if (xmlhttp) {
            xmlhttp.open("get", "/indexleft1.asp", true);
            xmlhttp.onreadystatechange = indexleft1complete;
            xmlhttp.send(null);
        }
    } catch (e) {
        alter(e);
    }
}

function indexleft1complete() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var e = document.getElementById("indexleft1");
            if (e) {
                e.innerHTML = xmlhttp.responseText;
                loadindexleft2();
            }
        }
        else {
            alert("error: XMLHttpRequest.status=" + xmlhttp.status);
        }
    }
}

var codeid; 
function getpicturecode()
{
	xmlhttp = getXMLObj();
	if (xmlhttp)
	{
		codeid = new Date().getTime(); 
		document.getElementById("picturecode").innerHTML = "<img src='/images/loading_small.gif' />"; 
		xmlhttp.open("get", "/GetCode.asp?id="+codeid, true); 
		xmlhttp.onreadystatechange = getpicturecodecomplete; 
		xmlhttp.send(null); 
	}
}
function getpicturecodecomplete()
{
	if (xmlhttp.readyState == 4)
	{
		if (xmlhttp.status == 200)
		{ 
			document.getElementById("picturecode").innerHTML = "<img src='/GetCode.asp?id="+codeid+"' onclick='getpicturecode();' />"; 
		}
	}
}
function loadindexleft2() {
    try {
        if (xmlhttp) {
            xmlhttp.open("get", "/indexleft2.asp", true);
            xmlhttp.onreadystatechange = indexleft2complete;
            xmlhttp.send(null);
        }
    } catch (e) {
        alter(e);
    }
}

function indexleft2complete() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var e = document.getElementById("indexleft2");
            if (e) {
                e.innerHTML = xmlhttp.responseText;
                loadindexleft3();
            }
        }
        else {
            alert("error: XMLHttpRequest.status=" + xmlhttp.status);
        }
    }
}

function loadindexleft3() {
    try {
        if (xmlhttp) {
            xmlhttp.open("get", "/indexleft3.asp", true);
            xmlhttp.onreadystatechange = indexleft3complete;
            xmlhttp.send(null);
        }
    }
    catch (e) {
        alter(e);
    }
}

function indexleft3complete() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var e = document.getElementById("indexleft3");
            if (e) {
                e.innerHTML = xmlhttp.responseText;
                loadrss6(); 
            }
        }
        else {
            alert("error: XMLHttpRequest.status=" + xmlhttp.status);
        }
    }
}

//加载正文
function loadindexright1() {
    try {
        xmlhttp.open("get", "/indexright1.asp", true);
        xmlhttp.onreadystatechange = indexright1complete;
        xmlhttp.send(null);
    } catch (e) {
        alter(e);
    }
}

function indexright1complete() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var e = document.getElementById("indexright1");
            if (e) {
                e.innerHTML = xmlhttp.responseText;
                loadindexright2();
            }
        }
        else {
            alert("error: XMLHttpRequest.status=" + xmlhttp.status);
        }
    }
}

function loadindexright2() {
    try {
        if (xmlhttp) {
            xmlhttp.open("get", "/indexright2.asp", true);
            xmlhttp.onreadystatechange = indexright2complete;
            xmlhttp.send(null);
        }
    } catch (e) {
        alter(e);
    }
}

function indexright2complete() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var e = document.getElementById("indexright2");
            if (e) {
                e.innerHTML = xmlhttp.responseText;
                loadindexright3();
            }
        }
        else {
            alert("error: XMLHttpRequest.status=" + xmlhttp.status);
        }
    }
}

function loadindexright3() {
    try {
        if (xmlhttp) {
            xmlhttp.open("get", "/indexright3.asp", true);
            xmlhttp.onreadystatechange = indexright3complete;
            xmlhttp.send(null);
        }
    } catch (e) {
        alter(e);
    }
}

function indexright3complete() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var e = document.getElementById("indexright3");
            if (e) {
                e.innerHTML = xmlhttp.responseText;
                loadindexright4();
            }
        }
        else {
            alert("error: XMLHttpRequest.status=" + xmlhttp.status);
        }
    }
}

function loadindexright4() {
    try {
        if (xmlhttp) {
            xmlhttp.open("get", "/indexright4.asp", true);
            xmlhttp.onreadystatechange = indexright4complete;
            xmlhttp.send(null);
        }
    } catch (e) {
        alter(e);
    }
}

function indexright4complete() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var e = document.getElementById("indexright4");
            if (e) {
                e.innerHTML = xmlhttp.responseText; 
                loadindexright5();
            }
        }
        else {
            alert("error: XMLHttpRequest.status=" + xmlhttp.status);
        }
    }
}

function loadindexright5() {
    try {
        if (xmlhttp) {
            xmlhttp.open("get", "/indexright5.asp", true);
            xmlhttp.onreadystatechange = indexright5complete;
            xmlhttp.send(null);
        }
    } catch (e) {
        alter(e);
    }
}

function indexright5complete() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var e = document.getElementById("indexright5");
            if (e) {
                e.innerHTML = xmlhttp.responseText;
                loadindexright6();
            }
        }
        else {
            alert("error: XMLHttpRequest.status=" + xmlhttp.status);
        }
    }
}

function loadindexright6() {
    try {
        if (xmlhttp) {
            xmlhttp.open("get", "/indexright6.asp", true);
            xmlhttp.onreadystatechange = indexright6complete;
            xmlhttp.send(null);
        }
    } catch (e) {
        alter(e);
    }
}

function indexright6complete() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var e = document.getElementById("indexright6");
            if (e) {
                e.innerHTML = xmlhttp.responseText;
                loadindexleft1();
            }
        }
        else {
            alert("error: XMLHttpRequest.status=" + xmlhttp.status);
        }
    }
}

// 加载“业内资讯”模块到index.asp
function loadrss() {
    try {
        xmlhttp.open("get", "/getrss.asp", true);
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {
                    var e = document.getElementById("rssnews");
                    if (e) {
                        e.innerHTML = xmlhttp.responseText;
                        loadindexright1();
                        document.getElementById('rss6').style.display = "block";
                        document.getElementById('rss1').style.display = "none";
                        document.getElementById('rss2').style.display = "none";
                        document.getElementById('rss3').style.display = "none";
                        document.getElementById('rss4').style.display = "none";
                        document.getElementById('rss5').style.display = "none";
                    }
                }
            }
        }
        xmlhttp.send(null);
    } catch (e) {
        alter(e);
    }
}
/*
function rsscomplete()
{
	if (xmlhttp.readyState == 4)
	{
		if (xmlhttp.status == 200)
		{ 
			var e = document.getElementById("rssnews"); 
			if (e)
			{
				e.innerHTML = xmlhttp.responseText; 
				loadindexright1();   
				document.getElementById('rss1').style.display = "block";
				document.getElementById('rss2').style.display = "none";
				document.getElementById('rss3').style.display = "none";
				document.getElementById('rss4').style.display = "none";
				document.getElementById('rss5').style.display = "none";
				loadrss1(); 
				loadrss2(); 
				loadrss3(); 
				loadrss4(); 
				loadrss5(); 
			//	loadrss6(); 
			}
			else
			{
				alert("没有找到对象！"); 
			}
		}
		else
		{
			alert("error: XMLHttpRequest.status=" + xmlhttp.status);   
		}
	}
}*/

function bytesToBSTR(body,Cset)
{
	var objstream;
	objstream = Server.CreateObject("Adodb.Stream");
	objstream.Type = 1;
	objstream.Mode = 3;
	objstream.Open();
	objstream.Write(body);
	objstream.Position = 0;
	objstream.Type = 2;
	objstream.Charset = Cset;
	bytesToBSTR = objstream.Readtext;
	objstream.Close;
	return(bytesToBSTR);
}
function getrss(id, url, tag, pagecode, fun) {
    try {
        var x = 'pagecode=' + pagecode + '&tag=' + escape(tag) + '&url=' + escape(url);
        xmlhttp.open('post', '/getdata2.asp', true);
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("If-Modified-Since", "0");
        xmlhttp.onreadystatechange = function ongetrss() {
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {
                    var items = xmlhttp.responseXML.getElementsByTagName("item");
                    if (!items)
                        alert("没有item标签");
                    else {
                        var tb = document.getElementById(id);
                        var tr = null;
                        if (!tb)
                            alert("没有找到" + id);
                        else {
                            while (tb.childNodes.length > 0)
                                tb.removeChild(tb.childNodes[0]);
                            for (var i = 0; i < items.length; i += 2) {
                                tr = document.createElement("tr");
                                tr.appendChild(createCellWithText(items[i].getElementsByTagName("title")[0].firstChild.nodeValue, items[i].getElementsByTagName("link")[0].firstChild.nodeValue));
                                tr.appendChild(createCellWithText(items[i + 1].getElementsByTagName("title")[0].firstChild.nodeValue, items[i + 1].getElementsByTagName("link")[0].firstChild.nodeValue));
                                tb.appendChild(tr);
                            }
                        }
                    }
                    if (fun != null) {
                        fun();
                    }
                }
            }
        }
        xmlhttp.send(x);
    } catch (e) {
        alert(e);
    }
}

function createCellWithText(text, url) {
    var cell = document.createElement("td");
    cell.appendChild(document.createTextNode(text));
    cell.innerHTML = "<li>" + text.link(url) + "</li>";
    cell.style.width = "300px";
    return cell;
}

function unselectallitem() {
    var c = readCookie('style');
    var bg = null;
    if (c == null) {
        bg = "url(/images/menubg2.gif) repeat-x";
    }
    else if (c == 'style2') {
        bg = "url(/images/black/title_bg.gif) repeat-x";
    }
    else if (c == 'style3') {
        bg = "url(/images/blue/title_bg.gif) repeat-x";
    }
    else {
        bg = "url(/images/menubg2.gif) repeat-x";
    }
    try {
        document.getElementById("rss1").style.background = bg;
        document.getElementById("rss2").style.background = bg;
        document.getElementById("rss3").style.background = bg;
        document.getElementById("rss4").style.background = bg;
        document.getElementById("rss5").style.background = bg;
        //	document.getElementById("rss6").style.background = bg;
        document.getElementById("rss1").style.border = "80px";
        document.getElementById("rss2").style.border = "80px";
        document.getElementById("rss3").style.border = "80px";
        document.getElementById("rss4").style.border = "80px";
        document.getElementById("rss5").style.border = "80px";
        //	document.getElementById("rss6").style.border = "80px"; 
        document.getElementById("rss1").style.width = "80px";
        document.getElementById("rss2").style.width = "80px";
        document.getElementById("rss3").style.width = "80px";
        document.getElementById("rss4").style.width = "80px";
        document.getElementById("rss5").style.width = "80px";
        //	document.getElementById("rss6").style.width = "80px"; 
    }
    catch (e) {
        return false;
    }
}

function cleanall(id) {
    var tb = document.getElementById(id);
    if (tb.childNodes.length < 1) {
        var tr = document.createElement("tr");
        var cell = document.createElement("td");
        cell.innerHTML = "<img src='/images/loading.gif' alt='正在加载...' />"
        tr.appendChild(cell);
        tb.appendChild(tr);
    }
}

// cnbeta新闻
function loadrss6() {
    hideallbut('rss6');
    cleanall('rss6')
    getrss('rss6', 'http://www.cnbeta.com/backend.php', 'cnBeta新闻', 'utf-8', null);
}

// 网络设备
function loadrss5() {
    cleanall('rss5')
    getrss('rss5', 'http://rss.mydrivers.com/rss.aspx?cid=5', '网络设备', 'GB2312', null);
}

// 最新评测
function loadrss4() {
    cleanall('rss4')
    getrss('rss4', 'http://rss.mydrivers.com/rss.aspx?Tid=2', '最新评测', 'GB2312', loadrss5);
}

// 业界科学
function loadrss3() {
    cleanall('rss3')
    getrss('rss3', 'http://rss.mydrivers.com/rss.aspx?cid=9', '业界科学', 'GB2312', loadrss4);
}

// OS软件
function loadrss2() {
    cleanall('rss1')
    getrss('rss2', 'http://rss.mydrivers.com/rss.aspx?cid=8', '软件资讯', 'GB2312', loadrss3);
}

// 硬件资讯
function loadrss1() {
    cleanall('rss1')
    getrss('rss1', 'http://blog.csdn.net/rss.html?type=Home&channel=', 'cnBlog精华', 'utf-8', loadrss2);
}

function hideallbut(id) {
    try {
        document.getElementById('rss1').style.display = 'none';
        document.getElementById('rss2').style.display = 'none';
        document.getElementById('rss3').style.display = 'none';
        document.getElementById('rss4').style.display = 'none';
        document.getElementById('rss5').style.display = 'none';
        document.getElementById('rss6').style.display = 'none';
        document.getElementById(id).style.display = 'block';

        var c = readCookie('style');
        var bg = null, bgselect = null;
        if (c == null) {
            bg = "url(/images/menubg2.gif) repeat-x";
        }
        else if (c == 'style2') {
            bg = "url(/images/black/title_bg.gif) repeat-x";
            bgselect = "url(/images/black/tab_select.png)";
        }
        else if (c == 'style3') {
            bg = "url(/images/blue/title_bg.gif) repeat-x";
            bgselect = "url(/images/blue/tab_select.png)";
        }
        else {
            bg = "url(/images/menubg2.gif) repeat-x";
            bgselect = "url(/images/tab_select.png)";
        }
        document.getElementById('rsstd1').style.background = bg;
        document.getElementById('rsstd2').style.background = bg;
        document.getElementById('rsstd3').style.background = bg;
        document.getElementById('rsstd4').style.background = bg;
        document.getElementById('rsstd5').style.background = bg;
        document.getElementById('rsstd5').style.background = bg;
        document.getElementById('rsstd6').style.background = bg;
        document.getElementById("rsstd1").style.width = "80px";
        document.getElementById("rsstd2").style.width = "80px";
        document.getElementById("rsstd3").style.width = "80px";
        document.getElementById("rsstd4").style.width = "80px";
        document.getElementById("rsstd5").style.width = "80px";
        document.getElementById("rsstd6").style.width = "80px";
        var idtitle = 'rsstd' + id.substr(3, 1);
        document.getElementById(idtitle).style.width = "100px";
        document.getElementById(idtitle).style.background = bgselect;
    }
    catch (e) {
        return false;
    }
}

function switchStylestyle(styleName)
{
	aa=document.styleSheets;
	for(i=0;i<aa.length;i++) 
	{
		aa[i].disabled = true;
		if (aa[i].title== styleName)
		{
			aa[i].disabled = false;
		}
	};
	createCookie('style', styleName, 365);
	hideallbut('rss6'); 
}
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') 
			c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) 
			return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
function clearAD()
{
	if(adframe.document.getElementById("divAD"))
		adframe.document.getElementById("divAD").innerHTML = none; 
}
function get_Code() 
{
    var Dv_CodeFile = "http://www.zscs.org/bbs/Dv_GetCode.asp";
    if(document.getElementById("imgid"))
        document.getElementById("imgid").innerHTML = '<img src="'+Dv_CodeFile+'?t='+Math.random()+'" alt="点击刷新验证码" style="cursor:pointer;border:0;vertical-align:middle;height:18px;" onclick="this.src=\''+Dv_CodeFile+'?t=\'+Math.random()" />'; 
}

