// **********************************************************************************
//	e3 : t_src06.htm用 JavaScript
// **********************************************************************************
function get_location() {
	var strLocation = "";

	strLocation = window.location.protocol;
	strLocation = strLocation + '//' + window.location.host;
	strLocation = strLocation + window.location.pathname;
	return strLocation;

}

function get_LinkPara() {
	var strCond = "";

	strPara = '?areacd=' + document.main.areacd.value;
	strPara = strPara + '&natcd='        + document.main.natcd.value;
	strPara = strPara + '&citycd='       + document.main.citycd.value;
	strPara = strPara + '&date_from='    + document.main.date_from.value;
	strPara = strPara + '&date_to='      + document.main.date_to.value;
	strPara = strPara + '&disp_picture=' + document.main.disp_picture.value;
	strPara = strPara + '&dispcnt='      + document.main.dispcnt.value;
	strPara = strPara + '&order_type='   + document.main.order_type.value;
	strPara = strPara + '&order_desc='   + document.main.order_desc.value;
	strPara = strPara + '&disp_page='    + document.main.disp_page.value;
	strPara = strPara + '&cntcd='        + document.main.cntcd.value;
	strPara = strPara + '&gdscd='        + document.main.gdscd.value;
	strPara = strPara + '&cond='         + document.main.cond.value;
	strPara = strPara + '&s_type='       + document.main.s_type.value;

	return strPara;

}

function get_condition(pn_mode, ps_cntcd) {
	var strCond = "";

	if ( ps_cntcd == "S1" ) {
		if ( document.frm1.cbox_S1_1.checked == true ) {
			strCond = document.frm1.cbox_S1_1.value;
		}
		else {
			strCond = "";
		}
		if ( document.frm1.cbox_S1_2.checked == true ) {
			strCond = strCond + "," + document.frm1.cbox_S1_2.value;
		}
		else {
			strCond = strCond + "," + "";
		}
		if ( document.frm1.cbox_S1_3.checked == true ) {
			strCond = strCond + "," + document.frm1.cbox_S1_3.value;
		}
		else {
			strCond = strCond + "," + "";
		}
		if ( document.frm1.cbox_S1_4.checked == true ) {
			strCond = strCond + "," + document.frm1.cbox_S1_4.value;
		}		else {			strCond = strCond + "," + "";		}		if ( document.frm1.cbox_S1_5.checked == true ) {			strCond = strCond + "," + document.frm1.cbox_S1_5.value;		}		else {			strCond = strCond + "," + "";		}		if ( document.frm1.cbox_S1_6.checked == true ) {			strCond = strCond + "," + document.frm1.cbox_S1_6.value;		}		else {			strCond = strCond + "," + "";		}		if ( document.frm1.cbox_S1_7.checked == true ) {			strCond = strCond + "," + document.frm1.cbox_S1_7.value;		}		else {			strCond = strCond + "," + "";		}		if ( document.frm1.cbox_S1_8.checked == true ) {			strCond = strCond + "," + document.frm1.cbox_S1_8.value;		}		else {			strCond = strCond + "," + "";		}		if ( document.frm1.cbox_S1_9.checked == true ) {			strCond = strCond + "," + document.frm1.cbox_S1_9.value;		}
		else {
			strCond = strCond + "," +  "";
		}
		if ( pn_mode == 1 ) {
			strCond = strCond + "," + wordReplace(document.frm1.S1_keyword.value, ",", " ");
		}
		else {
			strCond = strCond + "," + wordReplace(document.frm1.S1_keyword_encode.value, ",", " ");
		}	}
	else if ( ps_cntcd == "C1" ) {
		strCond = document.frm1.C1_car_capacity.value;
		if ( document.frm1.cbox_C1_1.checked == true ) {
			strCond = strCond + "," + document.frm1.cbox_C1_1.value;
		}
		else {
			strCond = strCond + "," + "";
		}
		if ( document.frm1.cbox_C1_2.checked == true ) {
			strCond = strCond + "," + document.frm1.cbox_C1_2.value;
		}
		else {
			strCond = strCond + "," + "";
		}
		if ( document.frm1.cbox_C1_3.checked == true ) {
			strCond = strCond + "," + document.frm1.cbox_C1_3.value;
		}
		else {
			strCond = strCond + "," + "";
		}
		if ( document.frm1.cbox_C1_4.checked == true ) {
			strCond = strCond + "," + document.frm1.cbox_C1_4.value;
		}
		else {
			strCond = strCond + "," + "";
		}
		if ( document.frm1.cbox_C1_5.checked == true ) {
			strCond = strCond + "," + document.frm1.cbox_C1_5.value;
		}
		else {
			strCond = strCond + "," + "";
		}
	}
	else if ( ps_cntcd == "C2" ) {
		strCond = "";
	}
	else if ( ps_cntcd == "G1" ) {
		if (document.frm1.ra_G1_playstyle[0].checked == true ) {
			strCond = "0";
		}
		else if (document.frm1.ra_G1_playstyle[1].checked == true ) {
			strCond = "1";
		}
		else {
			strCond = "2";
		}
		if ( pn_mode == 1 ) {
			strCond = strCond + "," + wordReplace(document.frm1.G1_keyword.value, ",", " ");
		}
		else {
			strCond = strCond + "," + wordReplace(document.frm1.G1_keyword_encode.value, ",", " ");
		}
	}
	else if ( ps_cntcd == "S2" ) {
		if ( document.frm1.cbox_S2_1.checked == true ) {
			strCond = document.frm1.cbox_S2_1.value;
		}
		else {
			strCond = "";
		}
		if ( document.frm1.cbox_S2_2.checked == true ) {
			strCond = strCond + "," + document.frm1.cbox_S2_2.value;
		}
		else {
			strCond = strCond + "," + "";
		}
		if ( pn_mode == 1 ) {
			strCond = strCond + "," + wordReplace(document.frm1.S2_keyword.value, ",", " ");
		}
		else {
			strCond = strCond + "," + wordReplace(document.frm1.S2_keyword_encode.value, ",", " ");
		}
	}
	else if ( ps_cntcd == "L1" ) {
		if ( document.frm1.cbox_L1_1.checked == true ) {
			strCond = document.frm1.cbox_L1_1.value;
		}
		else {
			strCond = "";
		}
	}
	else if ( ps_cntcd == "T1" ) {
		strCond = "";
	}
	else if ( ps_cntcd == "M1" ) {
		if ( pn_mode == 1 ) {
			strCond = wordReplace(document.frm1.M1_keyword.value, ",", " ");
		}
		else {
			strCond = wordReplace(document.frm1.M1_keyword_encode.value, ",", " ");
		}
	}
	else if ( ps_cntcd == "R1" ) {
		if ( pn_mode == 1 ) {
			document.main.cond.value = document.main.cond_noencode.value;
		}
		else {
			document.main.cond.value = document.main.cond_encode.value;
		}
		strCond = document.main.cond.value;
	}
	else if ( ps_cntcd == "P1" ) {
		if ( pn_mode == 1 ) {
			document.main.cond.value = document.main.cond_noencode.value;
		}
		else {
			document.main.cond.value = document.main.cond_encode.value;
		}
		strCond = document.main.cond.value;
	}

	return strCond;

}

function changeContent(po_cntcd) {
	var w_cntcd = po_cntcd.value;

	if ( w_cntcd != "00") {

		//コンテンツが変更されたら表示ページを初期化
		document.main.disp_page.value = 1;

		document.main.cntcd.value = w_cntcd;
		if ( document.main.cntcd.value == "R1" ) {
			strLocation = "../t/t_inf_R_01.php";
		}
		else if ( document.main.cntcd.value == "P1" ) {
			strLocation = "../t/t_inf_P_01.php";
		}
		else {
			document.main.cond.value = "";
			document.main.action = get_location() + get_LinkPara();
			document.main.method="post";
			document.main.target="_self";
			document.main.submit();
		}
	}
}

//****************************************
// 2010.07.15 IL 追加
// 表示するコンテンツの切り替え
//****************************************
function changeContentList(ps_cntcd) {
	var w_cntcd = ps_cntcd;

	//コンテンツが変更されたら表示ページを初期化
	document.main.disp_page.value = 1;

	document.main.cntcd.value = w_cntcd;
	if ( document.main.cntcd.value == "R1" ) {
		strLocation = "../t/t_inf_R_01.php";
	}
	else if ( document.main.cntcd.value == "P1" ) {
		strLocation = "../t/t_inf_P_01.php";
	}
	else {
		document.main.cond.value = "";
		document.main.action = get_location() + get_LinkPara();
		document.main.method="post";
		document.main.target="_self";
		document.main.submit();
	}
}

function clickGuide(ps_cntcd, ps_cntsub, ps_type) {
	var strUrl  = "";

	strUrl = '../t/t_inf01.php';
	strUrl = strUrl + '?cntcd='  +  ps_cntcd;
	strUrl = strUrl + '&cntsub=' +  ps_cntsub;
	strUrl = strUrl + '&type='   +  ps_type;

	window.open(strUrl,"guide","toolbar=0, scrollbars=1, location=0,statusbar=0,menubar=0,resizable=1,width=500,height=480,left = 30,top = 30");

}

function clickSearch(ps_cntcd) {
	var strCond = "";
	var strUrl  = "";

	document.main.disp_page.value = 1;

	if ( checkInputData(ps_cntcd) == true ) {
		//パラメータ受け渡し用変数に値を設定
		document.main.date_from.value = document.frm1.date_from.value;	//日付FROM
		document.main.date_to.value   = document.frm1.date_to.value;	//日付TO
		document.main.cntcd.value     = ps_cntcd;
		document.main.cond.value      = get_condition(1, ps_cntcd);

		strUrl = get_location() + get_LinkPara();

//		window.location.href = strUrl;

		document.main.action = strUrl;
		document.main.method="post";
		document.main.target="_self";
		document.main.submit();
	}
}

function clickDISPCNT(pnDispCount) {

	document.main.dispcnt.value = pnDispCount;
	document.main.disp_page.value = 1;

	window.location.href = get_location() + get_LinkPara();

//	document.main.action = get_location() + get_LinkPara();
//	document.main.method="post";
//	document.main.target="_self";
//	document.main.submit();

}

function clickSORT(pnOrderType, pnOrderDesc) {

	document.main.order_type.value = pnOrderType;
	document.main.order_desc.value = pnOrderDesc;

	window.location.href = get_location() + get_LinkPara();

//	document.main.action = get_location() + get_LinkPara();
//	document.main.method="post";
//	document.main.target="_self";
//	document.main.submit();

}

function clickJUMP(pnDispPage) {

	document.main.disp_page.value = pnDispPage;
	window.location.href = get_location() + get_LinkPara();

//	document.main.action = get_location() + get_LinkPara();
//	document.main.method="post";
//	document.main.target="_self";
//	document.main.submit();

}

function displayImage(fl){
	//↓2010.07.16 Delete
//
//	if (fl==1){
//		//no display
//		document.main.disp_picture.value = 1;
//		document.getElementById("disp_img").value = fl;
//		var rImageCheck1=document.getElementById("image_disp1");
//		var rImageCheck2=document.getElementById("image_disp2");
//		rImageCheck1.checked = true;
//		rImageCheck2.checked = false;
//
//		for (i=document.main.number_min.value;i<=document.main.number_max.value;i++ ){
//			document.getElementById(i).style.display = "none";
//		}
//	}
//	else {
//		//display
//		document.main.disp_picture.value = 2;
//		document.getElementById("disp_img").value = fl;
//		var rImageCheck1=document.getElementById("image_disp1");
//		var rImageCheck2=document.getElementById("image_disp2");
//		rImageCheck1.checked = false;
//		rImageCheck2.checked = true;
//
//		for (i=document.main.number_min.value; i<=document.main.number_max.value;i++ ){
//			document.getElementById(i).style.display = "block";
//		}
//	}
//
//↑2010.07.16 Delete
}

function clickDetail(ps_cntcd, ps_cntsub, ps_gdscd, ps_classp, ps_gdsfrm, ps_tfrm) {
	var strCntcd   = ps_cntcd + ps_cntsub;
	var strCond    = get_condition(2, strCntcd);
	var strBackUrl = document.jumpDetail.back_url.value;
	var strLocation = "";
	var strPara = "";

	if ( strCntcd == "S1" ) {		//観光
		strLocation = "../t/t_inf_S1_01.php";
	}
	else if ( strCntcd == "C1" ) {	//専用車
		strLocation = "../t/t_inf_C1_01.php";
	}
	else if ( strCntcd == "C2" ) {	//混乗者
		strLocation = "../t/t_inf_C2_01.php";
	}
	else if ( strCntcd == "G1" ) {	//ゴルフ
		strLocation = "../t/t_inf_G_01.php";
	}
	else if ( strCntcd == "S2" ) {	//現地発着
		strLocation = "../t/t_inf_S2_01.php";
	}
	else if ( strCntcd == "L1" ) {	//ランドパック
		strLocation = "../t/t_inf_L_01.php";
	}
	else if ( strCntcd == "T1" ) {	//チケット
		strLocation = "../t/t_inf_T_01.php";
	}
	else if ( strCntcd == "M1" ) {	//スパ
		strLocation = "../t/t_inf_M_01.php";
	}
	else if ( strCntcd == "P1" ) {	//鉄道パス
		strLocation = "../t/t_inf_P_03.php";
	}
	else if ( strCntcd == "R1" ) {	//レンタカー
		strLocation = "../t/t_inf_R_03.php";
	}

	//パラメータ受け渡し用変数に値を設定
	strPara = '?cntcd=' + ps_cntcd;
	strPara = strPara + '&cntsub='   + ps_cntsub;
	strPara = strPara + '&gdscd='    + ps_gdscd;
	strPara = strPara + '&classp='   + ps_classp;
	strPara = strPara + '&gdsfrm='   + ps_gdsfrm;
	strPara = strPara + '&tfrm='     + ps_tfrm;
	strPara = strPara + '&opt='      + strCond;

	if ( strBackUrl != "" ) {
		strPara = strPara + '&back_url=' + strBackUrl;
	}
//	alert(strLocation + strPara);

	if ( strLocation != "" ) {
		document.jumpDetail.action = strLocation + strPara;
		document.jumpDetail.method="post";
		document.jumpDetail.target="_self";
		document.jumpDetail.submit();
	}
	else {
		alert("このコンテンツはまだ未対応です。しばらくお待ちください。");
	}
}

function checkInputData(ps_cntcd) {
	var bRet = true;

	bRet = checkDateCompare();
	if ( bRet == true ) {
		bRet = checkOption(ps_cntcd);
	}

	return bRet;

}

function checkDateCompare() {

	var now          = new Date();
	var w_today      = formatDate(now, "yyyy/MM/dd")
	var w_date_from  = document.frm1.date_from.value;
	var w_date_to    = document.frm1.date_to.value;

	var w_isDate_from = isDate(w_date_from, "yyyy/MM/dd");
	var w_isDate_to   = isDate(w_date_to, "yyyy/MM/dd");

	var w_check_date = compareDates(w_date_from, "y/MM/dd", w_date_to, "y/MM/dd");
	var isOKFormat = true;

	if ( (w_date_from != "") && (w_date_to != "") ) {
		if ( w_isDate_from == false ) {
			msg = "日付を正しく入力してください。";
			document.frm1.date_from.focus();
			isOKFormat = false;
		}
		else if ( w_date_from < w_today ) {
			msg = "開始日は本日以降の日付を入力してください。";
			document.frm1.date_from.focus();
			isOKFormat = false;
		}
		else if ( w_isDate_to == false ) {
			msg = "日付を正しく入力してください。";
			document.frm1.date_to.focus();
			isOKFormat = false;
		}
		else if ( w_check_date == -1 ) {
			msg = "日付を正しく入力してください。";
			document.frm1.date_from.focus();
			isOKFormat = false;
		}
		else if ( w_check_date == 1 ) {
			msg = '終了日は開始日より後の日付を入力してください。';
			document.frm1.date_to.focus();
			isOKFormat = false;
		}
		else if ( compareDates2(w_date_from, "y/MM/dd", w_date_to,"y/MM/dd", 30) == false ) {
			msg = '終了日は開始日より３０日以内の日付を入力してください。';
			document.frm1.date_to.focus();
			isOKFormat = false;
		}
	}

	if ( isOKFormat == true ) {
		document.main.strDayList.value = getDayList(w_date_from, w_date_to)
	}
	else {
		alert(msg);
	}

	return isOKFormat;

}

function checkDate(dateField) {
	var i = 0;
	var j = 0;
	var strWork = z2h_ascii(dateField.value, "");
	var strWorkLen = strWork.length;
	var strDate = "";
	var strLen  = 0;

	for ( i=0; i<strWorkLen; i++ ) {
		if ( strWork.substr(i,1) != "/" ) {
			strDate = strDate + strWork.substr(i,1);
		}
	}
	strLen  = strDate.length;

	if ( strLen == 0 ) {
		return true;
	}

	if ( strLen < 8 ) {
		alert('日付を正しく入力してください。');
		dateField.focus();
		return false;
	}

	dateField.value = strDate.substr(0,4) + "/" + strDate.substr(4,2) + "/" + strDate.substr(6,2);
	return true;
}

function checkOption(ps_cntcd) {
	var bRet = true;

	if ( ps_cntcd == "S1") {
		if ( check_iregstr(wordReplace(document.frm1.S1_keyword.value, ",", " ")) == false ) {
			bRet = false;
			alert("キーワードに不正文字が含まれています。");
			document.frm1.S1_keyword.focus();
		}
	}
	else if ( ps_cntcd == "C1") {
		if ( check_numstring(document.frm1.C1_car_capacity.value) == false ) {
			bRet = false;
			alert("定員は半角数値で入力してください。");
			document.frm1.C1_car_capacity.focus();
		}
	}
	else if ( ps_cntcd == "G1") {
		if ( check_iregstr(wordReplace(document.frm1.G1_keyword.value, ",", " ")) == false ) {
			bRet = false;
			alert("キーワードに不正文字が含まれています。");
			document.frm1.G1_keyword.focus();
		}
	}
	else if ( ps_cntcd == "S2") {
		if ( check_iregstr(wordReplace(document.frm1.S2_keyword.value, ",", " ")) == false ) {
			bRet = false;
			alert("キーワードに不正文字が含まれています。");
			document.frm1.S2_keyword.focus();
		}
	}
	else if ( ps_cntcd == "M1") {
		if ( check_iregstr(wordReplace(document.frm1.M1_keyword.value, ",", " ")) == false ) {
			bRet = false;
			alert("キーワードに不正文字が含まれています。");
			document.frm1.M1_keyword.focus();
		}
	}
	return bRet;

}

function z2h_ascii(src, exc) {
  var str = new String;
  var len = src.length;
  for (var i = 0; i < len; i++) {
    var c = src.charCodeAt(i);
    if (exc.indexOf(src.charAt(i)) > -1) {
      str += src.charAt(i); /* 除外 */
    } else if (c >= 65281 && c <= 65374 && c != 65340) {
      str += String.fromCharCode(c - 65248);
    } else if (c == 8217) {
      str += String.fromCharCode(39);
    } else if (c == 8221) {
      str += String.fromCharCode(34);
    } else if (c == 12288) {
      str += String.fromCharCode(32);
    } else if (c == 65507) {
      str += String.fromCharCode(126);
    } else if (c == 65509) {
      str += String.fromCharCode(92);
    } else {
      str += src.charAt(i);
    }
  }
  return str;
}

// 半角数字文字チェック
function check_numstring(str) {
	var i = 0;
	var len = str.length;

	// Null OK
	if (len==0 || len==null)
		return true

	// 数値型(0-9)以外はエラー
	for (i=0; i<len; i++) {
		if ( str.substring(i,i+1)<'0' || '9'<str.substring(i,i+1))
			return false;
	}
	return true;
}

// 文字列中の不正文字存在チェック
// ｢'｣ ｢,｣｢"｣｢<｣｢>｣｢$｣｢\｣が存在する場合はfalseを返却
function check_iregstr(str) {
	if ((str.indexOf("'") == -1)
		&&(str.indexOf('.') == -1)
		&&(str.indexOf('"') == -1)
		&&(str.indexOf("<") == -1)
		&&(str.indexOf(">") == -1)
		&&(str.indexOf("$") == -1)
		&&(str.indexOf("\\") == -1))
		return true;
	else
		return false;
}

function wordReplace(inText, beforeWord, afterWord) {
	var strText   = inText;
	var strLength = strText.length;
	var strNewText = "";
	var i = 0;

	for ( i=0; i<strLength; i++ ) {
		if ( strText.substr(i,1) == beforeWord ) {
			strNewText = strNewText + afterWord;
		}
		else {
			strNewText = strNewText + strText.substr(i,1);
		}
	}

	return strNewText;
}

function addFav(cntcd,gdscd,areacd,natcd,citycd,zonecd,areanm,natnm,citynm,zonenm,gdsnm){

	gds_ar = gdscd.split(":");							//配列に格納

	//要素数分ループする
	for(i=0,f=0;i<gds_ar.length;i++){
		if(gds_ar[i]=="商品コード"){
			f = 1;
		}
		else if((gds_ar[i]=="等級")||(gds_ar[i]=="店名")){
				f = 0;
		}
		else{
			if(f==1){
				n = gds_ar[i].length;					//文字列終端値を取得
				gdscd_val = gds_ar[i].substring(1,n);	//先頭の空白文字を除き文字列取得
				f = 0;
			}
		}
	}

	document.favform.product_type.value = cntcd;

	document.favform.areacd.value = areacd;
	document.favform.natcd.value = natcd;
	document.favform.citycd.value = citycd;
	document.favform.zonecd.value = zonecd;
	document.favform.jhc_code.value = gdscd_val;

	document.favform.area_name.value = areanm;
	document.favform.nation_name.value = natnm;
	document.favform.city_name.value = citynm;
	document.favform.zone_name.value = zonenm;
	document.favform.product_name.value = gdsnm;

	document.favform.action_type.value = "add";
	document.favform.action = "../c/c_fav01.php";
	document.favform.method = "post";
	document.favform.target = "_self";
	document.favform.submit();
}

function moveExp(cntcd,gdscd,areacd,natcd,citycd){
	var gdscd_val = "";

	gds_ar = gdscd.split(":");							//配列に格納

	//要素数分ループする
	for(i=0,f=0;i<gds_ar.length;i++){
		if(gds_ar[i]=="商品コード"){
			f = 1;
		}
		else if((gds_ar[i]=="等級")||(gds_ar[i]=="店名")){
				f = 0;
		}
		else{
			if(f==1){
				n = gds_ar[i].length;					//文字列終端値を取得
				gdscd_val = gds_ar[i].substring(1,n);	//先頭の空白文字を除き文字列取得
				f = 0;
			}
		}
	}

	//追加するGET引数を設定
	addget = "?cntcd=" + cntcd + "&gdscd=" + gdscd_val + "&areacd=" + areacd +
				"&natcd=" + natcd + "&citycd=" + citycd;

	//移動するURL文字列を作成
	jumpurl = "../c/c_exp01.php" + addget;

	//体験談画面を新しいウィンドウで開く
	window.open(jumpurl,'体験談');
}

function getDayList(date_from, date_to) {
	var arrDayName=new Array('SUN','MON','TUE','WED','THU','FRI','SAT');
	if(compareDates2(date_from,"y/MM/dd",date_to,"y/MM/dd",7)==false)
		return "SUN,MON,TUE,WED,THU,FRI,SAT";

	var strDayListReturn = "";
	var time1 = Date.parse(date_from);
	var time2 = Date.parse(date_to);
	var timeTemp = time1;
	var dateTemp = "";
	for(var i=1;i<7; i++)
	{
		if(timeTemp>time2) break;
		dateTemp = new Date(timeTemp);
		strDayListReturn += arrDayName[dateTemp.getDay()] + ",";

		timeTemp = time1 + (1000*60*60*24)*i;
	}
	return strDayListReturn.substring(0,strDayListReturn.length-1);
}


