﻿var PageUrl = "http://www.ds2win.com/";
function ChangeImg(a)
{
   document.getElementById(a).src = document.getElementById(a).src + "?";
   return false;
}

function GetCity(state,i)
{
    var drp2=i;
    drp2.options.length=0;
    var newOption = document.createElement("OPTION");
    newOption.text = "所在城市";
    newOption.value = "";
    drp2.options.add(newOption);
    if (state!= "")
    {
        if (state == "国外")
        {
            newOption = document.createElement("OPTION");
            newOption.text = "国外";
            newOption.value = "国外";
            drp2.options.add(newOption); 
            return;         
        }
        var oHttpReq = GetXMLHTTP();
        oHttpReq.open("POST", PageUrl + "HtmlAjax.aspx?i=" + escape(state) + "&type=6", false);
        oHttpReq.send("");
        var result = oHttpReq.responseText;        
        result = result.replace("<NewDataSet>","");
        result = result.replace("</NewDataSet>","");
        while (result.indexOf("<E_City>") > -1)
        {
            result = result.replace("<E_City>","");
            result = result.replace("</E_City>","");        
        }
        while (result.indexOf("<City>") > -1)
        {
            result = result.replace("<City>","|");
            result = result.replace("</City>","");
        }
        var city = result.split("|");
        for (var i=0;i<city.length;i++)
        {
            if (city[i].trim() != "")
            {
                var newOption = document.createElement("OPTION");
                newOption.text = city[i].trim();
                newOption.value = city[i].trim();
                drp2.options.add(newOption);                
            }
        }
    }
}

function SetDDListDay()
{
    var Year=parseInt(document.getElementById("DDListYear").value.trim());
    var Month=parseInt(document.getElementById("DDListMonth").value.trim());
    var Day = document.getElementById("DDListDay");
    Day.options.length=0;
    var newOption = document.createElement("OPTION");
    newOption.text = "日";
    newOption.value = "-1";
    Day.options.add(newOption);
    if (Month != -1)
    {
        var MaxValue=31;
        if (Month == 2)
        {
            if (Year % 400 == 0 || (Year % 4 == 0 && Year % 100 != 0))
            {
                MaxValue=29;
            }
            else
            {
                MaxValue=28;
            }
        }         
        else if (Month>0 && Month<=6)
        {
            if (Month%2==0)
            {
                MaxValue=30;
            }
        }
        else
        {
            if (Month%2!=0)
            {
                MaxValue=30;
            }            
        }
        
        for (i=1;i<=MaxValue;i++)
        {
            newOption = document.createElement("OPTION");
            newOption.text = i + "日";
            newOption.value = i;
            Day.options.add(newOption);                
        }
    }            
}

function CloseNotice(a)
{
    document.getElementById(a).style.display = "none";
    return false;
}

function AllTxtOnFocus(a)
{
    a.className="inputCN1";
}

function AllTxtonblur(a)
{
    a.className="inputCN";
}

function PointUseDes()
{
    document.getElementById("SetBC").style.width = 400 + "px";
    document.getElementById("SetBC").style.height = 140+ "px";
    parent.frames["SetBC"].location.href = PageUrl + "General/PointUseDes.aspx";
    document.getElementById("BDDiv").style.display="block";
    document.getElementById("CCDiv").style.display="block";
    document.getElementById("BDDiv").style.width = (document.documentElement.clientWidth-2) + "px";
    document.getElementById("BDDiv").style.height = document.body.scrollHeight + "px";
    document.getElementById("CCDiv").style.top = (parseInt(document.getElementById("BDDiv").offsetHeight / 2) - 110) + "px";
    document.getElementById("CCDiv").style.left = (parseInt(document.getElementById("BDDiv").offsetWidth / 2) - parseInt(document.getElementById("CCDiv").offsetWidth / 2)) + "px";
    return false;
}

function VIPUseDec()
{
    document.getElementById("SetBC").style.width = 400 + "px";
    document.getElementById("SetBC").style.height = 210+ "px";
    parent.frames["SetBC"].location.href = PageUrl + "General/VIPUseDec.aspx";
    document.getElementById("BDDiv").style.display="block";
    document.getElementById("CCDiv").style.display="block";
    document.getElementById("BDDiv").style.width = (document.documentElement.clientWidth-2) + "px";
    document.getElementById("BDDiv").style.height = document.body.scrollHeight + "px";
    document.getElementById("CCDiv").style.top = (parseInt(document.getElementById("BDDiv").offsetHeight / 2) - 110) + "px";
    document.getElementById("CCDiv").style.left = (parseInt(document.getElementById("BDDiv").offsetWidth / 2) - parseInt(document.getElementById("CCDiv").offsetWidth / 2)) + "px";
    return false;
}

function RecDes()
{
    document.getElementById("SetBC").style.width =650 + "px";
    document.getElementById("SetBC").style.height = 390+ "px";
    parent.frames["SetBC"].location.href = PageUrl + "General/RecDes.aspx";
    document.getElementById("BDDiv").style.display="block";
    document.getElementById("CCDiv").style.display="block";
    document.getElementById("BDDiv").style.width = (document.documentElement.clientWidth-2) + "px";
    document.getElementById("BDDiv").style.height = document.body.scrollHeight + "px";
    document.getElementById("CCDiv").style.top = (parseInt(document.getElementById("BDDiv").offsetHeight / 2) - 195) + "px";
    document.getElementById("CCDiv").style.left = (parseInt(document.getElementById("BDDiv").offsetWidth / 2) - parseInt(document.getElementById("CCDiv").offsetWidth / 2)) + "px";
    return false;
}

function Getvalue(a,b)
{
    var Txt= document.getElementById(b);
    var Files = a;
	Txt.value=Files.value.trim();
}

var flag=false;
function DrawImage(a,b)
{
    var ImgD=a;
    var iwidth = 135; 
    var iheight = 160;
    var oheight = ImgD.height;
    var owidth = ImgD.width;
    if(oheight>0 && owidth>0)
    {
        flag=true;
        if(owidth/oheight>=iwidth/iheight)
        { 
            if(owidth>iwidth)
            { 
                ImgD.width=iwidth; 
                ImgD.height=(oheight*iwidth)/owidth; 
            }
            else
            { 
                ImgD.width=owidth; 
                ImgD.height=oheight; 
            } 
        } 
        else
        { 
            if(oheight>iheight)
            { 
                ImgD.height=iheight; 
                ImgD.width=(owidth*iheight)/oheight; 
            }
            else
            { 
                ImgD.width=owidth; 
                ImgD.height=oheight; 
            } 
        }                 
     }
     
     if (iheight > ImgD.height)
     {
        ImgD.style.marginTop = (((iheight - ImgD.height) / 2) + b) + "px";
     }
     else
     {
        ImgD.style.marginTop = b + "px";
     }
     
     if (iwidth > ImgD.width)
     {
        ImgD.style.marginLeft = (((iwidth - ImgD.width) / 2) + b) + "px";
     }
     else
     {
        ImgD.style.marginLeft = b + "px";
     }
}

var flag=false;
function DrawImage1(w,h,a,b)
{
    var ImgD=a;
    var iwidth = w; 
    var iheight = h;
    var oheight = ImgD.height;
    var owidth = ImgD.width;
    if(oheight>0 && owidth>0)
    {
        flag=true;
        if(owidth/oheight>=iwidth/iheight)
        { 
            if(owidth>iwidth)
            { 
                ImgD.width=iwidth; 
                ImgD.height=(oheight*iwidth)/owidth; 
            }
            else
            { 
                ImgD.width=owidth; 
                ImgD.height=oheight; 
            } 
        } 
        else
        { 
            if(oheight>iheight)
            { 
                ImgD.height=iheight; 
                ImgD.width=(owidth*iheight)/oheight; 
            }
            else
            { 
                ImgD.width=owidth; 
                ImgD.height=oheight; 
            } 
        }                 
     }
     
     if (iheight > ImgD.height)
     {
        ImgD.style.marginTop = (((iheight - ImgD.height) / 2) + b) + "px";
     }
     else
     {
        ImgD.style.marginTop = b + "px";
     }
     
     if (iwidth > ImgD.width)
     {
        ImgD.style.marginLeft = (((iwidth - ImgD.width) / 2) + b) + "px";
     }
     else
     {
        ImgD.style.marginLeft = b + "px";
     }
}

function CheckGetRecCode(a,b,c)
{
    if (c <= 0)
    {
        alert("对不起您推荐代码已经到达上限，如果想生成更多的，请督促已收到的邀请的好友赶快注册Ds2win。");
        return false;           
    }
    
    var Txt = document.getElementById(a);
    if (Txt.value.trim() == "")
    {
        alert("请填写推荐好友的真实姓名");
        return false;               
    }
    if (!/^[\u4E00-\u9FA5A-Za-z]*$/.test(Txt.value.trim()))
    {
        alert("推荐好友的真实姓名只能为中文或字母");
        return false;	
    }
    if (SumGBK(Txt.value.trim()) > 20)
    {
        alert("推荐好友的真实姓名不能超过10个汉字");
        return false;
    }
    
    var items=null;
    var oHttpReq = GetXMLHTTP(); //获取XMLHTTP对象
    var oDoc = null;             
    var c=b + "|" + Txt.value.trim();
    oHttpReq.open("POST", PageUrl + "HtmlAjax.aspx?i=" + escape(c) + "&type=16", false);
    oHttpReq.send("");
    var result = oHttpReq.responseText;
    if (getOs() == "MSIE")
    {
        oDoc = new ActiveXObject("MSXML2.DOMDocument");
        oDoc.loadXML(result);
        items = oDoc.selectNodes("//NewDataSet/Rec");
        for (var item = items.nextNode(); item; item = items.nextNode())
        {
            var Num = item.selectSingleNode("RecNameNum").nodeTypedValue;
            if (parseInt(Num) > 0)
            {
                alert("该好友您已经生成过了");
                return false;        
            }      
        }
    }
    else
    {
        result = result.substring(result.indexOf("<RecNameNum>") + "<RecNameNum>".length);
        result = result.substring(0,result.indexOf("</RecNameNum>"));
        if (parseInt(result) > 0)
        {
            alert("该好友您已经生成过了");
            return false;	     
        }            
    }
    
    return true;     
}

function LinkFriendStr()
{
    location.href = PageUrl + "Member/"
}
