//插入表情
insert_face = function(sid){
	if(sid){
		var textObj = $('#reply_content');
		textObj.focus();
		var html = "[:s"+sid+"]";
		if($.browser.msie){
			document.selection.createRange().text = html;
		}else{
		  var rangeStart=document.formComment.reply_content.selectionStart;
		  var rangeEnd=document.formComment.reply_content.selectionEnd;
		  var tempStr1=textObj.val().substring(0,rangeStart);
		  var tempStr2=textObj.val().substring(rangeEnd);
		  textObj.val(tempStr1+html+tempStr2);
		  //光标设定到插入处
		  document.formComment.reply_content.selectionStart = rangeStart+html.length;
		  document.formComment.reply_content.selectionEnd = rangeStart+html.length;
		}
	}
}
//评论表情更多更少
show_more_face = function(){
	if($("#reply_content").attr("class") == "small"){
		$("#reply_content").attr("class","big") ;
		$("#icons").attr("class","allface"); 
		$("#face_button").html("↑收起");
	}else{
		$("#reply_content").attr("class","small");
		$("#icons").attr("class","liteface");
		$("#face_button").html("更多表情↓");
	}
}


check_select = function(v,url){
	if(navigator.appName == "Microsoft Internet Explorer"){
		
		if(document.selection.createRange().text == v){
			alert(document.selection.createRange().text);
			document.location.href = url;
		}
	}else{
		if(window.getSelection().toString().match(v)){
			alert(window.getSelection().toString());
			document.location.href = url;
		}
	}
}

$(document).ready(function(){
	$('#formComment').submit(function(){
		if($('#reply_content').val() == ''){
			alert('请写入内容');
			return false;
		}
		if($('#reply_content').val().length > 500){
			alert('您写了过多的内容，评论内容不能超过250字');
			return false;
		}
		if($('#check_code').val() == ''){
			alert('请填写验证码');
			return false;
		}
		$.ajax({
			type: "POST",
			url: "/review.php",
			data: $('#formComment').formSerialize(),
			dataType:"json",
			success: function(msg){
				if(msg["return"] == 1){
					alert('提交评论成功');
					window.location.reload();
				}
				else{
					if(msg["bo"] == 'check_code'){
						alert('验证码不正确');
					}
				}
			}
		});
		return false;

	});
	
	
	$('#formLogin').submit(function(){
		if($('#ecnavi_username').val() == ''){
			alert('用户名不能空');
			return false;
		}
		if($('#ecnavi_pwd').val() == ''){
			alert('密码不能空');
			return false;
		}
		$.ajax({
			type: "POST",
			url: "/passport.php",
			data: $('#formLogin').formSerialize(),
			dataType:"json",
			success: function(msg){
				if(msg["issucess"] == 1){
					alert('登录成功');
					$('#logConent').html("用户 "+$('#ecnavi_username').val()+" 登录中 --- [ <a id='logOut' href='/logout.php'>退出</a> ]");
					//window.location.reload();
				}
				else{
					if(msg["reason"] == 'user_none_exist'){
						alert('用户不存在');
					}
					if(msg["reason"] == 'password_wrong'){
						alert('密码不正确');
					}
					if(msg["reason"] == 'user_none_valid'){
						alert('此用户尚未被激活');
					}
				}
			}
		});
		return false;

	});




	function change_code(){
		var mydate = new Date();
		$('#ccode').attr('src','/async_ccode.php?'+mydate.getTime());
	}
	$('#ccode').bind('click',change_code);
	
	
	$('#hideorshow').bind('click',function(){
		if($("#catemore").attr("class") == "hideit"){
			$("#catemore").attr("class","showit") ;
			$("#hideorshow").html("收起↑");
		}else{
			$("#catemore").attr("class","hideit");
			$("#hideorshow").html("展开更多类别↓");
		}
	});
});