﻿var xmlHttp = false;

function CreatexmlHttp() {
    try {
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e2) {
            xmlHttp = false;
        }
    }
    if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
        xmlHttp = new XMLHttpRequest();
    }
    return xmlHttp;
}
function startload() {
    CreatexmlHttp();
    if (!xmlHttp) {
        alert("xmlHttp对象建立失败！");
        return;
    }

    xmlHttp.open("POST","_login.ashx", true);
    xmlHttp.onreadystatechange = loginInfo;
    xmlHttp.send("");
}
function Login() {
    var userName=document.getElementById("u").value;
    var passWord=document.getElementById("p").value;
    var check = 0;
    if (document.getElementById("r").checked)
        check = 1;
    if (userName.length == 0 || passWord.length == 0) {
        alert("请填写好邮箱和密码...");
        return;
    }
    var data = "u=" + userName + "&p=" + passWord + "&r=" + check;
    CreatexmlHttp();
    if (!xmlHttp) {
        alert("xmlHttp对象建立失败！");
        return;
    }
    var url = "_login.ashx?"+data;

    xmlHttp.open("POST", url, true);
    xmlHttp.onreadystatechange = loginInfo;
    xmlHttp.send("");
}
function loginInfo()
{
    if(xmlHttp.readyState==4)
        if(xmlHttp.status==200)
	    {
	        var result=xmlHttp.responseText;
	        if (result == "-1")
	             window.location = "login.aspx";
	        else if(result=="1")
	            return;
	        else
	           document.getElementById("userInfo").innerHTML = result;
	    }   
	    else if(xmlHttp.status==404)
	        alert("Request URL does not exist!");
	    else
	        alert("Error:status code is:"+xmlHttp.status);
}

function ControlTable(tdHid,tdShow,aHid,aShow,tbHid,tbShow)
{
   var objTdHid = document.getElementById(tdHid);
   var objTdShow = document.getElementById(tdShow);
   
   var objAHid = document.getElementById(aHid);
   var objAShow = document.getElementById(aShow);
   
   var objTbHid = document.getElementById(tbHid);
   var objTbShow = document.getElementById(tbShow);
   
   objTdShow.style.background='url(Images/Index/button1.gif)';
   objTbShow.style.display='';
   objAShow.className='health';
   
   objTdHid.style.background='url(Images/Index/button2.gif)';
   objTbHid.style.display='none';
   objAHid.className='diary';
}
/*-----------------首页投票--------------------*/
function GetRadioValue(RadioName){
    var obj;    
    obj=document.getElementsByName(RadioName);
    if(obj!==null)
    {
        var i;
        for(i=0;i<obj.length;i++)
            {if(obj[i].checked)
                return obj[i].value;}
    }
    return null;
}
function jump(voteid){
    window.open("vote/show2.aspx?sc="+GetRadioValue("Sc")+"&voteid="+voteid);
}

function getck(sname,id,url)
{//获取单个cookies
    var acookie=document.cookie.split("; ");
    for(var i=0;i<acookie.length;i++)
    {
        var arr=acookie[i].split("=");
        if(sname==arr[0])//有cookie
        {
            if(arr.length>1)
                if(chk(arr[1],id))//有id，跳转
                    {
                        window.open(url);
                        return;
                    }
                else//没有id
                    alert("您还未投票！");
            else//没有cookie
                alert("您还未投票！");
            return;
        }   
    }
    alert("您还未投票！");
}
function chk(cookie,id)//有id返回true
{
    var str=cookie.toString();
    var i=str.indexOf(id);
    return i!=-1;// this.indexOf(str);
}


