/*
 * 共通 JavaScript
 *
 *
 * Copyright (c) 2003 DRECOM CO.,LTD. All rights reserved.
 * 
 * info@drecom.co.jp
 * http://www.drecom.co.jp/
 */

/**
 * a 要素の onclick 属性で使う。href 属性を調べ、それを URL として使用。
 * 別ウインドウを開き、meta http-equiv refresh を使ってリダイレクトすることにより、
 * "Referer" を削除
 */
function openExternalLink(arg) {
	var externalLink = (arg.href != null) ? arg.href : arg;
	
	var w = window.open();
	w.document.write('<meta http-equiv="refresh" content="0;url='+externalLink+'">');
	w.document.close();
	return false;
}

/**
 * 常に手前に表示するウィンドウを開く
 */
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);
	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);
	subWindow.blur();
	window.focus();
	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 selectSkin(id, login)
{
	if (login) {
		location.href="/sec/DesignChangeConfirm.blog?selectedId=" + id;
	} else {
		location.href="/sec/MakeBlogInput.blog?selectedId=" + id + "&blogType=user";
	}
}
/**
 * id が name の img 要素の画像パスを imgPath に設定
 */
function imgSwap(name,imgPath) {
	document.images[name].src = imgPath ;
}

// -----------------------------------------------------------
// Window Functions
//-----------------------------------------------------------
/** Help */
function openHelpWindow() { /* standard */
  openWindow('/html/help/', 'help', '660', '660', 'yes', 'yes', 'no');
}

// -----------------------------------------------------------
// ユーザブログコメント投稿
//-----------------------------------------------------------
function loadCookie(){
      
  ckary = document.cookie.split("; ");
  str = 0;
  i = 0;
  while (ckary[i]){
    if (ckary[i].substr(0,3) == "c1="){
	  str = 1;
	  break;
    }
    i++;
  }
  return str;
}

function CheckCookie(){
  value = loadCookie();
  if (value == 0) {
    document.write('<div style="display:none">');
  } else {
    document.write('<div style="display">');
  }
}

function CheckCookieLogin(){
  value = loadCookie();
  if (value == 0) {
	document.write('<div style="display">');
  } else {
	document.write('<div style="display:none">');
  }
}

function CheckCookieTR(){
  value = loadCookie();
  if (value == 0) {
    document.write('<tr style="display:none">');
  } else {
    document.write('<tr style="display">');
  }
}

function CheckCookieLoginTR(){
  value = loadCookie();
  if (value == 0) {
	document.write('<tr style="display">');
  } else {
	document.write('<tr style="display:none">');
  }
}

