
messages = {};
messageCtl = {};
messageCtl.run = false;
messageCtl.load = function() {
	if (messageCtl.run) return;
	SimpleAjax.executeXHRequest("post", "/action/messages.do", true, null, messageCtl.callBack, null, "e4x");
	messageCtl.run = true;
	return;
};
messageCtl.callBack = function(e4xData, args) {
	messageCtl.run = false;
	if ((e4xData) && (e4xData.messages)) {
		var key;
		messages = {};
		for (key in e4xData.messages) {
			var msg = decodeURIComponent(e4xData.messages[key]);
			messages[key] = msg.replace(/\\n/gi,"\n");
		}
		return;
	}
	alert("ページ ローディング中にエラーが発生しました。\nしばらくしてからもう一度お試し下さい。");
	return;
};


autoLabel = {};
autoLabel.initialize = function(obj) {
	if (obj) {
		f_addEvent (obj, "onfocus", autoLabel.onFocusAutoLabel.bind(obj), false);
		f_addEvent (obj, "onblur", autoLabel.onBlurAutoLabel.bind(obj), false);
		autoLabel.onBlurAutoLabel.bind(obj)();
	}
	return;
};
autoLabel.onFocusAutoLabel = function() {
	if (this.value.trim() == this.title) this.value = "";
};
autoLabel.onBlurAutoLabel = function() {
	if (this.value.trim() == "") this.value = this.title;
};


formPrepare = {};
formPrepare.obj = null;
formPrepare.run = false;
formPrepare.send = function(obj, func) {
	if (formPrepare.run) return;
	if (obj) {
		formPrepare.obj = obj;
		SimpleAjax.executeXHRequest("post", "/action/prepareForm.do", true, null, formPrepare.callBack, func, "e4x");
		formPrepare.run = true;
	}
	return;
};
formPrepare.callBack = function(e4xData, func) {
	formPrepare.run = false;
	if ((e4xData) && (e4xData.response) && (e4xData.response.uid)) {
		if (formPrepare.obj) {
			formPrepare.obj.value = e4xData.response.uid;
			if (func && (func.constructor == Function)) {
				func();
				return;
			}
		}
	}
	alert(messages.err_001);
	return;
};


cooperationForm = {};
cooperationForm.form = null;
cooperationForm.run = false;
cooperationForm.initialize = function() {
	messageCtl.load();
	var form = document.forms["formCooperation"];
	if (form) {
		cooperationForm.form = form;
		autoLabel.initialize(form.name);
		autoLabel.initialize(form.email);
	}
};
cooperationForm.checkForm = function() {
	if (cooperationForm.form) {
		var result = true;
		f_formValueTrim(cooperationForm.form);
		cooperationForm.form.name.className = "input_text";
		cooperationForm.form.email.className = "input_text";
		cooperationForm.form.message.className = "";
		if (f_getFormValue(cooperationForm.form.message) == "") {
			cooperationForm.form.message.className = "omission";
			cooperationForm.form.message.focus();
			result = false;
		}
		if ((f_getFormValue(cooperationForm.form.email) == "") || (f_getFormValue(cooperationForm.form.email) == cooperationForm.form.email.title)) {
			cooperationForm.form.email.className = "input_text omission";
			cooperationForm.form.email.focus();
			result = false;
		}
		if (!f_isEmailAddress(f_getFormValue(cooperationForm.form.email))) {
			cooperationForm.form.email.className = "input_text omission";
			cooperationForm.form.email.select();
			result = false;
		}
		if ((f_getFormValue(cooperationForm.form.name) == "") || (f_getFormValue(cooperationForm.form.name) == cooperationForm.form.name.title)) {
			cooperationForm.form.name.className = "input_text omission";
			cooperationForm.form.name.focus();
			result = false;
		}
		if (!result) {
			alert(messages.err_003);
			return false;
		}
		
		if (f_getFormValue(cooperationForm.form.name).length > 100) {
			cooperationForm.form.name.className = "input_text omission";
			alert(messages.email_006);
			cooperationForm.form.name.focus();
			return false;
		}
		if (f_getFormValue(cooperationForm.form.email).length > 100) {
			cooperationForm.form.email.className = "input_text omission";
			alert(messages.email_007);
			cooperationForm.form.email.focus();
			return false;
		}
		if (f_getFormValue(cooperationForm.form.message).length > 2000) {
			cooperationForm.form.message.className = "omission";
			alert(messages.email_008);
			cooperationForm.form.message.focus();
			return false;
		}
		
		return true;
	}
	
};
cooperationForm.send = function() {
	if (cooperationForm.form) {
		if (cooperationForm.checkForm())
			formPrepare.send(cooperationForm.form.uid, cooperationForm.submitForm);
	}
	return;
};
cooperationForm.submitForm = function() {
	if (cooperationForm.run) return;
	if (cooperationForm.form) {
		SimpleAjax.executeXHFormRequest("post", "/action/sendCooperationMail.do", true, cooperationForm.form, ["uid","name","email","message"], cooperationForm.callBack, null, "e4x");
		cooperationForm.run = true;
	}
	return;
};
cooperationForm.callBack = function(e4xData, args) {
	cooperationForm.run = false;
	if ((e4xData) && (e4xData.response) && (e4xData.response.code)) {
		cooperationForm.form.name.className = "input_text";
		cooperationForm.form.email.className = "input_text";
		cooperationForm.form.message.className = "";
		if (e4xData.response.code == "0") {
			alert(messages.email_005);
			cooperationForm.form.reset();
			cooperationForm.initialize();
			return;
		}else if (e4xData.response.code == "-101") {
			cooperationForm.form.name.className = "input_text omission";
			alert(messages.email_001); 
			cooperationForm.form.name.select();
			return;
		}else if (e4xData.response.code == "-102") {
			cooperationForm.form.name.className = "input_text omission";
			alert(messages.email_006); 
			cooperationForm.form.name.select();
			return;
		}else if (e4xData.response.code == "-103") {
			cooperationForm.form.email.className = "input_text omission";
			alert(messages.email_002); 
			cooperationForm.form.email.select();
			return;
		}else if (e4xData.response.code == "-104") {
			cooperationForm.form.email.className = "input_text omission";
			alert(messages.email_007); 
			cooperationForm.form.email.select();
			return;
		}else if (e4xData.response.code == "-105") {
			cooperationForm.form.message.className = "omission";
			alert(messages.email_004); 
			cooperationForm.form.message.select();
			return;
		}else if (e4xData.response.code == "-106") {
			cooperationForm.form.message.className = "omission";
			alert(messages.email_008); 
			cooperationForm.form.message.select();
			return;
		}else if (e4xData.response.code == "-201") {
			alert(messages.err_002); 
			return;
		}else if (e4xData.response.code == "-202") {
			alert(messages.err_011); 
			return;
		}
	}
	alert(messages.err_001);
	return;
};


contactForm = {};
contactForm.form = null;
contactForm.run = false;
contactForm.initialize = function() {
	messageCtl.load();
	var form = document.forms["formContact"];
	if (form) {
		contactForm.form = form;
		autoLabel.initialize(form.name);
		autoLabel.initialize(form.email);
	}
};
contactForm.checkForm = function() {
	if (contactForm.form) {
		var result = true;
		f_formValueTrim(contactForm.form);
		contactForm.form.name.className = "input_text";
		contactForm.form.email.className = "input_text";
		contactForm.form.message.className = "";
		if (f_getFormValue(contactForm.form.message) == "") {
			contactForm.form.message.className = "omission";
			contactForm.form.message.focus();
			result = false;
		}
		if ((f_getFormValue(contactForm.form.email) == "") || (f_getFormValue(contactForm.form.email) == contactForm.form.email.title)) {
			contactForm.form.email.className = "input_text omission";
			contactForm.form.email.focus();
			result = false;
		}
		if (!f_isEmailAddress(f_getFormValue(contactForm.form.email))) {
			contactForm.form.email.className = "input_text omission";
			contactForm.form.email.select();
			result = false;
		}
		if ((f_getFormValue(contactForm.form.name) == "") || (f_getFormValue(contactForm.form.name) == contactForm.form.name.title)) {
			contactForm.form.name.className = "input_text omission";
			contactForm.form.name.focus();
			result = false;
		}
		if (!result) {
			alert(messages.err_003);
			return false;
		}
	
		if (f_getFormValue(contactForm.form.name).length > 100) {
			contactForm.form.name.className = "input_text omission";
			alert(messages.email_006);
			contactForm.form.name.focus();
			return false;
		}
		if (f_getFormValue(contactForm.form.email).length > 100) {
			contactForm.form.email.className = "input_text omission";
			alert(messages.email_007);
			contactForm.form.email.focus();
			return false;
		}
		if (f_getFormValue(contactForm.form.message).length > 2000) {
			contactForm.form.message.className = "omission";
			alert(messages.email_013);
			contactForm.form.message.focus();
			return false;
		}

		return true;
	}
	
};
contactForm.send = function() {
	if (contactForm.form) {
		if (contactForm.checkForm())
			formPrepare.send(contactForm.form.uid, contactForm.submitForm);
	}
	return;
};
contactForm.submitForm = function() {
	if (contactForm.run) return;
	if (contactForm.form) {
		SimpleAjax.executeXHFormRequest("post", "/action/sendContactMail.do", true, contactForm.form, ["uid","name","email","message"], contactForm.callBack, null, "e4x");
		contactForm.run = true;
	}
	return;
};
contactForm.callBack = function(e4xData, args) {
	contactForm.run = false;
	if ((e4xData) && (e4xData.response) && (e4xData.response.code)) {
		contactForm.form.name.className = "input_text";
		contactForm.form.email.className = "input_text";
		contactForm.form.message.className = "";
		if (e4xData.response.code == "0") {
			alert(messages.email_011);
			contactForm.form.reset();
			contactForm.initialize();
			return;
		}else if (e4xData.response.code == "-101") {
			contactForm.form.name.className = "input_text omission";
			alert(messages.email_001); 
			contactForm.form.name.select();
			return;
		}else if (e4xData.response.code == "-102") {
			contactForm.form.name.className = "input_text omission";
			alert(messages.email_006); 
			contactForm.form.name.select();
			return;
		}else if (e4xData.response.code == "-103") {
			contactForm.form.email.className = "input_text omission";
			alert(messages.email_002); 
			contactForm.form.email.select();
			return;
		}else if (e4xData.response.code == "-104") {
			contactForm.form.email.className = "input_text omission";
			alert(messages.email_007); 
			contactForm.form.email.select();
			return;
		}else if (e4xData.response.code == "-105") {
			contactForm.form.message.className = "omission";
			alert(messages.email_012); 
			contactForm.form.message.select();
			return;
		}else if (e4xData.response.code == "-106") {
			contactForm.form.message.className = "omission";
			alert(messages.email_013); 
			contactForm.form.message.select();
			return;
		}else if (e4xData.response.code == "-201") {
			alert(messages.err_002); 
			return;
		}else if (e4xData.response.code == "-202") {
			alert(messages.err_011); 
			return;
		}
	}
	alert(messages.err_001);
	return;
};


recruitForm = {};
recruitForm.form = null;
recruitForm.run = false;
recruitForm.initialize = function() {
	messageCtl.load();
	var form = document.forms["formRecruit"];
	if (form)
		recruitForm.form = form;
};
recruitForm.checkForm = function() {
	if (recruitForm.form) {
		var result = true;
		f_formValueTrim(recruitForm.form);
		recruitForm.form.work_type.className = "";
		recruitForm.form.name.className = "input_text";
		recruitForm.form.address.className = "input_text";
		recruitForm.form.phone.className = "input_text";
		recruitForm.form.email.className = "input_text";
		recruitForm.form.attach_name.className = "";
		recruitForm.form.comment.className = "";

		if (f_getFormValue(recruitForm.form.comment) == "") {
			recruitForm.form.comment.className = "omission";
			recruitForm.form.comment.focus();
			result = false;
		}
		if (recruitForm.form.attach_name.value == "") {
			recruitForm.form.attach_name.className = "omission";
			recruitForm.form.attach_name.focus();
			result = false;
		}
		if (f_getFormValue(recruitForm.form.email) == "") {
			recruitForm.form.email.className = "input_text omission";
			recruitForm.form.email.focus();
			result = false;
		}
		if (!f_isEmailAddress(f_getFormValue(recruitForm.form.email))) {
			recruitForm.form.email.className = "input_text omission";
			recruitForm.form.email.select();
			result = false;
		}
		if (f_getFormValue(recruitForm.form.phone) == "") {
			recruitForm.form.phone.className = "input_text omission";
			recruitForm.form.phone.focus();
			result = false;
		}
		if (f_getFormValue(recruitForm.form.address) == "") {
			recruitForm.form.address.className = "input_text omission";
			recruitForm.form.address.focus();
			result = false;
		}
		if (f_getFormValue(recruitForm.form.name) == "") {
			recruitForm.form.name.className = "input_text omission";
			recruitForm.form.name.focus();
			result = false;
		}
		if (f_getFormValue(recruitForm.form.work_type) == "") {
			recruitForm.form.work_type.className = "omission";
			recruitForm.form.work_type.focus();
			result = false;
		}
		if (!result) {
			alert(messages.err_003);
			return false;
		}
		
		if (f_getFormValue(recruitForm.form.name).length > 100) {
			recruitForm.form.name.className = "input_text omission";
			alert(messages.recruit_008);
			recruitForm.form.name.focus();
			return false;
		}
		if (f_getFormValue(recruitForm.form.address).length > 200) {
			recruitForm.form.address.className = "input_text omission";
			alert(messages.recruit_009);
			recruitForm.form.address.focus();
			return false;
		}
		if (f_getFormValue(recruitForm.form.phone).length > 100) {
			recruitForm.form.phone.className = "input_text omission";
			alert(messages.recruit_010);
			recruitForm.form.phone.focus();
			return false;
		}
		if (f_getFormValue(recruitForm.form.email).length > 100) {
			recruitForm.form.email.className = "input_text omission";
			alert(messages.email_007);
			recruitForm.form.email.focus();
			return false;
		}
		if (attachTypes) {
			var arrAttachTypes = attachTypes.split(',');
			var checkExt = false;
			for (var i=0; i<arrAttachTypes.length; i++) {
				if (recruitForm.form.attach.value.endsWith('.' + arrAttachTypes[i], true)) checkExt = true;
			}
			if (!checkExt) {
				recruitForm.form.attach_name.className = "omission";
				alert(messages.recruit_006);
				recruitForm.form.attach_name.focus();
				return false;
			}
		}
		if (f_getFormValue(recruitForm.form.comment).length > 5000) {
			recruitForm.form.comment.className = "input_text omission";
			alert(messages.recruit_011);
			recruitForm.form.comment.focus();
			return false;
		}
	
		return true;
	}
};
recruitForm.goConfirm = function() {
	if (recruitForm.form) {
		if (recruitForm.checkForm())
			formPrepare.send(recruitForm.form.uid, recruitForm.submitConfirm);
	}
	return;
};
recruitForm.submitConfirm = function() {
	if (recruitForm.run) return;
	if (recruitForm.form) {
		recruitForm.form.action = "./careers_form_confirm.html";
		recruitForm.run = true;
		recruitForm.form.submit();
	}
	return;
};
recruitForm.goModify = function() {
	if (recruitForm.run) return;
	if (recruitForm.form) {
		recruitForm.form.action = "./careers_form.html";
		recruitForm.run = true;
		recruitForm.form.submit();
	}
	return;
};
recruitForm.send = function() {
	if (recruitForm.form) {
		formPrepare.send(recruitForm.form.uid, recruitForm.submitForm);
	}
	return;
};
recruitForm.submitForm = function() {
	if (recruitForm.form) {
		SimpleAjax.executeXHFormRequest("post", "/action/applyRecruit.do", true, recruitForm.form, ["uid","work_type","name","address","phone","email","attach_name","attach_file","comment"], recruitForm.callBack, null, "e4x");
		recruitForm.run = true;
	}
	return;
};
recruitForm.callBack = function(e4xData, args) {
	recruitForm.run = false;
	if ((e4xData) && (e4xData.response) && (e4xData.response.code)) {
		if (e4xData.response.code == "0") {
			alert(messages.recruit_013);
			self.location.href = './careers_list.html';
			return;
		}else if (e4xData.response.code == "-101") {
			alert(messages.recruit_001); 
			recruitForm.goModify();
			return;
		}else if (e4xData.response.code == "-102") {
			alert(messages.recruit_002);
			recruitForm.goModify();
			return;
		}else if (e4xData.response.code == "-103") {
			alert(messages.recruit_008);
			recruitForm.goModify();
			return;
		}else if (e4xData.response.code == "-104") {
			alert(messages.recruit_003);
			recruitForm.goModify();
			return;
		}else if (e4xData.response.code == "-105") {
			alert(messages.recruit_009);
			recruitForm.goModify();
			return;
		}else if (e4xData.response.code == "-106") {
			alert(messages.recruit_004);
			recruitForm.goModify();
			return;
		}else if (e4xData.response.code == "-107") {
			alert(messages.recruit_010);
			recruitForm.goModify();
			return;
		}else if (e4xData.response.code == "-108") {
			alert(messages.email_003);
			recruitForm.goModify();
			return;
		}else if (e4xData.response.code == "-109") {
			alert(messages.email_007);
			recruitForm.goModify();
			return;
		}else if (e4xData.response.code == "-110") {
			alert(messages.recruit_005);
			recruitForm.goModify();
			return;
		}else if (e4xData.response.code == "-111") {
			alert(messages.recruit_005);
			recruitForm.goModify();
			return;
		}else if (e4xData.response.code == "-112") {
			alert(messages.err_001);
			recruitForm.goModify();
			return;
		}else if (e4xData.response.code == "-113") {
			alert(messages.recruit_007);
			recruitForm.goModify();
			return;
		}else if (e4xData.response.code == "-114") {
			alert(messages.recruit_011);
			recruitForm.goModify();
			return;
		}else if (e4xData.response.code == "-201") {
			alert(messages.err_002);
			recruitForm.goModify();
			return;
		}else if (e4xData.response.code == "-202") {
			alert(messages.err_011);
			recruitForm.goModify();
			return;
		}
	}
	alert(messages.err_001);
	return;
};


