﻿//******************金币历史记录开始***************//
var HistoryAjax;
function GoldHistory()
{
var game=document.getElementById("drpGame").options[document.getElementById("goldGame").selectedIndex].value;
var date=document.getElementById("goldDate").options[document.getElementById("goldDate").selectedIndex].value;
var idx=getCookie("idx");
document.getElementById("goldhistory").style.display='';
HistoryAjax=new Ajax.Request(
'ashx/gold.ashx',//需要请求的url
{
 method:'get',//get 方式提交
 parameters:'game='+game+'&date='+date+'&idx='+idx,//要传递的参数
 onSuccess:GoldHistoryBind,
 onError:function(HistoryAjax){alert("error,HttpStatus:"+HistoryAjax.status);}//调用发生错误执行
} 
);
}

function GoldHistoryBind(HistoryAjax)
{
 
            if(HistoryAjax.readyState==4)
            {
                        if(HistoryAjax.status==200)
                        {
                        document.getElementById("goldhistory").style.display="none";
                        var xmldoc=HistoryAjax.responseXML;
                        var orderlist=xmldoc.getElementsByTagName("Table");
                        var historyorder=document.getElementById("historyorder");
                        var y=historyorder.rows.length;
                    for(var i=0;i<y;i++)
                    {
                     historyorder.removeChild(historyorder.rows.item(0));
                    }
                        for(var i=0;i<orderlist.length;i++)
                        {
                        var serno=orderlist[i].getElementsByTagName("SerialNo")[0].childNodes[0].nodeValue;
                        var game=orderlist[i].getElementsByTagName("Game")[0].childNodes[0].nodeValue;
                        var server=orderlist[i].getElementsByTagName("Server")[0].childNodes[0].nodeValue;
                        var volume=orderlist[i].getElementsByTagName("Volume")[0].childNodes[0].nodeValue;
                        var execdate=orderlist[i].getElementsByTagName("ExecDate")[0].childNodes[0].nodeValue;
                        var exectime=orderlist[i].getElementsByTagName("ExecTime")[0].childNodes[0].nodeValue;
                           
                           var row=document.createElement("tr");
                           var cell=document.createElement("td");
                               
                                cell.innerHTML=serno;
                               row.appendChild(cell);
                               
                               var cell2=document.createElement("td");
                               cell2.innerHTML= game;
                               row.appendChild(cell2);
                                
                                var cell3=document.createElement("td");
                                 cell3.innerHTML= server;
                               row.appendChild(cell3);
                               
                               var cell4=document.createElement("td");
                                    cell4.innerHTML= volume+" G";
                               row.appendChild(cell4);
                               
                               var cell5=document.createElement("td");
                                    cell5.innerHTML= execdate;
                               row.appendChild(cell5);
                               
                               if(i%2==1)
                               {
                               row.style.backgroundColor="#fbfdf0";
                               }
                               
                          
                             row.style.cursor="pointer";
                              document.getElementById("historyorder").appendChild(row);
                        }
                         if( orderlist.length==0)
                        {
                          var row=document.createElement("tr");
                           var cell=document.createElement("td");
                               
                                cell.innerHTML="No Result";
                                cell.style.color="red";
                                cell.setAttribute("colSpan",5);
                                row.appendChild(cell);
                                document.getElementById("historyorder").appendChild(row);
                        }
                        
                        }
            }
}

//******************金币历史记录结束***************//


//******************代练历史记录开始***************//
function PowerHistory()
{
var idx=getCookie("idx");
var game=document.getElementById("powerGame").options[document.getElementById("powerGame").selectedIndex].value;
var date=document.getElementById("powerDate").options[document.getElementById("powerDate").selectedIndex].value;
document.getElementById("goldhistory").style.display='';
HistoryAjax=new Ajax.Request(
'ashx/power.ashx',//需要请求的url
{
 method:'get',//get 方式提交
 parameters:'game='+game+'&date='+date+'&idx='+idx,//要传递的参数
 onSuccess:PowerHistoryBind,
 onError:function(HistoryAjax){alert("error,HttpStatus:"+HistoryAjax.status);}//调用发生错误执行
} 
);
}
function PowerHistoryBind(HistoryAjax)
{
            if(HistoryAjax.readyState==4)
            {
                        if(HistoryAjax.status==200)
                        {
                       document.getElementById("goldhistory").style.display="none";
                        var xmldoc=HistoryAjax.responseXML;
                        var orderlist=xmldoc.getElementsByTagName("Table");
                        var historyorder=document.getElementById("historyorder");
                        var y=historyorder.rows.length;
                    for(var i=0;i<y;i++)
                    {
                     historyorder.removeChild(historyorder.rows.item(0));
                    }
                        for(var i=0;i<orderlist.length;i++)
                        {
                        var serno=orderlist[i].getElementsByTagName("SerialNo")[0].childNodes[0].nodeValue;
                        var game=orderlist[i].getElementsByTagName("Game")[0].childNodes[0].nodeValue;
                        var server=orderlist[i].getElementsByTagName("Server")[0].childNodes[0].nodeValue;
                        var aclass=orderlist[i].getElementsByTagName("Class")[0].childNodes[0].nodeValue;
                          var actorname=orderlist[i].getElementsByTagName("ActorName")[0].childNodes[0].nodeValue;
                        var execdate=orderlist[i].getElementsByTagName("ExecDate")[0].childNodes[0].nodeValue;
                       
                           
                           var row=document.createElement("tr");
                           var cell=document.createElement("td");
                               
                               cell.innerHTML=serno;
                               row.appendChild(cell);
                               
                               var cell2=document.createElement("td");
                               cell2.innerHTML= game;
                               row.appendChild(cell2);
                                
                                var cell3=document.createElement("td");
                                cell3.innerHTML= server;
                                row.appendChild(cell3);
                               
                               var cell4=document.createElement("td");
                                    cell4.innerHTML= aclass;
                               row.appendChild(cell4);
                               
                                var cell5=document.createElement("td");
                                    cell5.innerHTML= actorname;
                               row.appendChild(cell5);
                               
                               var cell6=document.createElement("td");
                                    cell6.innerHTML= execdate;
                               row.appendChild(cell6);
                               
                               if(i%2==1)
                               {
                               row.style.backgroundColor="#fbfdf0";
                               }
                               
                            //row.setAttribute("onmouseover","NewColor(this)");
                           //  row.setAttribute("onmouseout","OldColor(this)");
                           //  row.setAttribute("onclick","TbClick(this)");
                             row.style.cursor="pointer";
                              document.getElementById("historyorder").appendChild(row);
                        }
                         if( orderlist.length==0)
                        {
                          var row=document.createElement("tr");
                           var cell=document.createElement("td");
                               
                                cell.innerHTML="No Result";
                                cell.style.color="red";
                                cell.setAttribute("colSpan",6);
                                row.appendChild(cell);
                                document.getElementById("historyorder").appendChild(row);
                        }
                        }
            }
}
//******************代练历史记录结束***************//

//*************************读取用户信息开始***********************//
var UserAjax;
function LoadInfo()
{
var idx=getCookie("idx");
UserAjax =new Ajax.Request(
'ashx/reglog.ashx',//需要请求的url
{
 method:'get',//get 方式提交
 parameters:'userid='+idx,//要传递的参数
 onSuccess:InfoBind,
 onError:function(UserAjax){alert("error,HttpStatus:"+UserAjax.status);}//调用发生错误执行
} 
);
}
function InfoBind(UserAjax)
{
                if(UserAjax.readyState==4)
                {
                                if(UserAjax.status==200)
                                {
                                        var xmldoc=UserAjax.responseXML;
                                        var userinfo=xmldoc.getElementsByTagName("Table");
                                        var email=userinfo[0].getElementsByTagName("Email")[0].childNodes[0].nodeValue;
                                        var customerid=userinfo[0].getElementsByTagName("CustomerID")[0].childNodes[0].nodeValue;
                                       var customername=userinfo[0].getElementsByTagName("CustomerName")[0].childNodes[0].nodeValue;
                                        var address=userinfo[0].getElementsByTagName("Address")[0].childNodes[0].nodeValue;
                                        var postno=userinfo[0].getElementsByTagName("PostNo")[0].childNodes[0].nodeValue;
                                        var city=userinfo[0].getElementsByTagName("City")[0].childNodes[0].nodeValue;                    
                                        var province=userinfo[0].getElementsByTagName("Province")[0].childNodes[0].nodeValue;
                                        var telephone=userinfo[0].getElementsByTagName("Telephone")[0].childNodes[0].nodeValue;
                                        var gender= userinfo[0].getElementsByTagName("Gender")[0].childNodes[0].nodeValue;
                                        var country=userinfo[0].getElementsByTagName("Nation")[0].childNodes[0].nodeValue;
                                        var icq=userinfo[0].getElementsByTagName("QQ")[0].childNodes[0].nodeValue;
                                        var dob=userinfo[0].getElementsByTagName("BornDate")[0].childNodes[0].nodeValue;
                                        var pwd=userinfo[0].getElementsByTagName("LoginPassword")[0].childNodes[0].nodeValue;
                       // var ppemail=userinfo[0].getElementsByTagName("BornDate")[0].childNodes[0].nodeValue;
                                       document.getElementById("oldpass").title=pwd;
                                        document.getElementById("email").innerHTML=email.substr(0,50);
                                        document.getElementById("customer").innerHTML=customerid;
                                        if(customername!="0")
                                        {
                                        document.getElementById("customerN").value=customername;
                                        }
                                        if(address!="0")
                                        {
                                        document.getElementById("address").value=address;
                                        }
                                        if(postno!="0")
                                        {
                                        document.getElementById("postCode").value=postno;
                                        }
                                        if(city!="0")
                                        {
                                        document.getElementById("city").value=city;
                                        }
                                        if(province!="0")
                                        {
                                        document.getElementById("state").value=province;
                                        }
                                        if(telephone!="0")
                                        {
                                        document.getElementById("telN").value=telephone;
                                        }
                                        if(gender=="M")
                                        {
                                        document.getElementById("male").checked=true;
                                        }
                                        else if(gender=="F")
                                        {
                                        document.getElementById("female").checked=true;
                                        }
                                        if(country!="0")
                                        {
                                        document.getElementById("country").value=country;
                                        }
                                        if(icq!="0")
                                        {
                                        document.getElementById("icq").value=icq;
                                        }
                                        if(dob!="0")
                                        {
                                            
                                            var year=dob.substr(0,4);
                                            var month="01";
                                            var day="01";
                                            if(dob.length==6)
                                            {
                                            month="0"+dob.substr(4,1);
                                            day="0"+dob.substr(5,1);
                                            }
                                            if(dob.length==7)
                                            {
                                            month="0"+dob.substr(4,1);
                                            day=dob.substr(5,2);
                                            }
                                            if(dob.length==8)
                                            {
                                            month=dob.substr(4,2);
                                            day=dob.substr(6,2);
                                            }
                                            
                                            
                                            document.getElementById("dob").value=year+"-"+month+"-"+day;
                                           document.getElementById("dob").lang=year+"-"+month+"-"+day;
                                            }
                                }
                }


}

function dobcheck()
{
var str=document.getElementById("dob").lang;
if(str!="")
{
document.getElementById("dob").value=str;
}
}

//更新用户信息
var UpdateAjax;
function UpdateUserInfo()
{
var idx=getCookie("idx");

UpdateAjax=getCookie("idx");
var rpass=document.getElementById("oldpass").title;
var oldpass=document.getElementById("oldpass").value;
var newpass1=document.getElementById("newpass1").value;
var newpass2=document.getElementById("newpass2").value;
var customername=document.getElementById("customerN").value;
var borndate=document.getElementById("dob").value;
 var gender="0";
    if(document.getElementById("male").checked==true)
    {
    gender=document.getElementById("male").value;
    }
    else
    {
    gender=document.getElementById("female").value;
    }
var icq=document.getElementById("icq").value;
var telephone=document.getElementById("telN").value;
var nation=document.getElementById("country").value;
var province=document.getElementById("state").value;
var city=document.getElementById("city").value;
var postno=document.getElementById("postCode").value;
var address=document.getElementById("address").value;
var paypalemail=document.getElementById("ppemail").value;
var emailformat = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
if(newpass1.length<6 &&newpass1.length>=1&&oldpass.length>=6)
{
 document.getElementById("pwdformat").style.display="";
}
else if(newpass1!=newpass2)
{
document.getElementById("pwdformat").style.display="none";
document.getElementById("pwdconfirm").style.display="";
}
else if(borndate.length>0&&!borndate.match(new RegExp("^((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})$")))
{
document.getElementById("pwdconfirm").style.display="none";
alert("Sorry, birth date format error!");
}
else if(paypalemail.length>0&&!emailformat.test(paypalemail))
{
alert("Sorry,you email fromat error!");
}
else
{
document.getElementById("updateload").style.display="";
 var xmlStr = "<userinfo>";
 xmlStr+="<idx>"+idx+"</idx>";
 xmlStr+="<rpass>"+rpass+"</rpass>";
 xmlStr+="<oldpass>"+oldpass+"</oldpass>";
 xmlStr+="<newpass>"+newpass1+"</newpass>";
 xmlStr+="<customername>"+customername+"</customername>";
 xmlStr+="<borndate>"+borndate+"</borndate>";
 xmlStr+="<gender>"+gender+"</gender>";
 xmlStr+="<icq>"+icq+"</icq>";
 xmlStr+="<telephone>"+telephone+"</telephone>";
 xmlStr+="<nation>"+nation+"</nation>";
 xmlStr+="<province>"+province+"</province>";
 xmlStr+="<city>"+city+"</city>";
 xmlStr+="<postno>"+postno+"</postno>";
 xmlStr+="<address>"+address+"</address>";
 xmlStr+="<paypalemail>"+paypalemail+"</paypalemail>";
 xmlStr+="</userinfo>";
UserAjax =new Ajax.Request('ashx/updateuserinfo.ashx',{method:'POST',
        postBody:xmlStr,
       onSuccess: UpdateEff,
       onError:function(UserAjax){alert("error,HttpStatus:"+UserAjax.status);}
       });
       }
}
function UpdateEff(UserAjax)
{
                if(UserAjax.readyState==4)
                            {
                                if(UserAjax.status==200)
                                {
                                document.getElementById("updateload").style.display="none";
                                 var status=UserAjax.responseText;
                                if(status=="1")
                                {
                                document.getElementById("oldpass").value="";
                                document.getElementById("newpass1").value="";
                                document.getElementById("newpass2").value="";
                                 alert("update your infomation success!");
                                }
                                else
                                {
                                document.getElementById("oldpass").value="";
                                document.getElementById("newpass1").value="";
                                document.getElementById("newpass2").value="";
                                alert("Sorry, you password wrong!");
                                }
                                }
                            }
}

//read COOKIE
function getCookie(cookiename)
{
    var result;
    var mycookie = document.cookie;
    var start2 = mycookie.indexOf(cookiename + "=");
    if(start2>-1)
    {
        start=mycookie.indexOf("=",start2)+1;
        var end = mycookie.indexOf(";",start);
        
        if (end == -1)
        {
            end = mycookie.length;
        }
        
        result = unescape(mycookie.substring(start,end));
    }
    
    return result;
}

//*************************读取用户信息结束***********************//