/* ----------------------------------------------------------------------------- */
//		検索条件ボックス（関東）
/* ----------------------------------------------------------------------------- */


//--------------------------------
// 検索条件表示欄をクリア
//--------------------------------
function removeDispValue(){
	document.getElementById('priceLower').parentNode.removeChild;
	document.getElementById('priceUpper').parentNode.removeChild;
	document.getElementById('areaLower').parentNode.removeChild;
	document.getElementById('areaUpper').parentNode.removeChild;
	document.getElementById('type').parentNode.removeChild;
	document.getElementById('madori').parentNode.removeChild;
	document.getElementById('access').parentNode.removeChild;
	document.getElementById('kodawari').parentNode.removeChild;
};

//--------------------------------
// Radioボタンをリセット
//--------------------------------
function setRadioBtn(num){
	var s00 = document.getElementById('S00');
	var s10 = document.getElementById('S10');
	var s15 = document.getElementById('S15');

	if(num==00 || num=='S00' || !num || num==''){
		s00.checked=true;
		s10.checked=false;
		s15.checked=false;

	}
	if(num==10 || num=='S10'){
		s00.checked=false;
		s10.checked=true;
		s15.checked=false;
	}
	if(num==15 || num=='S15'){
		s00.checked=false;
		s10.checked=false;
		s15.checked=true;
	}
};

//--------------------------------
// 選択されているRADIOボタンを取得
//--------------------------------
function getRadioValue(){
	chkIdx[0] = '';
	var chk_access = '';
	var access = document.getElementById('access');
	var s00 = document.getElementById('S00');	// 指定無し
	var s10 = document.getElementById('S10');	// 徒歩10分
	var s15 = document.getElementById('S15');	// 徒歩15分

	if(s00.checked=='false' && s10.checked=='false' && s15.checked=='false') chkIdx[0]='';
	if(s00.checked) chkIdx[0]='S00';
	if(s10.checked) chkIdx[0]='S10';
	if(s15.checked) chkIdx[0]='S15';

	if(chkIdx[0]=='') chk_access = '指定なし';
	if(chkIdx[0]!='') chk_access = document.getElementById(chkIdx[0]+'_txt').firstChild.nodeValue;
	access.innerHTML = chk_access;
};

//--------------------------------
// CHECKBOXの値を取得
//--------------------------------
var chkName = new Array();
chkName[1]='ADM';
chkName[2]='BTP';
chkName[3]='MTP';

function getCheckValue(){
	var frm = document.form3.elements;
	var kanri	 = document.getElementById('kanri');
	var type	 = document.getElementById('type');
	var madori	 = document.getElementById('madori');
	var kodawari = document.getElementById('kodawari');
	var cnt_t = 0;
	var cnt_m = 0;
	var cnt_k = 0;
	var chk_kanri	 = '';
	var chk_type	 = '';
	var chk_madori	 = '';
	var chk_kodawari = '';

	chkIdx[1] = '';
	chkIdx[2] = new Array();
	chkIdx[3] = new Array();
	chkIdx[4] = new Array();

	for(var i=0; i<frm.length; i++) {
		if(frm[i].type == 'checkbox'){
			if(frm[i].checked){
				// 管理費
				if(frm[i].name == chkName[1]){
					chkIdx[1] = frm[i].name;
					chk_kanri = '（管理・共益費等を含む）';
				}
				// 物件種別
				if(frm[i].name == chkName[2]){
					chkIdx[2][i]=frm[i].name+frm[i].value;
					cnt_t++;
					if(cnt_t>1) chk_type += '、';
					chk_type += document.getElementById(frm[i].name+frm[i].value+'_txt').firstChild.nodeValue;
				}
				// 間取り
				if(frm[i].name == chkName[3]){
					chkIdx[3][i]=frm[i].name+frm[i].value;
					cnt_m++;
					if(cnt_m>1) chk_madori += '、';
					chk_madori += document.getElementById(frm[i].name+frm[i].value+'_txt').firstChild.nodeValue;
					if(cnt_m==13) chk_madori = '1R～4LDK以上';
				}

				// こだわり条件
				else if(frm[i].name!=chkName[1] && frm[i].name!=chkName[2] && frm[i].name!=chkName[3]){
					chkIdx[4][i]=frm[i].name;
					cnt_k++;
					if(cnt_k>1) chk_kodawari += '、';
					var optionElm=document.getElementById(frm[i].name+'_txt');
					if(optionElm.firstChild && optionElm.firstChild.nodeValue) chk_kodawari += optionElm.firstChild.nodeValue;
					else if(optionElm.alt && optionElm.alt !="" ) chk_kodawari += optionElm.alt;
				}
			}
		}
	}

	kanri.innerHTML		= chk_kanri;
	if(!cnt_t) chk_type = '指定なし';
	type.innerHTML		= chk_type;
	if(!cnt_m) chk_madori = '1R～4LDK以上';
	madori.innerHTML	= chk_madori;
	kodawari.innerHTML	= chk_kodawari;
};

//--------------------------------
// 検索条件の値を挿入(この条件で検索)
//--------------------------------
function dispValue(){
	removeDispValue();			// 検索条件表示欄をクリア
	getSelectValue();			// SELECTの値を取得
	getRadioValue();			// RADIOボタンのチェックを取得
	getCheckValue();			// CHECKBOXの値を取得
};

//--------------------------------
// CHECKBOXのチェックを破棄
//--------------------------------
function dumpCheck(){
	var obj	 = document.form3.elements;
	for(var i=0; i<obj.length; i++){
		if(obj[i].tagName=='INPUT' && obj[i].type=='checkbox' && (!chkIdx[2] || !chkIdx[3] || !chkIdx[4])){
			for(var j=0; j<obj.length; j++) obj[j].checked=false;
		}

		if(obj[i].tagName=='INPUT'){

			if(obj[i].type=='checkbox'){

				// 管理費
				if(obj[i].name == chkName[1]){
					if(chkIdx[1]!='undefined'){
						if(!obj[i].checked && [chkIdx[1]]!='') obj[i].checked=true;
						if(obj[i].checked && [chkIdx[1]]=='') obj[i].checked=false;
					}
				}
				// 物件種別
				if(obj[i].name == chkName[2]){
					if(!chkIdx[2] || !chkIdx[2][i]) obj[i].checked=false;
					else if(chkIdx[2][i]!='undefined'){
						if(!obj[i].checked && [chkIdx[2][i]]!='') obj[i].checked=true;
						if(obj[i].checked && [chkIdx[2][i]]=='') obj[i].checked=false;
					}
				}
				// 間取り
				if(obj[i].name == chkName[3]){
					if(!chkIdx[3] || !chkIdx[3][i]) obj[i].checked=false;
					else if(chkIdx[3][i]!='undefined'){
						if(!obj[i].checked && [chkIdx[3][i]]!='') obj[i].checked=true;
						if(obj[i].checked && [chkIdx[3][i]]=='') obj[i].checked=false;
					}
				}
				// こだわり条件
				if(obj[i].name!=chkName[1] && obj[i].name!=chkName[2] && obj[i].name!=chkName[3]){
					if(!chkIdx[4] || !chkIdx[4][i]) obj[i].checked=false;
					else if(chkIdx[4][i]!='undefined'){
						if(!obj[i].checked && [chkIdx[4][i]]!='') obj[i].checked=true;
						if(obj[i].checked && [chkIdx[4][i]]=='') obj[i].checked=false;
					}
				}

			}
			if(obj[i].type=='radio') return;

		}

	}
};

//--------------------------------
// 検索条件の値を破棄(閉じる/キャンセル)
//--------------------------------
function dumpValue(){
	var obj	 = document.form3.elements;
	var slt1 = document.getElementById('CFR');
	var slt2 = document.getElementById('SFR');
	var hdn	 = document.getElementById('cacheList');

	dumpCheck();
	setRadioBtn(chkIdx[0]);			// Radioボタンをリセット

	for(var i=0; i<obj.length; i++){

		if(obj[i].tagName == 'SELECT'){
			if(obj[i].name=='rent_price' || obj[i].name=='area_size') continue;
			if(obj['CFR']=='undefined' && obj['SFR']=='undefined') return;
			if(!obj['CFR'].options[sltIdx[0]] || !obj['SFR'].options[sltIdx[2]]){
				if(obj['CFR'].options[0].getAttribute('mapi')){
					obj['CFR'].options[0].selected = true;
					makeRange('CFR','CTO','priceR',1);
				}
				if(obj['SFR'].options[0].getAttribute('mapi')){
					obj['SFR'].options[0].selected = true;
					makeRange('SFR','STO','areaR',2);
				}
				return;
			}

			if(sltIdx[0]!=slt1.selectedIndex) obj['CFR'].options[sltIdx[0]].selected=true;
			if(sltIdx[2]!=slt2.selectedIndex) obj['SFR'].options[sltIdx[2]].selected=true;

			// プルダウンに幅を持たせていた場合
			if(sltIdx[1]!=slt1.getAttribute('mapi')){
				if(hdn.value.match(/&&/i)) return;
				else{
					makeRange('CFR','CTO','priceR',1);
					obj['CTO'].options[sltIdx[1]].selected=true;
				}
			}
			if(sltIdx[3]!=slt2.getAttribute('mapi')){
				if(hdn.value.match(/&&/i)) return;
				else{
					makeRange('SFR','STO','areaR',2);
					obj['STO'].options[sltIdx[3]].selected=true;
				}
			}
		}
	}
};


/* ----------------------------------------------------------------------------- */
//		リスト部分
/* ----------------------------------------------------------------------------- */
var cnt_c=0;

// 各ボタンに合わせたURLへPOIコードをPOST
// 積和不動産コードを取得し、POST先URLを各社ごとに変更
function checkList(act,type,domobj){
	var shSkw = skw;
	var shUrl = '';
	var shStr = '';
	var list = poiList;
	var ipt = list.document.getElementsByTagName('input');
	var frm = document.requestDetail;
	var ipt1 = document.getElementById('roomId');
	var ipt2 = document.getElementById('roomCode');
	var targetName="";
	var winName=window.name;
	if(typeof(list.holdCheck)=="function" )list.holdCheck();
	if(skw=='' || skw=='undefined') return;
	if(ipt1.value.match(/,/i)) ipt1.value = ipt1.value.replace(/^,/, '');
	for(var i=0; i<ipt.length; i++){
		if(ipt[i].type=='checkbox'){
			if(act=='store'){
				if(ipt1.value==''){popen(domobj);return;}
				// 詳細ページ
				if(type=='detail'){
					// 詳細ページURL
					var detailStr = 'detail/all_show'
						shUrl = mstKanto+detailStr;
						shStr = ipt1.value;
				}

				// 空室物件の問合せ
				if(type=='vacant'){
					// お問い合せページURL
					//var vacantStr = 'mast-web/inquiry/equipment/entry';
						var vacantStr = 'inquiry/equipment/entry';
						//shUrl = 'https://www.skwf.net/'+vacantStr;
						shUrl = 'https://www.mast-net.jp/'+vacantStr;
						shStr = ipt1.value;
				}
			}
			// 全ての選択を解除
			if(act=='undo'){
				for(i=0; i<ipt.length; i++) ipt[i].checked=false;
				shUrl = '';
				ipt1.value = '';
				return;
			}
		}
	}
	if(shUrl!=''){
		// 詳細を見る
		if(type=='detail'){
			ipt2.value	= shStr;
			ipt2.name	= 'PCD';
			targetName=decideWindowTarget('requestDetail',frm,winName);
			window.open('',targetName,'');
			frm.action	= shUrl;
			frm.method	= 'POST';
			frm.submit();
		}
		// 空室物件の問合せ・資料請求
		if(type=='vacant'){
			ipt2.value	= shStr;
			ipt2.name	= 'PCD';
			targetName=decideWindowTarget('requestDetail',frm,winName);
			window.open('',targetName,'');
			frm.action	= shUrl;
			frm.method	= 'POST';
			frm.submit();
		}
//debug.print('URL: '+shUrl);
//debug.print('PCD: '+shStr);
	}
};

// POIコードをPOSTするとき、windowの名前を変える
function decideWindowTarget(wName,FrmObj,selfName){
	var ret=wName;
	var myName=selfName.split('_');
	if(myName[0]==ret){
		for (var i=0; ;i++){
			if(i>parseInt(myName[1])){
				ret=ret+"_"+i;
				FrmObj.target=ret;
				break;
			}
			else {
				continue;
			}
		}
	}
	else{
		ret+="_0";
		FrmObj.target=ret;
	}
//debug.print(ret);
	return ret;
};


/* ----------------------------------------------------------------------------- */
//		物件お知らせメール登録
/* ----------------------------------------------------------------------------- */

var tParam = new Array();
	tParam[4] = 'CFR=';
	tParam[5] = 'CTO=';
	tParam[6] = 'SFR=';
	tParam[7] = 'STO=';
	tParam[8] = 'MTP=';
	tParam[9] = 'BTP=';
	tParam[10] = '';
	tParam[11] = '';
	tParam[12] = '';
	tParam[13] = '';
	tParam[14] = '';
	tParam[15] = '';
	tParam[16] = '';
	tParam[17] = '';
	tParam[18] = 'KD=';

var CNT_KD=0;

// メール登録用パラメータの抽出
function getRegParam(){

	//緯度経度
	var ipt_nl = document.getElementById('cacheNl').value;
	var ipt_el = document.getElementById('cacheEl').value;
	if(ipt_nl!='' || ipt_el!=''){
		tParam[0] = 'nl='+ipt_nl;
		tParam[1] = 'el='+ipt_el;
	}else return;

	// 都道府県・市区町村コードがないとき
	if(!document.getElementById('where')) return;
	tParam[2] = 'PRF='+document.getElementById('where').getAttribute('admi2');
	tParam[3] = 'CTY='+document.getElementById('where').getAttribute('admi2')+document.getElementById('where').getAttribute('admi3');

	//間取り・賃料・面積・こだわり条件
	if(_mm=='' || _mm=='undefined') return;
	var tmpParam = decodeURL(_mm.gatherConditions());

//debug.print('decodeURL:'+decodeURL(_mm.gatherConditions()));

	tParam[10] = '';
	tParam[11] = '';
	tParam[12] = '';
	tParam[13] = '';
	tParam[14] = '';
	tParam[15] = '';
	tParam[16] = '';
	tParam[17] = '';

	for(var i=0; i<tmpParam.length; i++){

/*
debug.print(tmpParam[i]+' : '+tParam[i]);
		if(tmpParam[i].match(tParam[i])){
			tParam[i] = tmpParam[i];
		}
*/

		if(tmpParam[i].match('&CFR=')){
			tmp	 = tmpParam[i].split('=');
			tParam[4] = 'CFR=';
			tParam[4] += tmp[1];
		}
		if(tmpParam[i].match('&CTO=')){
			tmp	 = tmpParam[i].split('=');
			tParam[5] = 'CTO=';
			tParam[5] += tmp[1];
		}
		if(tmpParam[i].match('&SFR=')){
			tmp	 = tmpParam[i].split('=');
			tParam[6] = 'SFR=';
			tParam[6] += tmp[1];
		}
		if(tmpParam[i].match('&STO=')){
			tmp	 = tmpParam[i].split('=');
			tParam[7] = 'STO=';
			tParam[7] += tmp[1];
		}
		if(tmpParam[i].match('&MTP=')){
			tmp	 = tmpParam[i].split('=');
			tParam[8] = 'MTP=';
			tParam[8] += tmp[1];
		}
		if(tmpParam[i].match('&BTP=')){
			tmp	 = tmpParam[i].split('=');
			tParam[9] = 'BTP=';
			tParam[9] += tmp[1];
		}
		if(tmpParam[i].match('&S10=')) tParam[10] = 'S10';
		if(tmpParam[i].match('&S15=')) tParam[11] = 'S15';
		if(tmpParam[i].match('&C05=')) tParam[12] = 'C05';
		if(tmpParam[i].match('&NEW=')) tParam[13] = 'NEW';
		if(tmpParam[i].match('&PET=')) tParam[14] = 'PET';
		if(tmpParam[i].match('&MSB=')) tParam[15] = 'MSB';
		if(tmpParam[i].match('&MST=')) tParam[16] = 'MST';
		if(tmpParam[i].match('&SHM=')) tParam[17] = 'SHM';
	}

	tParam[18] = 'KD=';
	if(tParam[10]!='' || tParam[11]!='' || tParam[12]!='' || tParam[13]!='' || tParam[14]!='' || tParam[15]!='' || tParam[16]!='' || tParam[17]!=''){
		tParam[18] = 'KD=';
		for(var k=10; k<18; k++){
			if(tParam[k]!=''){
				if(CNT_KD>=1) tParam[18] += ',';
				tParam[18] += tParam[k];
				CNT_KD++;
			}
		}
	}
	CNT_KD=0;
};

// 物件お知らせメール登録
function registerNote(){
	getRegParam();

	var frm = document.requestMail;
	for(var i=0; i<frm.length; i++){
		if(i==10){
			var t = tParam[18].split('=');
			frm[10].name	= t[0];
			frm[10].value	= t[1];
		}else{
			var t = tParam[i].split('=');
			frm[i].name	 = t[0];
			frm[i].value = t[1];
		}
//debug.print('n:'+frm[i].name + ' v:'+frm[i].value);
	}

	window.open('','requestMail','');
	frm.action	= mstKanto+'request_reg/form';
	frm.method	= 'POST';
	frm.submit();

	for(var i=0; i<frm.length; i++){
		frm[i].name = '';
		frm[i].value = '';
	}
};

