/**
 *
 */
var PitacriUtils = {

	/**
	 *
	 */
	popupTitle : "pitacri_popup_window",

	/**
	 *
	 */
	popupOptions : $H( {
		width : 100,
		height : 100,
		status : "no",
		scrollbars : "no",
		directories : "no",
		menubar : "no",
		resizable : "no",
		toolbar : "no"
	}).inject( [], function(a, values) {
		a.push(values.join("="));
		return a;
	}).join(","),

	/**
	 *
	 */
	install : function() {
		PitacriUtils.installPopupDetailWindow();
		PitacriUtils.installSelectJumpMenu();
		PitacriUtils.installSubmitForm();
		PitacriUtils.installInputFileUpload();
	},

	/**
	 *
	 */
	installPopupDetailWindow : function() {
		$$("a.popup").each(
				function(a) {
					$(a).observe(
							"click",
							(function(e) {
								var w = window.open(this.href,
										PitacriUtils.popupTitle,
										PitacriUtils.popupOptions);
								w.focus();
								Event.stop(e);
							}).bindAsEventListener(a));
				});
	},

	/**
	 *
	 */
	installSelectJumpMenu : function() {
		$$("select.jump-menu").each(function(select) {
			$(select).observe("change", (function() {
				try {
					window.location = this.options[this.selectedIndex].value;
				} catch (e) {
					console && console.log(e);
				}
			}).bindAsEventListener(select));
		});
	},

	/**
	 *
	 */
	installSubmitForm : function() {
		$$("a.submit-form").each(
				function(a) {
					$(a).observe(
							"click",
							PitacriUtils._onSubmitFormClick
									.bindAsEventListener(a));
				});
	},

	_onSubmitFormClick : function(event) {
		for ( var p = this; p && (p.tagName != "FORM"); p = p.parentNode)
			;
		try {
			p && p.submit();
		} catch (e) {
			console && console.log(e);
		}

		Event.stop(event);
	},

	/**
	 * input type="file" 要素 IE6でファイルパスを直接入力できなくします。
	 */
	installInputFileUpload : function() {
		$$("input[type=file]").each(function(input) {
			$(input).setStyle( {
				imeMode : "disabled"
			}).observe("keydown", function(e) {
				Event.stop(e);
			});
		});
	}
};

Event.observe(window, "load", function() {
	PitacriUtils.install();
});