﻿/*
            1、WebService请求类型都为Post，WebService的Url为“[WebServiceUrl]/[WebMethod]”
            2、contentType声明为Json
            3、data要用Json的字符串格式传入
            4、设置了dataType为json后，result就直接为返回的Json对象。

        */
        function btnSupport(btnSupport,ShdUserId,ShdAsId,lblnum)
        {
        $("#"+btnSupport).click(function(){
             var UserId=ShdUserId;
            var AnswerId=ShdAsId;
            $.ajax({
                type: "POST",
                contentType:"application/json",
                url:"WebServiceAs.asmx/Support",
                data:"{CurrentUserId:3,UserId:"+UserId+",AnswerId:"+AnswerId+"}",
                dataType:'json',
                
                success:function(result){
                
                switch(result.d) {
		                        case 0:
			                   alert("不允许自己评价自己！");
			                    break;
		                        case 2:		                       
			                    alert("您已经评价！");
			                    break;
		                        case 1:
		                        var num=parseInt($("#"+lblnum).html());
		                        $("#"+lblnum).html(num+1);
			                    alert("评价成功");
			                    break;
		                        }
                }
            });
        });
        }
    
    function btnOppose(btnOppose,OhdUserId,OhdAsId,lblnum)
    {
    $("#"+btnOppose).click(function(){
            var UserId=OhdUserId;
            var AnswerId=OhdAsId;
            $.ajax({
                type: "POST",
                contentType:"application/json",
                url:"WebServiceAs.asmx/Oppose",
                data:"{CurrentUserId:1,UserId:"+UserId+",AnswerId:"+AnswerId+"}",
                dataType:'json',
                success:function(result){                    
                    switch(result.d) {
		                        case 0:
			                   alert("不允许自己评价自己！");
			                    break;
		                        case 2:		                        
			                    alert("您已经评价！");
			                    break;
		                        case 1:
		                         var num=parseInt($("#"+lblnum).html());
		                        $("#"+lblnum).html(num+1);
			                    alert("评价成功");
			                    break;
		                        }
                }
                });
            });
    }

function setHot(Id,QsId)
        {
           var QsHot;
           var str= $("#"+Id).html();
           if(str=="设为推荐")
           {
            QsHot=1;
           }
           else
           {
           QsHot=0;
           }
            $.ajax({
                type: "POST",
                contentType:"application/json",
                url:"../WebServiceAs.asmx/setHotQs",
                data:"{QsId:"+QsId+",QsHot:"+QsHot+"}",
                dataType:'json',
                 
                success:function(result){
                
                switch(result.d) {
		                        case 0:
			                   alert("设为推荐失败！");
			                    break;
		                        case 1:
		                        if(str=="设为推荐")
		                        {
			                        $("#"+Id).html("取消推荐");
			                        $("#"+Id).addClass("deep");
			                    }
			                    else
			                    {
			                        $("#"+Id).html("设为推荐");
			                        $("#"+Id).removeClass("deep");
			                    }
			                    break;
		                        }
                }
            });
        }
        function setExpert(Id,QsId)
        {
           var QsIsExpert;
           var str= $("#"+Id).html();
           if(str=="设为推荐")
           {
            QsIsExpert=1;
           }
           else
           {
           QsIsExpert=0;
           }
            $.ajax({
                type: "POST",
                contentType:"application/json",
                url:"../WebServiceAs.asmx/setExpertQs",
                data:"{QsId:"+QsId+",QsIsExpert:"+QsIsExpert+"}",
                dataType:'json',
                 
                success:function(result){
                
                switch(result.d) {
		                        case 0:
			                   alert("设为推荐失败！");
			                    break;
		                        case 1:
		                        if(str=="设为推荐")
		                        {
			                        $("#"+Id).html("取消推荐");
			                        $("#"+Id).addClass("deep");
			                    }
			                    else
			                    {
			                        $("#"+Id).html("设为推荐");
			                        $("#"+Id).removeClass("deep");
			                    }
			                    break;
		                        }
                }
            });
        }
function setIsDisplayBrand(Id,BrandID)
        {
           var IsDisplay;
           var str= $("#"+Id).html();
           if(str=="设为前台显示")
           {
            IsDisplay=1;
           }
           else
           {
           IsDisplay=0;
           }
            $.ajax({
                type: "POST",
                contentType:"application/json",
                url:"../WebServiceAs.asmx/setIsDisplayBrand",
                data:"{BrandID:"+BrandID+",IsDisplay:"+IsDisplay+"}",
                dataType:'json',
                 
                success:function(result){
                
                switch(result.d) {
		                        case 0:
			                   alert("设为前台显示失败！");
			                    break;
		                        case 1:
		                        if(str=="设为前台显示")
		                        {
			                        $("#"+Id).html("取消前台显示");
			                        $("#"+Id).addClass("deep");
			                    }
			                    else
			                    {
			                        $("#"+Id).html("设为前台显示");
			                        $("#"+Id).removeClass("deep");
			                    }
			                    break;
		                        case 2:
			                    alert("最多设置五个前台显示品牌！");
			                    break;
		                        }
                }
            });
        }
		 function SetStoreQs(Id,UserId,QsId)
        {
			var State=$("#"+Id).attr("title");
			var option;
			if(State=="收藏")
			{
				option=1;
			}
			else
			{
				option=0;
			}
            $.ajax({
                type: "POST",
                contentType:"application/json",
                url:"../WebServiceAs.asmx/SetStoreQs",
                data:"{UserId:"+UserId+",QsId:"+QsId+",option:"+option+"}",
                dataType:'json',
                 
                success:function(result){
                if(result.d!=0)
					{
						if(option==1)
						{
							 $("#"+Id).removeClass("collect");
							 $("#"+Id).addClass("uncollect");
							 $("#"+Id).attr("title","取消收藏");
						}
						else
						{
							 $("#"+Id).removeClass("uncollect");
							 $("#"+Id).addClass("collect");
							 $("#"+Id).attr("title","收藏");
						}
						
					}
				else
					 {
						alert("收藏失败！");
					 }
                }
            });
        }
        
         function setViewState(QsId)
        {
            $.ajax({
                type: "POST",
                contentType:"application/json",
                url:"WebServiceAs.asmx/setViewState",
                data:"{QsId:"+QsId+"}",
                dataType:'json',
                 
                success:function(result){
                if(result.d==0)
					{
						alert("系统故障！");
					}
				
                }
            });
        }
        
         function setIsViewAs(QsId)
        {
            $.ajax({
                type: "POST",
                contentType:"application/json",
                url:"../WebServiceAs.asmx/setIsViewAs",
                data:"{QsId:"+QsId+"}",
                dataType:'json',
                
                success:function(result){
                
				
                }
            });
        }
        
            function setPassed(btn)
            {
            $("#"+btn).click(function(){         
            var day;
            var QsReward;
            var QsId=Number(btn);                                                                                                    
            var	types= "重新提问";
            var html=" <div id=\"popwinfriendlistbox\" class=\"popwinfriendlistbox\">"+
                        "<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">"+
                        "<tr> "+
                         " <td align=\"left\">悬赏银币："+
                          "</td>"+
                            " <td align=\"left\">"+
                                "<select name=\"Rewardgroup\" id=\"Rewardgroup\">"+
                                    " <option value=\"10\" selected>10</option>"+
                                    " <option value=\"20\" >20</option>"+
                                    " <option value=\"30\" >30</option>"+
                                    " <option value=\"40\" >40</option>"+
                                    " <option value=\"50\" >50</option>"+
                                    " <option value=\"60\" >60</option>"+
                            "   </select>"+
                            "</td>"+
                           
                        "</tr>"+
                        "<tr> "+
                         " <td align=\"left\">征答期限(天)："+
                          "</td>"+
                            " <td align=\"left\">"+
                                "<select name=\"PassedTimegroup\" id=\"PassedTimegroup\">"+
                                    " <option value=\"10\" selected>10</option>"+
                                    " <option value=\"20\" >20</option>"+
                                    " <option value=\"30\" >30</option>"+
                                    " <option value=\"40\" >40</option>"+
                                    " <option value=\"50\" >50</option>"+
                                    " <option value=\"60\" >60</option>"+
                            "   </select>"+
                            "</td>"+ 
                        "</tr>"+
                        "<tr> "+
                         "<td align=\"left\">"+
                         "<input id=\"Ok\" type=\"button\" class=\"button\" value=\"确定\">"+
                         "<input id=\"Cancel\" type=\"button\" class=\"button\" value=\"取消\">"+
                          "</td>"+ 
                        "</tr> "+
                      "</table>"+
                   "</div>"+
                    "<div id=\"popwinsearchresultbox\" class=\"popwinsearchresultbox\" style>"+
                    "</div> ";
            var $msgbox=$.msgbox.popupwin(150,100,types,html);
            $msgbox.find("input[id='Cancel']").click(function(){
                                            $.msgbox.closemsgbox()});
           day=Number($msgbox.find("select[id='PassedTimegroup']").val());
           $msgbox.find("select[id='PassedTimegroup']").change(function(){
                     $("select option:selected").each(function(){
                     day=Number($(this).text());
                });
             })
           QsReward=Number($msgbox.find("select[id='Rewardgroup']").val());
           $msgbox.find("select[id='Rewardgroup']").change(function(){
                     $("select option:selected").each(function(){
                      QsReward=Number($msgbox.find("select[id='Rewardgroup']").val());
                });
             })
            $msgbox.find("input[id='Ok']").click(function(){
            
	         $.ajax({
                type: "POST",
                contentType:"application/json",
                url:"../WebServiceAs.asmx/setPassedTime",
                data:"{QsId:"+QsId+",day:"+day+",QsReward:"+QsReward+"}",
                dataType:'json',
                 
                success:function(result){
                
                            if(result.d!=0)
                                {
                                     $.msgbox.closemsgbox();
                                }
                            else
                                {
                                    alert("失败");
                                    $.msgbox.closemsgbox();
                                }
                            }
                        });
                   })  
               })
            }
    function messagebox(title,contxt)
    {
            var html="<div id=\"popwinfriendlistbox\" class=\"popwinfriendlistbox\">"+
                        contxt+
                   "</div>"+
                    "<div id=\"popwinsearchresultbox\" class=\"popwinsearchresultbox\" style>"+
                    "</div> ";
              jQuery.msgbox.popupwin(150,100,title,html);											 
}
jQuery(document).ready(function() {
    jQuery("#q").val("息票债券的久期如何计算 ");
	jQuery("#q").click(function() {
		if(jQuery("#q").val()=="息票债券的久期如何计算 ")
        {
        jQuery("#q").val("")
        }
	});
	
	jQuery("#q").blur(function() {
		 if(jQuery("#q").val()=="")
        {
        jQuery("#q").val("息票债券的久期如何计算 ")
        }
	});
});

function addmini(miniurl,obj,pointval){
				
				var offsetleft=$(obj).offset().left;
				var offsettop=$(obj).offset().top+$(obj).innerHeight();
				
	    		var content=$.trim($("#ctnt").val());
	    		var point=parseInt($("#"+pointval).val());
	    		if (content==''||content=='我在做什么……'){
	    			$.msgbox.confirmbox("","添加迷你博客,内容不能为空!",offsetleft,offsettop);
	    			$.msgbox.closemsgbox(2000);
	    			return false;
	    		}
	    		else if(point<=-100){
	    			$.msgbox.confirmbox("","添加迷你博客,你的银币数小于-100！不能发表！",offsetleft,offsettop);
	    			$.msgbox.closemsgbox(2000);
	    			return false;
	    		}
	    		else{
						$.ajax({
								url:miniurl+"?callback=?&content="+encodeURI(encodeURI(content)),
								dataType: "jsonp",
								cache:false,
								success:function(html){
									$.msgbox.confirmbox("","添加迷你博客,"+html.items,offsetleft,offsettop);
									$("#ctnt").val('');
								},
								error:function(){
										$.msgbox.confirmbox("","添加迷你博客,提交失败！",offsetleft,offsettop);
								},
								beforeSend:function(){
										$.msgbox.confirmbox("","添加迷你博客,提交中！",offsetleft,offsettop);
								},
								complete: function(){
								$.msgbox.closemsgbox(2000);
											return false;
								}					
							});
	    		}
}

//显示输入用户名的窗口
function showInputPopwin(cluburl)
 {
    var html="<div id=\"popwinfriendlistbox\" class=\"popwinfriendlistbox\">"+
                  "<table width='260' border='0' cellspacing='4' cellpadding='4' class='formtable' >"+
                      "<tr>"+
                         "<td valign='top'>用户名：</td>"+
                         "<td align='left'><input name='username' type='text' class='text' id='username' value='邮件地址或用户名' onclick=\"if (this.value=='邮件地址或用户名') this.value=''\" /><br/>"+
                             "<span id='sendpasswordmsg'></span></td>"+
                      "</tr>"+
                      "<tr>"+
                          "<td>&nbsp;</td>"+
                          "<td align='left'>"+
                              "<input  class='button' type='submit' value='发送' name='a_sendpassword' id='a_sendpassword' onClick='javascript:;'/> <span></span></td>"+
                       "</tr>"+  
                    "</table>"+
               "</div>"+
               "<div id=\"popwinsearchresultbox\" class=\"popwinsearchresultbox\" style></div> ";
	 $forgetPasswordPopwin=$.msgbox.popupwin(250,100,"取回密码",html);
	 sendPassword($forgetPasswordPopwin,cluburl);
}
				   
 //发送密码
function sendPassword($obj,cluburl)
{
	var $userNameObj=$obj.find("#username");
	var $aSendPassword=$obj.find("#a_sendpassword");
	var $sendPasswordMsg=$obj.find("#sendpasswordmsg");
				   
	$aSendPassword.click(function(){
		$sendPasswordMsg.html("");
		if ($userNameObj.val()==""){
													 //$sendPasswordMsg.html("请输入需要取回密码的用户名！");
			$aSendPassword.next().html("请输入需要取回密码的用户名！");
			}else{ 
			$aSendPassword.next().html("密码发送中！");
			var $this=$(this);
			$this.hide();
			$.ajax({
					url:cluburl+"portlet/user/sendPassword.do?callback=?",
					data:"username="+$userNameObj.val(),
					cache:false,
					dataType: "jsonp",
					success:function(html){
															//alert(html);
					if (html.error == 1 ){
						$aSendPassword.next().html("密码发送至您的邮箱！");
						$.msgbox.closemsgbox(1000);
						}else{
						$aSendPassword.next().html("密码取回失败！");
						$this.show();
					}},
					error:function(){$aSendPassword.next().html("密码取回失败！");},
					beforeSend:function(){$aSendPassword.next().html("密码发送中！");},
					complete: function(){}
		    })
		}
	})
}
