var InfoBadNess = {};

InfoBadNess.save = function(e){
	var content = InfoBadNess.getHtmlStringInEditor();
	var title = $F('infoTitle');
	var email = $F('infoEmail');
	var name = $F('infoName');
	var link = $F('infoLink');
	InfoBadNess.process(content, title, email, name, link);
}

InfoBadNess.getHtmlStringInEditor = function () {
	return xed.getCurrentContent();
}

InfoBadNess.process = function(content, title, email, name, link){
	if(title.blank()){
		alert("제목을 입력해 주세요");
	}else if(email.blank()){
		alert("이메일 주소를 입력해 주세요");
	}else if(name.blank()){
		alert("이름을 입력해 주세요");
	}else if(content.blank()){
		alert("내용을 입력해 주세요");
	}else if(link.blank()){		
		alert("참고 링크를 입력해 주세요");
	}else{
		if(InfoBadNess.isValidEmail(email)){
			InfoBadNess.submit(content, title, email, name, link);
		}
	}
}

InfoBadNess.submit = function(content, title, email, name, link){
	new Ajax.Request( 
			Constants.CONTEXT_NAME + '/customer/info/badnessSubmit.do', 
			{
				method: 'post', 
				encoding: "utf-8",
				parameters: {
					content : content,
					title : title,
					email : email,
					name : name,
					link : link
				}, 
				onFailure: function (e) {
					return alert("member_join.js error HTTPRequest Err:" + e);
				}
			} 
		);
	alert('접수되었습니다.');
	location.href = Constants.CONTEXT_NAME + '/index.do';	
}


/**
 * 이메일 유효성 검사
 * @param {Object} value
 */
InfoBadNess.isValidEmail = function (value) {
	if (value.blank()) {
		alert('이메일을 입력해 주세요.');
		
		return false;
	}
	var regex=/^\s*[\w\~\-\.]+\@[\w\~\-]+(\.[\w\~\-]+)+\s*$/g;
	if (value.match(regex) != value) {		
		alert('이메일 형식이 잘못되었습니다.');
		$('infoEmail').value = "";		
		return false;
	}
	return true;
}

