//ajax文件
//var file="http://news.99ys.com/article.php"
var file="../article.php"
//随机数 
var rand=Math.random()*(200-50);

//头部搜索框
function get_value(id){
				input_id=document.getElementById("search_"+id).value;
				for(i=1;i<7;i++){
					var val=document.getElementById("search_"+i);
						val.value=input_id;
				}
			}
//搜索按钮
function searchn(id){
			if(id==""){ alert("请选择要搜索的频道！！"); return false;}
				key=document.getElementById("search_"+id);
				key_value=encodeURI(key.value)
			if(key_value==""){ alert("请填写要搜索的内容！！"); return false;}
				switch(id){
					case 1:
					window.location.href='http://news.99ys.com/search.php?key='+key_value;
					break;
					case 2:
					window.location.href='http://news.99ys.com/search.php?key='+key_value;
					break;
					case 3:
					window.location.href='http://exhibit.99ys.com/search/exhibit/'+key_value;
					break;
					case 4:
					window.location.href='http://gallery.99ys.com/search/gallery/'+key_value;
					break;
					case 5:
					window.location.href='http://auction.99ys.com/search/auction/'+key_value;
					break;
					case 6:
					window.location.href='http://artist.99ys.com/search/artist/'+key_value;
					break;
					default :
					window.location.href='http://news.99ys.com/search.php?key='+key_value;
					break;
				}
}

function get_search() {
	var id = document.getElementById('search_id').value;

	if(!id) {
		alert('请选择要搜索的频道！');	
		return false;
	}
	key = encodeURI(keyword.value);
	if(!key) {
		alert('请输入关键字');
		return false;
	}
	switch(parseInt(id)){
		case 1:
			window.location.href='http://news.99ys.com/search.php?key='+key;
		break;
		case 2:
			window.location.href='http://news.99ys.com/search.php?key='+key;
		break;
		case 3:
			window.location.href='http://exhibit.99ys.com/search.php?keyword='+key;
		break;
		case 4:
			window.location.href='http://gallery.99ys.com/search/gallery/'+key;
		break;
		case 5:
			window.location.href='http://auction.99ys.com/search/auction/'+key;
		break;
		case 6:
			window.location.href='http://artist.99ys.com/search/artist/'+key;
		break;
		default :
			window.location.href='http://news.99ys.com/search.php?key='+key;
		break;
	}
}
$(document).ready(function(){
	//加载验证码
	createCode();
	//评论分页
	//当前页面id
	//var nonce=
	//alert( $("select[@name=page_select] option[@selected]").val());
	$("[@name=page_select]").change(function(){
		alert($(this).val());
	})
	//$("select[@name=page_select] option[@selected]").val(); 
	//$("#comment_ajax").html();
	
	
})



	var code ; 
     function createCode() {      
       code = "";     
       var codeLength = 4;
       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 (page_title_id){     
       var inputCode = document.getElementById("input1").value;  
       if(inputCode.length <=0)  {     
           alert("请输入验证码");
           return false;     
       }     
       else if(inputCode != code ){    
          alert("验证码错误");     
          createCode();
          return false;      
       }else { 
       	subt(page_title_id);
         return true;     
         
       }     
            
       }   
         //提交评论
	function subt(page_title_id){
		//当前页数
		var con_page=$("select[@name=page_select] option[@selected]").val();
		//新闻id
		var id=$(".review_text_content2").attr('id');
		var tid=$("#tid").val();
		//评论内容
		var content=$(".review_text_content2").val();
		//评论者
		var petname=$("input[name=petname]").val();
		$.trim(petname);
		if(petname.length>15){alert("对不起 昵称长度最多十五");return false;}
		if(content==''){alert("评论内容不能为空!!");return false;}
		$.ajax({
                url: file,
                type:'POST',
                complete :function(){}, 
                dataType: 'json',
                data: {action:'sumbit_comment',id:id,content:content,rand:rand,page_title_id:page_title_id,petname:petname,tid:tid},
                error: function() { alert('Ajax request 發生錯誤');},
                success: function(response) {
	                if(response==0){
	                	alert("对不起，您的评论失败！");
	                	return false;
	                }else{
	                	alert("评论成功 感谢！");
	                	  window.location.href=window.location.href;
	                	return true;
	                }
                }
           });
	}
     



	function list_page(id,page,count,onepage,listname){
		var pagecount=Math.ceil(count/onepage);
		if(pagecount==1){return false;}
		if(listname=='content' || listname=='image_article'){ 
			var page_file='http://news.99ys.com/article.php'; 
		}else if(listname=='image' || id.length>2 || listname=='news_list'){
			var page_file='http://news.99ys.com/list.php'; 
		}else if(listname == 'critical_list') {
			var page_file = 'http://critical.99ys.com/list.php';
		}else{
			var page_file='http://news.99ys.com/list.php';
		}
		if(id=='all' || id=='focus' || id=='chief'){var page_file='interview.php';}
		var url=this.location.href;
		$.ajax({
                url: page_file,
                type:'POST',
                complete :function(){}, 
                dataType: 'json',
                data: {id:id,page:page,count:count,onepage:onepage,listname:listname,rand:rand,url:url},
                error: function() { alert('Ajax request 发生错误');},
                success: function(response) {
                	if(id=='all' || id=='focus' || id=='chief'){
                		switch(id){
                		case 'all':
                			var r_id='con_twelve_1';
                			break;
                		case 'focus':
                			var r_id='con_twelve_2';
                			break;
                		case 'chief':
                			var r_id='con_twelve_3';
                			break;
             			}
             			$(document.getElementById(r_id)).html(response.list);
                		return false;
                	}else if(listname=='image_article'){
                		$("#list_ajax_image").html(response.list);
	               		$("#page_breaks_image").html(response.page_breaks);
	               		return false;
                	}else if(listname=='critical_list'){
                		$("#listbox").html(response);
                		return false;
                	}
                	
	                $("#list_ajax").html(response.list);
	               	$("#page_breaks").html(response.page_breaks);
                }
           });
	}
	
	function cri_list_page(id,page,count,onepage,listname){
		$("#con_menu > a").removeClass();
		$("#con_menu > a").addClass("listtab");
		$("#"+id).removeClass();
		$("#"+id).addClass("lbhover");
		
		var img_name = '';
		switch(id) {
			case '15' :
				img_name = 'xsgd.jpg';
			break;
			case '16' :
				img_name = 'scjd.jpg';
			break;
			case '17' :
				img_name = 'zlgc.jpg';
			break;
			case '18' :
				img_name = 'zppl.jpg';
			break;
			case '19' :
				img_name = 'ryjd.jpg';
			break;
		}
		document.images['img_title'].src = 'http://z.99ys.com/critical/'+img_name;
		
		var url=this.location.href;
		$.ajax({
                url: 'http://critical.99ys.com/cri_list.php',
                type:'POST',
                complete :function(){}, 
                dataType: 'json',
                data: {id:id,page:page,count:count,onepage:onepage,listname:listname,rand:rand,url:url},
                error: function() { alert('Ajax request 发生错误');},
                success: function(response) {
					$("#listbox").html(response);
                }
           });
	}
	
	function article_image_page(id,page,count,onepage){
		if(page==1){ window.location.href=this.location.href; return false;}
		var url=this.location.href;
		if(url.indexOf('critical')==-1){ var file="http://news.99ys.com/article_image.php";}else{
			var file="http://critical.99ys.com/article_image.php";
		}
		$.ajax({
                url: file,
                type:'POST',
                complete :function(){}, 
                dataType: 'json',
                data: {id:id,page:page,count:count,onepage:onepage,rand:rand,url:url},
                error: function() { alert('Ajax request 发生错误');},
                success: function(response) {
					$("#image_main").html(response.image);
					$("#image_page").html(response.image_page);
					$("#image_page1").html(response.image_page);
					return true;
                }
           });
	}
	

	

	