function getHotArticleHTML(url,pages,hours,template,id)
{
	new Ajax.Request(uu.urlUtil.encode(url),
		{	
			asynchronous: 'true',
		    method: 'post',
		    postBody:'pages = ' + pages + '&hours = ' + hours + '&template' + template,
		    onSuccess:function(transport){
				var response = transport.responseText || "";
      			$(id).innerHTML = response;
		    },
		    onFailure: function(){ $(id).innerHTML = "ajax loading fail."; }
		}
	);
}

function getGuideArticleHTML(url,pages,template,id)
{
	new Ajax.Request(uu.urlUtil.encode(url),
		{
			asynchronous:'true',
			method:'post',
			postBody:'pages = ' + pages + '&template = ' + template,
			onSuccess:function(transport){
				var response = transport.responseText || "";
				$(id).innerHTML = response;
			},
			onFailure: function(){ $(id).innerHTML = "ajax loading fail."; }
		}
	
	);
}

function getUpdateArticleHTML(url,pages,template,id)
{
	new Ajax.Request(uu.urlUtil.encode(url),
		{
			asynchronous:'true',
			method:'post',
			postBody:'pages = ' + pages + '&template = ' + template,
			onSuccess:function(transport){
				var response = transport.responseText || "";
				$(id).innerHTML = response;
			},
			onFailure: function(){ $(id).innerHTML = "ajax loading fail."; }
		}
	
	);
}

function getHtmlInTag(url,pages,template,id,mType,lType,userName,draftID)
{
	var param = "pages=" + pages + "&template=" + template + "&mType=" + mType + "&lType=" + lType + "&userName=" + userName + "&draftID=" + draftID;
	new Ajax.Request(uu.urlUtil.encode(url),
		{
			asynchronous:'true',
			method:'post',
			postBody:param,
			onComplete:function(transport){
				var response = transport.responseText || "";
				$(id).innerHTML = response;
			}
		}

	);
}

function getBlogHTML(url,userName,pages,id)
{
	new Ajax.Request(uu.urlUtil.encode(url),
	{
		asynchronous:'true',
		method:'post',
		postBody:'name = '+ encodeURI(encodeURI(userName)) +'&pages = ' + pages,
		onSuccess:function(transport){
			var response = transport.responseText || "";
			$(id).innerHTML = response;
		},
		onFailure: function()
		{
			$(id).innerHTML = "<center>加载数据出错,您可以选择导航到其他页面</center>"; 
		}
	}
	);
}

function indexLogin()
{
	var name = $("uName").value;
	if(name == '')
	{
		alert("请填写用户名!");
		$("uName").focus();
		return false;
	}
	
	var pwd = $("passd").value;
	if(pwd == '')
	{
		alert("密码为空!");
		$("passd").focus();
		return false;
	}
	
	var rememberMe = $("rememberMe").checked;
	var flag;
	if(rememberMe)
	{
		flag = 1;
	}else{
		flag = 0;
	}
	
	var url = "/blog/accountAction!indexLogin.uu";
	var param = "userName=" + encodeURI(encodeURI(name)) + "&pwd=" + encodeURI(encodeURI(pwd)) + "&flag=" + flag;
	new Ajax.Request(uu.urlUtil.encode(url),
		{
			asynchronous:'true',
			method:'post',
			postBody:param,
			onSuccess:function(transport){
				var response = transport.responseText || "";
				var json = response.evalJSON(true);
				if(json.status == 1)
				{
					alert(json.html);
				}else{
					var html = "<div style=\"line-height:33px;float:left;padding-left:10px\">欢迎您，";
					html += "<font color=\"#FF0000\">" +json.account.blogName+ "</font> | ";
					html += "<a href=\""+ json.account.url +"\">我的主页</a> | ";
					html += "<a href=\""+uu.urlUtil.encode("/blog/controlAction!addArticle.uu")+"\" target=\"_blank\">发博文</a> | ";
					html += "<a href=\""+uu.urlUtil.encode("/blog/accountAction!logout.uu")+"\">退出</a>";
					html += "</div>";
					$("loginInfo").innerHTML = html;
				}
			}			
		}
	);
	
}

function addFavorites(id){
	var url = uu.urlUtil.encode("/blog/blogAction!addFavorites.uu");
	new Ajax.Request(
		url,
		{
			asynchronous:'true',
			method:'post',
			postBody:'id=' + id,
			onSuccess:function(transport){
				var resp = transport.responseText || "";
				var json = resp.evalJSON(true);
				if(json.status == 0)
				{
					alert("日志收藏成功!!");
					var fCount = parseInt($("review_" + id).innerHTML) + 1;
					$("review_" + id).innerHTML = fCount;
				}else if(json.status == 1){
					alert("您还没登陆哦!请先登录吧.");
				}else if(json.status == 2){
					alert("您已经收藏了此日志!!!");
				}
			}
		}
	);
}

function addRecommend(id){
	var url = uu.urlUtil.encode("/blog/blogAction!addRecommend.uu");
	new Ajax.Request(
		url,
		{
			asynchronous:'true',
			method:'post',
			postBody:'id=' + id,
			onSuccess:function(transport){
				var resp = transport.responseText || "";
				var json = resp.evalJSON(true);
				if(json.status == 0)
				{
					var fCount = parseInt($("recom_" + id).innerHTML) + 1;
					$("recom_" + id).innerHTML = fCount;
					//$("ding_" + id).innerHTML = "顶&nbsp;<img src='http://i.66fund.com/i/blog/images/list/dyg.jpg' />";
				}
			}
		}
	);
}

function setTab(name,cursel,n){
	for(i=1;i<=n;i++){
		var menu=document.getElementById(name+i);
		var con=document.getElementById("con_"+name+"_"+i);
		menu.className=i==cursel?"hover":"";
		con.style.display=i==cursel?"block":"none";
	}
}

function setSelect(searchObj,tagName)
{
	var elements_li = $(searchObj).getElementsByTagName(tagName);
	for(var i=0;i<elements_li.length;i++)
	{
		var elements_a = elements_li[i].getElementsByTagName("a");
		if(i == 0)
		{
			elements_a[0].onclick = function(){
				$("selectType").value = "c";
				for(var i=0;i<elements_li.length;i++)
				{
					elements_li[i].className = "";
				}
				this.parentNode.className = "hover";
			}
		
		}else if(i == 1){
			elements_a[0].onclick = function(){
				$("selectType").value = "t";
				
				for(var i=0;i<elements_li.length;i++)
				{
					elements_li[i].className = "";
				}
				this.parentNode.className = "hover";
			}
		}else if(i == 2){
			elements_a[0].onclick = function(){
				$("selectType").value = "author";
				for(var i=0;i<elements_li.length;i++)
				{
					elements_li[i].className = "";
				}
				this.parentNode.className = "hover";
			}
		}
	}
}
	
function searchSub()
{
	var inp = $("inpValue").value;
	if(inp == "")
	{
		alert("请输入关键字!");
		return false;
	}
	
	var hidInp = $("selectType").value;
	var form = $("searchForm");
	var url = "";
	alert(hidInp);
	if(hidInp == "author")
	{
		//url = "http://blog.66money.com.cn/search/" + encodeURI(encodeURI(inp)) + "/author_1.shtml";
		url = "http://uu.66money.com.cn:8086/blog_blogAction!searchByAuthor__4__.shtml?author=" + encodeURI(encodeURI(inp));
		alert(url);
		//return false;
		form.action=url;
		
	}else{
		url = uu.urlUtil.encode("http://blog.66money.com.cn/uusearch/search/search.uu?indexType=BLOGBBS&wd=" + inp + "&searchCategories=" + hidInp);
		form.action=url;
	}
}

function optSubmit()
{
	var inp = $("optValue").value;
	if(inp == "")
	{
		alert("请输入关键字!");
		return false;
	}
	
	var optType = $("optType").value;
	var form = $("searchOpt");
	var url = "";
	if(optType == "author")
	{
		//url = "http://blog.66money.com.cn/search/" + encodeURI(encodeURI(encodeURI(inp))) + "/author_1.shtml"
		url = "http://uu.66money.com.cn:8086/blog_blogAction!searchByAuthor__4__.shtml?author=" + encodeURI(encodeURI(inp));
		
	}else{
		url = uu.urlUtil.encode("http://blog.66money.com.cn/uusearch/search/search.uu?indexType=BLOGBBS&wd=" + inp + "&searchCategories=" + optType);
	}
	form.action=url;
}

/*将首页加为收藏*/
function addToFavorite(){
    var url = window.location.href;
    var title = document.title;
    if (window.sidebar){
        window.sidebar.addPanel(title, url,"");
    }else if(window.external){
    	window.external.AddFavorite(url, title);
    }else if(window.opera){
    	return false;
    }else{ 
         alert("你使用的浏览器不支持加为收藏,请手动收藏");
    }
}

