// ---------- ブラウザを判別する
function JS_GetBrowserType() {
	// ブラウザを判別
	//	IE : 0
	//	Netscape : 1
	//	上記以外 : -1
	var retval;
	var BrowserName = navigator.appName;
	if (BrowserName.match("Microsoft")) {
		retval = 0;
	}else if (BrowserName.match("Netscape")) {
		var BrowserAppVersion = eval(navigator.appVersion.substring(0,3));
		if (BrowserAppVersion >= 5) {
			retval = 1;
		} else {
			retval = 2;
		}
	} else {
		retval = -1;
	}
	return retval;
}
// ---------- 自分のウィンドウを最前面に移動する
function JS_FocusMyself() {
	window.focus();
}

// ---------- 停留所選択画面で停留所を選択
function JS_SelectBusStop(StopName, StopCode, StrRef) {
		var BrowserType = JS_GetBrowserType();		//0:IE, 1:NN
		opener.parent.JS_SetCookie('CkCode' + StrRef, escape(StopCode));
		//opener.JS_SetCookie('CkCode' + StrRef, escape(StopCode));
		opener.parent.JS_SetCookie('CkName' + StrRef, escape(StopName));
		//opener.JS_SetCookie('CkName' + StrRef, escape(StopName));
		//opener.JS_TestCookie();
	if (BrowserType == 0) {		//IE or NN
		ObjStopName = opener.document.getElementById(StrRef);
		ObjStopName.innerHTML = StopName;
		opener.document.FormStopSelect['StrName_' + StrRef].value = StopName;
		opener.document.FormStopSelect['StrCode_' + StrRef].value = StopCode;
		window.close();
	} else if (BrowserType == 2 || BrowserType == 1) {					//それ以外のﾌﾞﾗｳｻﾞ
		opener.location.reload();
		window.close();
	}

}

// ---------- NULLのチェック
function JS_CheckNULL() {
	// NULL : False
	// not NULL : True
	var i, NumArgs = JS_CheckNULL.arguments.length;
	for (i = 0; i < NumArgs; i++ ) {
		if (JS_CheckNULL.arguments[i] == '') {
			return false;
		}
	}
	return true;
}

// ---------- 発着停留所チェック
function JS_CheckNULLStop() {
	// NULL : False
	// not NULL : True
	var i, j, NumArgs = JS_CheckNULLStop.arguments.length;

	for (i = 0; i < NumArgs; i++ ) {
		if (JS_CheckNULLStop.arguments[i] == '') {
			return false;
		}
		for (j = i + 1; j < NumArgs; j++){
			if (JS_CheckNULLStop.arguments[i] == JS_CheckNULLStop.arguments[j]){
				alert("出発地と目的地に同じ停留所が指定されています。");
				return false;
			}
		}
	}
	
	return true;
}
// ---------- 発停留所のみチェック(停留所選択画面から）
function JS_CheckNULLStopDep() {
	var i, j, NumArgs = JS_CheckNULLStopDep.arguments.length;

	for (i = 0; i < NumArgs; i++ ) {
		if (JS_CheckNULLStopDep.arguments[i] == '') {
			return false;
		}
	}
//alert("OK");	
	document.FormStopSelect.action = "../time/tm_pole.asp";
	return true;
}

// ---------- SelectBoxのチェック
function JS_CheckCombo(ObjCombo) {
	OptNum = ObjCombo.options.length;
	for (i=0; i<OptNum; i++) {
		if (ObjCombo.options[i].selected == true) {
			return true;
		}
	}
	return false;
}

// ---------- Cookie初期化
function JS_InitCookie() {
	//document.cookie = 'CkCodeDepBusStop=;';
	//document.cookie = 'CkNameDepBusStop=;';
	//document.cookie = 'CkCodeArrBusStop=;';
	//document.cookie = 'CkNameArrBusStop=;';
	//document.cookie = 'CkIndex_DT=;';
	//document.cookie = 'CkIndex_DAYTYPE=;';
	//document.cookie = 'CkIndex_TMCK=;';
	//document.cookie = 'CkIndex_HOUR=;';
	//document.cookie = 'CkIndex_DEPORARR=;';
}

// ---------- Cookie表示
function JS_TestCookie() {
	alert (document.cookie);
}

// ---------- Cookieに値をセット
function JS_SetCookie(StrCookieName, StrCookieValue) {
	document.cookie = StrCookieName + '=' + StrCookieValue;
}

// ---------- Cookieを読込
function JS_ReadCookie(StrCookieName) {
	retval = "";
	AllCookies = document.cookie;
	Pos = AllCookies.indexOf(StrCookieName + "=");
	
	if (Pos != -1) {
		PosStart = Pos + StrCookieName.length + 1;
		PosEnd = AllCookies.indexOf(";", PosStart);
		if (PosEnd == -1) {
			PosEnd = AllCookies.length;
		}
		
		retval = unescape(AllCookies.substring(PosStart, PosEnd));
	}
	
	return retval;
}

// ---------- SelectBoxをすべて選択
function JS_SelectAll(ObjCombo) {
	OptNum = ObjCombo.options.length;
	for (i=0; i<OptNum; i++) {
		ObjCombo.options[i].selected = true;
	}
}

// ---------- 表示する時刻表を切替（常磐交通版）
function JS_ChangeHtml(StopCode, PoleNo, ObjCombo) {
	if (ObjCombo.options[ObjCombo.selectedIndex].value != PoleNo.toString()) {
		var newURL = 'busstop_result.asp?StrStopKey=' + StopCode.toString() + '&StrPoleNo=' + ObjCombo.options[ObjCombo.selectedIndex].value;
		location.href = newURL;
	}
}

// ---------- 表示する時刻表を切替(三重交通版)
function JS_ChangeHtmlMIe(RouteNo, StrName_DepBusStop, StrCode_DepBusStop, StrName_ArrBusStop, StrCode_ArrBusStop, DayType, ObjCombo) {
	if (ObjCombo.options[ObjCombo.selectedIndex].value != RouteNo.toString()) {
		var newURL = 'time_rslt.asp?RouteNo=' + RouteNo.tostring() + '&StrName_DepBusStop=' + StrName_DepBusStop.toString() + '&StrCode_DepBusStop=' + StrCode_DepBusStop + 'StrName_ArrBusStop=' +  StrName_ArrBusStop + '&StrCode_ArrBusStop' + StrCode_ArrBusStop + 'DayType=' + DayType;
		location.href = newURL;
	}
}

// ---------- NULLのチェック
function JS_CheckNULL_ChangeAction() {
	// NULL : False
	// not NULL : True
	var i, NumArgs = JS_CheckNULL.arguments.length - 1;
	for (i = 0; i < NumArgs; i++ ) {
		if (JS_CheckNULL.arguments[i] == '') {
			return false;
		}
	}
alert (JS_CheckNULL.arguments[2]);
	document.FormLogin.action = JS_CheckNULL.arguments[2];
	return true;
}
// ---------- 時間の保存
function JS_KeepHour() {
	var CkName;
	var SelectName;
	var Index;

	CkName = "CkIndex_HOUR";
	SelectName = document.FormStopSelect.hour;
	Index = document.FormStopSelect.hour.selectedIndex;

	JS_SetCookie(CkName,  SelectName[Index].value);
//alert (SelectName[Index].value);

	return true;
}

// ---------- 分の保存
function JS_KeepMinute() {
	var CkName;
	var SelectName;
	var Index;

	CkName = "CkIndex_MIN";
	SelectName = document.FormStopSelect.min;
	Index = document.FormStopSelect.min.selectedIndex;

	JS_SetCookie(CkName,  SelectName[Index].value);
//alert (SelectName[Index].value);

	return true;
}
// ---------- 時間指定区分の保存
function JS_TimeCheck() {
	var CkName;
	var SelectName;

	CkName = "CkIndex_TMCK";
	SelectName = document.FormStopSelect.time;

	JS_SetCookie(CkName,  SelectName.checked);
//alert (SelectName.checked);

	return true;
}

// ---------- wwwで許されない文字チェック
function CheckRegularStopName(b){
	var S = b.value;
	if (S.match(/['!"#\$%&=~^|\\`@\[\{\]\}\*:+;_\?\.>\,<]/)){
		alert("不正な文字を含んでいます。");
		return false;
	}
	if (S == ''){
		return false;
	}

}

// ---------- 停留所を選択した時間をフォームに入れる
function SetSelectedTime(objTime)
{
	objTmpTime = new Date();
	objTime.value = objTmpTime.getTime();
}

// ---------- 停留所を選択した時間をCookieに入れる
function SetSelectedTimeToCookie()
{
	objTmpTime = new Date();
	CkName = "CkTime";
	opener.JS_SetCookie(CkName, objTmpTime.getTime());
	
	return true;
}

// ---------- 表示する時刻表を切替(発着時刻表のコンボ)
function JS_ChangeDay(DefaultWeekDay, ObjCombo, StrCode_DepBusStop, StrName_DepBusStop, StrCode_ArrBusStop, StrName_ArrBusStop, time, hour, min, deporarr, Generation, Norikae_Kanou, Norikae_Sitei)
{
	if (ObjCombo.options[ObjCombo.selectedIndex].value != DefaultWeekDay.toString()) 
	{
		var newURL = 'tm_find.asp?DT=' + ObjCombo.options[ObjCombo.selectedIndex].value; 
		newURL = newURL + '&S1=' + StrCode_DepBusStop.toString();
		newURL = newURL + '&StrName_DepBusStop=' + escape(StrName_DepBusStop.toString());
		newURL = newURL + '&S3=' + StrCode_ArrBusStop.toString();
		newURL = newURL + '&StrName_ArrBusStop=' + escape(StrName_ArrBusStop.toString());
		newURL = newURL + '&time=' + time.toString();
		newURL = newURL + '&hour=' + hour.toString();
		newURL = newURL + '&min=' + min.toString();
		newURL = newURL + '&deporarr=' + deporarr.toString();
		newURL = newURL + '&GE=' + Generation.toString();
		newURL = newURL + '&NK=' + Norikae_Kanou.toString();
		newURL = newURL + '&NS=' + Norikae_Sitei.toString();
		newURL = newURL + '&DC=1';
		location.href = newURL;
	}
}
// ---------- 表示する時刻表を切替(三重交通)
function JS_BackWayInfoSet(DepCode, DepName, ArrCode, ArrName)
{
//alert(DepCode);
//alert(DepName);
//alert(ArrCode);
//alert(ArrName);

	document.form1.action = "../time/tm_index.asp";

	top.JS_SetCookie("CkCodeDepBusStop",  DepCode);
	top.JS_SetCookie("CkNameDepBusStop",  escape(DepName));
	top.JS_SetCookie("CkCodeArrBusStop",  ArrCode);
	top.JS_SetCookie("CkNameArrBusStop",  escape(ArrName));

}
// ---------- 表示する乗換時刻表を切替(三重交通)
function JS_ChangeDay_cn(DefaultWeekDay, ObjCombo, StrCode_DepBusStop1, StrCode_ArrBusStop1, StrCode_DepBusStop2, StrCode_ArrBusStop2, hour, min, deporarr, Generation, Norikae_Kanou, Norikae_Sitei)
{
//alert(ObjCombo.options[ObjCombo.selectedIndex].value);
//alert(ObjCombo.options[ObjCombo.selectedIndex].value);
//alert( Norikae_Kanou.toString());
	if (ObjCombo.options[ObjCombo.selectedIndex].value != DefaultWeekDay.toString()) 
	{
		var newURL = '../time/tm_find.asp?DT=' + ObjCombo.options[ObjCombo.selectedIndex].value; 
		newURL = newURL + '&S1=' + StrCode_DepBusStop1.toString();
		newURL = newURL + '&S3=' + StrCode_ArrBusStop2.toString();
		newURL = newURL + '&hour=' + hour.toString();
		newURL = newURL + '&min=' + min.toString();
		newURL = newURL + '&deporarr=' + deporarr.toString();
		newURL = newURL + '&GE=' + Generation.toString();
		newURL = newURL + '&NK=' + Norikae_Kanou.toString();
		newURL = newURL + '&NS=' + Norikae_Sitei.toString();
		newURL = newURL + '&DD=1';
		location.href = newURL;
	}
}
// ---------- 表示する乗換時刻表を切替(停留所時刻表−乗換えあり)
function JS_ChangeDay_cn2(DefaultWeekDay, ObjCombo, StrCode_DepBusStop1, StrCode_ArrBusStop1, StrCode_DepBusStop2, StrCode_ArrBusStop2, hour, min, deporarr, Generation, Norikae_Kanou, Norikae_Sitei)
{
//alert(StrCode_DepBusStop1.toString() + '->' + StrCode_ArrBusStop1.toString());
//alert(StrCode_DepBusStop2.toString() + '->' + StrCode_ArrBusStop2.toString());

	if (ObjCombo.options[ObjCombo.selectedIndex].value != DefaultWeekDay.toString()) 
	{
		var newURL = '../busstop/tm_rslt_cn.asp?DT=' + ObjCombo.options[ObjCombo.selectedIndex].value; 
		newURL = newURL + '&S1=' + StrCode_DepBusStop1.toString();
		newURL = newURL + '&S2=' + StrCode_ArrBusStop1.toString();
		newURL = newURL + '&S2_2=' + StrCode_DepBusStop2.toString();
		newURL = newURL + '&S3=' + StrCode_ArrBusStop2.toString();
		newURL = newURL + '&hour=' + hour.toString();
		newURL = newURL + '&min=' + min.toString();
		newURL = newURL + '&deporarr=' + deporarr.toString();
		newURL = newURL + '&GE=' + Generation.toString();
		newURL = newURL + '&NK=' + Norikae_Kanou.toString();
		newURL = newURL + '&NS=' + Norikae_Sitei.toString();
		newURL = newURL + '&DD=1';
		location.href = newURL;
	}
}
// ---------- 表示する乗換時刻表を切替(三重交通)
function JS_ChangeDay_TimeTable(DefaultWeekDay, ObjCombo, StrCode_DepBusStop1, Generation, PlatForm)
{
//alert(ObjCombo.options[ObjCombo.selectedIndex].value);
	if (ObjCombo.options[ObjCombo.selectedIndex].value != DefaultWeekDay.toString()) 
	{
		var newURL = '../timetable/tt_rslt.asp?DT=' + ObjCombo.options[ObjCombo.selectedIndex].value; 
		newURL = newURL + '&S1=' + StrCode_DepBusStop1.toString();
		newURL = newURL + '&GE=' + Generation.toString();
		newURL = newURL + '&PF=' + PlatForm;
		location.href = newURL;
	}
}
	
// ---------- 経路図の表示
function JS_openRouteChart(depName, depCode, arrName, arrCode, routeCode, dm, ge, fs)
{
    depName = escape(depName);
    arrName = escape(arrName);
    MM_openBrWindow(
        '../routechart/routechart_index.asp' +
        '?DepName=' + depName +
        '&DepCode=' + depCode +
        '&ArrName=' + arrName +
        '&ArrCode=' + arrCode +
        '&RouteCodee=' + routeCode +
        '&DM=' + dm +
        '&GE=' + ge +
        '&FS=' + fs,
        'subwin',
        'scrollbars=yes,resizable=yes,width=500,height=500'
    );
}

