$(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;
		keyword=encodeURI(keyword);
		if(keyword==''){
			$("#keyword").css("border","1px solid red");return false;	
		}else{
			$("#form1").attr("action",'admin_video.php?action=listbysc&keyword=' + keyword);
			$("#form1").submit();
		}
	})
	
	
	$("#torun").click(function(){
		if(confirm('确定执行此操作吗?')){return true;}else{return false;}
	})

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

function trim(str,filter){
	var len
	len=filter.length;
	if(str.substr(0,len)==filter){
		str=str.substr(len)
		}
	if(str.substr(str.length-len)==filter){
		str=str.substr(0,str.length-len)
		}
	return str
}	

	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=1&action=topic&tid="+topicid);
	}
	
	function remarksel(){
		var s_id=$(this).attr("r_id");
		var rid=$(this);
		var offset=rid.offset();
		var topicTop=offset.top;
		var topicLeft=offset.left;
		creatediv(99997,250,20);
		var ShowDiv=$("#confirm");
	}
	

	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=0&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=1&tid="+tid+"&action=topicsave", 
		  function(obj){
			  if(obj=='ok'){
				  $("#confirm").remove(); 
				  if(tid==0){
					  $("#ss"+ids).find("img").attr('src','images/topicno.gif');
				  }else{
				      $("#ss"+ids).find("img").attr('src','images/topicyes.gif');
				  }
			  }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();
			}				   
		 });
	}