﻿function CreateAjax()
 {
    var XMLHttp;
    try
    {
        XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");   
    }
    catch(e)
    {
        try
        {
            XMLHttp = new XMLHttpRequest();     
        }
        catch(e)
        {
            XMLHttp = false;        
        }
    }
    return XMLHttp;     
 }
 
function Dig(id)
{
	_xmlhttp = CreateAjax();
	var url = 'dig.php?id='+id+'';		
	if(_xmlhttp)    
    {
        var content = document.getElementById("dig"+id);      
		var dig = document.getElementById(id);					
        _xmlhttp.open('GET',url,true);
        _xmlhttp.onreadystatechange=function()
        {
            if(_xmlhttp.readyState == 4)        
            {
                if(_xmlhttp.status == 200)      
                {
                    var ResponseText = _xmlhttp.responseText;	
					var r=ResponseText.split(",");								
                    if(r[0] == "Dig" )   
                    {
						dig.innerHTML="<a style='color:#999999'>("+r[1]+")</a>";
                        alert("您已经投过票了 不能再投了！");
                        
                    }
					
					else if (r[0]=="login_no")
					{
					 dig.innerHTML="<a style='color:#999999'>("+r[1]+")</a>";
					 alert("请登录后再投票！");
					}
					
                    else if(ResponseText == "NoData")
					{
						alert("参数错误！");	
					}
					
					else
                    {
						
						dig.innerHTML="<a style='color:red'>("+ResponseText+")</a>";
						alert("投票成功");
                    }
                }
                else    
                {
                    alert("服务器返回错误！");
                    top.location.href='index.php';
                }
            }
            else    
            {
                dig.innerHTML='<img src="css/Loading.gif">';
            }
        }
        _xmlhttp.send(null);  
    }
    else    
    {
        alert("您的浏览器不支持或未启用 XMLHttp!");
    }
}

function Dig_2(id)
{
	_xmlhttp = CreateAjax();
	var url = 'dig.php?id='+id+'';		
	if(_xmlhttp)    
    {
        var content = document.getElementById("dig_2"+id);      
	var dig = document.getElementById("dig_2_s"+id);					
        _xmlhttp.open('GET',url,true);
        _xmlhttp.onreadystatechange=function()
        {
            if(_xmlhttp.readyState == 4)        
            {
                if(_xmlhttp.status == 200)      
                {
                    var ResponseText = _xmlhttp.responseText;			
					var r=ResponseText.split(",");								
                    if(r[0] == "Dig" )   
                    {
						dig.innerHTML="<a style='color:#999999'>("+r[1]+")</a>";
                        alert("您已经投过票了 不能再投了！");

                    }
					
					else if (r[0]=="login_no")
					{
					 dig.innerHTML="<a style='color:#999999'>("+r[1]+")</a>";
					 alert("请登录后再投票！");
					}
					
                    else if(ResponseText == "NoData")
					{
						alert("参数错误！");	
					}
					else
                    {
						
						dig.innerHTML="<a style='color:red'>("+ResponseText+")</a>";
						alert("投票成功");
                    }
                }
                else    
                {
                    alert("服务器返回错误！");
                    top.location.href='index.php';
                }
            }
            else    
            {
                dig.innerHTML='<img src="css/Loading.gif">';
            }
        }
        _xmlhttp.send(null);  
    }
    else    
    {
        alert("您的浏览器不支持或未启用 XMLHttp!");
    }
}

function Dig_3(id)
{
	_xmlhttp = CreateAjax();
	var url = 'dig.php?id='+id+'';		
	if(_xmlhttp)    
    {
        var content = document.getElementById("dig_3"+id);      
		var dig = document.getElementById("dig_3_s"+id);					
        _xmlhttp.open('GET',url,true);
        _xmlhttp.onreadystatechange=function()
        {
            if(_xmlhttp.readyState == 4)        
            {
                if(_xmlhttp.status == 200)      
                {
                    var ResponseText = _xmlhttp.responseText;			
					var r=ResponseText.split(",");								
                    if(r[0] == "Dig" )   
                    {
						dig.innerHTML="<a style='color:#999999'>("+r[1]+")</a>";
                        alert("您已经投过票了 不能再投了！");   
                    }
					
					else if (r[0]=="login_no")
					{
					 dig.innerHTML="<a style='color:#999999'>("+r[1]+")</a>";
					 alert("请登录后再投票！");
					}
					
                    else if(ResponseText == "NoData")
					{
						alert("参数错误！");	
					}
					else
                    {
						
						dig.innerHTML="<a style='color:red'>("+ResponseText+")</a>";
						alert("投票成功");
                    }
                }
                else    
                {
                    alert("服务器返回错误！");
                    top.location.href='index.php';
                }
            }
            else    
            {
                dig.innerHTML='<img src="css/Loading.gif">';
            }
        }
        _xmlhttp.send(null);  
    }
    else    
    {
        alert("您的浏览器不支持或未启用 XMLHttp!");
    }
}