Event.observe(window, 'load', history_back);

function history_back(){
	if ($('history_back') != null) {
		Event.observe('history_back', 'click', function(){
			history.back();
		});
	};
}

var Standard = Class.create();
Standard.prototype = {
	initialize: function() {
	},

	open: function(openId) {
		$(openId).className = "";
	},
	
	ajaxDispChange: function(url, dispId, options){
		options = options || {};
		new Ajax.Request( 
			url, 
			{ 
				method: 'get',
				onSuccess: function(request) {
				}.bind(this),
				onFailure: function(request) { 
					alert('読み込みに失敗しました'); 
				}.bind(this),
				onComplete: function(request) { 
					$(dispId).innerHTML = request.responseText;
				}.bind(this),
				onException: function (request) { 
					alert('読み込み中にエラーが発生しました'); 
	            }.bind(this)
	        }
	    );
	},
	
	ajaxPopup: function(url, formId, submitTagId, popupId, options){
		options = options || {};
		new Ajax.Request( 
			url, 
			{ 
				method: 'post',
				postBody: Form.serialize(formId), 
				onSuccess: function(request) {
				}.bind(this),
				onFailure: function(request) { 
					alert('読み込みに失敗しました'); 
				}.bind(this),
				onComplete: function(request) {
					this.popup(submitTagId, popupId, options);
					$(popupId).innerHTML = request.responseText;
				}.bind(this),
				onException: function (request) { 
					alert('読み込み中にエラーが発生しました'); 
	            }.bind(this)
	        }
	    );
	},
	
	ajaxGetPopup: function(url, query, triggerId, popupId, options){
		options = options || {};
		query = query || null;
		new Ajax.Request( 
			url, 
			{ 
				method: 'get',
				parameters: query, 
				onSuccess: function(request) {
				}.bind(this),
				onFailure: function(request) { 
					alert('読み込みに失敗しました'); 
				}.bind(this),
				onComplete: function(request) { 
					this.popup(triggerId, popupId, options);
					$(popupId).innerHTML = request.responseText;
				}.bind(this),
				onException: function (request) { 
					alert('読み込み中にエラーが発生しました'); 
	            }.bind(this)
	        }
	    );
	},
	
	popup: function(triggerId, popupId, options) {
		options = options || {};
		var offset = $(triggerId).positionedOffset();
		$(popupId).className = (options.popupClass == undefined) ? "" : options.popupClass;
		$(popupId).style.position = "absolute";
		if (parseInt(offset[0]) < 600) {
			var left = (options.left == undefined) ? parseInt(offset[0]) + 60 : parseInt(offset[0]) + options.left;
			$(popupId).style.left = left + "px";
		} else {
			var left = (options.left == undefined) ? parseInt(offset[0]) - 250 : parseInt(offset[0]) + options.left;
			$(popupId).style.left = left + "px";
		}
		if (parseInt(offset[1]) < 100) {
			var top = (options.top == undefined) ? parseInt(offset[1]) + 60 : parseInt(offset[1]) + options.top;
			$(popupId).style.top = top + "px";
		} else {
			var top = (options.top == undefined) ? parseInt(offset[1]) - 60 : parseInt(offset[1]) + options.top;
			$(popupId).style.top = top + "px";
		}
//		leftDefault = (parseInt(offset[0] < 600)) ? parseInt(offset[0]) + 60 : parseInt(offset[0]) * 0.9;
//		var left = (options.left == undefined) ? parseInt(offset[0]) + leftMov : parseInt(offset[0]) + options.left;
//		topDefault = (parseInt(offset[0] < 100)) ? 60 : -60;
//		var top = (options.top == undefined) ? offset[1] + topMov : offset[1] + options.top;
//		$(popupId).style.left = left + "px";
//		$(popupId).style.top = top + "px";
	},
	
	popupClose: function(popupId) {
		$(popupId).className = 'hide';
	}
}
