$(document).ready(function(){
	//加载验证码
	createCode();
});

var rand=Math.random()*(200-50);
function list_page(type,page,count,onepage,category){
	if(page==1){ window.location.href=window.location.href; return;}
	var path;
	switch(category){
		case 'publish_article':
			path='../../';
			break;
		default :
			path='';
			break;
	}
	$.ajax({
                url: path+"publish.php",
                type:'POST',
                complete :function(){}, 
                dataType: 'json',
                data: {type:type,page:page,count:count,onepage:onepage,category:category,rand:rand},
                error: function() { alert('Ajax request 发生错误');},
                success: function(response) {
                	if(category=='publish_article'){ 
                		$('#comment_page').html(response); return true;}
                	$('#con_six_1').html(response.list);
                	return;
                }
});
}


var code ; 
function createCode() {      
       code = "";     
       var codeLength = 6;
       var checkCode = document.getElementById("checkCode");     
       var selectChar = new Array(0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
	   for(var i=0;i<codeLength;i++) {      
       var charIndex = Math.floor(Math.random()*36);     
       code +=selectChar[charIndex];                
       }  
       if(checkCode){     
         checkCode.className="code";     
         checkCode.value = code;     
	}      
} 
function validate (id){     
  var inputCode = document.getElementById("input1").value;  
   if(inputCode.length <=0)  {  
     alert("请输入验证码");
     return false;     
   }else if(inputCode != code ){    
         alert("验证码错误");     
		createCode();
         return false;      
   }else { 
   		sumbit_comment(id);
       return true;     
   }     
} 

function sumbit_comment(id){
	//评论内容
	var content=$(".review_text_content2").val();
	if(content==''){alert("评论内容不能为空!!");return false;}
	
	//评论者
	var petname=$("input[name=petname]").val();
	$.trim(petname);
	if(petname.length>15){alert("对不起 昵称长度最多十五");return false;}
	
	$.ajax({
		url:'../../publish.php',
		type:'POST',
		dataType: 'json',
		data: {type:'sumbit',id:id,petname:petname,content:content},
		success: function(response) {
			if(response>0){
				$.get("../../../admin/main.php",{name:'static',action:'publish',c:'per_article', id:id}, function(data){
	              	if(data.length>0){
	              		alert("评论成功！感谢");
	              		window.location.href=window.location.href;}else{alert("对不起评论失败");}
	             }); 
			}else{ alert("对不起！评论失败！");return false;}
		}
	});
	
}

function get_per_month(id,year){
	if(year==0){ $('#month_sel').html('<option value="0">--请选择月份--</option>'); return false;}
	$.post("../../publish.php",{type:'per_month',id:id,year:year}, function(data){
		$('#month_sel').html(data);
		return ;
	});
}

function read_online_page(page,onepage,count){
	var id=$("#id").val();
	var nu='';
	$.ajax({
		url:'../publish.php',
		type:'POST',
		dataType: 'json',
		data: {type:'read_online',id:id,page:page,onepage:onepage,count:count},
		success: function(response) {
			$(".Pro_Images").html(response.image);
			$("#online_page").html(response.page_breaks);
			$("#page_a").html(response.page_breaks_a);
			$(".Pro_BigImage").html(nu);
			$("input[name=page_jq]").val(page);
			aaa();
		}
	});
}

function mag_do(id,act){
	$.post("../publish.php",{type:'mag_'+act,id:id}, function(data){
		$('#hdbox').html(data);
		return ;
	});
}
function mag_do_r(){
	alert("您已经参与了！");
}

function per_catelog(){
	var year=$("select[name=year]").val();
	var month=$("select[name=month]").val();
	var n_id=$("input[name=n_id]").val();
	if(year<1990 || month<1){ alert("请选择期号！"); return false;}
	window.location.href='http://magazine.99ys.com/periodical/per_'+n_id+'/catalog_'+month+'.shtml';
	return false;
}