﻿// JScript 文件
var Page = function(){
    this.pageCount;
    this.pageSize;
    this.pageIndex;
    this.count;
}
Page.prototype={
    PageTo:function(pageIndex){
        var page = Page;
        page.pageIndex = pageIndex;
    }
}
var GiftInfo=function(){      
      this.UrlHander;
      this.OP;
      this.OrderName;
      this.ParentTypeID;
      this.ChildTypeID;
      this.Gift_div;
      this.PageCount_div;
      this.PageIndex_div;
      this.PageMenu_div1;
      this.PageMenu_div2;
      this.page;
}
GiftInfo.prototype= {    
    SendRequest:function()
    {
        var Gift=this;
        var url=Gift.UrlHander+"?op="+Gift.OP+"&ChildTypeID="+Gift.ChildTypeID+"&PageIndex="+Gift.page.pageIndex+"&PageSize="+Gift.page.pageSize;
        url+="&OrderName="+Gift.OrderName+"&dt="+GetMyDate();        
        Request.sendGET(url,Gift.Success_SendRequest,Gift.Failture,Gift);        
    },
    Success_SendRequest:function(response,obj)
    {
        if(response.responseText!="")
        { 
            var Gift=obj;
            var GiftList=eval(response.responseText);
            var page=GiftList[0];
            Gift.PageCount_div.innerHTML="<span class=\"uid_index_num\">"+page.pageIndex+"</span>/"+page.pageCount+"页";            
            Gift.page.pageCount=GiftList[0].pageCount;
            Gift.Gift_div.innerHTML="";
            var Str="";
            for(i=1;i<GiftList.length;i++)
            {
               var item=GiftList[i];
               Str+="<div class=\"uid_msg_gift_imgBox\">";
               Str+="<div class=\"uid_msg_gift_img\">";
               Str+="<img src=\""+item.imagePath+"\" onclick=\"SendGift("+item.id+");\" /></div>";
               Str+="<div class=\"uid_msg_gift_li\">"+item.name+"</div>";
               Str+="<div class=\"uid_msg_gift_li\">"+item.price+"</div>";
               Str+="</div>";
            }
           //alert(Str);
           Gift.Gift_div.innerHTML=Str;
           Gift.SetPage();
           Gift.ClickMenu();

           $("Popularity").onclick=Gift.CkOrderName.bind(Gift,"Popularity");
           $("PubilshDate").onclick=Gift.CkOrderName.bind(Gift,"PubilshDate");           
           $("Page_Go").onclick=Gift.page_Goto.bind(Gift);
           
        }
    },
    Failture:function()
    {
        //alert("失败!");
    },
    ClickMenu:function()
    {
        var Gift=this;        
        var Alist=Gift.PageMenu_div1.getElementsByTagName("a");
        for(i=0;i<Alist.length;i++)
        {
            Alist[i].className="";
            Alist[i].onclick=Gift.ATypeClick.bind(Gift,Alist[i].lang);
        }
        $("AType_"+Gift.ChildTypeID).className="aCurrent";
    },
     ATypeClick:function(TypeID)
     {
        var Gift=this;
        Gift.ChildTypeID=TypeID;
        Gift.page.pageIndex=1;
        Gift.SendRequest();
     },
     CkOrderName:function(OrderName)
     {        
        var Gift=this;
        Gift.OrderName=OrderName;
        Gift.SendRequest();
        $("Popularity").className="";
        $("PubilshDate").className="";
        $(OrderName).className="aCurrent";

    },PageTo:function(index)
    {
        var Gift=this;
        Gift.page.pageIndex=index;
        Gift.SendRequest();
    },SetPage:function()
    {
        var Gift=this;
        Gift.PageIndex_div.innerHTML="";
        var Page_str="<a href=\"javaScript:void(0);\" id=\"page_Up\" >上一页</a>";
        var Begin=Gift.page.pageIndex-2;
        var End=Gift.page.pageIndex+2;
        if(Begin<=0)
        {
            Begin=1;
        }
        if(End>Gift.page.pageCount)
        {
            End=Gift.page.pageCount;
        }
        
        for(x=Begin;x<=End;x++)
        {
            if(Gift.page.pageIndex!=x)
            {         
                Page_str+="<a id=\"AIndex_"+x+"\" href=\"javaScript:void(0);\">"+x+"</a>";
            }else
              {
                Page_str+="<a href=\"javaScript:void(0);\" class=\"page_Current\">"+x+"</a>";
              }
        }
        Page_str+="<a href=\"javaScript:void(0);\" id=\"page_Next\" >下一页</a>";
        Gift.PageIndex_div.innerHTML=Page_str;
        
        for(x=Begin;x<=End;x++)
        {
            if(Gift.page.pageIndex!=x)
            {         
                $("AIndex_"+x).onclick=Gift.PageTo.bind(Gift,x);
            }
        }
        if(Gift.page.pageIndex>1){
              $("page_Up").onclick=Gift.PageTo.bind(Gift,Gift.page.pageIndex-1);
        }
        if(Gift.page.pageIndex<Gift.page.pageCount){        
            $("page_Next").onclick=Gift.PageTo.bind(Gift,Gift.page.pageIndex+1);
        }
    }
    ,page_Goto:function()
    { 
    var Gift=this;
    if(!isNaN($("txt_Index").value))
    {
        var index=Number($("txt_Index").value)
        if(index<=0)
        {    
            alert("您输入的不正确!");
            return;
        }
        if(index>Gift.page.pageCount)
        {
            alert("超出总页数!");
            return;
        }       
            Gift.PageTo(index);
    }else
    {
        alert("您输入的不正确!");
    }
    }    
}
function GiftInfoLoad(ChildTypeID){
    var Gift=new GiftInfo();
    Gift.UrlHander=GetGiftUrl();
    Gift.OP="GetGiftInfo";
    Gift.OrderName="Popularity";
    Gift.ChildTypeID=ChildTypeID;
    Gift.page=new Page();
    Gift.page.pageSize=14;
    Gift.page.pageIndex=1;
    Gift.Gift_div=$("Gift_Container");
    Gift.PageCount_div=$("PageCount_div");
    Gift.PageIndex_div=$("PageIndex_div");
    Gift.PageMenu_div1=$("gift_Menu_span1");
    Gift.PageMenu_div2=$("gift_Menu_span2");
    Gift.SendRequest();
}
function GetGiftUrl()
{
    return path+"Dating/Handler/GiftHandler.ashx";
}

   
   ///
   function GetMyDate()
   {
        var date=new Date();
        var now = "";
        now = date.getFullYear()+"-"; //读英文就行了
        now = now + (date.getMonth()+1)+"-";//取月的时候取的是当前月-1如果想取当前月+1就可以了
        now = now + date.getDate()+" ";
        now = now + date.getHours()+":";
        now = now + date.getMinutes()+"";
        return now;

   }
   //意中人
   function SendLoved()
    {
        var url=GetGiftUrl()+"?op=GetFriendInfo&dt="+GetMyDate();
        Request.sendGET(url,LovedList,failture);
    }
   //礼物对象
   function SendGiftInfo(ID)
   {
        var url=GetGiftUrl()+"?op=GetGiftInfoById&ID="+ID+"&dt="+GetMyDate();
        Request.sendGET(url,SetSendGift,failture);
   }
   //便利礼物类型
   function SendTypeList()
   {
        var url=GetGiftUrl()+"?op=display_ChildType&dt="+GetMyDate();
        Request.sendGET(url,SetSendType,failture);        
   }
   //提交
   function SendRequestGift()
   {
        var url=GetGiftUrl()+"?op=SendGift&dt="+new Date();
        url+="&GiftID="+$("hid_GiftID").value;
        url+="&FriendID="+$("txt_friendID").value;
        url+="&Comment="+escape($("txt_Comment").value)
        if($("Radio_Sendway2").checked){
              url+="&SendWay=3";
        }
        
        $("SendButton").disabled="disabled";
        Request.sendGET(url,SubmitGift,failture);  
   }
   //Send提交
   function SubmitGift(response)
   {
    if(response.responseText!=""){
        if(response.responseText=="true")
        {
            alert("赠送成功!");            
            CloseModeDialog("Send_");
        }else
        {
            alert(response.responseText);
            $("SendButton").disabled="";
        }
     }
   }
   
    function failture()
    {

    }
    
    function SetSendType(response)
    { 
        if(response.responseText!=""){
        
            var itemList=eval(response.responseText);
            var Str="";
            for(i=0;i<itemList.length;i++)
            {
                var item=itemList[i];
                Str+="<a onmouseover=\"aMouseover(this)\" onmouseout=\"aMouseout(this);\" id=\"AType_"+item.ID+"\" lang=\""+item.ID+"\">"+item.Type+"</a>";
            }            
            $("gift_Menu_span1").innerHTML=Str;
            GiftInfoLoad(0);
        }
    }
    function SetSendGift(response)
    {
        if(response.responseText!=""){
            var item=eval(response.responseText)[0];         
            $("hid_GiftID").value=item.ID;
            $("send_txt_Name").innerHTML=item.Name;
            $("imagePath").src=item.imgPath;
            $("send_txt_Price").innerHTML=item.Price;
            $("send_txt_Count").innerHTML=item.Count;
        }
    }
    function LovedList(response)
    {   var Str="";
        if(response.responseText!="")
        {
            var lovedList=eval(response.responseText);
            
            for(i=0;i<lovedList.length;i++)
            {
                Str+="<div class=\"friend_li\">";
                Str+="<a href=\"javaScript:void(0);\" onclick=\"SetFriend('"+lovedList[i].UID+"');\">"+lovedList[i].NickName+"</a></div>";   
            }
            $("friend_box").innerHTML=Str;             
        }else
        {
            Str+="<div>";
            Str+="<a href=\"../Search.aspx\" style=\"color:#CC3366;\" target=\"_blank\">&nbsp;您还没添加意中人!<br>&nbsp;点击搜索意中人</a></div>";
            $("friend_box").innerHTML=Str;
        }
        
    }
        
    
    function displayMore(UID)
    {
        var title="选择礼物";
        var nWidth=670;
        var nHeight=335;
        var contentHtml=GetGiftList();
        divModalDialog(nWidth,nHeight,"选择礼物",contentHtml,"list_",1000);
        SendTypeList();
        if(UID!=0)
        {
           $("SendUID").value=UID;
        }
        //window.showModalDialog(strFile,window,"dialogWidth:" + nWidth + "px;dialogHeight:" + nHeight + "px;center:yes;status:no;scroll:no;help:no;status:no;");
    }
    
        function SendGift(id)
         {
            var title="送礼物";
            var SendID="";
            //var strFile="GiftSendWindows.aspx?title="+escape(title)+SendID+"&id="+id+"&dt="+new Date();
            var nWidth=470;
            var nHeight=230;
            //var iTop = (window.screen.availHeight-30-nWidth)/2;       //获得窗口的垂直位置;
            //var iLeft = (window.screen.availWidth-10-nHeight)/2;           //获得窗口的水平位置;
            var contentHtml=GetGiftSend();            
            divModalDialog(nWidth,nHeight,"送礼物",contentHtml,"Send_",1500);
            SendGiftInfo(id);
            if($("SendUID")!=undefined){
                if($("SendUID").value!="0")
                {
                  $("txt_friendID").value=$("SendUID").value+"";
                }
            }
            $("hid_GiftID").value=id;
        }
        function aMouseover(ahref)
        {
            if(ahref.className=="aCurrent"){return false;}
            ahref.className="aMoverover";
        }
        function aMouseout(ahref)
        {
            if(ahref.className=="aCurrent"){return false;}
            ahref.className="aMouseout";
        }
        function $(id)
        {
            return document.getElementById(id);
        }
        
        function SetFriend(UID)
        {
            $("txt_friendID").value =UID;
            CloseModeDialog("friend_");
        }
        
        function SendFriend()
         {
            var nWidth=140;
            var nHeight=250;            
            var contentHtml=GetFriend();
            divModalDialog(nWidth,nHeight,"选择意中人",contentHtml,"friend_",2000);
            SendLoved();            
            //if(UID!=undefined){
            //$("txt_friendID").value=UID;
            //}
        }
        function checkSendGift()
        {   
            if($("txt_friendID").value==""||isNaN($("txt_friendID").value))
            {
                alert("您输入的ID不正确!");
                return false;
            }
            if($("txt_Comment").value=="")
            {
                alert("赠言不能为空!");
                return false;
            }
            return true;
        }
      //div模式窗口
      function divModalDialog(iWidth,iHeight,title,icontentHtml,prefix,Zindex)
      {
            var contentHtml=icontentHtml;
            var titleHtml=title;

        	var ModeDialogGgIframe = document.getElementById(prefix+"ModeDialogGgIframe");
	        if(ModeDialogGgIframe!=null)document.removeElement();// getElementById("ModeDialogGgIframe");
	        if(document.getElementById(prefix+"ModeDialogMsgDiv")!=null)return;	
	        var msgw,msgh,bordercolor,titleheight;
            msgw =iWidth;
	        msgh =iHeight; 
	        var sWidth,sHeight;
	        sWidth=document.body.offsetWidth-20;
	        sHeight=document.body.offsetHeight;
	        
	        var bg=document.createElement("iframe");
            
	        bg.setAttribute('id',prefix+'ModeDialogGgIframe');
	        bg.className="ModeDialogGgIframe";
	        var bgwidth = document.body.scrollWidth > sWidth?document.body.scrollWidth:sWidth;
	        var bgheight = document.body.scrollHeight>(screen.height-147)?document.body.scrollHeight:(screen.height-147);
	        bg.style.width = bgwidth > msgw ? bgwidth : msgw + "px";
	        bg.style.height = bgheight > msgh ? bgheight : msgh + "px";
	        bg.style.zIndex = Zindex; 
	        //ModeDialogMsgDiv
	        var msg=document.createElement("div");
	        msg.setAttribute("id",prefix+"ModeDialogMsgDiv");
	        msg.className="ModeDialogMsgDiv";
	        msg.style.position = "absolute";
	        msg.style.left = Number(window.document.documentElement.offsetWidth)/2-msgw/2+document.documentElement.scrollLeft + "px";
	        msg.style.top = Number(document.documentElement.clientHeight)/2-msgh/2+document.documentElement.scrollTop + "px";
	        msg.style.width = msgw + "px";
	        msg.style.zIndex = Zindex+200;
	                	
	        //ModeDialogTitleDiv
	        var title=document.createElement("div");
	        title.setAttribute("id",prefix+"ModeDialogTitleDiv");
	        title.setAttribute("align","left");
	        title.setAttribute("title","关闭");
	        title.className="ModeDialogTitleDiv";
	        title.innerHTML= "<strong style='float:left'>"+titleHtml+"</strong><span style='float: right;cursor:pointer;' onclick=\"CloseModeDialog('"+prefix+"');\">关闭</span>";

	        var content=document.createElement("div")
	        content.setAttribute("id",prefix+"ModeDialogContenDiv");
	        content.style.width = msgw;
	        content.innerHTML = contentHtml;
	        document.body.appendChild(bg);
	        document.body.appendChild(msg);
	        msg.appendChild(title);
	        msg.appendChild(content);
      }
        function CloseModeDialog(prefix)
        {
	        document.getElementById(prefix+"ModeDialogMsgDiv").removeChild(document.getElementById(prefix+"ModeDialogContenDiv"));
	        document.getElementById(prefix+"ModeDialogMsgDiv").removeChild(document.getElementById(prefix+"ModeDialogTitleDiv"));
	        document.body.removeChild(document.getElementById(prefix+"ModeDialogMsgDiv"));
	        document.body.removeChild(document.getElementById(prefix+"ModeDialogGgIframe"));
        }
    
      //选择礼物
      function GetGiftList()
      {
        var Str="";
            Str+="<input type=\"hidden\" id=\"SendUID\" value=\"0\" />";
            Str+="<div style=\"width: 670px;\">";
            Str+="<div class=\"uid_msg_Menu\">";
            Str+="<span id=\"gift_Menu_span1\" class=\"uid_msg_span1\">";
            Str+="<a>数据加载中...</a></span>";
            Str+="<span id=\"gift_Menu_span2\" class=\"uid_msg_span2\">";
            Str+="<span class=\"uid_msg_span3\">排序：</span>";
            Str+="<a onmouseover=\"aMouseover(this)\" onmouseout=\"aMouseout(this);\" id=\"Popularity\" class=\"aCurrent\">人气</a>";
            Str+="<a onmouseover=\"aMouseover(this)\" onmouseout=\"aMouseout(this);\" id=\"PubilshDate\">时间</a></span></div>";
           
            Str+="<div id=\"Gift_Container\" class=\"uid_msg_giftBox uid_msg_width\">";
            Str+="<div class=\"uid_msg_gift_imgBox\">数据加载中...";
            Str+="</div>";            
            Str+="</div>";
            
            Str+="</div>";
            Str+="<div class=\"uid_msg_pageBox\">";
            Str+="<span id=\"PageCount_div\" class=\"uid_msg_pageBox_count\"><span class=\"uid_index_num\">1</span>/1页</span>";
            Str+="<span id=\"PageIndex_div\" class=\"uid_msg_pageBox_index\"><div style=\"margin:auto;\"><a>上一页</a>";
            Str+="<a class=\"page_Current\">1</a><a>2</a><a>3</a><a>下一页</a></div></span>";
            Str+="<span class=\"uid_msg_pageBox_Go\">转到<input type=\"text\" id=\"txt_Index\" class=\"GoIndex\" />页";
            Str+="<input type=\"button\" id=\"Page_Go\" value=\"Go\" class=\"uid_GoBtn\" /></span>";
            Str+="</div>"; 
            return Str;
      }
      
      
      
      //送礼物
      function GetGiftSend(){
        var Str="<div class=\"gift_windows1\"><input id=\"hid_GiftID\" type=\"hidden\" value=\"0\"/>";
            Str+="<div class=\"gift_windows\">";
            Str+="<div class=\"uid_msg_gift_imgBox\">";
            Str+="<div class=\"uid_msg_gift_img\"><img id=\"imagePath\" alt=\"数据加载中...\" src=\"..\" /></div>";
            Str+="<div id=\"send_txt_Name\" class=\"uid_msg_gift_li\"></div>";
            Str+="<div id=\"send_txt_Price\" class=\"uid_msg_gift_li\"></div>";
            Str+="<div id=\"send_txt_Count\" class=\"uid_msg_gift_li\"></div>";
            Str+="</div>";
            Str+="<div class=\"gift_windows_right\">";
            Str+="<div class=\"gift_windows_right_li\">";
            Str+="<span style=\"float:left; line-height:23px;\">意中人ID：";
            Str+="<input id=\"txt_friendID\" type=\"text\" style=\"width: 100px;\" /></span>";
            Str+="<a href=\"javaScript:void(0);\" class=\"gift_windows_xuze\" onclick=\"SendFriend();\">请选择意中人</a>";
            Str+="</div>";
            Str+="<div class=\"gift_windows_right_li\" style=\"height: 25px; line-height: 25px;\">赠&nbsp;&nbsp;&nbsp;&nbsp;言：</div>";
            Str+="<div class=\"gift_windows_right_li\">";
            Str+="<span style=\"float: left;\">";
            Str+="<textarea id=\"txt_Comment\" class=\"gift_txt_Comment\">希望我们能成为好朋友!</textarea></span></div>";
            Str+="<div class=\"gift_windows_right_li\" style=\"height: 25px; line-height: 25px;\">";
            Str+="<span style=\"float:left;\">赠送方式：</span>";
            Str+="<span style=\"float:left;\">";
            Str+="<input type=\"radio\" id=\"Radio_Sendway1\" name=\"Sendway\" checked=\"checked\" value=\"1\" />公开赠送";
            Str+="<input type=\"radio\" id=\"Radio_Sendway2\" name=\"Sendway\" value=\"3\" />匿名赠送";
            Str+="</span>";
            Str+="</div>";
            Str+="</div>";
            Str+="</div>";
            Str+="<div class=\"gift_windows_bottom\">";
            Str+="<span class=\"gift_windows_span\">";
            Str+="<input type=\"button\" id=\"SendButton\" value=\"赠送\" class=\"gift_button\" onclick=\"if(checkSendGift()){SendRequestGift();}\" />";
            Str+="<input type=\"button\" value=\"取消\" class=\"gift_button\" onclick=\"CloseModeDialog('Send_');\" />";
            Str+="</span>";
            Str+="</div>";
            Str+="</div>";
            return Str;
      }
      
      //好友列表
       function GetFriend(){
           var Str="<div id=\"friend_box\" class=\"friend_container\">";
               Str+="<div class=\"friend_li\">";
               Str+="<a href=\"javaScript:void(0);\">数据加载中...</a></div>";
               Str+="</div>";
               return Str;
        }
