﻿// JScript 文件
function share(id)
{

    //alert(id);
    var rv=wangluoyingxiao_ViewsList.shareArticle(id).value;
     //alert(rv);
        if(rv=="-1"){
         var fromurl=window.location.href;
          alert('匿名用户不能对观点分享，请先登录能力秀');
          window.location.href="http://abc.wm23.com/login.aspx?from="+fromurl;
        }
        else if(rv=="0")
          alert('分享失败！');
        else if(rv=="1")
           alert('分享成功！');
        else if(rv=="2")
            alert('对不起！你已经分享该文章！');
        else if(rv=="3")
            alert('不能分享本人文章！');
        else 
           return;
}

//打分
function shareScoring(articleId)
{
    var score = document.getElementById("ddlScore").value;
            if(score ==0){
                alert("请选择分值！");
                return;
            }
    var rv=wangluoyingxiao_ViewsList.Scoring(score,articleId).value;
         if(rv=="0"){
//                alert("匿名用户不能对观点进行打分，请先登录能力秀！");
                var fromurl=window.location.href;
//                window.setTimeout("alert('匿名用户不能对观点进行打分，请先登录能力秀！');window.location.href='http://abc.wm23.com/login.aspx?from="+fromurl+"';",3000);
                alert("匿名用户不能对观点进行打分，请先登录能力秀！");
                window.location.href="http://abc.wm23.com/login.aspx?from="+fromurl;
                return;
            }
	    if(rv=="6"){
                alert("您的账号还未进行任何有效操作，不能评分！");
                return;
            }
             if(rv=="1"){
                alert("您已经为该文章打分了！");
                return;
            }
             if(rv=="2"){
                alert("打分成功，谢谢您的参与。");
                return;
            }
             if(rv=="3"){
                alert("打分失败，谢谢您的参与。");
                return;
            }
            if(rv=="4"){
                alert("用户不能给自己的观点进行打分，您可以邀请其他参赛选手为您的观点进行打分。");
                return;
            }
            if(rv=="5"){
                alert("该文章发布已超过1周，不能再进行打分了！");
                return;
            }
            return;
        
}

//打分方法结束


function check()
{
    var username=document.getElementById("username");
    var password=document.getElementById("password");
    if(username!=null)
    {
        if(username.value=="")
        {
            alert("你还没有登录，请输入用户名！");
            return false;
        }
    }
      if(password!=null)
    {
        if(password.value=="")
        {
            alert("请输入密码！");
            return false;
        }
    }
    var commenttitle=document.getElementById("commenttitle");
    if(commenttitle.value!="")
    {
        if(commenttitle.value.length>15)
        {
             alert("标题字符不能大于15个！");
             return false;
        }
    }
     var commentcontent=document.getElementById("commentcontent");
    if(commentcontent.value!="")
    {
        if(commentcontent.value.length>200)
        {
             alert("评论内容不能大于200个！");
             return false;
        }
    }
    else
    {
         alert("评论内容不能为空！");
         return false;
    }
    
}
function zhichi(ActicleId)
{
  var param ="";
    var options = {
    method: 'post',
    parameters: param,
    onComplete:
        function(transport) {
            var retv = transport.responseText;
            if(retv=="true")
            {
                alert("支持成功，谢谢您的投票！");
            }
        }
}
new Ajax.Request("/filehandle/UpComment.aspx?type=zhichi&ActicleId="+ActicleId, options);
}
function fenxiang(ActicleId)
{
  var param ="";
    var options = {
    method: 'post',
    parameters: param,
    onComplete:
        function(transport) {
            var retv = transport.responseText;
            if(retv=="true")
            {
                alert("共享成功，谢谢您的投票！");
            }
        }
}
new Ajax.Request("/filehandle/UpComment.aspx?type=fenxiang&ActicleId="+ActicleId, options);
}
function Jubao(ArtID)
{
    var content=$("JuBaoContent").value
    if(content!="")
    {
        if(content.length>200)
        {
             alert("举报内容不能多于200个字！");
             return;
        }
    }
    else
    {
         alert("举报内容不能为空！");
         return;
    }
    alert(wangluoyingxiao_ViewsList.UpJubao(ArtID,content).value);
    CloseDiv();
}
function Ding(id)
{
    alert(wangluoyingxiao_ViewsList.CommentDing(id).value);
     $("newcomment").innerHTML="正在加载";
    RefreshComment();
}
function ShowReply(id)
{
    $("ReplyMent"+id).style.display="block";
}
function CancelReply(id)
{
    $("ReplyMent"+id).style.display="none";
}
function UpReplyContent(id)
{
    var text=$("CommentReplyContent"+id);
     if(text.value!="")
    {
        if(text.value.length>200)
        {
             alert("回复内容不能大于200个！");
             return;
        }
    }
    else
    {
         alert("回复内容不能为空！");
         return;
    }
    alert(wangluoyingxiao_ViewsList.CommentReply(id,text.value).value);
    //$("ReplyMent"+id).style.display="none";
    $("newcomment").innerHTML="正在加载";
    RefreshComment();
}
function CloseReplyContentDiv(id)
{
    var ReplyContent=$("ReplyContentDiv"+id);
    ReplyContent.style.display="none";
    $("CloseOpenDiv"+id).innerHTML="<a onclick=\"OpenReplyContentDiv("+id+")\">展开</a>";
}
function OpenReplyContentDiv(id)
{
    var ReplyContent=$("ReplyContentDiv"+id);
    ReplyContent.style.display="block";
    $("CloseOpenDiv"+id).innerHTML="<a onclick=\"CloseReplyContentDiv("+id+")\">收起</a>";
}
function RefreshComment()
{
    Request = {
    QueryString : function(item){
      var svalue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)","i"));
      return svalue ? svalue[1] : svalue;
    }
    }
    var id=Request.QueryString("ID");
     var param ="";
        var options = {
        method: 'post',
        parameters: param,
        onComplete:
            function(transport) {
                var retv = transport.responseText;
                    $("newcomment").innerHTML=retv;
                
            }
    }
    new Ajax.Request("/filehandle/NewComment.aspx?ArticleId="+id, options);
}
//创建遮罩层
	function AlertMsg(){
        var rv=wangluoyingxiao_ViewsList.jubaoLogin().value;
        if(rv=="-1"){
         var fromurl=window.location.href;
          alert('匿名用户不能对观点分享，请先登录能力秀');
          window.location.href="http://abc.wm23.com/login.aspx?from="+fromurl;
        }
        else
        {
        
	   /**第一步：创建DIV遮罩层。*/
		var sWidth,sHeight;
		sWidth = window.screen.availWidth;
		//屏幕可用工作区高度： window.screen.availHeight;
		//屏幕可用工作区宽度： window.screen.availWidth;
		//网页正文全文宽：     document.body.scrollWidth;
		//网页正文全文高：     document.body.scrollHeight;
		if(window.screen.availHeight > document.body.scrollHeight){  //当高度少于一屏
			sHeight = window.screen.availHeight;  
		}else{//当高度大于一屏
			sHeight = document.body.scrollHeight;   
		}
		//创建遮罩背景
		var maskObj = document.createElement("div");
		maskObj.setAttribute('id','BigDiv');
		maskObj.style.position = "absolute";
		maskObj.style.top = "0";
		maskObj.style.left = "0";
		maskObj.style.background = "#777";
		maskObj.style.filter = "Alpha(opacity=30);";
		maskObj.style.opacity = "0.3";
		maskObj.style.width = sWidth + "px";
		maskObj.style.height = sHeight + "px";
		maskObj.style.zIndex = "10000";
		document.body.appendChild(maskObj);

      
        /**第二步：动态设置div的上边距和左边距，使弹出div居中打开。*/
        var MyDiv =document.getElementById("MyDiv");
		var MyDiv_w = getStyle(MyDiv,"width");
		var MyDiv_h = getStyle(MyDiv,"height");
	    
		MyDiv_w = parseInt(MyDiv_w); //去掉 单位 "px"
		MyDiv_h = parseInt(MyDiv_h);

		var width = pageWidth(); 
		var height = pageHeight();
		var left = leftPosition();
		var top = topPosition();

		var Div_topposition = top + (height / 2) - (MyDiv_h / 2); //计算上边距
		var Div_leftposition = left + (width / 2) - (MyDiv_w / 2); //计算左边距

		MyDiv.style.left = Div_leftposition + "px";  //拼接上 单位"px"
		MyDiv.style.top =  Div_topposition + "px";
		MyDiv.style.display = "block";  //设置弹出div显示
		}
	}

		/**第三步：关闭窗口和遮罩层。*/
	function CloseDiv(){
		var Bigdiv = document.getElementById("BigDiv");
		var Mydiv = document.getElementById("MyDiv");
		document.body.removeChild(Bigdiv); 
		Mydiv.style.display="none";
	}
	  /** 第四步：弹出层拖动。*/ 
	 window.onload = function(){
	   if(document.getElementById("MyDiv")){
			var MyDiv = document.getElementById("MyDiv");
			var dragMe   = document.getElementById("dragMe");
			Drag.init(dragMe, MyDiv);
		}
	}

      /**第五步：弹出层跟随滚动条滚动。*/
	window.onscroll = window_onscroll;
	function window_onscroll(){
		var MyDiv =document.getElementById("MyDiv");
		var MyDiv_h = getStyle(MyDiv,"height");
		MyDiv_h = parseInt(MyDiv_h);
		var height = pageHeight();
		var top = topPosition();
		var Div_topposition = top + (height / 2) - (MyDiv_h / 2); //计算上边距
		MyDiv.style.top =  Div_topposition + "px";
	}

/**
下面都是常用函数，已经收录在我的jsskep.js中。可以在里面找到。
工程地址：http://code.google.com/p/jsskep/
**/
// 计算当前窗口的宽度 //
function pageWidth(){
			 return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

// 计算当前窗口的高度 //
function pageHeight(){
			 return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

// 计算当前窗口的上边滚动条//
function topPosition(){
			  return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

// 计算当前窗口的左边滚动条//
function leftPosition(){
			 return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

//解决外嵌样式style , 用js获取不到的问题。
function getStyle(elem, name){
			if(elem.style[name])
				return elem.style[name];
			else if(elem.currentStyle)	//ie
				return elem.currentStyle[name];
			else if(document.defaultView && document.defaultView.getComputedStyle){	//w3c
				name = name.replace(/([A-Z])/g,"-$1");
				name = name.toLowerCase();
				
				var s = document.defaultView.getComputedStyle(elem,"");
				return s && s.getPropertyValue(name);
			} else
				return null
}





