////////////////////////////////////////////////////////////////////////////////
//
// クライアントスクリプト定義
//
////////////////////////////////////////////////////////////////////////////////

// ブラウザのバージョン番号
var _version = parseInt(navigator.appVersion);

// ブラウザの種類（Microsoft Internet Explorer 系）
var _ismsie  = isMSIE();

//------------------------------------------------------------------------------
// 表示する画像を変更します
//------------------------------------------------------------------------------
function changeImage(targetName, srcName)
{
	if( _version >= 4 )
	{
		window.document.images[targetName].src = srcName;
	}
}

//------------------------------------------------------------------------------
// 指定した要素のスタイルクラスを変更します
//------------------------------------------------------------------------------
function changeStyle(target, style)
{
	if( _version >= 4 )
	{
		target.className = style;
	}
}

//------------------------------------------------------------------------------
// ウィンドウを閉じます
//------------------------------------------------------------------------------
function closeWindow()
{
	//ウィンドウを閉じます
	window.close();
	
	//イベントをキャンセルさせます
	window.event.cancelBubble = true;
	window.event.returnValue = false;
	return false;
}

//------------------------------------------------------------------------------
// フォーム送信時の確認メッセージを表示します
//------------------------------------------------------------------------------
function confirmPostData(message)
{
	//確認メッセージを表示します
	var ret = window.confirm( message );
	
	//「いいえ」の時はイベントバブルを停止します
	window.event.cancelBubble = !ret;
	window.event.returnValue = ret;
	
	//「いいえ」の時は false を返し、フォーム送信をキャンセルさせます
	return ret;
}

//------------------------------------------------------------------------------
// Microsoft Internet Explorer 系ブラウザかどうかを調べます
//------------------------------------------------------------------------------
function isMSIE()
{
	var app = window.navigator.appName.toLowerCase();
	return ( app.indexOf( "microsoft" ) > -1 || app.indexOf( "opera" ) > -1 );
}

//------------------------------------------------------------------------------
// 日付入力用のカレンダーウィンドウを表示します
//------------------------------------------------------------------------------
function openCalendarWindow(elementName)
{
	//ウィンドウを開くためのパラメータを設定します
	var url  = 'calendar.aspx?e=' + elementName;
	var name = '_calendar';
	var features = 'width=280,height=380' 
			+ ',menubar=no,toolbar=no,location=yes,personalbar=no,status=no' 
			+ ',scrollbars=no,resizable=yes';
	
	//カレンダーウィンドウを表示します
	return openWindow( url, name, features );
}

//------------------------------------------------------------------------------
// 画像表示用のイメージウィンドウを表示します
//------------------------------------------------------------------------------
function openImageWindow(url, width, height)
{
	width  += 20;
	height += 30;
	
	//ウィンドウを開くためのパラメータを設定します
	var name     = '_image';
	var features = 'width=' + width + ',height=' + height 
			+ ',menubar=no,toolbar=no,location=yes,personalbar=no,status=yes' 
			+ ',scrollbars=no,resizable=yes';
	
	//イメージウィンドウを表示します
	return openWindow( url, name, features );
}

//------------------------------------------------------------------------------
// 簡易ページ用のシンプルウィンドウを表示します
//------------------------------------------------------------------------------
function openSimplePageWindow(url)
{
	//ウィンドウを開くためのパラメータを設定します
	var height   = window.screen.availHeight * 0.8;
	var name     = '_page';
	var features = 'width=660,height=' + height 
			+ ',menubar=no,toolbar=no,location=yes,personalbar=no,status=yes' 
			+ ',resizable=yes';
	
	//シンプルウィンドウを表示します
	return openWindow( url, name, features );
}

//------------------------------------------------------------------------------
// 新しいウィンドウを表示します
//------------------------------------------------------------------------------
function openWindow(url, name, features)
{
	//新しいウィンドウを開きます
	var win = window.open( url, name, features );
	
	//イベントをキャンセルさせます
	window.event.cancelBubble = true;
	window.event.returnValue = false;
	
	//新たに開いたウィンドウをアクティブにします
	win.focus();
	
	return false;
}

//------------------------------------------------------------------------------
// 指定のコントロールに今日から一番近い年度初めの日付を設定します
//------------------------------------------------------------------------------
function setFirstDateOfFiscalYear(elementName)
{
	//Date オブジェクトを作成します
	var dte = new Date();
	
	var year  = dte.getFullYear();
	if( dte.getMonth() > 8 )
	{
		year += 1;
	}
	
	//指定のコントロールに年度初めの日付を設定します
	window.document.forms[0].elements(elementName).value 
			= year.toString() + "/04/01";
	
	//イベントバブルを停止します
	window.event.cancelBubble = true;
	window.event.returnValue = false;
	
	//イベントをキャンセルさせます
	return false;
}

//------------------------------------------------------------------------------
// 指定のコントロールに現在の日付を設定します
//------------------------------------------------------------------------------
function setDateToday(elementName)
{
	//Date オブジェクトを作成します
	var dte = new Date();
	
	//表示する文字列を作成します
	var year  = dte.getFullYear();
	var month = "0" + (dte.getMonth() + 1);
	var day   = "0" + dte.getDate();
	
	//指定のコントロールに現在の日付を設定します
	window.document.forms[0].elements(elementName).value 
			= year + "/" + month.substring( month.length - 2, month.length ) 
				   + "/" + day.substring( day.length - 2, day.length );
	
	//イベントバブルを停止します
	window.event.cancelBubble = true;
	window.event.returnValue = false;
	
	//イベントをキャンセルさせます
	return false;
}

//------------------------------------------------------------------------------
// 指定のコントロールに日付を設定します
//------------------------------------------------------------------------------
function setDateThisDay(textBoxName1, textBoxName2)
{
	var dt2 = new Date();
	setDateTime( textBoxName1, dt2 );
	setDateTime( textBoxName2, dt2 );
}

function setDateThisWeek(textBoxName1, textBoxName2)
{
	var dt2 = new Date();
	var dt1 = new Date( dt2.getFullYear(), dt2.getMonth(), dt2.getDate() - 6 );
	setDateTime( textBoxName1, dt1 );
	setDateTime( textBoxName2, dt2 );
}

function setDateThisMonth(textBoxName1, textBoxName2)
{
	var dt2 = new Date();
	var dt1 = new Date( dt2.getFullYear(), dt2.getMonth() - 1, dt2.getDate() + 1 );
	setDateTime( textBoxName1, dt1 );
	setDateTime( textBoxName2, dt2 );
}
