$(document).ready(function(){
	$("#ChkAll").click(function(){
		if($(this).attr("checked")==true){
			$("input[id='S_ID']").each(function(){
				$(this).attr("checked",true);									 
			})							
		}else{
			$("input[id='S_ID']").each(function(){
				$(this).attr("checked",false);									 
			})							
		}
	})
	$("#search").click(function(){
		var keyword=$("#keyword")[0].value;
		if(keyword==''){
			$("#keyword").css("border","1px solid red");return false;	
		}else{
			$("#form1").attr("action",'admin_article.php?action=listbysc&keyword=' + keyword);
			$("#form1").submit();
		}
	})
	
	$("#delallsel4").click(function(){
		$("#ClassIDs").show();
		$("#TopicID").hide();
	})
	
	$("#delallsel5").click(function(){
		$("#ClassIDs").hide();
		$("#TopicID").show();
	})
	
	$("#torun").click(function(){
		if(confirm('确定执行此操作吗?')){return true;}else{return false;}
	})

	$("span[id=topicsel]").bind("click",topicsel)
	

	
	function topicsel(){
		var s_id=$(this).attr("s_id");
		var topicid=$(this).attr("topicid");
		var topicName=$(this);
		var offset=topicName.offset();
		var topicTop=offset.top;
		var topicLeft=offset.left;
		creatediv(99997,250,20);
		var ShowDiv=$("#confirm");
		ShowDiv.css('border','1px solid #55BBFF').css('background','#C1E7FF').css('padding',' 3px 0px 3px 4px').css('top',topicTop-4+'px').css('left',topicLeft-100+'px').html('正在加载内容......');
		ShowDiv.load("js/ajaxfun.php?s_id="+s_id+"&types=2&action=topic&tid="+topicid);
	}

	function creatediv(z,w,h){
		$('<div id="adddiv"></div>')
        .css('top', '0')
		.css('width',document.documentElement.scrollWidth+"px")
		.css('height',document.documentElement.scrollHeight+"px")
		.css('z-index',z)
		.css('filter','Alpha(Opacity=0)')
		.css('position','absolute')
        .appendTo("body");
		
		$('<div id="confirm"></div>')
		.css('position','absolute')
		.css('z-index',z+1)
		.css('width',w+"px")
		.css('height',h+"px")
		.css('top','200px')
		.css('left','300px')
		.appendTo("body");
	}
	
})

function ShowStar(level,ids){
		   var htmlStr=""
			if(level==0){level=0}
			if (level>0){htmlStr+="<img src='images/starno.gif' border='0' style='cursor:pointer;margin-left:2px;' title='取消推荐' onclick='EditReco("+ids+",0)'/>"}
			for(i=1;i<=level;i++){
			htmlStr+= "<img src='images/star0.gif' border='0' style='cursor:pointer;margin-left:2px;'  title='推荐为"+i+"星级' id='star"+ids+"_"+i+"' onclick='EditReco("+ids+","+i+")' />"}
			for(j=level+1;j<=5;j++){
			htmlStr+= "<img src='images/star1.gif' border='0' style='cursor:pointer;margin-left:2px;'  title='推荐为"+j+"星级' id='star"+ids+"_"+j+"' onclick='EditReco("+ids+","+j+")' />"
	}
		   $("#S_Reco"+ids).html(htmlStr);
		   }
		   
function EditReco(ids,level){
  $.get(
	  "js/ajaxfun.php?id="+ids+"&types=1&level="+level+"&action=editreco", 
	  function(obj){
		  if(obj=='ok'){
			  ShowStar(level,ids);
		  }else{
			  $("#S_Reco"+ids).html("<font color='red'>Error!</font>");		
		  }
	  }
  );
} 

function ctopic(ids){
	var tid=$("#videotopicid").val();
	$.get( 
		  "js/ajaxfun.php?id="+ids+"&types=2&tid="+tid+"&action=topicsave", 
		  function(obj){
			  if(obj=='ok'){
				$("#confirm").remove(); 
				window.location='admin_article.php'
			  }else{
				$("#ss"+ids).html("<font color='red'>Error!</font>")
				  }
			  	  
			  }
		  );
	}
function closet(){
	$("#confirm").remove();
	}
	
function spango(id,url){
	$.post(''+url+'&id='+id,function (R){
		if(R=='ok'){
			$('#span'+id).remove();
			}				   
		 });
	}	