// ダイアログファイルを指定します。
var DialogBase = "/dialogbase.aspx";
var DialogSelectDay = "/selectday.aspx";
var DialogRelease = "/DialogRelease.aspx";

// フォーカスのあるコントロールの背景色を変えるための初期値を指定します。
var colorful = new ColorfulInput;
colorful.skip = ['submit'];
colorful.color['focus'] = '#FFFF99';

/// <summary>
/// Bodyのonloadイベントです。
/// </summary>
function OnloadEvent()
{	
	// 自身のフォームにフォーカスを当てます。
	self.focus();

	// 二重Submit防止用コントロールを初期化します。
	if (document.getElementById("hiddenSubmit") != null){document.getElementById("hiddenSubmit").value = ""};
	
	
	// フォーカスのあるコントロールの背景色を変えます。
	colorful.set();
	
	//history.forward();

}

/// <summary>
/// 別ウィンドウでURLを開きます。
/// </summary>
function OpenLinkWindow(url)
{
	var winoption;
	var winname,winwidth,winheight,winscroll,winresize,xpos,ypos,tbar,loc;
	
	winwidth = 800;
	winheight = 600;
	
	xpos = (screen.width - winwidth) / 2;
	ypos = (screen.height - winheight) / 2;
	winname = '';
	winscroll = 'yes';
	winresize = 'yes';
	tbar = 'no';
	loc = 'no';
	
	winoption = "left="+xpos+",top="+ypos+",width="+winwidth+",height="+winheight+",scrollbars="+winscroll+",resizable="+winresize+",toolbar="+tbar+",location="+loc;
	window.open(url, winname, winoption);
}

/// <summary>
/// 別ウィンドウでページ内ヘルプを開きます。
/// </summary>
function OpenHelpWindow(url)
{
	var winoption;
	var winname,winwidth,winheight,winscroll,winresize,xpos,ypos,tbar,loc;
	
	winwidth = 500;
	winheight = 300;
	
	xpos = (screen.width - winwidth) / 2;
	ypos = (screen.height - winheight) / 2;
	winname = '';
	winscroll = 'yes';
	winresize = 'yes';
	tbar = 'no';
	loc = 'no';
	
	winoption = "left="+xpos+",top="+ypos+",width="+winwidth+",height="+winheight+",scrollbars="+winscroll+",resizable="+winresize+",toolbar="+tbar+",location="+loc;
	window.open(url, winname, winoption);
}

/// <summary>
/// Modalダイアログを開きます。
/// </summary>
function OpenDialogWindow(pagename, arg)
{
	var url;
	var positoin;
	var width,height,left,top;

	switch (pagename)
	{
		case DialogSelectDay :
			url  = DialogBase;
			url += "?url=" ;
			url += DialogSelectDay;
			width = 310;
			height = 500;
			break;
			
		case DialogRelease :
			url  = DialogBase;
			url += "?url=" ;
			url += DialogRelease;
			width = 800;
			height = 768;
			break;
						
		default :
			return null;
			break;
	}
 
	if( screen.width == width && screen.height == height )
	{
		width = width - 9;
		left = 0;
		top = 0;
	}
	else
	{
		left = (screen.width - width) / 2;
		top  = (screen.height - height) / 2;
	}
	height = height - 56;
	
	position = "status:off;dialogHeight:" + height + "px;dialogWidth:" + width + "px;dialogLeft:" + left + "px;dialogTop:" + top + "px;";

	return window.showModalDialog(url, arg, position);
}

/// <summary>
/// Formのonsubmitイベントです。
/// </summary>
function SubmitEvent(msg)
{
	var SubmitValue;
	SubmitValue = document.getElementById("hiddenSubmit").value;
	document.getElementById("hiddenSubmit").value = "BeGone";
	if( SubmitValue != "" )
	{
		window.alert(msg);
		window.event.returnValue = false;
	}
}


/// <summary>
/// フォーカスのあるコントロールの背景色を変えます。
/// </summary>
function ColorfulInput() {
   this.skip  = [];
   this.color = { 'blur': '', 'focus': '#EEEEEE' };

   this.set = function() {
      for (var i = 0; i < document.forms.length; i++) {
         for (var f = 0; f < document.forms[i].length; f++) {
            var elm = document.forms[i][f];
            if(!this._checkSkip(elm)) continue;

            this._setColor(elm, 'focus');
            this._setColor(elm, 'blur');
         }
      }
   }

   this._checkSkip = function(elm) {
      for(var i in this.skip) {
         if(elm.type == this.skip[i]) return false;
      }
      return true;
   }

   this._setColor = function(elm, type) { 
      var color = this.color[type];
      var event = function() { elm.style.backgroundColor = color; };

      if(elm.addEventListener) {
         elm.addEventListener(type, event, false);
      } else if(elm.attachEvent) {
         elm.attachEvent('on'+type, event);
      } else {
         elm['on'+type] = event;
      }
   }
}

/// <summary>
/// テキストエリアの入力値を制限します。
/// </summary>
function InputLength(str)
{ 
	var len =str.length;
	var cnt =x=y=0;
	var Result;
	
	///
	/// 改行をカウントする
	///
	for(i=0; ;cnt++)
	{
		x = str.indexOf("\n",y);
		if( x == -1 ) break;
		y = x+2;	
	}
	
	///
	/// 改行をカウントせず文字数のみチェックする
	///
	if ( len-(cnt*2) > 300 )
	{
		document.forms[0].elements['textboxRecital'].innerText = str.substring(0,300);
	}
}

