﻿function Search(){
	var $Keyword=$('#search-keyword').val();
		if($Keyword==""){
			return alert('关键字不能为空！');
		}
		$Keyword=$Keyword.replace(/\'/gi,"");
		$Keyword=$Keyword.replace(/\"/gi,"");
		$Keyword=$Keyword.replace(/\?/gi,"");
		$Keyword=$Keyword.replace(/\%/gi,"");
		$Keyword=$Keyword.replace(/\./gi,"");
		$Keyword=$Keyword.replace(/\*/gi,"");
		//return alert($Keyword);
	window.location.href="index.php?keyword="+encodeURI($.trim($Keyword));
}
function GetContent($ID)
{
	var $password=$('#password').val();
	if ($.trim($password)=='')
	{
		alert('请输入密码！');
		$('#password').focus();
		return false;
	}
	$.ajax({
		url:'index.php?interface=ajax.get.content&id='+$ID+'&password='+encodeURI($.trim($password)),
		type:'GET',
		success:function(){
			if (arguments[0]=='ERROR:PASSWORD')
			{
				alert('密码不正确！');
				$('#password').val("");
				$('#password').focus();
				return false;
			}
			$('.summary').html(arguments[0]);
		}
	});
}

function GetTVContent($ID)
{
	var $password=$('#password').val();
	if ($.trim($password)=='')
	{
		alert('请输入密码！');
		$('#password').focus();
		return false;
	}
	$.ajax({
		url:'tv.php?interface=ajax.get.content&id='+$ID+'&password='+encodeURI($.trim($password)),
		type:'GET',
		success:function(){
			if (arguments[0]=='ERROR:PASSWORD')
			{
				alert('密码不正确！');
				$('#password').val("");
				$('#password').focus();
				return false;
			}
			$('#caonima').html(arguments[0]);
		}
	});
}


function GetZJContent($ID)
{
	var $password=$('#password').val();
	if ($.trim($password)=='')
	{
		alert('请输入密码！');
		$('#password').focus();
		return false;
	}
	$.ajax({
		url:'zj.php?interface=ajax.get.content&id='+$ID+'&password='+encodeURI($.trim($password)),
		type:'GET',
		success:function(){
			if (arguments[0]=='ERROR:PASSWORD')
			{
				alert('密码不正确！');
				$('#password').val("");
				$('#password').focus();
				return false;
			}
			$('#caonima').html(arguments[0]);
		}
	});
}



function GetComment($ParentID){
	$.ajax({
		url:'index.php?interface=ajax.comment&parentid='+$ParentID,
		type:'GET',
		success:function(){
			$('#getcomment').html(arguments[0]);
			$("#commentuser").val(GetCookie('commentuser'));
			$("#commentmail").val(GetCookie('commentmail'));
		}
	});
}

function support($id)
{
	if (!GetCookie('comment_'+$id))
	{	
		$.ajax({
			url:'index.php?interface=ajax.comment.support&id='+$id,
			type:'GET',
			success:function(){
				$('#support_'+$id).html(arguments[0]);
				SetCookie('comment_'+$id,true,365);
			}
		});
	}else{
		alert('该评论您已经参与过辩论！');
	}
}
function against($id)
{
	if (!GetCookie('comment_'+$id))
	{	
		$.ajax({
			url:'index.php?interface=ajax.comment.against&id='+$id,
			type:'GET',
			success:function(){
				$('#against_'+$id).html(arguments[0]);
				SetCookie('comment_'+$id,true,365);
			}
		});
	}else{
		alert('该评论您已经参与过辩论！');
	}
}
function sendcomment($parentid)
{
	var $authcode	=$('#commentauthcode').val();
	/*
	if ($.trim($authcode)==''){
		alert('请您填写验证码！');
		$('#commentauthcode').focus();
		return false;
	}*/
	var $user=$('#commentuser').val();
	if ($.trim($user)==''){
		alert('请您填写昵称！');
		$('#commentuser').focus();
		return false;
	}
	var $mail=$('#commentmail').val();
	if ($.trim($mail)==''){
		alert('请您填写邮箱！');
		$('#commentmail').focus();
		return false;
	}
	var $text=$('#commenttext').val();
	if ($.trim($text)==''){
		alert('请您填写评论内容！');
		$('#commenttext').focus();
		return false;
	}
	if ($text.length>300){
		alert('对不起，评论内容不能超过300字！');
		return false;
	}
	SetCookie('commentuser',$user,365);
	SetCookie('commentmail',$mail,365);
	StopButton('commentsubmit',10);
	$.ajax({
		url:'index.php?interface=ajax.comment.ok&parentid='+$parentid+'&user='+encodeURI($user)+'&mail='+encodeURI($mail)+'&text='+encodeURI($text),/*+'&authcode='+parseInt($authcode),*/
		type:'GET',
		success:function(){
				//alert(arguments[0]);
				if (arguments[0]=='ERROR'){
					return alert('验证码出错！');
				}
			GetComment($parentid);
			$('#commenttext').val("");
		}
	});
	
}
function StopButton(){
	document.getElementById(arguments[0]).disabled=true;
	document.getElementById(arguments[0]).value="Submit("+arguments[1]+")";
	if(--arguments[1]>0){
		window.setTimeout("StopButton('"+arguments[0]+"',"+arguments[1]+")",1000);
	}
	if(arguments[1]<=0){
		document.getElementById(arguments[0]).value="Submit";
		document.getElementById(arguments[0]).disabled=false;
	}
}
function GetCookie(){
		var m='';
		if(window.RegExp)
		{
			var re=new RegExp(';\\s*'+arguments[0]+'=([^;]*)','i');
			m=re.exec(';'+document.cookie);
		}
		return(m?unescape(m[1]):'');
}
	
function SetCookie(){
	var $Date=new Date();
	var $Expires=($Date.setTime($Date.getTime()+(arguments[2]*86400000)));
	var $Time=$Date.toGMTString();
	var exp=';expires='+ $Time;
	document.cookie=arguments[0]+'='+escape(arguments[1])+exp+';path=/';
}

function Totop(){
	if (document.documentElement.scrollTop>0){
		for(var i=document.documentElement.offsetHeight;i>1;i-=Math.ceil(i/4)){
			window.scrollTo(0,i);
		}
	}
	window.scroll(0,0);
	return false;
}
function ResizeImages($Width){
 	var $Images=document.getElementsByTagName("img");
		for(var $I=0;$I<$Images.length;$I++){
			var $Image=new Image();
				$Image.src=$Images[$I].src;
				if ($Image.width>$Width)
				{
					$Images[$I].style.width=$Width+'px';
				}
				$Images[$I].ondblclick=function(){
					window.open(this.src);
				}
		}
}
function AddFavorite(sURL, sTitle){
	try{
		window.external.addFavorite(sURL, sTitle);
	}catch (e){
		try{
			window.sidebar.addPanel(sTitle, sURL, "");
		}catch (e){
		alert("加入收藏失败，请使用Ctrl+D进行添加");
		}
	}
}
// 消除link虚线效果
function autoBlur()
{ 
  if(event.srcElement.tagName=="A"||event.srcElement.tagName=="IMG") //html tag
  document.body.focus(); 
} 
  document.onfocusin=autoBlur;


// 弹窗效果
function view_img($img_id)
{
	var mask=$('<div />');
		mask.addClass('mask');
		mask.attr('id','mask');
		mask.height($(document).height()+"px");
		mask.appendTo('body');
	var box=$('<div />');
		box.addClass('box');
		box.attr('id','box');
		box.width("450px");
		box.height("550px");
		box.css('left',(document.documentElement.offsetWidth-450)/2);
		box.css('top',$(window).scrollTop()+10);
		box.appendTo('body');

		$.ajax({
			url:'#',
			type:'GET',
			success:function(){
			box.html(arguments[0]);
			$("#close_top,#close_bottom").click(function(){
					mask.remove();
					box.remove();		
			});
			}
		});

}
//add by pickle
function tv_comment($parentid)
{
	$.ajax({
		url:'tv.php?interface=ajax.comment&parentid='+$parentid,
		type:'GET',
		success:function(){
			//alert(arguments[0]);
			$('#tv_comment_list').html(arguments[0]);
		}
	});
}

function tv_comment_add($parentid)
{
	var $Z=$("#tv_comment_content").val();
	if ($.trim($Z)=='')
	{
		alert("您没有填写评论内容！");
		return;
	}
	var $X=$("#tv_comment_rank").val();
	//alert($X);
	$.ajax({
		url:'tv.php?interface=ajax.comment.add&parentid='+$parentid+"&content="+encodeURI($Z)+"&rank="+$X+"&time="+new Date().toString(),
		type:'GET',
		success:function(){
			//alert(arguments[0]);
			$("#tv_comment_content").val("");
			tv_comment($parentid)
		}
	});
}
function tv_comment_edit($parentid,$commentid)
{
	var mask=$('<div />');
		mask.addClass('mask');
		mask.height($(document).height()+"px");
		mask.appendTo('body');
	var box=$('<div />');
		box.addClass('box');
		box.width("700px");
		box.height("100px");
		box.css('left',(document.documentElement.offsetWidth-700)/2);
		box.css('top',$(window).scrollTop()+250);
		box.appendTo('body');
	    box.html('<table><tr><td><textarea style="margin:5px;width:600px;height:80px;" id="edit_tv_comment_content"></textarea></td><td><input type="button" id="edit_comment_button" value="修改" /></td></tr></table>');
		$("#edit_tv_comment_content").val($("#_"+$commentid).html());
		mask.click(function(){
			mask.remove();
			box.remove();
		});
		$("#edit_comment_button").click(function(){
			var $Z=$("#edit_tv_comment_content").val();
			if ($.trim($Z)=='')
			{
				alert("您没有填写评论内容！");
				return;
			}
			$.ajax({
			url:'tv.php?interface=ajax.comment.edit&id='+$commentid+"&content="+encodeURI($Z)+"&time="+new Date().toString(),
			type:'GET',
			success:function(){
				tv_comment($parentid);
				mask.remove();
				box.remove();
				}
			});			
		});
}

function tv_comment_delete($parentid,$commentid)
{
	if (confirm("您真的要删除吗？"))
	{
		$.ajax({
			url:'tv.php?interface=ajax.comment.delete&id='+$commentid+'&time='+new Date().toString(),
			type:'GET',
			success:function(){
				//alert(arguments[0]);
				tv_comment($parentid);
			}
		});
	}
}

//add by pickle
function zj_comment($parentid)
{
	$.ajax({
		url:'zj.php?interface=ajax.comment&parentid='+$parentid,
		type:'GET',
		success:function(){
			//alert(arguments[0]);
			$('#zj_comment_list').html(arguments[0]);
		}
	});
}

function zj_comment_add($parentid)
{
	var $Z=$("#zj_comment_content").val();
	if ($.trim($Z)=='')
	{
		alert("您没有填写评论内容！");
		return;
	}
	var $X=$("#zj_comment_rank").val();
	//alert($X);
	$.ajax({
		url:'zj.php?interface=ajax.comment.add&parentid='+$parentid+"&content="+encodeURI($Z)+"&rank="+$X+"&time="+new Date().toString(),
		type:'GET',
		success:function(){
			alert(arguments[0]);
			$("#zj_comment_content").val("");
			zj_comment($parentid)
		}
	});
}
function zj_comment_edit($parentid,$commentid)
{
	var mask=$('<div />');
		mask.addClass('mask');
		mask.height($(document).height()+"px");
		mask.appendTo('body');
	var box=$('<div />');
		box.addClass('box');

		box.width("700px");
		box.height("100px");
		box.css('left',(document.documentElement.offsetWidth-700)/2);
		box.css('top',$(window).scrollTop()+250);
		box.appendTo('body');
	    box.html('<table><tr><td><textarea style="margin:5px;width:600px;height:80px;" id="edit_zj_comment_content"></textarea></td><td><input type="button" id="edit_comment_button" value="修改" /></td></tr></table>');
		$("#edit_zj_comment_content").val($("#_"+$commentid).html());
		mask.click(function(){
			mask.remove();
			box.remove();
		});
		$("#edit_comment_button").click(function(){
			var $Z=$("#edit_zj_comment_content").val();
			if ($.trim($Z)=='')
			{
				alert("您没有填写评论内容！");
				return;
			}
			$.ajax({
			url:'zj.php?interface=ajax.comment.edit&id='+$commentid+"&content="+encodeURI($Z)+"&time="+new Date().toString(),
			type:'GET',
			success:function(){
				zj_comment($parentid);
				mask.remove();
				box.remove();
				}
			});			
		});
}

function zj_comment_delete($parentid,$commentid)
{
	if (confirm("您真的要删除吗？"))
	{
		$.ajax({
			url:'zj.php?interface=ajax.comment.delete&id='+$commentid+'&time='+new Date().toString(),
			type:'GET',
			success:function(){
				//alert(arguments[0]);
				zj_comment($parentid);
			}
		});
	}
}
//add by pickle
function art_comment($parentid)
{
	//alert($parentid);
	$.ajax({
		url:'art.php?interface=ajax.comment&parentid='+$parentid,
		type:'GET',
		success:function(){
			//alert(arguments[0]);
			$('#art_comment_list').html(arguments[0]);
		}
	});
}

function art_comment_add($parentid)
{
	var $Z=$("#art_comment_content").val();
	if ($.trim($Z)=='')
	{
		alert("您没有填写评论内容！");
		return;
	}
	var $X=$("#art_comment_rank").val();
	//alert($X);
	$.ajax({
		url:'art.php?interface=ajax.comment.add&parentid='+$parentid+"&content="+encodeURI($Z)+"&rank="+$X+"&time="+new Date().toString(),
		type:'GET',
		success:function(){
			//alert(arguments[0]);
			$("#art_comment_content").val("");
			art_comment($parentid)
		}
	});
}
function art_comment_edit($parentid,$commentid)
{
	var mask=$('<div />');
		mask.addClass('mask');
		mask.height($(document).height()+"px");
		mask.appendTo('body');
	var box=$('<div />');
		box.addClass('box');
		box.width("700px");
		box.height("100px");
		box.css('left',(document.documentElement.offsetWidth-700)/2);
		box.css('top',$(window).scrollTop()+250);
		box.appendTo('body');
	    box.html('<table><tr><td><textarea style="margin:5px;width:600px;height:80px;" id="edit_art_comment_content"></textarea></td><td><input type="button" id="edit_comment_button" value="修改" /></td></tr></table>');
		$("#edit_art_comment_content").val($("#_"+$commentid).html());
		mask.click(function(){
			mask.remove();
			box.remove();
		});
		$("#edit_comment_button").click(function(){
			var $Z=$("#edit_art_comment_content").val();
			if ($.trim($Z)=='')
			{
				alert("您没有填写评论内容！");
				return;
			}
			$.ajax({
			url:'art.php?interface=ajax.comment.edit&id='+$commentid+"&content="+encodeURI($Z)+"&time="+new Date().toString(),
			type:'GET',
			success:function(){
				//alert(arguments[0]);
				art_comment($parentid);
				mask.remove();
				box.remove();
				}
			});			
		});
}

function art_comment_delete($parentid,$commentid)
{
	if (confirm("您真的要删除吗？"))
	{
		$.ajax({
			url:'art.php?interface=ajax.comment.delete&id='+$commentid+'&time='+new Date().toString(),
			type:'GET',
			success:function(){
				//alert(arguments[0]);
				art_comment($parentid);
			}
		});
	}
}