/*
 * 共通 JavaScript
 *
 *
 * Copyright (c) 2003 DRECOM CO.,LTD. All rights reserved.
 * 
 * info@drecom.co.jp
 * http://www.drecom.co.jp/
 */
 
/**
 * 常に手前に表示するウィンドウを開く
 */
function openModalWindow(url, name, height, width, scrollbars, resizable, status)
{
	ModalWindow = openWindow(url, name, height, width, scrollbars, resizable, status);
	onfocus = function onFocus(){
		if (null !=ModalWindow && !ModalWindow.closed) {
			try {
				ModalWindow.focus();
			} catch(e) {
				document.onmousemove = null;
			}
		} else {
			document.onmousemove = null;
		}
	}
	
	document.onmousemove = onfocus;

	return ModalWindow;
}

/**
 * ウィンドウを開く
 */
function openWindow(url, name, height, width, scrollbars, resizable, status)
{
	var window_condition = "height=" + height + ",width=" + width + 
					",scrollbars=" + scrollbars + ",resizable=" + resizable + ",toolbar=no,status=" + status;

	subWindow = window.open(url, name, window_condition);
	if (subWindow != null) {
		subWindow.focus();
	}
	return subWindow;
}

/**
 * ウィンドウを後ろに開く
 */
function openWindowBack(url, name, height, width, scrollbars, resizable, status)
{
	var window_condition = "height=" + height + ",width=" + width + 
					",scrollbars=" + scrollbars + ",resizable=" + resizable + ",toolbar=no,status=" + status +
					",left=" + window.screen.width;
	subWindow = window.open(url, name, window_condition);
	if (subWindow != null) {
		subWindow.blur();
	}
	window.focus();
	if (subWindow != null) {
		subWindow.moveTo(0,0);
	}
	return subWindow;
}
/**
 * Alert, Confirm window
 */

// 2004-06-09 Takanori Ishikawa 
// -----------------------------------------------------------
// htmlAlert(), htmlConfirm() は html をそのまま
// 出力せず、サニタイズするようにした。

// sanitize html message
function sanitize_msg(msg)
{
	msg = msg.replace(/</g, '&lt;');
	msg = msg.replace(/>/g, '&gt;');
	msg = msg.replace(/&lt;br\s*&gt;/g, '<br>');

	return msg;
}
// alert
function htmlAlert(msg, height, width)
{
	height = (null == height) ? 130: height;
	width  = (null == width) ? 300: width;
	msg = sanitize_msg(msg);
	
	if (defined(window.showModalDialog)) {
		showModalDialog("/html/message_box.html", msg, "dialogHeight: " + height + "px; dialogWidth: " + width + "px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");
	} else {
		dialogArguments = msg;
		ModalWindow = open("/html/message_box.html", "sub_alert","height=" + height + ",width=" + width + 
					",scrollbars=no,resizable=no,toolbar=no,status=no,alwaysRaised=yes");
		onfocus = function onFocus(){
			if (null !=ModalWindow && !ModalWindow.closed) {
				ModalWindow.focus();
			}
		}
		document.onmousemove = onfocus;
		return ModalWindow;
	}
}
// confirm
function htmlConfirm(msg, height, width)
{
	height = (null == height) ? 130: height;
	width  = (null == width) ? 300: width;
	if (defined(window.showModalDialog)) {
		var value = showModalDialog("/html/confirm.html", sanitize_msg(msg), "dialogHeight: " + height + "px; dialogWidth: " + width + "px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");
		if (typeof value == "undefined") {
			value = false;
		} 
		return value;
	} else {
		return window.confirm(msg.replace(/<br[^>]*\/?>/, '\n'));
	}
}

/**
  * 曜日を取得する関数
  * year:  年
  * month: 月
  * day:   日
  */
function getDayOfWeek(year, month, day) {

	DateOfWeek	= new Date();
	DateOfWeek.setYear(year);
	DateOfWeek.setMonth(month - 1);
	DateOfWeek.setDate(day);
	day_of_week_number	= DateOfWeek.getDay();

	days = new Array('日','月','火','水','木','金','土');
	return days[day_of_week_number];
}


// -----------------------------------------------------------
// ポータル、ヘッダ
// -----------------------------------------------------------
/**
 * INPUT FORM の背景色変更
 */
function focusForm(obj,flag){
	if (obj == null || obj.style == null) {
		return;	
	}
	obj.style.backgroundColor = flag ? '#FFFFCC' : '#FFFFFF' 
}

function imgSwap(name,gifPath) {
	document.images[name].src = gifPath ;
}

