﻿var xmlReq = false;

function createXMLHttpRequest() 
{
     if(window.XMLHttpRequest)
    {
        xmlReq = new XMLHttpRequest();
        if(xmlReq.overrideMimeType)  xmlReq.overrideMimeType('text/xml');
    }
    else if(window.ActiveXObject)
    { 
       try
       {
            xmlReq = new ActiveXObject('Msxml2.XMLHTTP');
       }
       catch(e)
       {
          try
          {
              xmlReq = new ActiveXObject('Microsoft.XMLHTTP');
          }
          catch(e){}
        }
    }
}


function children_vote_help_add(review_id,vote_type,product_id,itemindex)
{
    createXMLHttpRequest();
//  var send_data=new Hashtable();
//	send_data.add("review_id",review_id);
//	send_data.add("vote_type",vote_type);
//	send_data.add("product_id",product_id);
    
	var vnum = Math.random();
	var url = 'ajax_vote_help.aspx?review_id='+review_id+'&vote_type='+vote_type+'&product_id='+product_id+'&num='+vnum;
	xmlReq.open("GET",url,false);
	xmlReq.send(null);
	
	var retval =  xmlReq.responseText;
	var votemsg = document.getElementById(itemindex.toString()+"vote");
	
	votemsg.style.display = "none";
	if(retval == '0')
	{
	    if(vote_type==1)//有用票
	    {
	        var help_num = document.getElementById(itemindex.toString()+"help").innerHTML;
            if (help_num=="")
                help_num="0";
            document.getElementById(itemindex.toString()+"help").innerHTML = parseInt(help_num)+1;
            votemsg.innerHTML="感谢您的投票";
	    }
	    else
	    {
	        votemsg.innerHTML="感谢您的投票";
	    }
	    votemsg.style.display = "block";
	}
	else
	{
	    switch(retval)
	    {
	        case "5":
            votemsg.innerHTML="请先完成<a href='http://customer.dangdang.com/auth/VerifyEmail.aspx' target='_blank'>邮箱验证</a>";
             votemsg.style.display = "block";
            break;
        
            case "4":
            votemsg.innerHTML="请先完成<a href='http://customer.dangdang.com/auth/Register1.aspx' target='_blank'>邮箱验证</a>";
            votemsg.style.display = "block";
            break;
            //未验证邮箱的帐户，点击“有用”“没用”，提示：请先完成邮箱验证。“邮箱验证”加链接，链接到相应的“被动验证”和“主动验证”页。 
            //5为被动验证  4为主动验证
            case "3":
             votemsg.innerHTML="请先<a href='http://login.dangdang.com/signin.aspx?returnURL="+ escape(window.location.href) + "'>登录</a>";  
             votemsg.style.display = "block";   
             //window.location.href="http://login.dangdang.com/signin.aspx?returnURL="+escape(window.location.href);
                break;
            case "2":
            alert("提交失败");
                break;
            case "1":
                votemsg.innerHTML="您已经投过票了";
                votemsg.style.display = "block";
                break;
            default:
                break;
	    }
	}
}



function ShowCustoemrByMoveIndex(move_index)
{
    var move_div = document.getElementById("move_index");
    if(move_div == null)
        return;
    
    var current = document.getElementById("txtPageIndex");
    var sizetxt = document.getElementById("txtPageCount");
    var current_index = parseInt(current.value);
    var size = parseInt(sizetxt.value);
    var go_index = current_index + move_index;
    
    if(go_index <= 0 || go_index > size)
        return ;
     
    var ctl_index = document.getElementById("page_index_"+go_index);
    var ctl_current = document.getElementById("page_index_"+current_index);
    var p_index = document.getElementById("page_"+go_index);  
    var p_current = document.getElementById("page_"+current_index);

    ctl_index.innerHTML = "<span class='num_now' >&gt;"+go_index+"</span>";
    ctl_current.innerHTML = "<a href='javascript:ShowCustomerByPageIndex("+current_index+")' class='num' >"+current_index+"</a>";
    
    p_index.style.display = "block";
    p_current.style.display = "none";
    current.value = go_index; 
    
    move_div.innerHTML= go_index;   
    
}


function ShowCustomerByPageIndex(page_index)
{
    var current = document.getElementById("txtPageIndex");
    var sizetxt = document.getElementById("txtPageCount");
    var current_index = parseInt(current.value);
    var size = parseInt(sizetxt.value);
    
    if(page_index != current_index)
    {
    //index,鼠标点中的页数，current，鼠标选中前显示的页数
        var ctl_index = document.getElementById("page_index_"+page_index);
        
        var ctl_current = document.getElementById("page_index_"+current_index);
        
        var p_index = document.getElementById("page_"+page_index);
        
        var p_current = document.getElementById("page_"+current_index);
        
        
        ctl_index.innerHTML = "<span class='num_now' >&gt;"+page_index+"</span>";
        ctl_current.innerHTML = "<a href='javascript:ShowCustomerByPageIndex("+current_index+")' class='num' >"+current_index+"</a>";
        
        p_index.style.display = "block";
        p_current.style.display = "none";
        current.value = page_index;
        
        if(document.getElementById("move_index") != null)
        {
            document.getElementById("move_index").innerHTML = page_index;
        }                 
    }
}



