//pic resize
function DrawImage(_s, _w, _h)
{
	var image = new Image(); 
	image.src = _s.src; 
	if(image.width > _w || image.height > _h)
	{
	    var cw = 0;
	    var ch = 0;
	    
	    cw = _w;
	    ch = (image.height*_w)/image.width;
	    if(ch > _h)
	    {
	        cw = (cw*_h)/ch;
	        ch = _h;
	    }
	    
	    _s.width = cw;
		_s.height = ch;
	}
}

 // 收藏
 function shouCang(rid,type,rname)
{
    var uid=getCookie("UGID");
    var k = Math.random()*100;
    if(uid!=null&&uid!=0){show("chouChangDiv");getListDataSource("Iface/resFav.aspx?res_id="+rid+"&type="+type+"&res_name="+rname+"&k="+k);}
    else{alert("请您先登陆!"); setTimeout("window.location.href='http://club.joyes.com/user/login.aspx';",50);}  
}
 function getCookie(cookieName) 
    {
	var cookieString = document.cookie;
	var start = cookieString.indexOf(cookieName + '=');
	if (start == -1)
	return null;
	start += cookieName.length+1;
	var end = "";
	if(cookieString.indexOf('&', start)>-1&&cookieString.indexOf(';', start)>-1)
	{
		end =cookieString.indexOf('&', start)>cookieString.indexOf(';', start)?cookieString.indexOf(';', start):cookieString.indexOf('&', start); 
	}else
	{
	    end =cookieString.indexOf('&', start)>-1?cookieString.indexOf('&', start):cookieString.indexOf(';', start);
	}
	if (end == -1)
	{
	end = cookieString.indexOf(';', start);
	if (end == -1) return unescape(cookieString.substring(start));
	}
	return unescape(cookieString.substring(start, end));
    }
 function WriteCookie(CookieName,CookieValue,time)
    {
     var expires = new Date(); 
     expires.setTime(expires.getTime() + time*1000);
     document.cookie = CookieName+'='+CookieValue+';expires=' + expires.toGMTString()+';';
    }
//默认选中
function Selected(obj,value)
{
  for(var i=0;i<document.getElementById(obj).options.length;i++)
        { 
         if(document.getElementById(obj).options[i].value==value)
         {
            document.getElementById(obj).options[i].selected=true;break;
         }   
       }
}
//转载资源
function resCite(res_id,type_id,user_id)
{
    if(getCookie("UGID") != null && getCookie("UGID") != "")
    {
        getListDataSource("Iface/CiteRes.aspx?res_id="+res_id+"&type_id="+type_id+"&user_id="+user_id);
        show("citeResDiv");
    }
    else
    {
        setTimeout("window.location.href='http://club.joyes.com/user/login.aspx';",50);
        return;
    }
}

function resCiteClose()
{
 document.getElementById("citeResDiv").style.display="none";
}
// 自动 COPY 代码开始 
function copyCode1(o){o.select();var js=o.createTextRange();js.execCommand("Copy");} 
// 自动 COPY 代码结束
function up(id, flg, cur, num, type_id)
{ 
    if(getCookie("UPResIDs")==null||getCookie("UPResIDs")=="")
    {
        WriteCookie("UPResIDs","|");
    }
    var res_idList = getCookie("UPResIDs");
    if(res_idList!=null&&res_idList.indexOf(id+"|")>-1)
    {
        if(flg == 1)
        {
            alert("请您稍后再顶!");return;
        }
        else
        {
            alert("请您稍后再踩!");return;
        }
    }
    else
    {
        var k = Math.random()*100;
        getListDataSource("Iface/IUpTop.aspx?k="+ k +"&res_id="+ id +"&up="+ flg +"&type_id="+ type_id +"");
        
        var temp = getCookie("UPResIDs") + id + "|";
        WriteCookie("UPResIDs",temp,"3600");
        
        if(cur < 0)
        {
            cur = 0;
        }
        if(num < 0)
        {
            num = 0;
        }
        var curUp = 0;
        var curDown = 0;
        var curGlv = "";
        var curDlv = "";
        if(flg == 1)
        {
            //up
            num = num + 1;
            curUp = cur + 1;
            curDown = num - curUp;
        }
        else
        {
            //down
            num = num + 1;
            curDown = cur + 1;
            curUp = num - curDown;
        }
        curGlv = theme.joyes.com.ThemeInfo.ajaxGetPercent(curUp, num).value;
        curDlv = theme.joyes.com.ThemeInfo.ajaxGetPercent(curDown, num).value;
        //
        document.getElementById("good_linebar").style.width = curGlv;
        document.getElementById("good_pbar").innerHTML = ""+ curGlv +"(<a id=\"topUpCounts\">"+ curUp +"</a>)";
        //
        document.getElementById("bad_linebar").style.width = curDlv;
        document.getElementById("bad_pbar").innerHTML = ""+ curDlv +"(<a id=\"topDownCounts\">"+ curDown +"</a>)";
    }
}

//提交举报
function ReportSub(url,res_id,object_uid,type_id)
{
  var uid=getCookie("UGID");
  if(uid==null||uid==0){alert("请您先登陆!");  setTimeout("window.location.href='http://club.joyes.com/user/login.aspx';",50);return;}
  var r= document.getElementById("ReportList").value;
  getListDataSource("Iface/Report.aspx?url="+escape(url)+"&r="+r+"&res_id="+res_id+"&puid="+object_uid+"&type_id="+type_id);
  close('reportSelectDiv');
}
//收藏或者转载提示页面弹出
 var obj = document.documentElement;
var w = obj.scrollWidth;
var h = window.screen.height;
function show(div1) {
window.onscroll = function() {document.getElementById(div1).style.top = (obj.scrollTop + 100) + "px";};
document.getElementById(div1).style.display = "block";
document.getElementById(div1).style.top = (obj.scrollTop + 100) + "px";
}

function close(div1) {
document.getElementById(div1).style.display = "none";
window.onscroll = null;
}
//评论的支持和反对
function commentUp(id,up,type_id,num)
{ 
 if(getCookie("CommentUPIDs")==null||getCookie("CommentUPIDs")=="")
   {
   WriteCookie("CommentUPIDs","|");
   }
   var res_idList= getCookie("CommentUPIDs");
   if(res_idList!=null&&res_idList.indexOf(id+"|")>-1)
   {
    alert("请不要频繁点击！");return;
   }else{
          var k = Math.random()*100;
          getListDataSource("Iface/CommentUp.aspx?k="+k+"&id="+id+"&up="+up+"&type_id="+type_id);  
            var temp=getCookie("CommentUPIDs")+id+"|";
          WriteCookie("CommentUPIDs",temp,"3600");
             if(up==1)
            {
            document.getElementById("commentUp"+id).innerHTML="支持["+(num+1)+"]";
            alert("支持！");return;
            }else
            {
            document.getElementById("commentDown"+id).innerHTML="反对["+(num+1)+"]";
             alert("反对！");return;
            }
        }
}