// ***************************************************
//
// OPEN＆CLOSEボタン動作速度処理
//
// ***************************************************

function add_toggle(elem){
	var target = elem.id+'_cont';
	Effect.BlindUp( target,{ duration:1.0 } );
	var func = function(){
		Effect.toggle( target,'blind',{ duration:1.0 } );
	};
	Event.observe( elem,'click',func );
}
function init(){
	var elem = $('news1');
	if (elem) add_toggle(elem);
}
Event.observe( window,'load',init );



// ***************************************************
//
// カウントダウン処理
//
// ***************************************************

var millenium = new Date(2006,8,1)
var tid;

function display() {
        today = new Date()
        days = Math.floor((millenium-today)/(24*60*60*1000))
        time1 = Math.floor(((millenium-today)%(24*60*60*1000))/(60*60*1000))
        time2 = Math.floor(((millenium-today)%(24*60*60*1000))/(60*1000))%60
        time3 = Math.floor(((millenium-today)%(24*60*60*1000))/1000)%60%60

        if((millenium - today) > 0){
                document.f.days.value = "2006年9月1日まで"+days+"日"+time1+"時間"+time2+"分"+time3+"秒"
        }else{
                document.f.days.value = "2006年9月1日になりました！"
        }
        tid = setTimeout('display()', 1000)
}



// ***************************************************
//
// サブウィンドウ表示処理
//
// ***************************************************

// alert/confirm/info ダイアログ表示中の背景色は alert.css 内の .orverlay_alert を編集する。
// .overlay_alert {
// background-color: #666666;
// filter:alpha(opacity=60);
// -moz-opacity: 0.6;
// opacity: 0.6;
//}
	
function showMyAlert() {
	Dialog.alert(
		"ここにお知らせ内容を記述して下さい！<br /><br />by CMS AGENT", 
		{
			windowParameters: {width:300, height:200},
			okLabel: "close", 
			ok:function(win) {return true;}
		}
	);
}

function showMyConfirm() {
	Dialog.confirm(
		"CMS AGENT Confirm", 
		{
			windowParameters: {width:300},
			okLabel: "close", 
			buttonClass: "myButtonClass",
			id: "myDialogId",
			cancel: function(win) {},
			ok: function(win) {return true;}
		}
	);
}

function showMyInfo() {
	Dialog.info(
		"ここにお知らせ内容を記述して下さい！<br /><br />by CMS AGENT",
		{
			windowParameters: {width:300, height:200},
			showProgress: true
		}
	);

	var timeout = 10;

	setTimeout(infoTimeout, 1000);
	function infoTimeout() {
		timeout--;
		if (timeout >0) {
			Dialog.setInfoMessage("ここにお知らせ内容を記述して下さい！<br />表示時間を設定できるお知らせバージョンです。 残り " + timeout + " 秒で閉じます。<br /><br />by CMS AGENT");
			setTimeout(infoTimeout, 1000);
		} else {
			Dialog.closeInfo();
		}
	}
}


// カスタム HTML のダイアログ表示中の背景色を変更するには、 alphacube.css の .orverlay_alphacube を編集する
// というか、 Dialog.alert() の第２引数の windowParameters: {} 内に、className: "abc" とかしたら、 .orverlay_abc になる
// 
// .overlay_alphacube {
// 	background-color: #85BBEF;
// filter:alpha(opacity=60);
// -moz-opacity: 0.6;
// opacity: 0.6;
// }

function showMyAjaxDialog() {
	Dialog.alert(
		{
			url: "ajaxdialog.html",
			options: {method: 'get'}
		}, 
		{
			windowParameters: {className: "alphacube", width:600},
			okLabel: "Close"
		}
	);
}
	
function doesDialogShow() {
  var show = document.cookie;
  show = show.match(/showdialog=(.)/);
  if (show && 2 <= show.length) {
    show = show[1];
  } else {
    show = 0;
  }
  return show;
}

function setShowDialog(show) {
  var expDay;
  if (show) {
    expDay = new Date();
    expDay.setTime(expDay.getTime() + (1 * 365 * 24 * 60 * 60 * 1000)); // +1Y
    expDay = expDay.toGMTString();
  } else {
    expDay = "Thu, 01-Jan-70 00:00:01 GMT";
  }
  document.cookie = "showdialog=" + show + ";expires=" + expDay;
}


//ここからスタイルシート切り替え処理01

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

