﻿///发送倡议书
$(document).ready(function(){
getExpertList("hot",1);
   $("#btnSendActivity").click(function(){
    var obj=document.getElementsByName("EmailList");
    var str="";
    for(var i=0;i<obj.length;i++){
        var e=obj[i].value;
        if(e!=""){
            if(!IsEmail(e)){
                with(obj[i]){
                    focus();
                    select();
                }
                alert("对不起，电子邮件格式不正确");
                return;
            }
            str=str==""?e:(str+","+e);
        }
    }
    
    if(str==""){
        alert("对不起，请输入邮件地址！");
        return;
    }

	if(!confirm("活动已经结束了，还要继续吗?")) return;
    $("#processTip").ajaxStart(function(){
        $("#btnSendActivity").attr("disabled","true");
        $(this).html("<img width='150px' height='10px' src='../images/load2.gif'><br>请稍等，正在发送倡议书......");
    });
    
    $.ajax({
        url:"../service.ashx?act=SponsorActive&d="+new Date(),
        data:"email="+escape(str),
        type:"post",
        success:function(msg){
            $("#btnSendActivity").attr("disabled","");
            switch(parseInt(msg)){
                case -999:
                    $("#processTip").html("对不起，你还没有登录！");
                    break;
                case 0:
                    $("#processTip").html("对不起，倡议书发送失败！");
                    break;
                default:
                    alert("发送成功");
				//，你的朋友点击注册后你就会收到一份家安礼品！");
                    self.location=self.location;
                    break;
            }
        }
    });
});
});

//加为好友
	var AddToMyFriend=function(){
		$.ajax({
			url:"../service.ashx?act=AddToMyFriend&d="+new Date(),
			data:"username="+escape($("#ctl00_ContentPlaceHolder1_currUserName").val()),
			type:"post",
			success:function(msg){
				switch(parseInt(msg)){
					case -999:
						alert("对不起，你还没有登录，不能加好友");
						break;
					case -3:
						alert("自己不能加自己");
						break;
					case -888:
						alert("好友的帐号不存在");
						break;
					case 0:
						alert("对不起，添加好友失败");
						break;
					case -1:
						alert("对不起,该好友已经添加过");
						break;
					default:
						alert("好友添加成功");
						break;
				}
			}
		});
	}

var RecommendFriend=function(){
    var list="";
    $("#myMailList li input").each(function(){
        var v=$(this).val();
        if(v!=""){
            list+=","+v;
        }
    });
    if(list==""){
		$("#ErrorMsg").html("请至少填写一个要推荐人的邮件地址");
        return;
    }
	 $("#ErrorMsg").ajaxStart(function(){
         //$("#btnSendInvite").attr("disabled","disabled");
         $(this).html("<img src=../images/load2.gif><br>请稍等，正在发送邀请......");
    });
	


    $.ajax({
        url:"../service.ashx?act=InviteFriend",
        data:"email="+list,
        type:"post",
        success:function(msg){
			var t=parseInt(msg);
			//alert(t);
            if(t==-999){
				$("#ErrorMsg").html("对不起，你还没有登录");
            }else if(t<=0){
				$("#ErrorMsg").html("发送邀请失败，请重试");
			}else{
				$("#ErrorMsg").html("共发送成功"+t+"封邮件");
			}

        }
    });
}

///打开地图功能
var OpenMap=function(){
    window.showModalDialog("../static/Map.Aspx","newwin","dialogHeight:500px;center:yes; dialogWidth: 858px;  scroll: No;");
}

///打开联系我们功能
var OpenContact=function(){    
    window.showModalDialog("../static/contact.html","newwin","dialogHeight:320px;center:yes; dialogWidth: 840px;  scroll: No;");
}

///打开联系我们功能
var OpenSale=function(){    
    window.showModalDialog("../static/venditioncity.html","newwin","dialogHeight:500px;center:yes; dialogWidth: 858px;  scroll: No;");
}

///打开友情链接功能
var OpenLink=function(){    
    window.showModalDialog("../static/links.html","newwin","dialogHeight:500px;center:yes; dialogWidth: 858px;  scroll: No;");
}


var quitLogin=function(){
    if(!confirm("真的确定要退出吗？")) return false;
	self.location="../bbs/logout.asp?isservice=1";
}

 ///会员登录操作
    var userLogin=function(){
        var username=$("#username");
        var password=$("#password");
        if(username.val()==""){
            username.focus();
            alert("请输入用户名");
            return;
        }
        if(password.val()==""){
            password.focus();
            alert("用户密码不能为空");
            return;
        }
        
        $.ajax({
            url:"../bbs/login.asp?action=chk&service=1&d="+new Date(),
            type:"post",
            data:"username="+escape(username.val())+"&password="+escape(password.val())+"&CookieDate=3",
            success:function(msg){
                if(msg.toLowerCase()=="true"){
                    alert("恭喜你，登录成功");
                    self.location=self.location;
                }else{
                    username.focus();
                    username.select();
					var tip="登录失败，请检查用户名和密码是否正确,或帐号是否已激活！";
                    alert(tip);
                }
            }
        });
    }

///取得专家在线提出的问题
var getExpertList=function(t,page,typeId,title){
    if(typeId==null) typeId=-1;
    if(title==null) title="";
    var initUrl="../service.ashx?act=GetExpertQuestion&d="+new Date()+"&page="+page+"&t="+t+"&typeid="+typeId+"&title="+escape(title);
    $.get(initUrl,function(msg){
            var list="";
            $(msg).find("table").each(function(){
                var obj=$(this);
                var username=obj.children("username").text();
                var content=obj.children("content").text();
                var replycontent=obj.children("replycontent").text();
                var replydate=obj.children("replydate").text().replace(/t.+/igm,"");
                list+=template.replace("$username$",username).replace("$content$",content).replace("$replycontent$",replycontent).replace("$replydate$",replydate);
            })
            var totalpage=$(msg).find("root").attr("pagecount");
            $("#problemList").html(list);
            var prevpage=parseInt(page)>1?"javascript:getExpertList('"+t+"',"+(page-1)+","+typeId+",'"+title+"')":"#";
            var nextpage=parseInt(page)<parseInt(totalpage)?"javascript:getExpertList('"+t+"',"+(page+1)+","+typeId+",'"+title+"')":"#";
            var pageBean=pageTemplate.replace("$totalpage$",totalpage).replace("$currengpage$",page).replace("$prevpage$",prevpage).replace("$nextpage$",nextpage)
            $("#pageBn").html(pageBean);
        });
    
}

//取得相应的文章内容
var getArticleList=function(categoryId,page){
    var InitUrl="../service.ashx?act=GetArticles&d="+escape(new Date());
     $.get(InitUrl+"&page="+page+"&categoryId="+categoryId,function(msg){
            var list="";
            var newsPage="";
            var pagecount=$(msg).find("root").attr("pagecount");
            for(var i=1;i<=pagecount;i++){
                if(page==i){
                    newsPage+="<span>"+i+"</span>";
                }else{
                    newsPage+="<a href=\"javascript:getArticleList('"+categoryId+"','"+i+"')\">"+i+"</a>";
                }
            }
            $("#newsPage").html(newsPage);
            $(msg).find("table").each(function(){
                var obj=$(this);
                var id=obj.children("id").text();
                var title=obj.children("title").text()+"$img$";
                var comefrom=obj.children("comefrom").text();
				var url=obj.children("url").text();
                var publishDate=obj.children("createdate").text();
                var sdate=publishDate.replace(/t.+/igm,"");
                var categoryId=obj.children("categoryid").text();
				if(url!=""){
					url="<img src='/images/tv.gif'>";
				}
				title=title.replace("$img$",url);
                list+=template.replace("$title$",title).replace("$comefrom$",comefrom).replace("$date$",sdate).replace("$id$",id).replace("$categoryId$",categoryId);
            });
            if(list=="") list="<div align=center style='color:red;font-weight:bold'><br/><br/>对不起，在本栏目中没有找到相关的文章！</div>";
            $("#newsList").html(list);
        });
}

$(document).ready(function(){
    ///点击网站logo时
    $("#sitelog").click(function(){
        self.location="../";
    });
    
    ///文章新闻类列表
    $("#tabBoxNews li").click(function(){
        $("#tabBoxNews li").each(function(){
            $(this).removeClass("nonceTab");
        })
        $(this).addClass("nonceTab");
        var categoryId=$(this).attr("linkId");
        getArticleList(categoryId,1);
    })
    
    ///专家在线列表
    $("#tabBoxExpert li").click(function(){
        $("#tabBoxExpert li").removeClass("nonceTab");
        $(this).addClass("nonceTab");
        var t="";
        var img="../images/h_04.jpg";
        if($(this).attr("id")=="tab1"){
            t="hot";
        }else{
            t="new";
            img="../images/h_06.jpg";
        }
        document.getElementById("activeImage").src=img;
        getExpertList(t,1);
    });
    
    
    ///实现象专家提问
    $("#btnAsk").click(function(){
        var username=$("#uname").html();
        var typeId=$("#ClassType2").val();
        if(typeId=="-1"){
            alert("对不起，请选择要提问的类别");
            return;
        }
        $.ajax({
            url:"../service.ashx?act=AskExpert&username="+escape(username)+"&d="+new Date(),
            data:"typeId="+typeId+"&content="+escape($("#Mycontent2").val()),
            type:"post",
            success:function(msg){
                switch(parseInt(msg)){        
                    case -999:
                        alert("对不起，你还没有登录！");
                        break;
                    case -888:
                        alert("对不起，提交的内容不能为空!");
                        $("#content2").focus();
                        break;
                    case 0:
                        alert("对不起，提交失败");
                        break;
                    default:
                        alert("提问成功，我们会尽快答复你!");
                        self.location="expert.aspx";
                        break;
                }
            }
        });
    });
})