var DisableSubmit = {
	init: function() {
		this.addEvent(window, 'load', this.set());
	},

	set: function() {
		var self = this;
		return function() {
			for (var i = 0; i < document.forms.length; ++i) {
				if(document.forms[i].onsubmit) continue;
					document.forms[i].onsubmit = function() {
					self.setDisable(this.getElementsByTagName('input'));
				};
			}
		}
	},

	setDisable: function(elms) {
		for (var i = 0, elm; elm = elms[i]; i++) {
			if ((elm.type == 'submit' || elm.type == 'image') && !elm.disabled) {
				Set(elm);
				unSet(elm);
			}
		}

		function Set(button) {
			window.setTimeout(function(){
				button.disabled = true;
			}, 1);
		}
	
		function unSet(button) {
			window.setTimeout(function(){
				button.disabled = false;
			}, 1000);
		}
	},

	addEvent: function(elm, type, event) {
		if(elm.addEventListener) {
			elm.addEventListener(type, event, false);
		} else if(elm.attachEvent) {
			elm.attachEvent('on'+type, event);
		} else {
			elm['on'+type] = event;
		}
	}
}

DisableSubmit.init();

$(function(){
	$('#contents input[@type*=text]').focus(function(){
		$(this).css('background', '#ffffcc');
	});
	
	$('#contents input[@type*=text]').blur(function(){
		$(this).css('background', '#fff');
	});
	
	$('#contents input[@type*=password]').focus(function(){
		$(this).css('background', '#ffffcc');
	});
	
	$('#contents input[@type*=password]').blur(function(){
		$(this).css('background', '#fff');
	});
	
	$('#col-contents input[@type*=text]').focus(function(){
		$(this).css('background', '#ffffcc');
	});
	
	$('#col-contents input[@type*=text]').blur(function(){
		$(this).css('background', '#fff');
	});
	
	$('#col-contents input[@type*=password]').focus(function(){
		$(this).css('background', '#ffffcc');
	});
	
	$('#col-contents input[@type*=password]').blur(function(){
		$(this).css('background', '#fff');
	});
});

function showCalendar(date, path) {
	$.ajax({
		url: '/ajax/calendar', 
		type: 'post', 
		dataType: 'json', 
		data: {date: date, path: path}, 
		success: function(json) {
			$('#calendar-box').html(decodeURIComponent(json.calendar));
		}
	});
}
