var content_hint='';
var content_pattern="^.{20,200}$";
var name_hint='';
var name_pattern="^.{4,20}$";
jQuery(document).ready(function(){
	load_sys();
	$("#yzm_img").click(function(){
		change_pic();						
	});
	$(".input_submit").focus(function(e){
		var input_name = $(e.target).attr("name");
		var offset2=$(e.target).offset();
		eval("var HINT=" + input_name+"_hint");
		show_hint('1');
		return false;
	});
	$("#comm_content").focus(function(e){
		if($(e.target).val()=='Type your comment here. 20 letters at least.'){
			$(e.target).val('');
			$(e.target).css('color','#000');
		}
	})
	$("#comm_content").blur(function(e){	
		if($(e.target).val()==''){
			$(e.target).val('Type your comment here. 20 letters at least.')
			$(e.target).css('color','#993300');
		}
	})
	$("input[name='submit']").click(function(e){
		var offset2=$(e.target).offset();
		$(".input_submit").blur();
		if($(".show_error").length>0){
			show_hint(input_invalid_hint,offset2.left-80,offset2.top-30,0,'show_page_hint');
			return false;	
		}
		show_hint(wait_process_hint,offset2.left-80,offset2.top-30,1,'show_page_hint');
		$.post("/proc/_comm.php",form_submit_date("form1"),function(a){
			eval(a);
			show_hint(hint,offset2.left-80,offset2.top-30,0,'show_hint_no');
		});
		clear_hint();
		document.getElementById('form1').reset();
	});
	list_comm();
})
function list_comm(page){
	var news_id = $('#news_id').val();
	$('#comm_list').load('/proc/_comm_list.php?news_id='+news_id+'&page='+page,function(){
		$('.xpages a').click(function(e){
			var page2 = $(e.target).attr('href');
			list_comm(page2);
			return false;
		});
		$('.vote_c').click(function(e){
			if(document.cookie.indexOf("cookie[vote_c"+$(e.target).attr("name")+"]")==-1){
				var offset=$(e.target).offset();	
				$.get('/proc/_vote_comm.php?id='+$(e.target).attr("name")+'&vote=1',function(a){															
					if(a=='SUCCESS'){
						show_hint(vote_hint,offset.left-10,offset.top+15,1);
						var vote_e = $(e.target).parent().prev().prev();
						vote_e.html(parseInt(vote_e.html())+1);
					}else{
						show_hint(has_voted,offset.left-10,offset.top+15,1);
					}
				});
			}else{
				show_hint(has_voted,offset.left-10,offset.top+15,1);
			}
			return false;					  
		});	
		$('.bury_c').click(function(e){
			var offset=$(e.target).offset();	
			if(document.cookie.indexOf("cookie[vote_c"+$(e.target).attr("name")+"]")==-1){
				$.get('/proc/_vote_comm.php?id='+$(e.target).attr("name")+'&vote=-1',function(a){	
					if(a=='SUCCESS'){
						var vote_e = $(e.target).parent().prev().prev();
						vote_e.html(parseInt(vote_e.html())-1);
					}else{
						show_hint(has_buried,offset.left-10,offset.top+15,1);
					}
				});
			}else{
				show_hint(has_buried,offset.left-10,offset.top+15,1);
			}
			return false;
		});		
	});
}
