﻿////////////////////////////////////////////////////////////////////////////
//
var favoriteCourseID;
var selectReplaceID;
//
var p_Length = 0;
//
var fList_nowNum = 0;
var favoriteListArray = new Array ();
//
/////////////////////////////////////////////////////////////////////////////
var addFavorite = function (courseid, favTitle)
{
	//var detailURL = "demo_addrecommend.html";
	//
	var detailURL = "/myworkout/course_favorite.html";
	//var detailURL = "/myworkout/addrecommend.html";
	//var detailURL = "/app/addrecommend/";
	//
	window.location = detailURL + "?/" + courseid + "/" + favTitle;
	return;
}
/////////////////////////////////////////////////////////////////////////////
var moveReplaceFavorite = function (idd)
{
	selectReplaceID = document.replaceFavForm_U.listSelect.options [document.replaceFavForm_U.listSelect.selectedIndex].value;
	//
	var adddddURL = "/app/html/addfavorite/" + idd + "/" + selectReplaceID;
	window.location = adddddURL;
	return;
}
/////////////////////////////////////////////////////////////////////////////
var makeFavoriteForm_AddFav = function (favTitle, favID, listArray)
{
	favoriteCourseID = favID;
	//
	var baseHtml_HD_FAV = '<!-- form-favorite -->\n'
	+ '<div class=\"form-favorite\">\n'
	+ '<form name=\"replaceFavForm_U\">\n'
	+ '<table>\n'
	+ '<tr>\n'
	+ '<td width=\"180\"><img src=\"/myworkout/images/images/h3_favoritecourse.gif\" alt=\"新規お気に入りコースの追加\" width=\"160\" height=\"100\" /></td>\n'
	+ '<td width=\"300\"><h4><img src=\"/images/common/bg_allow.gif\" alt=\"\" />'
	+ '<input name="id" value=\"' + favoriteCourseID + '\" type=\"hidden\">'
	+ favTitle
	+ '</h4></td>\n'
	+ '<td class=\"br-w\">お気に入りコースの登録は最大5件です。<br />\n'
	+ '入れ替えるコースを選択してください。<br />\n'
	+ '<select name=\"listSelect\">\n';
	//
	for (var i = 0; i < listArray.length; i ++)
	{
		if (i == 0)
		{
			selectReplaceID = listArray [i].getAttribute ('id');
			baseHtml_HD_FAV += '<option name=\"replaceid\" value=\"' + listArray [i].getAttribute ('id') + '\" selected=\"selected\">' + listArray [i].getAttribute ('title') + '</option>\n';
		} else
		{
			baseHtml_HD_FAV += '<option name=\"replaceid\" value=\"' + listArray [i].getAttribute ('id') + '\">' + listArray [i].getAttribute ('title') + '</option>\n';
		}
	}
	//
	baseHtml_HD_FAV += '</select></td>\n'
	+ '<td width=\"240\" class=\"center\" id=\"replaceFavAnchor\">'
	+ '<a href=\"javascript:moveReplaceFavorite(\'' + favoriteCourseID + '\')\"><img src=\"/myworkout/images/images/btn_favorite.gif\" alt=\"このコースをお気に入りに追加\" width=\"186\" height=\"32\" /></a>\n'
	+ '</td>\n'
	+ '</tr>\n'
	+ '</table>\n'
	+ '</form>\n'
	+ '</div>\n'
	+ '<!-- /form-favorite -->\n'
	+ '<br class=\"fl-clear\" />\n';
	//
	return baseHtml_HD_FAV;
}
//////////////////////////////////////////////////////////////////////////////
var makeSWF_AddFav = function (courseID)
{
	var flashAreaID = "flashContentsArea";
	//
	alert(courseID)
	//
	var swfHtml = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"450\" height=\"700\" id=\"course\">"
	+ "<param name=\"movie\" value=\"" + swfDir + "course.swf\">"
	+ "<param name=\"quality\" value=\"high\">"
	+ "<param name=\"wmode\" value=\"transparent\">"
	+ "<param name=\"FlashVars\" value=\"xml_id="
	+ courseID
	+ "\">"
	+ "<embed src=\"" + swfDir + "course.swf\" quality=\"high\" wmode=\"transparent\" width=\"450\" height=\"700\" name=\"course\" pluginspage=\"https://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" FlashVars=\"xml_id="
	+ courseID
	+ "\">"
	+ "</embed>"
	+ "</object>";
	//
	setInnnnerHTML (flashAreaID, swfHtml);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<<<<<
var initFavListArry = function (courseID)
{
	var element = document.getElementById ('entryArea');
	//
	var div = element.getElementsByTagName ("div");
	leg_Nm_Div = div.length;
	//
	var divCnt = 0;
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	for (var d = 0; d < leg_Nm_Div; d ++)
	{
		var myDIV = div [d];
		//
		if ((myDIV.getAttribute ('class') || myDIV.getAttribute ('className')) == 'entry-course')
		{
			var childs = myDIV.getElementsByTagName ('DIV');
			//
			for (var cc = 0; cc < childs.length; cc ++)
			{
				if (divCnt < p_Length)
				{
					favoriteListArray [divCnt] = new Array ();
					//
					var targetItem = myDIV.getElementsByTagName ('DIV').item (cc);
					if (isIE)
					{
						if ((targetItem.getAttribute ('className') == claStr) || (targetItem.getAttribute ('className') == claStr_Choice) || (targetItem.getAttribute ('className') == claStr_Hover))
						{
							favoriteListArray [divCnt] = targetItem;
							//
							targetItem.setAttribute ('className', claStr);
							//
							divCnt ++;
						}
					} else
					{
						if ((targetItem.getAttribute ('class') == claStr) || (targetItem.getAttribute ('class') == claStr_Choice) || (targetItem.getAttribute ('class') == claStr_Hover))
						{
							favoriteListArray [divCnt] = targetItem;
							//
							targetItem.setAttribute ('class', claStr);
							//
							//alert(divCnt+'  :  '+favoriteListArray [divCnt])
							//alert (divCnt)
							//
							divCnt ++;
						}
					}
				} else
				{
					break;
				}
			}
			//
			
		}
	}
	//
	//alert(fList_nowNum)
	if (isIE)
	{
		favoriteListArray [fList_nowNum].setAttribute ('className', claStr_Choice);
	} else
	{
		favoriteListArray [fList_nowNum].setAttribute ('class', claStr_Choice);
	}
	//
	makeSWF_AddFav(courseID);
	/*
	var noneHTML = '<div class=\"cf-none\">'
	+ '<h4><img src=\"/images/myworkout/h3_runwalk_none.gif\" alt=\"RUN&amp;WALK\" /></h4>'
	+ '<h5>該当のコースはありませんでした</h5>'
	+ '</div>';
	*/
}
//////////////////////////////////////////////////////////////////////////////
var setFavCourse = function (listNum, courseID)
{
	fList_nowNum = listNum;
	//
	//alert(favoriteListArray.length)
	//
	fList_length = p_Length;
	//
	for (var i = 0; i < fList_length; i ++)
	{
		if (i == listNum)
		{
			if (isIE)
			{
				favoriteListArray [i].setAttribute ('className', claStr_Choice);
			} else
			{
				favoriteListArray [i].setAttribute ('class', claStr_Choice);
			}
		} else
		{
			//alert (i + '  :  ' + favoriteListArray [i])
			if (isIE)
			{
				favoriteListArray [i].setAttribute ('className', claStr);
			} else
			{
				favoriteListArray [i].setAttribute ('class', claStr);
			}
		}
	}
	//
	makeSWF_AddFav(courseID);
}
/////////////////////////////////////////////////////////////////////////////
var favOnMouseOver = function (targetObj, listNum)
{
	if (isIE)
	{
		if ((targetObj.getAttribute ('className') == claStr))
		{
			targetObj.setAttribute ('className', claStr_Hover);
			//
			
		}
	} else
	{
		if ((targetObj.getAttribute ('class') == claStr))
		{
			targetObj.setAttribute ('class', claStr_Hover);
		}
	}
}
//////////////////////////////////
var favOnMouseOut = function (targetObj)
{
	if (targetObj != favoriteListArray [fList_nowNum])
	{
		if (isIE)
		{
			targetObj.setAttribute ('className', claStr);
			//
		} else
		{
			targetObj.setAttribute ('class', claStr);
			//
		}
	}
}
////////////////////////////////////////////////////////////////////////////
var makeFavoriteList = function (courseID)
{
	var searchRealFlg = true;
	//
	//////////////////////////////////
	var baseHtml_HD = '';
	//
	var baseHtml_DT = '';
	//
	var baseHtml_FT = '</div>\n'
	+ '<!-- /entry-course -->\n'
	+ '</div>\n'
	+ '<!-- /entry-wrapper -->\n'
	+ '</div>\n'
	+ '<!-- /first -->\n';
	//
	//////////////////////////////////
	var targetTab;
	var tagetID;
	var tagetHTML;
	//////////////////////////////////
	var courseXmlUrl;
	//
	setActiveTab ('favorite');
	//
	courseMapUrl = return_url_API ('course') + courseID;
	//
	courseXmlUrl = baseURL + 'app/courselist/favorite';
	//
	baseHtml_HD = '<!-- first -->\n'
	+ '<div class=\"first\">\n'
	+ '<!-- entry-wrapper -->\n'
	+ '<div class=\"entry-wrapper\">\n'
	+ '<div>\n'
	+ '<h3><img src=\"/myworkout/images/h3_favorite.gif\" alt=\"お気に入りコース\" width=\"243\" height=\"12\" /></h3>\n'
	+ '</div>\n'
	+ '<br class=\"fl-clear\" />\n'
	+ '<!-- entry-course -->\n'
	+ '<div class=\"entry-course\">\n';
	//
	//////////////////////////////////
	var httpObj = new JKL.ParseXML.DOM (courseXmlUrl);
	var XMLdata = httpObj.parse ();
	//////////////////////////////////
	XMLdata.getAttribute ('courcelist');
	////////////////////////////////////////////////////////////////////
	var courseList = XMLdata.getElementsByTagName ("course");
	////////////////////////////////////////////////////////////////////
	var category = XMLdata.getAttribute ('both');
	//
	var search_result = courseList.length;
	p_Length = search_result;
	//
	//////////////////////////////////
	var checkId = courseList [0].getAttribute ('id');
	if (checkId == undefined)
	{
		glob_totalpage = 1;
		searchRealFlg = false;
	}
	//
	if ((search_result > 0) && (searchRealFlg == true))
	{
		////////////////////////////////////////////////////////////////////
		if ((search_result >= courseListMaxNum) && (courseID != undefined))
		{
			////////////////////////////////
			var httpObj_MAP = new JKL.ParseXML.DOM (courseMapUrl);
			var XMLdata_MAP = httpObj_MAP.parse ();
			//////////////////////////////////////////////////////////////////////////////////////////////////////
			var courseTITLE = XMLdata_MAP.getAttribute ('title');
			var courseID = XMLdata_MAP.getAttribute ('id');
			//
			//
			baseHtml_HD = makeFavoriteForm_AddFav (courseTITLE, courseID, courseList) + baseHtml_HD;
		}
		////////////////////////////////////////////////////////////////////
		//
		for (var i = 0; i < search_result; i ++)
		{
			if (i < courseListMaxNum)
			{
				favoriteListArray[i] = new Array ();
				//////////////////////////////////
				var id = courseList [i].getAttribute ('id');
				favoriteListArray [i] = id;
				//////////////////////////////////
				var recommendClass = courseList [i].getAttribute ('recommend');
				if (recommendClass == "true")
				{
					recommendClass = "<h4 class=\"favorite\">";
				} else
				{
					recommendClass = "<h4>";
				}
				//////////////////////////////////
				var title = courseList [i].getAttribute ('title');
				//////////////////////////////////
				var status = courseList [i].getAttribute ('status');
				switch (status)
				{
					case "ok" :
					status = "OK";
					break;
					case "error" :
					status = "NG";
					break;
					default :
					status = "&nbsp;";
					break;
				}
				//////////////////////////////////
				var area = courseList [i].getAttribute ('area');
				//////////////////////////////////
				var type = courseList [i].getAttribute ('type');
				switch (type)
				{
					case "run" :
					type = "Run";
					break;
					case "bike" :
					type = "Bike";
					break;
					default :
					type = "";
					break;
				}
				//////////////////////////////////
				var dist = courseList [i].getAttribute ('totaldistance');
				dist = "距離 " + dist + "km";
				//////////////////////////////////
				var member = courseList [i].getAttribute ('member');
				switch (member)
				{
					case "basic" :
					member = "<li><img src=\"/myworkout/images/icon_basic.gif\" alt=\"Basic\" /></li>\n";
					break;
					case "lite" :
					member = "<li><img src=\"/myworkout/images/icon_lite.gif\" alt=\"Lite\" /></li>\n";
					break;
					case "premium" :
					//member = "<li><img src=\"/myworkout/images/icon_premium.gif\" alt=\"Premium\" /></li>\n";
					member = "";
					break;
					case "lite-basic" :
					member = "<li><img src=\"/myworkout/images/icon_basic.gif\" alt=\"Basic\" /></li>\n";
					member += "<li><img src=\"/myworkout/images/icon_lite.gif\" alt=\"Lite\" /></li>\n";
					break;
					default :
					member = "";
					break;
				}
				//
				//////////////////////////////////
				var newBool = courseList [i].getAttribute ('new');
				//
				if (newBool == "true")
				{
					var newObj = '<img src=\"/images/common/icon_new.gif\" alt=\"NEW\" width=\"24\" height=\"9\" />';
				} else
				{
					var newObj = '&nbsp;';
				}
				//////////////////////////////////
				var node_photo = courseList [i].getElementsByTagName ("photo");
				//
				//////////////////////////////////-----------------------------------------------------ERROR PROC
				if (node_photo [0] == undefined)
				{
					var photo_url = '';
				} else
				{
					var photo_url = node_photo [0].getAttribute ('url_t');
				}
				//////////////////////////////////-----------------------------------------------------ERROR PROC
				//////////////////////////////////
				baseHtml_DT += '<!-- entry -->\n'
				+ '<div class=\"entry\" onClick=\"setFavCourse(\'' + i + '\', \'' + id + '\')\" onMouseOver=\"favOnMouseOver(this, \'' + i + '\')\" onMouseOut=\"favOnMouseOut(this, \'' + i + '\')\">\n'
				+ '<h4 class=\"favorite\"><img src=\"/images/common/bg_allow.gif\" alt=\"\" />' + title + '</h4>\n'
				+ '<div class=\"entry-data\">\n'
				+ '<p><img src=\"' + photo_url + '\" alt=\"\" /></p>\n'
				+ '<dl>\n'
				+ '<dt>' + area + '<br />\n'
				+ dist + '</dt>\n'
				+ '<dd>\n'
				+ '<input name=\"detail\" value=\"' + id + '\" type=\"hidden\" />\n'
				+ '<img src=\"/images/common/bg_allow.gif\" alt=\"\" /> <a href=\"javaScript:makeSWF_AddFav(\'' + i + '\');\">コースの詳しいデータを表示</a></dd>\n'
				+ '</dl>\n'
				+ '</div>\n'
				+ '<div class=\"entry-member\">\n'
				+ '<ul>\n' + member + '</ul>\n'
				+ '</div>\n'
				+ '</div>\n'
				+ '<!-- /entry -->\n';
			}
		}
	} else
	{
		baseHtml_DT = '<div class=\"cf-none\">\n'
		+ '<h4><img src=\"/images/myworkout/h3_runwalk_none.gif\" alt=\"RUN&amp;WALK\" /></h4>\n'
		+ '<h5>現在、お気に入りコースの登録が　' + search_result + '件です。</h5>\n'
		+ '</div>\n';
		//
	}
	//
	baseHtml_FT += '<!-- last -->\n'
	+ '<!-- course-info -->\n'
	+ '<div class="course-info">\n'
	+ '<h3><img src="images/h3_info.gif" alt="コース情報" width="243" height="12" /></h3>\n'
	+ '<div id="flashContentsArea"></div>\n'
	+ '<!-- /course-info -->\n'
	+ '</div>\n'
	+ '<!-- /last -->\n';
	//}
	//////////////////////////////////
	////////////////////////////////////////////////////////////////////
	document.write (baseHtml_HD + baseHtml_DT + baseHtml_FT);
	//
	//makeSWF_AddFav (0);
	initFavListArry (checkId);
}

