
	
	var giRegionIx;
	var giServiceIx;
	var giShift;
	var garrHour;
	var giIsService;
	var giDaysIx = 1;
	var giWeeksIx = 1;
	
	var DEF_MINIMUM_HOUR = 3;
	var DEF_SERVICE_HOUR = 5;
	var DEF_COMMITION_FEE = 0.15;
	
	var DEF_SHIFT_DAIRY = 0;
	var DEF_SHIFT_NIGHT = 1;
	var DEF_SHIFT_STAY = 2;
	
	// 
	function fMain()
	{
		// 入力チェック
		if( !fValidateEnter( ) )
		{
			return false;
		}
		
		// 合計金額取得
		var iTotalPrice = fGetTotalPrice();
		
		// 金額表示
		fPrintTotalPrice( iTotalPrice );
		
		return true;
		
	}
	
	// 
	function fReset()
	{
		// 
		document.form1.reset();
		
		// 金額表示
		fPrintTotalPrice( 0 );
		
		return true;
		
	}
	
	// 入力チェック
	function fValidateEnter( )
	{
		
		var i;
		var iChecked;
		
		// 地域
		iChecked = false
		for( i = 0; i < document.form1.region.length; i++ )
		{
			if( document.form1.region[i].checked )
			{
				giRegionIx = document.form1.region[i].value;
				iChecked = true;
				break;
			}
		}
		if( !iChecked )
		{
			alert( "ご利用の地域を選択してください。" );
			return false;
		}
		
		// サービス
		iChecked = false
		for( i = 0; i < document.form1.service.length; i++ )
		{
			if( document.form1.service[i].checked )
			{
				giServiceIx = document.form1.service[i].value;
				iChecked = true;
				break;
			}
		}
		if( !iChecked )
		{
			alert( "ご希望のサービスを選択してください。" );
			return false;
		}
		
		// 利用時間
		if( !document.form1.hour[0].checked &&
			!document.form1.hour[1].checked &&
			!document.form1.hour[2].checked )
		{
			alert( "「通い」・「夜勤」もしくは「泊り」のどれかを選択してください。" );
			return false;
		}
		
		if( document.form1.hour[0].checked )
		{
			// 時間計算
			
			// 開始時間
			var iStart = 0;
			if( document.form1.start[ document.form1.start.selectedIndex ].value )
			{
				iStart = document.form1.start[  document.form1.start.selectedIndex ].value;
				iChecked = true;
			}
			else
			{
				alert( "「開始時間」を入力してください。" );
				return false;
			}
			
			// 終了時間
			var iEnd = 0;
			if( document.form1.end[ document.form1.end.selectedIndex ].value )
			{
				iEnd = document.form1.end[ document.form1.end.selectedIndex ].value;
				iChecked = true;
			}
			else
			{
				alert( "「終了時間」を入力してください。" );
				return false;
			}
			
			
			if( ( iEnd - iStart ) <  DEF_MINIMUM_HOUR )
			{
				// DEF_MINIMUM_HOUR 時間以上選択させる
				alert( "時間は合計で" + DEF_MINIMUM_HOUR + " 時間以上になるように選択してください。" );
				return false;
			}
			
			giIsService = 0;
			if( ( iEnd - iStart ) >= DEF_SERVICE_HOUR )
			{
				// 単価割引
				giIsService = 1;
			}
			garrHour = fGetHourArray( iStart, iEnd );
			giShift = DEF_SHIFT_DAIRY;
		}
		else if( document.form1.hour[1].checked )
		{
			// 夜勤
			giShift = DEF_SHIFT_NIGHT;
		}
		else if( document.form1.hour[2].checked )
		{
			// 泊り
			giShift = DEF_SHIFT_STAY;
		}
		
		// 日
		iChecked = false
		for( i = 0; i < document.form1.days.length; i++ )
		{
			if( document.form1.days[i].checked )
			{
				giDaysIx = document.form1.days[i].value;
				iChecked = true;
			}
		}
		if( !iChecked )
		{
			giDaysIx = document.form1.days[0].value;
			return false;
		}
		
		// 週
		iChecked = false
		for( i = 0; i < document.form1.week.length; i++ )
		{
			if( document.form1.week[i].checked )
			{
				giWeeksIx = document.form1.week[i].value;
				iChecked = true;
			}
		}
		if( !iChecked )
		{
			giWeeksIx = document.form1.week[0].value;
			return false;
		}
		
		return true;
	}
	
	
	// 単価取得(時間ごと)
	function fGetUnitPriceHour( iRegionIx, iServIx, iRangeIx, iExIx )
	{
		
		var arrUnitPrice = new	Array(
									Array(
										// 千葉
										Array(
											Array( 0, 0 ),
											Array( 1400, 1350 ),
											Array( 1680, 1620 ),
											Array( 2100, 2025 )
										),
										Array(
											Array( 0, 0 ),
											Array( 1600, 1550 ),
											Array( 1920, 1860 ),
											Array( 2400, 2325 )
										),
										Array(
											Array( 0, 0 ),
											Array( 1450, 1400 ),
											Array( 1740, 1680 ),
											Array( 2175, 2100 )
										),
										Array(
											Array( 0, 0 ),
											Array( 1450, 1400 ),
											Array( 1740, 1680 ),
											Array( 2175, 2100 )
										)
									),
									Array(
										// 東京
										Array(
											Array( 0, 0 ),
											Array( 1700, 1650 ),
											Array( 2040, 1980 ),
											Array( 2550, 2475 )
										),
										Array(
											Array( 0, 0 ),
											Array( 1750, 1700 ),
											Array( 2100, 2040 ),
											Array( 2625, 2550 )
										),
										Array(
											Array( 0, 0 ),
											Array( 1600, 1550 ),
											Array( 1929, 1860 ),
											Array( 2400, 2325 )
										),
										Array(
											Array( 0, 0 ),
											Array( 1600, 1550 ),
											Array( 1929, 1860 ),
											Array( 2400, 2325 )
										)
									)
								);
								
		var iRet = arrUnitPrice[ iRegionIx ][ iServIx ][ iRangeIx ][ iExIx ];
		return iRet;
		
	}
	
	// 夜勤の日給
	function fGetUnitPriceNightShift( iRegionIx, iServIx )
	{
		
		var arrUnitPrice = new	Array(
									// 千葉
									Array( 11000, 13000, 12500, 12500 ),
									// 東京
									Array( 13000, 14000, 13000, 13000 )
								);
		var iRet = arrUnitPrice[ iRegionIx ][ iServIx ];
		
		return iRet;
		
	}
	
	// 泊りの日給
	function fGetUnitPriceStay( iRegionIx, iServIx )
	{
		
		var arrUnitPrice = new	Array(
									Array( 15000, 17380, 14400, 14400 ),
									Array( 16000, 17600, 15000, 15000 )
								);
		var iRet = arrUnitPrice[ iRegionIx ][ iServIx ];
		
		return iRet;
		
	}
	
	// 時間配列取得
	function fGetHourArray( iStart, iEnd )
	{
		var arrHour = new	Array(
								Array( 9, 1 ),
								Array( 10, 1 ),
								Array( 11, 1 ),
								Array( 12, 1 ),
								Array( 13, 1 ),
								Array( 14, 1 ),
								Array( 15, 1 ),
								Array( 16, 1 ),
								Array( 17, 2 ),
								Array( 18, 2 ),
								Array( 19, 2 ),
								Array( 20, 2 ),
								Array( 22, 2 )
							);
		var arrRet = new Array(  );
		var i;
		var j = 0;
		
		for( i = 0; i < arrHour.length; i++ )
		{
			if( iStart <= arrHour[ i ][ 0 ]  && arrHour[ i ][ 0 ] < iEnd )
			{
				arrRet[ j ] = arrHour[ i ][ 1 ];
				j++;
			}
		}
		
		return arrRet;
		
	}
	
	// 日単価取得
	function fGetDailyTotalPrice()
	{
		var iRet = 0;
		var i;
		
		if( giShift == DEF_SHIFT_DAIRY )
		{
			// 時間給
			for( i = 0; i < garrHour.length; i++ )
			{
				iRet += fGetUnitPriceHour( giRegionIx, giServiceIx, garrHour[ i ], giIsService );
			}
		}
		else if( giShift == DEF_SHIFT_NIGHT )
		{
			// 夜勤
			iRet = fGetUnitPriceNightShift( giRegionIx, giServiceIx );
		}
		else if( giShift == DEF_SHIFT_STAY )
		{
			// 泊り
			iRet = fGetUnitPriceStay( giRegionIx, giServiceIx );
		}
		
		return iRet + Math.round( iRet * DEF_COMMITION_FEE );
		
	}
	
	// 合計金額取得
	function fGetTotalPrice()
	{
		var iRet = 0;
		
		// 日給
		iRet = fGetDailyTotalPrice();
		
		iRet = iRet * giDaysIx * giWeeksIx;
		
		return iRet;
	}
	
	// 合計金額表示
	function fPrintTotalPrice( iPrice )
	{
		document.price.document.open( "text/html", "replace" );
		document.price.document.writeln( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"" );
		document.price.document.writeln( "\"http://www.w3.org/TR/html4/loose.dtd\">" );
		document.price.document.writeln( "<html>" );
		document.price.document.writeln( "<head>" );
		document.price.document.writeln( "<meta http-equiv=\"Content-Type\" content=\"text/html\; charset=shift_jis\">" );
		document.price.document.writeln( "<title>お見積もり金額</title>" );
		document.price.document.writeln( "<link href=\"style_cal.css\" rel=\"stylesheet\" type=\"text/css\">" );
		document.price.document.writeln( "</head>" );
		document.price.document.writeln( "<body style=\"margin:0px\" bgcolor=\"#FFFFFF\"> " );
		document.price.document.writeln( "<center> " );
		document.price.document.writeln( "<table cellpadding=\"0\"  cellspacing=\"0\"> " );
		document.price.document.writeln( "<tr> " );
		document.price.document.writeln( "<td class=\"kingaku\"> " );
		document.price.document.writeln( "<center><font face=\"MS Gothic\">" );
		document.price.document.writeln( fNumberFormat( iPrice ) + "円" );
		document.price.document.writeln( "</font></center> " );
		document.price.document.writeln( "</td> " );
		document.price.document.writeln( "</tr> " );
		document.price.document.writeln( "</table> " );
		document.price.document.writeln( "</center> " );
		document.price.document.writeln( "</body>" );
		document.price.document.writeln( "</html>" );
		document.price.document.close();
		
		return true;
	}
	
	// 金額フォーマット
	function fNumberFormat( iPrice )
	{
		var i,j;
		var arrTmp = iPrice.toString().split("").reverse();
		var arrTmp2 = new Array();
		
		j = 0;
		for( i = 0; i < arrTmp.length; i++ )
		{
			if( j == 3 )
			{
				arrTmp2.push( "," );
				j = 0;
			}
			else
			{
				j++;
			}
			arrTmp2.push( arrTmp[ i ] );
		}
		
		var iRet = arrTmp2.reverse(  ).join( "" );
		
		return iRet;
	}
	