﻿/*
 * 此js主要包含div切换的功能
 *
 */

// 对于不同的browser, 扩展其mouse event
var Browser = new Object();
Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument != 'undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox") != - 1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != - 1);
if (Browser.isFirefox)
{
    // entend Event Mod for FireFox
    ExtendEventObject();
}
function ExtendEventObject()
{
    Event.prototype.__defineGetter__("srcElement", function ()
    {
        var node = this.target;
        while (node.nodeType != 1)
        {
            node = node.parentNode;
        }
        return node;
    }
    );
    Event.prototype.__defineGetter__("fromElement", function ()
    {
        var node;
        if (this.type == "mouseover")
        {
            node = this.relatedTarget;
        }
        else if (this.type == "mouseout")
        {
            node = this.target;
        }
        if( ! node)
        {
            return;
        }
        while (node.nodeType != 1)
        {
            node = node.parentNode;
        }
        return node;
    }
    );
    Event.prototype.__defineGetter__("toElement", function ()
    {
        var node;
        if (this.type == "mouseout")
        {
            node = this.relatedTarget;
        }
        else if (this.type == "mouseover")
        {
            node = this.target;
        }
        if ( ! node)
        {
            return;
        }
        while (node.nodeType != 1)
        {
            node = node.parentNode;
        }
        return node;
    }
    );
}
function IsChild(cNode, pNode)
{
    while(cNode != null)
    {
        cNode = cNode.parentNode;
        if(cNode == pNode)
        {
            return true;
        }
    }
    return false;
}
var jzcache = new Object();
var waitInterval;
var tempref;
// 鼠标感应延迟150毫秒
var MouseDelayTime = 150;
function InitTabpages()
{
    for(var i = 0; i < arguments.length; i ++ )
    {
        var ulobj = document.getElementById(arguments[i]);
        ulist = ulobj.getElementsByTagName("li");
        for(var j = 0; j < ulist.length; j ++ )
        {
            var thelist = ulist[j];
            // 只有第一层li有效
            if(thelist.parentNode.parentNode != ulobj)
            {
                continue;
            }
            var ulistlink = thelist.getElementsByTagName("a")[0];
            var ulistlinkurl = ulistlink.getAttribute("urn");
            var ulistlinktarget = ulistlink.getAttribute("rel");
            thelist.setActive = function(bactive)
            {
                if(bactive)
                {
                    this.status = "active";
                    this.className = "cc62222282";
                }
                else
                {
                    this.status = "normal";
                    this.className = "jz62222282";
                }
            }
            thelist.LoadTab = function()
            {
                this.setActive(true);
                this.parentNode.parentNode.activetab.setActive(false);
                this.parentNode.parentNode.activetab = this;
                var ulistlink = this.getElementsByTagName("a")[0];
                LoadTabPage(ulistlink.getAttribute("urn"), ulistlink.getAttribute("rel"));
            }
            thelist.onmouseover = function(aEvent)
            {
                var myEvent = window.event ? window.event : aEvent;
                var fm = myEvent.fromElement;
                // 过滤子元素event
                if(IsChild(fm, this) || fm == this)
                {
                    return;
                }
                if(this.status == "active") return;
                tempref = this;
                clearTimeout(waitInterval);
                waitInterval = window.setTimeout("tempref.LoadTab();", MouseDelayTime);
            }
            thelist.onmouseout = function(aEvent)
            {
                var myEvent = window.event ? window.event : aEvent;
                var em = myEvent.toElement;
                // 过滤子元素event
                if(IsChild(em, this) || em == this)
                {
                    return;
                }
                if(this.status == "active")
                {
                    return;
                }
                clearTimeout(waitInterval);
            }
            if(ulistlinkurl.indexOf("#62222282_") != - 1)
            {
                thelist.setActive(true);
                ulobj.activetab = thelist;
                jzcache[ulistlinkurl] = getElement(ulistlinktarget).innerHTML;
            }
            else
            {
                thelist.setActive(false);
            }
        }
        if(ulobj.activetab == null)
        {
            ulobj.activetab = ulist[0];
        }
    }
}
function GetXmlHttp()
{
    var http_request;

    if(window.XMLHttpRequest)
    {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType)
        {
            http_request.overrideMimeType("text/xml");
        }
    }
    else if (window.ActiveXObject)
    {
        try
        {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
            }
        }
    }
    if ( ! http_request)
    {
        window.alert("can't create XMLHttpRequest object.");
        return null;
    }
    return http_request;
}
function LoadTabPage(url, contentid)
{
    var ocontent = getElement(contentid);
    if(jzcache[url] == null)
    {
        var xhttp = GetXmlHttp();
        xhttp.onreadystatechange = function()
        {
            if(xhttp.readyState == 4 && (xhttp.status == 200 || window.location.href.indexOf("http") == - 1))
            {
                ocontent.innerHTML = xhttp.responseText;
                jzcache[url] = ocontent.innerHTML;
            }
        }
        xhttp.open("GET", url, true);
        xhttp.send(null);
    }
    else
    {
        ocontent.innerHTML = jzcache[url];
    }
}

// 会员名录的动态切换
var comCount = 0;
var jzComCache = new Object();
function ClearCache()
{
    if(document.getElementById("memlist") == null)
    {
        return;
    }
    var url = document.getElementById("memlist").urn;
    setTimeout("ClearCache()",1000 * 15);
    var divObj = getElement('divhydttab0');
    if(divObj.innerHTML == jzcache[url])
    {
        jzcache[url] = null;
        divObj.style.visibility = "hidden";
        if(comCount < 10)
        {
            LoadTabPage(url, 'divhydttab0');
            jzComCache[comCount] = divObj.innerHTML;
        }
        else
        {
            jzcache[url] = jzComCache[comCount % 10];
            divObj.innerHTML = jzComCache[comCount % 10];
        }
        AnimationShow(divObj);
        comCount = comCount + 1;
    }
}

function AnimationShow(oDiv)
{
   oDiv.filters.revealTrans.apply();
   oDiv.style.visibility = "visible";
   oDiv.filters.revealTrans.play();
}
setTimeout("ClearCache()",1000 * 15);
//window.onerror = function()
//{
//    return true;
//}

// xml.js
function GetXHR()
{
    var xhr;
    try
    {
        xhr = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
        try
        {
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e)
        {
            xhr = false;
        }
    }
    if( ! xhr && typeof XMLHttpRequest != 'undefined')
    {
        xhr = new XMLHttpRequest();
    }

    return xhr;
}
function openXHR(method, url, callback)
{
    GetXHR();
    xhr.open(method, url);
    xhr.onreadystatechange = function()
    {
        if(xhr.readyState != 4)return;
        callback(xhr);
    }
    xhr.send(null);
}
function LoadXml(method, url, callback)
{
    GetXHR();
    xhr.open(method, url);
    xhr.setRequestHeader("Content-Type", "text/xml");
    xhr.setRequestHeader("Content-Type", "GBK");
    xhr.onreadystatechange = function()
    {
        if(xhr.readyState != 4)
        {
            return;
        }
        callback(xhr.responseXML);
    }
    xhr.send(null);
}
/* weather begin */
function getElement(aID)
{
    return (document.getElementById) ? document.getElementById(aID) : document.all[aID];
}
// local
function getWeather(xmlDom)
{
    var contemt = "";
    var doc = document.getElementById("div_weather");
    var node = xmlDom.getElementsByTagName("weather");
    if(node.length)
    {
        var len = node.length;
        for(var i = 0; i < len; i ++ )
        {
            var c = node[i].getAttribute("c");
            var city = node[i].getAttribute("city");
            var wd = node[i].getAttribute("wd");
            var qx = node[i].getAttribute("qx");
            var img = node[i].getAttribute("qximg");
            if(img != '' && img.length > 0)
            {
                var imgs = img.split(",");

                contemt += '<div class="s"><a href="#">' + c + ':' + wd + ' ' + qx + '</a></div>';
                for( var j = 0; j < imgs.length; j ++ )
                {
                    // contemt += '<img src=http://www.cc2282.com/cnews/img/weatherlogo/' + imgs[j] + '>';
                }
            }
        }
        doc.innerHTML = contemt;
    }
}
function weather(coder)
{
    LoadXml("GET", "/weatherxml/" + coder + ".xml", getWeather);
}
var city = new Array("安徽", "黑龙江", "山东", "北京", "湖北", "山西", "福建", "湖南", "陕西", "甘肃", "吉林", "上海", "广东", "江苏", "四川", "广西", "江西", "天津", "贵州", "辽宁", "西藏", "海南", "内蒙古", "新疆", "河北", "宁夏", "云南", "河南", "青海", "浙江", "重庆");
var weaths = new Array('58321', '50953', '54823', '54511', '57494', '53772', '58847', '57679', '57036', '52889', '54161', '58367', '59287', '58238', '56294', '59431', '58606', '54527', '57816', '54342', '55591', '59758', '53463', '51463', '53698', '53614', '56778', '57083', '52866', '58457', '57516');
function getCookieVal (offset)
{
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == - 1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name)
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
        return getCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0)
        break;
    }
    return "";
}
function SetCookie(cookieName, cookieValue, nDays)
{
    var today = new Date();
    var expire = new Date();
    if (nDays == null || nDays == 0) nDays = 1;
    expire.setTime(today.getTime() + 3600000 * 24 * nDays);
    document.cookie = cookieName + "=" + escape(cookieValue) + ";path=/;domain=.cc2282.com;expires="+expire.toGMTString();
}
// 首行登录
function loginSubmit(login)
{
    var userName = login.elements['username'];
    var password = login.elements['password'];
    var ursname = login.elements['ursname'];
    var loginSelect = login.elements['loginSelect'].value;
    var selectNum = login.elements["loginSelect"].selectedIndex;
    SetCookie("selectValue", selectNum, 365);
    if (userName.value == "")
    {
        alert("请输入用户名");
        return false;
    }
    if (password.value == "")
    {
        alert("请输入密码");
        password.focus();
        return false;
    }
    login.submit();
}
function enterSubmit(event)
{
    var obj = event.srcElement ? event.srcElement : event.target;
    var login = obj.form;
    if(event.keyCode == 13) 
    {
        loginSubmit(login);
    }
}
function getCityWeatherID(cityname)
{
    for(i = 0; i < city.length; i ++ )
    {
        if(city[i] == cityname)
        {
            return weaths[i];
        }
    }
    return "54511";
}
var loc = GetCookie("theaddr");
if( ! loc)
{
    document.write("<script type='text/javascript' src='http://61.135.253.46/ipquery'><" + "/script>");
}
var wloc = GetCookie("NTES_WeatherAddr");
if( ! wloc)
{
    wloc = getCityWeatherID(loc);
}
