﻿

//  機能1　　　　：プルダウンメニューより選択された生年月日から対象となるコースを検索後に移動
//  
//  現在時刻など動的な取得なし

//  機能2　　　：プルダウンメニューより選択された生年月日と現在の年月日を計算しリンク振り分け
//  時刻取得参照




function popJump(selOBJ){
	/**
	 * 
	 * 現在の時間
	 * 誕生日の設定
	 * ※各月で2日以降に生まれた場合は、その月の2日に誕生日設定
	 * 
	 */
	y = document.myForm.nen.selectedIndex;
	m = document.myForm.tuki.selectedIndex;
	d = document.myForm.niti.selectedIndex;
	yy = document.myForm.nen.options[y].value;
	mm = document.myForm.tuki.options[m].value;
	dd = document.myForm.niti.options[d].value > 1 ? 2 : 1;

//	var nowDate = new Date();
	var nowDate = new Date(2010,2,22);
//年度が替わる（3月）まではダミーデータを入れる↑
	var birthDate = new Date(yy, mm - 1, dd);




	/**
	 * 
	 * 年度（fiscalYear）の取得
	 * 
	 */
	if(nowDate.getMonth() < 2)
	{
		var fiscalYear = nowDate.getFullYear() - 1;
	}
	else
	{
		var fiscalYear = nowDate.getFullYear();
	}




	/**
	 * 
	 * 各コースのオブジェクトコンストラクタ
	 * .dateStr 対象となる誕生日の期間、最初
	 * .dateEnd 対象となる誕生日の期間、最後
	 * .url     リンク先
	 * 
	 */
	function course(url, target, yearAdjust)
	{
		this.url = url;
		this.dateStr = new Date(fiscalYear + yearAdjust, 3, 2);
		this.dateEnd = new Date(fiscalYear + yearAdjust + 1, 3, 2);
		this.target = target;
	}




	/**
	 * 
	 * 各コースの期間設定
	 * 
	 */
	var mama = new course("/baby/maternity/index.html", "self", +1);

	var baby = new course("/baby/maternity/index.html", "self", 0);

	//07.05.14 22:00にプチファーへ切り替え
	//coursechg = new Date(2007, (05-1), 14, 22, 00);
	//if (nowDate < coursechg){
	//	var petitFirst = new course("/age0.html", "self", -1);
	//}
	//else {
		var petitFirst = new course("/age1.html", "self", -1);
	//}
	//切り替えしたいときはスラッシュをトル

	var petit = new course("/course/petit/index.html", "self", -2);
	var pocket = new course("/course/pocket/index.html", "self", -3);
	var hop = new course("/course/hop/index.html", "self", -4);
	var step = new course("/course/step/index.html", "self", -5);
	var jump = new course("/course/jump/index.html", "self", -6);
	var zemi = new course("/elementary.html", "blank", -7);
	var zemi2 = new course("/elementary.html", "blank", -8);
	var zemi3 = new course("/elementary.html", "blank", -9);

	var error = new course("/err.html", "self");




	/**
	 * 
	 * 誕生日による条件分岐
	 * 
	 */

	// マタニティ
	if(birthDate >= mama.dateStr && birthDate < mama.dateEnd)
	{
		wind(mama.url, mama.target);
	}

	// baby
	else if(birthDate >= baby.dateStr && birthDate < baby.dateEnd)
	{
		wind(baby.url, baby.target);
	}

	// プチファースト
	else if(birthDate >= petitFirst.dateStr && birthDate < petitFirst.dateEnd)
	{
		wind(petitFirst.url, petitFirst.target);
	}
	
	// ぷち
	else if(birthDate >= petit.dateStr && birthDate < petit.dateEnd)
	{
		wind(petit.url, petit.target);
	}

	// ぽけっと
	else if(birthDate >= pocket.dateStr && birthDate < pocket.dateEnd)
	{

		wind(pocket.url, pocket.target);
	}

	// ほっぷ
	else if(birthDate >= hop.dateStr && birthDate < hop.dateEnd)
	{
		wind(hop.url, hop.target);
	}

	// すてっぷ
	else if(birthDate >= step.dateStr && birthDate < step.dateEnd)
	{
		wind(step.url, step.target);
	}

	// じゃんぷ
	else if(birthDate >= jump.dateStr && birthDate < jump.dateEnd)
	{
		wind(jump.url, jump.target);
	}

	// 小ゼミ
	else if(birthDate >= zemi.dateStr && birthDate < zemi.dateEnd)
	{
		wind(zemi.url, zemi.target);
	}
	// 小ゼミその2
	else if(birthDate >= zemi2.dateStr && birthDate < zemi2.dateEnd)
	{
		wind(zemi2.url, zemi2.target);
	}
	// 小ゼミその3
	else if(birthDate >= zemi3.dateStr && birthDate < zemi2.dateEnd)
	{
		wind(zemi3.url, zemi3.target);
	}


	// mama
	else
	{
		wind(mama.url, mama.target);
	}

	// エラー
//	else
//	{
//		window.alert("該当するコースはありませんでした。");
//	}




	/**
	 * 
	 * ウィンドウ処理
	 * 
	 */
	function wind(url, target)
	{
		if(target == "blank")
		{
			var newWind = window.open(url,"subwindow");
			newWind.focus();
		}
		else
		{
			location.href = url;
		}
	}




}


