var DialogSelectDay = "./selectday.aspx";
var DialogAttach    = "./attachment.aspx";
var DialogModel		= "./modelnumber.aspx";
var DialogUpdateGoods = "./goodsupdate.aspx"

/// <summary>
/// Bodyのonloadイベントです。
/// </summary>
function OnloadEvent()
{
	// 自身のフォームにフォーカスを当てます。
	self.focus();

	// 二重Submit防止用コントロールを初期化します。
	document.getElementById("hiddenSubmit").value = "";

	// 画面上の最上位のテキストボックスにフォーカスを当てます。
	SetFocus();

	// 残りセッション時間のカウントダウンを行います。
	StartTimer();
}	

/// <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 SetFocus()
{
	var I;
	var j;
	var DocID;
	for (I = 0; I < document.forms.length; I++) 
	{
		for (j = 0; j < document.forms[I].length; j++) 
		{
			if (document.forms[I].elements[j].type == "text" || document.forms[I].elements[j].type == "password" || document.forms[I].elements[j].type == "textarea" ) 
			{
				if( document.forms[I].elements[j].disabled == false )
				{
					//document.forms[I].elements[j].id.focus() = "";
					DocID = document.forms[I].elements[j].id;
					document.getElementById(DocID).focus();
					return;
				}
			}
		}
	}
}

/// <summary>
/// 別ウィンドウでURLを開きます。
/// </summary>
function OpenLinkWindow(url)
{
	window.open(url);
}

/// <summary>
/// Modalダイアログを開きます。
/// </summary>
function OpenDialogWindow(pagename, arg)
{
	var url;
	var positoin;
	var width,height,left,top;

	switch (pagename)
	{
		case DialogSelectDay :
			url  = "./../dialogbase.aspx";
			url += "?url=" ;
			url += DialogSelectDay;
			width = 310;
			height = 460;
			break;

		case DialogAttach :
			url  = "./dialogbase.aspx";
			url += "?url=" ;
			url += DialogAttach;
			width = 650;
			height = 510;
			break;

		case DialogModel :
			url  = "./dialogbase.aspx";
			url += "?url=" ;
			url += DialogModel;
			width = 650;
			height = 813;
			break;

		case DialogUpdateGoods :
			url  = "./../dialogbase.aspx";
			url += "?url=" ;
			url += DialogUpdateGoods;
			width = 540;
			height = 480;
			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;";
	//position = "status:off;dialogHeight:" + height + "px;dialogWidth:" + width + "px;center:yes;";

	return window.showModalDialog(url, arg, position);
}


///
///タイマーに関するメソッドです。
///画面上にLabelを貼り付け、idを「labelCountDown」とすること。
///
var tid;
var nMax;
var nNow;
var TimerID = "labelCountDown";
var LabelID = "labelRemainsTime";
var UrgencyFontSize = "14px";
var UrgencyFontColor = "red";

///
///タイマー開始
///
function StartTimer()
{
	nMax = 3600;	//カウントする最大値（秒）
	nNow = nMax;	//現在のカウント
	SetTimer();
}
///
///タイマー処理
///
function SetTimer()
{

	var Min = new String;
	var Second = new String;

	Min = Math.floor(nNow / 60);
	Second = nNow - (Min * 60);

	//残り１分から点滅
	if(nNow == 59 )
	{
		Tenmetsu_h();
		if (document.getElementById(LabelID))
		{
			document.getElementById(LabelID).style.fontSize = UrgencyFontSize;
			document.getElementById(LabelID).style.color = UrgencyFontColor;
		}
	}

	if (document.getElementById(TimerID))
	{
		if( Min < 10 )
		{
			Min = "0" + Min;
		}
		if( Second < 10 )
		{
			Second = "0" + Second;
		}
		document.getElementById(TimerID).innerText = Min + ":" + Second;
	}
	else
	{
		return false;
	}

	//ひとつづつカウントダウン
	nNow -= 1;
	
	//nNowの値がマイナスになったら終了
	if (nNow < 0)
	{
		//タイマー終了
		clearTimeout(tid);
	}
	else
	{
		//リピート
		tid=setTimeout('SetTimer()',1000);
	}

}

///
/// 点滅処理（非表示）
///
function Tenmetsu_h()
{
	if (document.getElementById(TimerID))
	{
		document.getElementById(TimerID).style.visibility = "hidden";
		document.getElementById(TimerID).style.fontSize = UrgencyFontSize;
		document.getElementById(TimerID).style.color = UrgencyFontColor;
		setTimeout('Tenmetsu_v()', 500);
	}
}
///
/// 点滅処理（表示）
///
function Tenmetsu_v()
{
	if (document.getElementById("labelCountDown"))
	{
		document.getElementById(TimerID).style.visibility = "visible";
		document.getElementById(TimerID).style.fontSize = UrgencyFontSize;
		document.getElementById(TimerID).style.color = UrgencyFontColor;
		setTimeout('Tenmetsu_h()', 500);
	}
}


