$(document).ready(function() {
	$("#username").focus(function() {
		hiddenTip("username");
	});
	$("#username").blur(function() {
		ckUsername();
	});
	$("#email").focus(function() {
		hiddenTip("email");
	});
	$("#email").blur(function() {
		ckEmail();
    });
    
    $("#message").focus(function() {
    	hiddenTip("message");
    });
    $("#message").blur(function() {
		ckMessage();
    });
});
function del(id){ 
	$.post("/message/submit/delete",{id:id},function(xml) {
		if(xml==1){
			$("div[id='"+id+"']").remove();
		}else{
			return;
		}
	});
}
function trash(tag){
	if(tag=="true"){
		$("#message").val("");
	}
	if(tag=="false"){
		$("#message").val("");
		$("#username").val("");
		$("#email").val("");
	}
}
function submitForm() {
	ckUsername();
	ckEmail();
	ckMessage();
	
	if ($("#err_username").html() == "true" && $("#err_email").html() == "true" && $("#err_message").html() == "true") {
		return true;
	}
	return false;
}

function ckUsername() {
		showWaitTip("username");
		var username = trim($("#username").val());
		if (isNull(username)) {
			showWrongTip("username", "用户名不能为空!");
		}  
		else {
	    	showRightTip("username");
		}
}

function ckEmail() {
		showWaitTip("email");
		var email = trim($("#email").val());
		if (isNull(email)) {
			showWrongTip("email", "邮箱地址不能为空!");
		} else if (isEmail(email) == false) {
			showWrongTip("email", "请输入正确的邮箱地址!");
		} else {
			showRightTip("email");
		}
}

function ckMessage() {
		showWaitTip("message");
		var message = trim($("#message").val());
		if (isNull(message)) {
			showWrongTip("message", "反馈内容不能为空!");
		} 
		else if(message.length>4000){
			showWrongTip("message", "反馈内容不能超过4000个字符!");			
		}else{
	    	showRightTip("message");
	    } 
}
function showWaitTip(type) {
	$("#img_" + type).html('<img src="/images/ico/ico_waiting2.gif" align="bottom">');
}

function showWrongTip(type, msg) {
	$("#img_" + type).html("&nbsp;");
	$("#img_" + type).removeClass();
	$("#img_" + type).addClass("r_wrong");
	$("#err_" + type).css("display", "");
	$("#err_" + type).html(msg);
}

function showRightTip(type) {
	$("#img_" + type).html("&nbsp;");
	$("#img_" + type).removeClass();
	$("#img_" + type).addClass("r_right");
	$("#err_" + type).css("display", "none");
	$("#err_" + type).html("true");
}

function hiddenTip(type) {
	$("#img_" + type).html("&nbsp;");
	$("#img_" + type).removeClass();
	$("#img_" + type).addClass("r");
	$("#err_" + type).css("display", "none");
}