//オセロ機能
function func_Othello(intNo) {
	var intCheckNo = '';

	if (document.getElementsByName('Switch')[0].checked) {
		if (document.getElementsByName('Layout')[intNo - 1].checked) {
			for (i=intNo + 1;i < document.getElementsByName('Layout').length; i++) {
				if (document.getElementsByName('Layout')[i - 1].checked) {
					intCheckNo = i;
					break;
				}
			}

			if (intCheckNo != '') {
				for (j=intNo - 1;j < intCheckNo; j++) {
					document.getElementsByName('Layout')[j].checked = true;
				}
			}

			intCheckNo = '';
			for (i=intNo - 1;0 < i; i--) {
				if (document.getElementsByName('Layout')[i - 1].checked) {
					intCheckNo = i;
					break;
				}
			}

			if (intCheckNo != '') {
				for (j=intNo - 1;intCheckNo <= j; j--) {
					document.getElementsByName('Layout')[j].checked = true;
				}
			}
		}
	}
}

//駅選択オセロ機能
function func_Othello_station(checkBox,key) {
	var stations = document.getElementsByName('StnCd');
	var intCheckNo = '';
	
//	alert(checkBox.id);
	var code = checkBox.id.substr(0,7);
	var from_num = -1;
	var to_num = -1;
	var current_num = -1;
	
	if ( document.getElementById('othelloSwitch' + key).checked == false ) {
		return;
	}
	if ( checkBox.checked == true ) {
		for(i=0;i<stations.length;i++) {
			if ( code == stations[i].id.substr(0,7) ) {
				if ( stations[i].id == checkBox.id ) {
					current_num = i;
				} else if ( stations[i].checked == true && current_num == -1 ) {
					from_num = i;
				} else if ( stations[i].checked == true && current_num != -1 && to_num == -1 ) {
					to_num = i;
				}
			}
		}
		for(i=0;i<stations.length;i++) {
			if (  from_num != -1 && from_num <= i && i < current_num ) {
				stations[i].checked = true;
			}
			if ( to_num != -1 && current_num < i && i<= to_num ) {
				stations[i].checked = true;
			}
		}
	}
}

//都道府県
function get_PrefParam() {
	var strTmpVal = '';
	strTmpVal = document.getElementsByName('PrefCd')[0].value;

	if (strTmpVal.length > 0) {
		return '/' + 'PrefCd/' + strTmpVal;
	} else {
		return '';
	}
}

//市区郡町村
function get_City() {
	var strTmpVal = '';

	for (i=0;i < document.getElementsByName('CityCd').length; i++) {
		if (document.getElementsByName('CityCd')[i].checked) {
			strTmpVal += document.getElementsByName('CityCd')[i].value + ','; 
		}
	}
	if (strTmpVal.length > 0) {
		return '/' + 'CityCd/' + strTmpVal.substring(0, strTmpVal.length - 1);
	} else {
		alert('市区町村を１つ以上お選びください');
		return '';
	}
}

//市区郡町村
function get_SearchCity(PrefId) {
	var strFlag = false;
	var strParam = '';
	var strCategoryParam = '';
	var strAllParam = '';
	var strTmpVal = '';
	var strClassName = '';
	var intClassCount = 0;
	var strTmpCategoryVal = '';
	var strTmpCategoryArray = new Array();

	for (i=0;i < document.getElementsByName('CityCd').length; i++) {
		if ( document.getElementsByName('CityCd')[i].id == 'city9' + document.getElementsByName('CityCd')[i].value ) {
			if (document.getElementsByName('CityCd')[i].checked) {
				strParam += PrefId + document.getElementsByName('CityCd')[i].value + ':'; 
			}
		} else {
			if ( strClassName != document.getElementsByName('CityCd')[i].className ) {
				strClassName = document.getElementsByName('CityCd')[i].className;
				intClassCount = $('.' + strClassName).size();
				$('.' + strClassName).each(function () {
					if ( $(this).is(":checked") ) {
						strTmpCategoryArray.push($(this).val());
					}
				});
/*
				for (j=0; j < document.getElementsByClassName(strClassName).length; j++) {
					if ( document.getElementsByClassName(strClassName)[j].checked ) {
						strTmpCategoryArray.push(document.getElementsByClassName(strClassName)[j].value);
					}
				}
*/
				if ( intClassCount == strTmpCategoryArray.length ) {
					strTmpCategoryVal += strClassName.replace('category','') + ':';
				} else {
					for (j=0; j < strTmpCategoryArray.length; j++) {
						strTmpVal += PrefId + strTmpCategoryArray[j] + ':'; 
					}
				}
				if (strTmpCategoryVal.length > 0) {
					strCategoryParam += strTmpCategoryVal;
				}
				if (strTmpVal.length > 0) {
					strParam += strTmpVal;
				}
			}
			strTmpVal = '';
			strTmpCategoryVal = '';
			strTmpCategoryArray = new Array();
		}
	}
	if (strCategoryParam == '' && strParam == '') {
		alert('市区町村を１つ以上お選びください');
		return '';
	} else {
		if (strCategoryParam != '') {
			strAllParam += 'p.mcity=' + strCategoryParam.substring(0, strCategoryParam.length - 1);
		}
		if (strParam != '') {
			if (strAllParam == '') {
				strAllParam += 'p.city=' + strParam.substring(0, strParam.length - 1);
			} else {
				strAllParam += '&p.city=' + strParam.substring(0, strParam.length - 1);
			}
		}
		return strAllParam;
	}
}



//大字・字
function get_Town() {
	var strTmpVal = '';

	for (i=0;i < document.getElementsByName('RgCd').length; i++) {
		if (document.getElementsByName('RgCd')[i].checked) {
			strTmpVal += document.getElementsByName('RgCd')[i].value + ','; 
		}
	}
	if (strTmpVal.length > 0) {
		return '/' + 'RgCd/' + strTmpVal.substring(0, strTmpVal.length - 1);
	} else {
		alert('町名を１つ以上お選びください');
		return '';
	}
}
//大字・字(一覧用)
function get_SearchTown(PrefId) {
	var strTmpVal = '';

	for (i=0;i < document.getElementsByName('RgCd').length; i++) {
		if (document.getElementsByName('RgCd')[i].checked) {
			strTmpVal += PrefId + document.getElementsByName('RgCd')[i].value + ':'; 
		}
	}
	if (strTmpVal.length > 0) {
		return 'p.region=' + strTmpVal.substring(0, strTmpVal.length - 1);
	} else {
		alert('町名を１つ以上お選びください');
		return '';
	}
}

//沿線
function get_Line() {
	var strTmpVal = '';
	var intCnt = 0;

	for (i=0;i < document.getElementsByName('LineCd').length; i++) {
		if (document.getElementsByName('LineCd')[i].checked) {
			strTmpVal += document.getElementsByName('LineCd')[i].value + ','; 
			intCnt++;
		}
	}
	if (strTmpVal.length > 0) {
		if (intCnt > 3) {
			alert('沿線は最大3つしか選択できません');
			return '';
		} else {
			return '/' + 'LineCd/' + strTmpVal.substring(0, strTmpVal.length - 1);
		}
	} else {
		alert('沿線を１つ以上お選びください');
		return '';
	}
}
//沿線(一覧用)
function get_SearchLine() {
	var strTmpVal = '';
	var intCnt = 0;

	for (i=0;i < document.getElementsByName('LineCd').length; i++) {
		if (document.getElementsByName('LineCd')[i].checked) {
			strTmpVal += document.getElementsByName('LineCd')[i].value + ':'; 
			intCnt++;
		}
	}
	if (strTmpVal.length > 0) {
		if (intCnt > 3) {
			alert('沿線は最大3つしか選択できません');
			return '';
		} else {
			return 'p.line=' + strTmpVal.substring(0, strTmpVal.length - 1);
		}
	} else {
		alert('沿線を１つ以上お選びください');
		return '';
	}
}



//駅
function get_Station() {
	var strTmpVal = '';

	for (i=0;i < document.getElementsByName('StnCd').length; i++) {
		if (document.getElementsByName('StnCd')[i].checked) {
			strTmpVal += document.getElementsByName('StnCd')[i].value + ','; 
		}
	}
	if (strTmpVal.length > 0) {
		return '/' + 'StnCd/' + strTmpVal.substring(0, strTmpVal.length - 1);
	} else {
		alert('駅を１つ以上お選びください');
		return '';
	}
}

//駅(一覧用)
function get_SearchStation() {
	var strTmpVal = '';

	for (i=0;i < document.getElementsByName('StnCd').length; i++) {
		if (document.getElementsByName('StnCd')[i].checked) {
			strTmpVal += document.getElementsByName('StnCd')[i].value + ':'; 
		}
	}
	if (strTmpVal.length > 0) {
		return 'p.station=' + strTmpVal.substring(0, strTmpVal.length - 1);
	} else {
		alert('駅を１つ以上お選びください');
		return '';
	}
}

//表示件数
function get_DispCnt(intNum) {
	var strTmpVal = '';

	if (intNum == '1') {
		for (i=0;i < document.getElementsByName('DispCnt').length; i++) {
			if (document.getElementsByName('DispCnt')[i].checked) {
				strTmpVal = document.getElementsByName('DispCnt')[i].value;
				break; 
			}
		}
	} else {
		for (i=0;i < document.getElementsByName('DispCntPreju').length; i++) {
			if (document.getElementsByName('DispCntPreju')[i].checked) {
				strTmpVal = document.getElementsByName('DispCntPreju')[i].value;
				break; 
			}
		}
	}

	if (strTmpVal.length > 0) {
		return '/DispCnt/' + strTmpVal;
	} else {
		return '';
	}
}

//表示件数
function get_SearchDispCnt(intNum) {
        var strTmpVal = '';

        if (intNum == '1') {
                for (i=0;i < document.getElementsByName('DispCnt').length; i++) {
                        if (document.getElementsByName('DispCnt')[i].checked) {
                                strTmpVal = document.getElementsByName('DispCnt')[i].value;
                                break;
                        }
                }
        } else {
                for (i=0;i < document.getElementsByName('DispCntPreju').length; i++) {
                        if (document.getElementsByName('DispCntPreju')[i].checked) {
                                strTmpVal = document.getElementsByName('DispCntPreju')[i].value;
                                break;
                        }
                }
        }

        if (strTmpVal.length > 0) {
                return 'p.perPage=' + strTmpVal;
        } else {
                return '';
        }
}


//物件種別
function get_PropKdCd() {
	var strTmpVal = '';

	for (i=0;i < document.getElementsByName('PropKdCd').length; i++) {
		if (document.getElementsByName('PropKdCd')[i].checked) {
			strTmpVal += document.getElementsByName('PropKdCd')[i].value + ','; 
		}
	}
	if (strTmpVal.length > 0) {
		return '/' + 'PropKdCd/' + strTmpVal.substring(0, strTmpVal.length - 1);
	} else {
		return '';
	}
}

function get_PropKdCd_Hidden(intNum) {
	if (document.getElementsByName('PropKdCd')[0].value != '') {
		if (intNum == 0) {
			return '/PropKdCd/' + document.getElementsByName('PropKdCd')[0].value; 
		} else {
			if (document.getElementsByName('PropKdCd')[0].value == '3') {
				return '&p.propKd3=1';
			} else {
				return '&p.propKd1=1';
			}
		}
	} else {
		return '';
	}
}

//家賃FROM
function get_HuRtFrom() {
	var strTmpVal = '';
	var n = document.getElementsByName('HuRtFrom')[0];

	return '/' + 'HuRtFrom/' + n.options[n.selectedIndex].value;
}

//家賃TO
function get_HuRtTo() {
	var strTmpVal = '';
	var n = document.getElementsByName('HuRtTo')[0];

	return '/' + 'HuRtTo/' + n.options[n.selectedIndex].value;
}

//間取り
function get_Layout() {
	var strTmpVal = '';

	for (i=0;i < document.getElementsByName('Layout').length; i++) {
		if (document.getElementsByName('Layout')[i].checked) {
			strTmpVal += document.getElementsByName('Layout')[i].value + ','; 
		}
	}
	if (strTmpVal.length > 0) {
		return '/' + 'Layout/' + strTmpVal.substring(0, strTmpVal.length - 1);
	} else {
		return '';
	}
}

//専有面積FROM
function get_UseSzSquFrom() {
	var strTmpVal = '';
	var n = document.getElementsByName('UseSzSquFrom')[0];

	return '/' + 'UseSzSquFrom/' + n.options[n.selectedIndex].value;
}

//専有面積TO
function get_UseSzSquTo() {
	var strTmpVal = '';
	var n = document.getElementsByName('UseSzSquTo')[0];

	return '/' + 'UseSzSquTo/' + n.options[n.selectedIndex].value;
}

//築年
function get_CompDt() {
	var strTmpVal = '';

	for (i=0;i < document.getElementsByName('CompDt').length; i++) {
		if (document.getElementsByName('CompDt')[i].checked) {
			strTmpVal = 'CompDt/' + document.getElementsByName('CompDt')[i].value;
			break;
		}
	}
	if (strTmpVal.length > 0) {
		return '/' + strTmpVal;
	} else {
		return '';
	}
}

//徒歩時間
function get_WalkTm() {
	var strTmpVal = '';

	for (i=0;i < document.getElementsByName('WalkTm').length; i++) {
		if (document.getElementsByName('WalkTm')[i].checked) {
			strTmpVal = 'WalkTm/' + document.getElementsByName('WalkTm')[i].value;
			break; 
		}
	}
	if (strTmpVal.length > 0) {
		return '/' + strTmpVal;
	} else {
		return '';
	}
}

//部屋階数FROM
function get_PjRmEnvFrom() {
	var strTmpVal = '';
	var n = document.getElementsByName('PjRmEnvFrom')[0];

	return '/' + 'PjRmEnvFrom/' + n.options[n.selectedIndex].value;
}

//部屋階数TO
/*
function get_PjRmEnvTo() {
	var strTmpVal = '';
	var n = document.getElementsByName('PjRmEnvTo')[0];

	return '/' + 'PjRmEnvTo/' + n.options[n.selectedIndex].value;
}
*/
//物件番号
function get_PropChk() {
	var strTmpVal = '';

	for (i=0;i < document.getElementsByName('PropChk').length; i++) {
		if (document.getElementsByName('PropChk')[i].checked) {
			strTmpVal += document.getElementsByName('PropChk')[i].value + ','; 
		}
	}
	if (strTmpVal.length > 0) {
		return '/' + 'PropChk/' + strTmpVal.substring(0, strTmpVal.length - 1);
	} else {
		return '';
	}
}

//半径
function get_List_Radius() {
	var strTmpVal = '';
	var n = document.getElementsByName('Radius')[0];

	for (i=0; i < 7; i++) {
		if (document.getElementsByName('Facility')[i].checked) {
			strTmpVal += document.getElementsByName('Facility')[i].value + ','; 
		}
	}

	if ( strTmpVal != '' ) {
		return '/' + 'Radius/' + n.options[n.selectedIndex].value;
	} else {
		return '';
	}
}

//周辺施設
function get_List_Facility() {
	var strTmpVal = '';

	for (i=0; i < 7; i++) {

		if (document.getElementsByName('Facility')[i].checked) {
			strTmpVal += document.getElementsByName('Facility')[i].value + ','; 
		}
	}
	if (strTmpVal.length > 0) {
		return '/' + 'Facility/' + strTmpVal.substring(0, strTmpVal.length - 1);
	} else {
		return '';
	}
}

//擬似ビットフラグ
function get_PjSusBit() {
	var bitValue = '__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________';
	var bitCheckValue = '';
	var bitArray = new Array(bitValue.length);
	var ChoosyArray = new Array('HuRtOth','PjRmEnv','PjMvCnd','PjBTK','PjRmEp','PjBdEp','PjInfo','PjSec','PjOth','PjUd','Info');

	for (i=0;i < bitValue.length; i++) {
		bitArray[i] = bitValue.charAt(i);
	}
	for (j=0;j < ChoosyArray.length; j++) {
		for (i=0;i < document.getElementsByName(ChoosyArray[j]).length; i++) {
			if (document.getElementsByName(ChoosyArray[j])[i].checked) {
				bitArray[document.getElementsByName(ChoosyArray[j])[i].value] = '1';
			}
		}
	}

	for (j=0;j < bitArray.length; j++) {
		bitCheckValue += bitArray[j];
	}

	//こだわり条件、外したいこだわり条件ダブりチェック
	if (bitCheckValue.substr(55, 1) == '1' && bitCheckValue.substr(215, 1) == '1') {
		if (window.confirm('入居条件「女性専用」と外したいこだわり条件「女性専用」は同時に選択できません。外したいこだわり条件「女性専用」を優先させます。よろしいですか？')) {
			for (i=0;i < bitCheckValue.length; i++) {
				bitArray[i] = bitCheckValue.charAt(i);
			}

			bitCheckValue = '';

			for (j=0;j < bitArray.length; j++) {
				if (j == 55) {
					bitCheckValue += '_';
				} else {
					bitCheckValue += bitArray[j];
				}
			}
		} else {
			return false;
		}
	}

	if (bitCheckValue.substr(53, 1) == '1' && bitCheckValue.substr(216, 1) == '1') {
		if (window.confirm('入居条件「ペット相談」と外したいこだわり条件「ペット相談」は同時に選択できません。外したいこだわり条件「ペット相談」を優先させます。よろしいですか？')) {
			for (i=0;i < bitCheckValue.length; i++) {
				bitArray[i] = bitCheckValue.charAt(i);
			}

			bitCheckValue = '';

			for (j=0;j < bitArray.length; j++) {
				if (j == 53) {
					bitCheckValue += '_';
				} else {
					bitCheckValue += bitArray[j];
				}
			}
		} else {
			return false;
		}
	}

	if (bitCheckValue.substr(66, 1) == '1' && bitCheckValue.substr(217, 1) == '1') {
		if (window.confirm('入居条件「楽器相談」と外したいこだわり条件「楽器相談」は同時に選択できません。外したいこだわり条件「楽器相談」を優先させます。よろしいですか？')) {
			for (i=0;i < bitCheckValue.length; i++) {
				bitArray[i] = bitCheckValue.charAt(i);
			}

			bitCheckValue = '';

			for (j=0;j < bitArray.length; j++) {
				if (j == 66) {
					bitCheckValue += '_';
				} else {
					bitCheckValue += bitArray[j];
				}
			}
		} else {
			return false;
		}
	}

	if (bitCheckValue.indexOf('1') >= 0) {
		return '/' + 'PjSusBit/' + bitCheckValue;
	} else {
		return '';
	}
}



//物件種別（hidden）
function get_Hidden_PropKdCd() {
	if (document.getElementsByName('PropKdCd')[0].value != '') {
		return '/' + 'PropKdCd/' + document.getElementsByName('PropKdCd')[0].value;
	} else {
		return '';
	}
}

//家賃FROM（hidden）
function get_Hidden_HuRtFrom() {
	if (document.getElementsByName('HuRtFrom')[0].value != '') {
		return '/' + 'HuRtFrom/' + document.getElementsByName('HuRtFrom')[0].value;
	} else {
		return '';
	}
}

//家賃TO（hidden）
function get_Hidden_HuRtTo() {
	if (document.getElementsByName('HuRtTo')[0].value != '') {
		return '/' + 'HuRtTo/' + document.getElementsByName('HuRtTo')[0].value;
	} else {
		return '';
	}
}

//間取り（hidden）
function get_Hidden_Layout() {
	if (document.getElementsByName('Layout')[0].value != '') {
		return '/' + 'Layout/' + document.getElementsByName('Layout')[0].value;
	} else {
		return '';
	}
}

//専有面積FROM（hidden）
function get_Hidden_UseSzSquFrom() {
	if (document.getElementsByName('UseSzSquFrom')[0].value != '') {
		return '/' + 'UseSzSquFrom/' + document.getElementsByName('UseSzSquFrom')[0].value;
	} else {
		return '';
	}
}

//専有面積TO（hidden）
function get_Hidden_UseSzSquTo() {
	if (document.getElementsByName('UseSzSquTo')[0].value != '') {
		return '/' + 'UseSzSquTo/' + document.getElementsByName('UseSzSquTo')[0].value;
	} else {
		return '';
	}
}

//築年（hidden）
function get_Hidden_CompDt() {
	if (document.getElementsByName('CompDt')[0].value != '') {
		return '/' + 'CompDt/' + document.getElementsByName('CompDt')[0].value;
	} else {
		return '';
	}
}

//徒歩時間（hidden）
function get_Hidden_WalkTm() {
	if (document.getElementsByName('WalkTm')[0].value != '') {
		return '/' + 'WalkTm/' + document.getElementsByName('WalkTm')[0].value;
	} else {
		return '';
	}
}

//部屋階数FROM（hidden）
function get_Hidden_PjRmEnvFrom() {
	if (document.getElementsByName('PjRmEnvFrom')[0].value != '') {
		return '/' + 'PjRmEnvFrom/' + document.getElementsByName('PjRmEnvFrom')[0].value;
	} else {
		return '';
	}
}

//部屋階数TO（hidden）
function get_Hidden_PjRmEnvTo() {
	if (document.getElementsByName('PjRmEnvTo')[0].value != '') {
		return '/' + 'PjRmEnvTo/' + document.getElementsByName('PjRmEnvTo')[0].value;
	} else {
		return '';
	}
}

//物件番号（hidden）
function get_Hidden_PropChk() {
	if (document.getElementsByName('PropChk')[0].value != '') {
		return '/' + 'PropChk/' + document.getElementsByName('PropChk')[0].value;
	} else {
		return '';
	}
}

//擬似ビットフラグ（hidden）
function get_Hidden_PjSusBit() {
	if (document.getElementsByName('PjSusBit')[0].value != '') {
		return '/' + 'PjSusBit/' + document.getElementsByName('PjSusBit')[0].value;
	} else {
		return '';
	}
}
//こだわり（hidden）
function get_Hidden_Kodawari() {
	if (document.getElementsByName('Kodawari')[0].value != '') {
		return '/' + 'Kodawari/' + document.getElementsByName('Kodawari')[0].value;
	} else {
		return '';
	}
}

