/**
 * 
 */

var saveurl;
var impression;
function souc(url,sctype){
	saveurl = url;
	impression = sctype;
	var newid = $("#scnewid").val();
	var maskWidth = $(window).width();
	var dialogLeft = (maskWidth/2) - ($('#idBox').width()/2); 
	var dialogTop = ($(window).height() - $('#idBox').height())/2 + $(document).scrollTop(); 
	var sctitle=$("#sctitle").val();
	$('#idBox').css({top:dialogTop, left:dialogLeft}).show();
	
	$.ajax({
		type:"get", 
		url:"/News/shoucang.php?type="+impression+"&newid="+newid,
		success:function(res){
			$('#ajaxstr').html(res);
			if(sctype == 2){
				$("#title").val(sctitle);
				$("#scurl").val(saveurl);
			}
		},
		error:function(){
			$('#ajaxstr').html("连接到服务器失败！");
		}
	})

}

function hidde(){
	$("#idBox").hide();
}
function login(){
	var	username=$("#txtEmail").val();
	var	password=$("#txtPwd").val();
	$.ajax({
		type:"post", 
		url:"/js/ajax.php?script=USERNORMAL,Login.html",   
	data:{
		username:username,
		password:password,
		loginIp:"unknow"
	},
	dataType:"json",
	success:function(res){
		if(res[0].errcode == 0){
			souc(saveurl,impression);
		}else{
			alert("用户名或密码错误！");
		}
	},
	error:function(){
		alert("登录失败！");
	}
	})
}
function addsc(){
	var	userid=$("#userid").val();
	var newid = $("#scnewid").val();
	var	title=$("#title").val();
	var	scurl=$("#scurl").val();
	var	miaoshu=$("#miaoshu").val();
	var	collecttypeid=$("#collecttypeid").val();
	var	addtype=$("#addtype").val();
	var	ispublic= $("#ispublic").attr("checked");
	var setpublic = 0
	if(ispublic == true)
		setpublic = 1;
	//添加分类
	if(collecttypeid==0 && addtype !=''){
$.ajax({
		type:"post", 
		url:"/js/ajax.php?script=collect,save.html",   
	data:{
		type:1,
		userid:userid,
		typename:addtype
	},
	dataType:"json",
	success:function(res){
		if(res[0].errcode == 0){
			alert("新增分类成功！");
			souc(saveurl,impression);
			$("#title").val(title);
			$("#scurl").val(scurl);
			$("#miaoshu").val(miaoshu);
		}else{
			alert("新增分类失败！");
		}
	},
	error:function(){
		alert("新增分类失败！");
	}
})
	}else{
$.ajax({
		type:"post", 
		url:"/js/ajax.php?script=collect,save.html",   
	data:{
		type:3,
		userid:userid,
		newid:newid,
		typeid:5,
		savetitile:title,
		saveurl:scurl,
		savedesc:miaoshu,
		collecttypeid:collecttypeid,
		ispublic:setpublic,
		impression:impression
	},
	dataType:"json",
	success:function(res){
		if(res[0].errcode == 0){
			alert("收藏成功！");
			$("#idBox").hide();
		}else{
			alert("收藏失败！");
		}
	},
	error:function(){
		alert("收藏失败！");
	}
})		
	}
}

//记录访问
function addvistor(impression)
{
	var newid= $("#newid").val();
    var uid = $("#uid").val();
    var recommend=1;
	
	if(!uid)
		return ;
$.ajax({
type:"post", 
url:"/js/ajax.php?script=THIRD,Add.html",   
data:{
	userid:uid,
	newid:newid,
	impression:impression,
	recommend:recommend
},
dataType:"json",
success:function(res)
{
},
error:function()
{
}
})
}

//newthird 新闻的访问用户
function newthird()
{
	addvistor(5);
	
	var newid=document.getElementById("newid").value;
	var sort = "desc";
	var filter = "and t1.newid="+newid;
	var pageIndex=0;
	var pageSize=7;
	var field="t1.userid";
$.ajax({ 
type:"post", 
url:"/js/ajax.php?script=newThird,List.html",   
data:{
	pageSize:pageSize,
	filter:filter,
	field:field,
	sort:sort,
	pageIndex:pageIndex
},
dataType:"json",
success:function(res)
{  
	var liststr="";
	if(res[0]._itemrecord>0)
		{
		for(var i=0;i<res[0]._itemrecord;i++)
			{
			    var userphoto=res[0]._modellist[i].userphoto;
			    var uid=res[0]._modellist[i].userid;
			    if(uid==0)
			    {
			    	userphoto="/images/ads/ads5.jpg";
					liststr+="<a href=\"#\" class=\"Phead\"><img src=\""+userphoto+"\" /><span>"+res[0]._modellist[i].usernickname+"</span></a>";
			    }else{
					liststr+="<a href=\"/home/home.php?uid="+uid+"\" class=\"Phead\"><img src=\""+userphoto+"\" /><span>"+res[0]._modellist[i].usernickname+"</span></a>";
				}
			}
		}
	
	document.getElementById("CorrPeople").innerHTML=liststr;
},
error:function()
{

}
})
}

function display($btnID,$divID)
{
	var btn=document.getElementById($btnID);
	var div=document.getElementById($divID);
	
	
	
	btn.style.color="red";
	btn.style.display="";
}

//搜索
function sousuo()
{
	var keyword= document.getElementById("ssk").value;
	if(keyword != ""){
		keywordadd(keyword);
		window.location.href="/News/index.php?keyword="+keyword;
	}else{
		alert("请输入搜索关键词");
	}
}

//keywordadd 搜索关键字添加
function keywordadd(keyword)
{
	$.ajax({
type:"post", 
url:"/js/ajax.php?script=keyWord,Add.html",   
data:{
	keyword:keyword,
	newtype:1,
	channelid:0
},
dataType:"json",
success:function(res)
{  
	
},
error:function()
{
}
})
}

//下载排行列表
/*
function downloadlist()
{
	var sort = "desc";
	var filter = "";
	var pageIndex=0;
	var pageSize=20;
	var field="downclick";
$.ajax({ 
type:"post",   
url:"/js/ajax.php?script=DOCS,List.html",   
data:{
	pageSize:pageSize,
	filter:filter,
	field:field,
	sort:sort,
	pageIndex:pageIndex},
dataType:"json",
success:function(res)
{  
	        var liststr="<ul>";
	        var str="<strong><a href=\""+res[0]._modellist[0].newhtmlurl+"\">"+res[0]._modellist[0].newtitle+"</a></strong><br />"+res[0]._modellist[0].newcontentdesc+"...";
		    for(var i=1;i<5;i++)
			{
		    	if(res[0]._modellist[i].newhtmlurl!=null)
		    		{
		    		liststr+="<li><a href=\""+res[0]._modellist[i].newhtmlurl+"\">"+res[0]._modellist[i].newtitle+"</a></li>";
		    		}
				
			}
		    liststr+="</ul>";
		
	document.getElementById("ph").innerHTML=str;
	document.getElementById("phb").innerHTML=liststr;
},
error:function()
{

}
})}
*/
