
window.onload = function() {
	var nav = document.getElementById('nav');
	var sub = nav.getElementsByTagName('DIV');
	for(var c=0;c<sub.length;c++) {
		if( c%2==0 ) {
			sub[c].className = 'sp';
			sub[c].innerHTML = "<img src='/css/nav_sp.jpg' style='width:3px;height:19px;'/>";
		}
		else {
			sub[c].onmouseover = function() { this.className = 'ho'; }
			sub[c].onmouseout = function() { this.className = ''; }
		}
		
	}

	var my = document.getElementById('my');
	var html = "<img src='/css/myface.jpg'/>";
		html = html+ "<br/>";
		html = html+ "<img src='/css/rss.png' width='10' height='10' /> ";
		html = html+ "<a target='_blank' href='atom.xml'title='Subscribe'>ATOM 2.0</a>&nbsp;&nbsp;";
		html = html+ "<img src='/css/rss.png' width='10' height='10' /> ";
		html = html+ "<a target='_blank' href='rss.xml'title='Subscribe'>RSS 2.0</a><br />";
		html = html+ "<a target='_blank' href='http://fusion.google.com/add?feedurl=http://cwq.yfjhh.com/atom.xml'><img alt='Add to iGoogle' src='/css/google.gif' /></a> ";
		html = html+ "<a target='_blank' href='http://add.my.yahoo.com/rss?url=http://cwq.yfjhh.com/atom.xml'><img alt='Add to My Yahoo!' src='/css/yahoo.gif' /></a><br />";
		html = html+ "<a target='_blank' href='http://www.live.com/?add=http://cwq.yfjhh.com/atom.xml'><img alt='Add to Live.com' src='/css/live.gif' /></a> ";
		html = html+ "<a target='_blank' href='http://www.bloglines.com/sub/http://cwq.yfjhh.com/atom.xml'><img alt='Add to BlogLines' src='/css/bloglines.gif' /></a><br />";
		html = html+ "<a target='_blank' href='http://www.zhuaxia.com/add_channel.php?url=http://cwq.yfjhh.com/atom.xml'><img alt='Add to ZhuaXia' src='/css/zhuaxia.gif' /></a> ";
		html = html+ "<a target='_blank' href='http://www.gougou.com/find_rss.jsp?url=http://cwq.yfjhh.com/atom.xml'><img alt='Add to GouGou' src='/css/gougou.gif' /></a><br />";
		html = html+ "<a target='_blank' href='http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http://cwq.yfjhh.com/atom.xml'><img alt='Add to Newsgator' src='/css/newsgator.gif' /></a> ";
		html = html+ "<a target='_blank' href='http://www.netvibes.com/subscribe.php?url=http://cwq.yfjhh.com/atom.xml'><img alt='Add to Netvibes' src='/css/netvibes.gif' /></a><br />";
		html = html+ "<a target='_blank' href='http://www.rojo.com/add-subscription?resource=http://cwq.yfjhh.com/atom.xml'><img alt='Add to RoJo.com' src='/css/rojo.gif' /></a> ";
		html = html+ "<a target='_blank' href='http://rss.hexun.com/sub.aspx?fromurl==http://cwq.yfjhh.com/atom.xml'><img alt='Add to HeXun.com' src='/css/hexun.gif' /></a>";
	my.innerHTML = html;



}

var loadComments = function(postId) {
	var loadComments = document.getElementById('loadComments');
	if(loadComments) {
		ajaxRequest('comments.php?type=load&post_id='+postId, {
				onComplete: function(originalRequest) {
					var r = originalRequest.responseText;
					loadComments.innerHTML = r;
				}
		   });
	}
}

var trimString = function(str) {
	return str.replace(/(^\s*)|(\s*$)/g, "");
}

var newComment = function() {
	var frm = document.getElementById('commentFrm');
	if(frm) {
		if( trimString(frm.comment_user.value)=='') {
			alert('请输入你的姓名！');
			return false;
		}
		else if( trimString(frm.comment_data.value)=='') {
			alert('请输入你的评论内容！');
			return false;
		}
		else if( trimString(frm.comment_code.value)=='') {
			alert('请输入验证码！');
			return false;
		}
		var params = 'type=new&post_id='+frm.post_id.value + '&comment_user='+frm.comment_user.value + '&comment_email='+frm.comment_email.value + '&comment_data='+frm.comment_data.value + '&comment_code='+frm.comment_code.value;
		ajaxRequest('comments.php', {
			    parameters: params,
				method: 'post',
				onComplete: function(originalRequest) {
					var r = originalRequest.responseText;
					if( r == 'errCode' ) {
						alert('验证码有错！');
						frm.comment_code.value = '';
					}
					else {
						alert('多谢你的评论！');
						frm.reset();

						var comms = document.getElementById('commentList');
						comms.innerHTML = r + comms.innerHTML;
					}

					var commentCode = document.getElementById('commentCode');
					commentCode.src = '';
					commentCode.src = '/comments.php?type=commentCode&rnd=' + Math.random();
				}
		   });
	}
}
