﻿var xmlHttp = false;
try {
	xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
	try {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (ex) {
		xmlHttp = false;
	}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
	xmlHttp = new XMLHttpRequest();
}
var d = document,w=window;
function switchmodTag(modtag,modcontent,modk){
    var id = rootID.split(',');
    for(i=0; i <id.length; i++) {
        if(id[i] != "")
        {
            if (id[i]==modk) {
                d.getElementById(modtag+id[i]).className="menuOn";
                if(modcontent != ""){
                   d.getElementById(modcontent+id[i]).className="slidingList";
                }
            }else if (id[i]==classID) {
                d.getElementById(modtag+id[i]).className="menuOn";
                if(modcontent != ""){
                   d.getElementById(modcontent+id[i]).className="slidingList";
                }
            }
			else {
                d.getElementById(modtag+id[i]).className="menuNo";
                if(modcontent != ""){
                   d.getElementById(modcontent+id[i]).className="slidingList_none";
                }
            }            
        }
    }
}
function ShowMenuOn()
{
    switchmodTag('root',"",classID);
}
function Search()
{
	var searchName = d.getElementById("searchName");
	if(searchName.value == "")
	{
		alert("请输入关键字");
		searchName.focus();
	}
	else
	{
    	w.location.href = "http://data.99pan.com/search?wd="+encodeURI(searchName.value);
	}
}
function onEnter()
{
    if(event.keyCode == 13)
    {
        Search();
    }
}
function onEnterSubmitForm(evt)
{
    if(evt.keyCode == 13)
    {
        return navSubmitForm();
    }
}
function navSubmitForm()
{
    var userName = d.getElementById("userName");
    var passWord = d.getElementById("passWord");        
    if(userName.value == "")
	{
        alert("请输入99盘帐号!");
		userName.focus();
        return false;
    }
    else if(passWord.value == "")
	{
		alert("请输入密码!");	
		passWord.focus();
		return false;
	}
    else
	{          
	    popupLoadLayer();
        openMask(); 
        return true;
    }
}
function getCookie(name)
{
	var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	if(arr=d.cookie.match(reg)) return decodeURI(arr[2]);
	else return null;
}
function setCookie(eN,eV)
{
	var Days = 365;
	var exp = new Date(); 
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	d.cookie = eN+"=" + escape(eV)+ "; expires ="+ exp.toGMTString() + "; path=/;";//domain=99pan.com";
}
var requestSetTime,setTimeCount;
w.onload = function()
{
	if(getCookie("loginName")!=null && getCookie("loginPass")!=null && classID == 1)
	{
		UpdateTop(getCookie("loginName"));
	}	
	
	if(getCookie("loginName")==null && getCookie("loginPass")==null && getCookie("Logout")==null)
	{
	    QeuryLogin();
		setTimeCount = 1;
	    requestSetTime = setTimeout("QeuryUser()",1000);
	}
}
function UpdateTop(u)
{
	if(d.getElementById("head_left") != null)
	{
		var content = "<div class=\"head_left\"><a href=\"http://www.99pan.com/Main\">"+u+"的网络硬盘</a> | <a href=\"http://www.99pan.com/forgetPassword.html\" target=\"_blank\">忘记密码</a> | <a href=\"http://www.99pan.com/help/help.html\" target=\"_blank\">帮助中心</a> | <a href=\"http://bbs.99pan.com\" target=\"_blank\">论坛</a> | <a href=\"javascript:\" onclick=\"if(confirm('您确定要安全退出吗？')==true)w.location.href='http://www.99pan.com/GlobalManager/Manager_99pan.aspx?action=exit';return false;\">退出</a></div>";
		d.getElementById("head_left").innerHTML = content;
	}
}

function QeuryUser()
{
    if(setTimeCount < 15){
		var url = "http://www.99pan.com/GlobalManager/Manager_99pan.aspx?action=user&val="+Math.random();
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange = function(){
			if(xmlHttp.readyState == 4){
				if(xmlHttp.status == 200){
					if(xmlHttp.responseText == 1)
					{
						requestSetTime = setTimeout("QeuryUser()",500);
					}
					else
					{
						closeSetTimeout(requestSetTime);
						UpdateTop(xmlHttp.responseText);
					}
				}	
			}
		}
		setTimeCount++;
		xmlHttp.send(null);
	}
	else
	{
		closeSetTimeout(requestSetTime);
	}
}

function closeSetTimeout(r)
{
	clearTimeout(r);
}

function QeuryLogin()
{     
    var obj = d.createElement("div");
    obj.id="loadobj";
    obj.innerHTML = "<iframe src=\"http://127.0.0.1:8800/login/http://www.99pan.com/LoginManager/loginManager.aspx?val="+Math.random()+"\" style=\"display:none;\"></iframe>";
    d.body.appendChild(obj);
}