//document.write('<script type="text/javascript" src="styles/cookiemanager.js"></script>');
//cookiemanagerのパスはドメイン全体に固定なので注意すること
var mypage = {
		property : new Array(),
		propertyData : new Array(),
		history : new Array(),
		inquiry : new Array(),
		inquiryDate : new Hash(),
		reminder : new Array(),
		reminderData : new Array(),
		test : "test",
		cookieMgr : null,
		init : function(){
			this.cookieMgr = new CookieManager({shelfLife:60});
			var tmp = this.cookieMgr.getCookie("property");
			if(tmp != null && tmp != "" && typeof tmp != "undefined"){
				this.property = eval(tmp);
			}
			var tmp = this.cookieMgr.getCookie("inquiry");
			if(tmp != null && tmp != "" && typeof tmp != "undefined"){
				this.inquiry = eval(tmp);
			}
			var tmp = this.cookieMgr.getCookie("inquiryDate");
			if(tmp != null && tmp != "" && typeof tmp != "undefined"){
				var tmpDate = eval("(" + tmp + ")");
				for(var key in tmpDate ){
					this.inquiryDate[key] = tmpDate[key];
				}
			}
			var tmp = this.cookieMgr.getCookie("history");
			if(tmp != null && tmp != "" && typeof tmp != "undefined"){
				this.history = eval(tmp);
			}
			var tmp = this.cookieMgr.getCookie("reminder");
			if(tmp != null && tmp != "" && typeof tmp != "undefined"){
				this.reminder = eval("(" + tmp + ")");
			}
		},
		
		/**
		 * マイページ表示
		 */
		showMyList : function(){
			if(!mypage.isNotBlank("myPropertyList")){
				return false;
			}
			this.getPropertyData(this.showMyListCompfunc);
		},
        showMyListCompfunc :function(transport){
        	this.propertyData = eval('(' + transport.responseText + ')');
        	this.optimizePropertis();
        	this.createMyList();
        },
		createMyList : function(){
			var myPropertyList = $("myPropertyList");
			this.empty(myPropertyList);
			
			var sortedList = this.property.clone();
			sortedList.sort(
					function(a,b){
						var propA = this.propertyData[a];
						var propB = this.propertyData[b];
						
						var sortedDataA = 0;
						var sortedDataB = 0;
						
						if(this.sortTarget == "conf_date" || this.sortTarget == "completion_date"){
                            if(propA[this.sortTarget] == null){
                                if(this.desc){
                                    sortedDataA = 0;
                                }else{
                                    sortedDataA = 99999999999999;
                                }
                            }else{
    							sortedDataA = propA[this.sortTarget].replace(RegExp("[- :]","g"),"");
                            }
                            if(propB[this.sortTarget] == null){
                                if(this.desc){
                                    sortedDataB = 0;
                                }else{
                                    sortedDataB = 99999999999999;
                                }
                            }else{
    							sortedDataB = propB[this.sortTarget].replace(RegExp("[- :]","g"),"");
    						}
						}else{
    						sortedDataA = propA[this.sortTarget];
    						sortedDataB = propB[this.sortTarget];
    					}
						
						var result = 0;
						if(parseFloat(sortedDataA) > parseFloat(sortedDataB)){
							result =  1;
						}else{
							result = -1;
						}
						if(this.desc){
							result = result * -1;
						}
						return result;
					}.bind(this));
//alert(sortedList);
			var data = "";
			for(var i=0;i<sortedList.length;i++){
				if(typeof this.propertyData[sortedList[i]] != "undefined" && this.propertyData[this.property[i]] != ""){
					var prop = this.propertyData[sortedList[i]];
					var tr = document.createElement("tr");
					var td = document.createElement("td");
					td.className = "check";
					td.setAttribute('colSpan', 7);
					
					
					var rFee = "";
					var mFee = "";
					
					if(prop.rent == null){
						prop.rent = 0;
					}
					if(prop.maintenance_fees == null){
						prop.maintenance_fees = 0;
					}
					
					switch(prop.rent_unit){
						case 1:
							rFee = '<strong>' + this.numberFormat(prop.rent) + '</strong>円';
							break;
						case 2:
							rFee = '<strong>' + this.numberFormat(Math.floor(prop.rent/0.3025)) + '</strong>円';
							break;
						case 3:
							rFee = '<strong>未定</strong>';
							break;
						case 4:
							rFee = '<strong>相談</strong>';
							break;
						case 5:
							rFee = '<strong>実費</strong>';
							break;
						case 6:
							rFee = '<strong>賃料に含む</strong>';
							break;
						case 7:
							rFee = '<strong>無し</strong>';
							break;
						default:
							rFee = '<strong></strong>';
							break;
					}
					switch(prop.maintenance_fees_unit){
						case 1:
							mFee = '<strong>' + this.numberFormat(prop.maintenance_fees) + '</strong>円';
							break;
						case 2:
							mFee = '<strong>' + this.numberFormat(Math.floor(prop.maintenance_fees/0.3025)) + '</strong>円';
							break;
						case 3:
							mFee = '<strong>未定</strong>';
							break;
						case 4:
							mFee = '<strong>相談</strong>';
							break;
						case 5:
							mFee = '<strong>実費</strong>';
							break;
						case 6:
							mFee = '<strong>賃料に含む</strong>';
							break;
						case 7:
							mFee = '<strong>無し</strong>';
							break;
						default:
							mFee = '<strong></strong>';
							break;
					}
					
					var imgFile = "/imgs/share/now_printing_78_104.jpg";
					if(prop.image_1 != null){
						imgFile = '/images/property/02_' + prop.image_1;
					}
					
					
					data ='<h4><a href="/property/index/propertydetail/id_property/' + prop.id_property + '">' + prop.building + '</a><span> [ID：' + prop.code_property + ']</span></h4>';
					data += '<div class="bt-set">';
					data += '<label for="inquiry' + prop.id_property + '">';
					data += '<input type="checkbox" name="id_property[]" id="inquiry' + prop.id_property + '" value="' + prop.id_property + '" />';
					data += '<span>まとめて問い合わせ</span></label>';
					data += '<a href="javascript:void(mypage.delAndShowMyList(' + prop.id_property + '));"><img src="/imgs/search/bt_del.gif" width="120" height="23" alt="マイリストから削除" /></a> </div></td>';
					td.innerHTML = data;
					tr.appendChild(td);
					myPropertyList.appendChild(tr);

					var tr = document.createElement("tr");
					data = '<a href="/property/index/propertydetail/id_property/' + prop.id_property + '"><img src="' + imgFile + '" width="78" height="104" alt="' + prop.building + '" /></a>';
					this.appendTd(tr, data,"pict").style.width = "80px";

					data = prop.address + '<br />' + prop.line_name + " " + prop.station_name + ' 徒歩' + prop.station_walk_1 + '分';
					this.appendTd(tr, data,"left").style.width = "155px";
					
					data = '<strong>' + Math.floor(prop.pyeong * 100)/100 + '</strong>坪<br />（' + Math.floor(prop.sqm * 100)/100 + 'm&sup2;）';
					this.appendTd(tr, data,"").style.width = "75px";
					
					data = rFee + '<br />' + mFee;
					this.appendTd(tr, data,"").style.width = "75px";
					
					data = String(prop.floor).replace("-","B");
					this.appendTd(tr, data,"").style.width = "40px";
					
					if(prop.completion_date != null){
    					data = prop.completion_date.substr(0,7).replace("-","/");
    				}else{
                        data = "&nbsp;";
                    }
					this.appendTd(tr, data,"").style.width = "60px";
					
					var oa = "";
					var oc = "";
					var ar = "";
					var pk = "";
					var ev = "";
					var eq = "";
					var h24 = "";
					
					if(prop.oa_floor_unit ==2){oa = "off";}
					if(prop.optical_cable ==2){oc = "off";}
					if(prop.air_conditioning ==2){ar = "off";}
					if(prop.parking ==1){pk = "off";}
					if(prop.lift ==1){ev = "off";}
					if(prop.earthquake_resistant ==1 || prop.earthquake_resistant ==2){eq = "off";}
					if(prop.throughout_the_day ==2){h24 = "off";}
					
					data = '<div><img src="/imgs/search/icon_opt_01' + oa + '.gif" width="22" height="22" alt="OAフロア" />';
					data += '<img src="/imgs/search/icon_opt_02' + oc + '.gif" width="22" height="22" alt="光ケーブル" />';
					data += '<img src="/imgs/search/icon_opt_07' + h24 + '.gif" width="22" height="22" alt="空調" />';
					data += '<img src="/imgs/search/icon_opt_05' + ev + '.gif" width="22" height="22" alt="駐車場" /></div>';
					data += '<div><img src="/imgs/search/icon_opt_03' + ar + '.gif" width="22" height="22" alt="エレベーター" />';
					data += '<img src="/imgs/search/icon_opt_06' + eq + '.gif" width="22" height="22" alt="耐震" />';
					data += '<img src="/imgs/search/icon_opt_04' + pk + '.gif" width="22" height="22" alt="24時間利用" /></div>';
					this.appendTd(tr, data,"opt").style.width = "104px";
					myPropertyList.appendChild(tr);
					


				}
			}
		},
		sortTarget: "conf_date",
		desc : true,
		sort : function(target){
			if(target.indexOf("_desc") != -1){
				this.sortTarget = target.replace("_desc","");
				this.desc = true;
			}else{
				this.sortTarget = target;
				this.desc = false;
			}
			
			

			
			var sortListLink = $('sortListLink');
			var sortListName = {
				    "conf_date_desc" : "新着順",
				    "pyeong" : "坪数が小さい順",
				    "pyeong_desc" : "坪数が大きい順",
				    "rent" : "賃料が安い順",
				    "rent_desc" : "賃料が高い順",
				    "completion_date_desc" : "竣工が新しい順",
				    "completion_date" : "竣工が古い順"
				};
			var link = "";
			for(val in sortListName){
				if(val == target){
					link += '｜' + sortListName[val];
				}else{
					link += '｜<a href="javascript:void(mypage.sort(\'' + val + '\'));">' + sortListName[val] + '</a>';
				}
			}
			
			sortListLink.innerHTML = link.substr(1);
			
			this.createMyList();
		},
		
		
		/**
		 * お問い合わせ済み物件表示
		 */
		showInquiryList : function(){
			if(!mypage.isNotBlank("myInquiryList")){
				return false;
			}
			this.getPropertyData(this.showInquiryListCompfunc);
		},
		showInquiryListCompfunc :function(transport){
			this.propertyData = eval('(' + transport.responseText + ')');
			this.optimizeInquiry();
			this.createInquiryList();
		},
		createInquiryList : function(){
			var myInquiryList = $("myInquiryList");
			this.empty(myInquiryList);
			
			var sortedList = this.inquiry.clone();
			sortedList.sort(
					function(a,b){
						var propA = this.propertyData[a];
						var propB = this.propertyData[b];
						
						var sortedDataA = 0;
						var sortedDataB = 0;
						
						if(this.sortTargetInq == "conf_date" || this.sortTargetInq == "completion_date"){
                            if(propA[this.sortTargetInq] == null){
                                if(this.descInq){
                                    sortedDataA = 0;
                                }else{
                                    sortedDataA = 99999999999999;
                                }
                            }else{
    							sortedDataA = propA[this.sortTargetInq].replace(RegExp("[- :]","g"),"");
                            }
                            if(propB[this.sortTargetInq] == null){
                                if(this.descInq){
                                    sortedDataB = 0;
                                }else{
                                    sortedDataB = 99999999999999;
                                }
                            }else{
    							sortedDataB = propB[this.sortTargetInq].replace(RegExp("[- :]","g"),"");
    						}
						}else{
    						sortedDataA = propA[this.sortTargetInq];
    						sortedDataB = propB[this.sortTargetInq];
    					}
						
						var result = 0;
						if(parseFloat(sortedDataA) > parseFloat(sortedDataB)){
							result =  1;
						}else{
							result = -1;
						}
						if(this.descInq){
							result = result * -1;
						}
						return result;
					}.bind(this));
//alert(sortedList);
			var data = "";
			for(var i=0;i<sortedList.length;i++){
				if(typeof this.propertyData[sortedList[i]] != "undefined" && this.propertyData[this.inquiry[i]] != ""){
					var prop = this.propertyData[sortedList[i]];
					var tr = document.createElement("tr");
					var td = document.createElement("td");
					td.className = "check";
					td.setAttribute('colSpan', 7);
					
					
					var rFee = "";
					var mFee = "";
					
					if(prop.rent == null){
						prop.rent = 0;
					}
					if(prop.maintenance_fees == null){
						prop.maintenance_fees = 0;
					}
					
					switch(prop.rent_unit){
						case 1:
							rFee = '<strong>' + this.numberFormat(prop.rent) + '</strong>円';
							break;
						case 2:
							rFee = '<strong>' + this.numberFormat(Math.floor(prop.rent/0.3025)) + '</strong>円';
							break;
						case 3:
							rFee = '<strong>未定</strong>';
							break;
						case 4:
							rFee = '<strong>相談</strong>';
							break;
						case 5:
							rFee = '<strong>実費</strong>';
							break;
						case 6:
							rFee = '<strong>賃料に含む</strong>';
							break;
						case 7:
							rFee = '<strong>無し</strong>';
							break;
						default:
							rFee = '<strong></strong>';
							break;
					}
					switch(prop.maintenance_fees_unit){
						case 1:
							mFee = '<strong>' + this.numberFormat(prop.maintenance_fees) + '</strong>円';
							break;
						case 2:
							mFee = '<strong>' + this.numberFormat(Math.floor(prop.maintenance_fees/0.3025)) + '</strong>円';
							break;
						case 3:
							mFee = '<strong>未定</strong>';
							break;
						case 4:
							mFee = '<strong>相談</strong>';
							break;
						case 5:
							mFee = '<strong>実費</strong>';
							break;
						case 6:
							mFee = '<strong>賃料に含む</strong>';
							break;
						case 7:
							mFee = '<strong>無し</strong>';
							break;
						default:
							mFee = '<strong></strong>';
							break;
					}
					
					var imgFile = "/imgs/share/now_printing_78_104.jpg";
					if(prop.image_1 != null){
						imgFile = '/images/property/02_' + prop.image_1;
					}
					
					
					
					data ='<h4><a href="/property/index/propertydetail/id_property/' + prop.id_property + '">' + prop.building + '</a><span> [ID：' + prop.code_property + ']</span></h4>';
					data += '<p class="inquiryDate">お問い合わせ日時：' + this.inquiryDate[String(prop.id_property)] + '</p>';
					td.innerHTML = data;
					tr.appendChild(td);
					myInquiryList.appendChild(tr);
					
					var tr = document.createElement("tr");
					data = '<a href="/property/index/propertydetail/id_property/' + prop.id_property + '"><img src="' + imgFile + '" width="78" height="104" alt="' + prop.building + '" /></a>';
					this.appendTd(tr, data,"pict").style.width = "80px";
					
					data = prop.address + '<br />' + prop.line_name + " " + prop.station_name + ' 徒歩' + prop.station_walk_1 + '分';
					this.appendTd(tr, data,"left").style.width = "155px";
					
					data = '<strong>' + Math.floor(prop.pyeong * 100)/100 + '</strong>坪<br />（' + Math.floor(prop.sqm * 100)/100 + 'm&sup2;）';
					this.appendTd(tr, data,"").style.width = "75px";
					
					data = rFee + '<br />' + mFee;
					this.appendTd(tr, data,"").style.width = "75px";
					
					data = String(prop.floor).replace("-","B");
					this.appendTd(tr, data,"").style.width = "40px";
					
					if(prop.completion_date != null){
    					data = prop.completion_date.substr(0,7).replace("-","/");
    				}else{
                        data = "&nbsp;";
                    }
					this.appendTd(tr, data,"").style.width = "60px";

					var oa = "";
					var oc = "";
					var ar = "";
					var pk = "";
					var ev = "";
					var eq = "";
					var h24 = "";
					
					if(prop.oa_floor_unit ==2){oa = "off";}
					if(prop.optical_cable ==2){oc = "off";}
					if(prop.air_conditioning ==2){ar = "off";}
					if(prop.parking ==1){pk = "off";}
					if(prop.lift ==1){ev = "off";}
					if(prop.earthquake_resistant ==1 || prop.earthquake_resistant ==2){eq = "off";}
					if(prop.throughout_the_day ==2){h24 = "off";}
					
					data = '<div><img src="/imgs/search/icon_opt_01' + oa + '.gif" width="22" height="22" alt="OAフロア" />';
					data += '<img src="/imgs/search/icon_opt_02' + oc + '.gif" width="22" height="22" alt="光ケーブル" />';
					data += '<img src="/imgs/search/icon_opt_07' + h24 + '.gif" width="22" height="22" alt="空調" />';
					data += '<img src="/imgs/search/icon_opt_05' + ev + '.gif" width="22" height="22" alt="駐車場" /></div>';
					data += '<div><img src="/imgs/search/icon_opt_03' + ar + '.gif" width="22" height="22" alt="エレベーター" />';
					data += '<img src="/imgs/search/icon_opt_06' + eq + '.gif" width="22" height="22" alt="耐震" />';
					data += '<img src="/imgs/search/icon_opt_04' + pk + '.gif" width="22" height="22" alt="24時間利用" /></div>';
					this.appendTd(tr, data,"opt").style.width = "104px";
					myInquiryList.appendChild(tr);
					
					
					
				}
			}
		},
		sortTargetInq: "conf_date",
		descInq : true,
		sortInq : function(target){
			if(target.indexOf("_desc") != -1){
				this.sortTargetInq = target.replace("_desc","");
				this.descInq = true;
			}else{
				this.sortTargetInq = target;
				this.descInq = false;
			}
			
			

			
			var sortListLinkInq = $('sortListLinkInq');
			var sortListName = {
				    "conf_date_desc" : "新着順",
				    "pyeong" : "坪数が小さい順",
				    "pyeong_desc" : "坪数が大きい順",
				    "rent" : "賃料が安い順",
				    "rent_desc" : "賃料が高い順",
				    "completion_date_desc" : "竣工が新しい順",
				    "completion_date" : "竣工が古い順"
				};
			var link = "";
			for(val in sortListName){
				if(val == target){
					link += '｜' + sortListName[val];
				}else{
					link += '｜<a href="javascript:void(mypage.sortInq(\'' + val + '\'));">' + sortListName[val] + '</a>';
				}
			}
			
			sortListLinkInq.innerHTML = link.substr(1);
			
			this.createInquiryList();
		},
		
		/**
		 * マイリスト表示
		 */
		showSubMyList : function(){
			if(!mypage.isNotBlank("myList")){
				return false;
			}
			var myList = $("myList");
			this.empty(myList);
			myList.appendChild(this.createNode("h3", "マイ物件リスト"));
			var data = '<img src="/imgs/ajax-loader1.gif" width="24" height="24" />';
			var prop = this.createNode("p",data);
			prop.className = "unknown";
			myList.appendChild(prop);
			
			
			this.getPropertyData(this.showSubMyListCompfunc);
		},
		createSubMyList : function(){
			if(!mypage.isNotBlank("myList")){
				return false;
			}
			var myList = $("myList");
			this.empty(myList);
			myList.appendChild(this.createNode("h3", "マイ物件リスト"));
			
			if(this.property.length == 0){
				var data = '<strong><span>物件が登録されていません。</span></strong><br />';
				data += 'マイ物件リストは物件一覧などから「マイリストに追加」を押すだけでご利用いただけます。<strong>（ユーザー登録不要・無料）</strong><br />';
				data += '気になった物件をマイ物件リストへ追加して物件の比較や、まとめてお問い合わせいただける便利な機能を是非ご活用ください。';
				var prop = this.createNode("p",data);
				prop.className = "unknown";
				myList.appendChild(prop);
				return;
				
			}
			for(var i=0;i<this.property.length;i++){
				if(typeof this.propertyData[this.property[i]] != "undefined" && this.propertyData[this.property[i]] != ""){
					var prop = this.propertyData[this.property[i]];

					var imgFile = "/imgs/share/now_printing_78_104.jpg";
					if(prop.image_1 != null){
						imgFile = '/images/property/02_' + prop.image_1;
					}
					var rFee = 0;
					switch(prop.rent_unit){
						case 1:
							rFee = this.numberFormat(prop.rent) + '円/坪';
							break;
						case 2:
							rFee = this.numberFormat(Math.floor(prop.rent/0.3025)) + '円/坪';
							break;
						case 3:
							rFee = '未定';
							break;
						case 4:
							rFee = '相談';
							break;
						case 5:
							rFee = '実費';
							break;
						case 6:
							rFee = '賃料に含む';
							break;
						case 7:
							rFee = '無し';
							break;
						default:
							rFee = '';
							break;
					}
					var data = '<p class="pict"><a href="http://www.yousan.co.jp/property/index/propertydetail/id_property/' + prop.id_property + '"><img src="' + imgFile + '" width="78" height="104" alt="' + prop.building + '" /></a></p>';
					data += '<h4><a href="http://www.yousan.co.jp/property/index/propertydetail/id_property/' + prop.id_property + '">'+prop.building+'</a></h4>';
					data += '<p>' + prop.address + '<br />';
					data += '広さ：' + prop.floor_area_for_mail + '坪<br />';
					data += '賃料：' + rFee + '</p>';
					var prop = this.createNode("div",data);
					prop.className = "rightList";
					myList.appendChild(prop);
				}
				if(i >= 4){
					break;
				}
			}
		},
		
		/**
		 * 閲覧履歴
		 */
		
		showHistory : function(){
			if(!mypage.isNotBlank("history")){
				return false;
			}
			var history = $("history");
			this.empty(history);
			history.appendChild(this.createNode("h3", "閲覧履歴"));
			var data = '<img src="/imgs/ajax-loader1.gif" width="24" height="24" />';
			var prop = this.createNode("p",data);
			prop.className = "unknown";
			history.appendChild(prop);
			this.getPropertyData(this.showHistoryCompfunc);
		},
		createHistory : function(){
			var history = $("history");
			this.empty(history);
			history.appendChild(this.createNode("h3", "閲覧履歴"));
			
			if(this.history.length == 0){
				var data = '<strong><span>閲覧履歴はありません。</span></strong><br />';
				var prop = this.createNode("p",data);
				prop.className = "unknown";
				history.appendChild(prop);
				return;
			}
			for(var i=0;i<this.history.length;i++){
				if(typeof this.propertyData[this.history[i]] != "undefined" && this.propertyData[this.history[i]] != ""){
					var prop = this.propertyData[this.history[i]];

					var imgFile = "/imgs/share/now_printing_78_104.jpg";
					if(prop.image_1 != null){
						imgFile = '/images/property/02_' + prop.image_1;
					}
					
					var rFee = 0;
					switch(prop.rent_unit){
						case 1:
							rFee = this.numberFormat(prop.rent) + '円/坪';
							break;
						case 2:
							rFee = this.numberFormat(Math.floor(prop.rent/0.3025)) + '円/坪';
							break;
						case 3:
							rFee = '未定';
							break;
						case 4:
							rFee = '相談';
							break;
						case 5:
							rFee = '実費';
							break;
						case 6:
							rFee = '賃料に含む';
							break;
						case 7:
							rFee = '無し';
							break;
						default:
							rFee = '';
							break;
					}
					var data = '<p class="pict"><a href="http://www.yousan.co.jp/property/index/propertydetail/id_property/' + prop.id_property + '"><img src="' + imgFile + '" width="78" height="104" alt="' + prop.building + '" /></a></p>';
					data += '<h4><a href="http://www.yousan.co.jp/property/index/propertydetail/id_property/' + prop.id_property + '">' + prop.building + '</a></h4>';
					data += '<p>' + prop.address + '<br />';
					data += '広さ：' + prop.floor_area_for_mail + '坪<br />';
					data += '賃料：' + rFee + '</p>';
					var prop = this.createNode("div",data);
					prop.className = "rightList";
					history.appendChild(prop);
				}
			}
		},
		
		/**
		 * 登録済み通知条件一覧表示
		 * 
		 */
		showReminder : function(){
			if(!mypage.isNotBlank("reminder")){
				return false;
			}
			var reminder = $("reminder");
			this.empty(reminder);
			reminder.appendChild(this.createNode("h3", "登録済み通知条件一覧"));
			var data = '<img src="/imgs/ajax-loader1.gif" width="24" height="24" />';
			var prop = this.createNode("p",data);
			prop.className = "unknown";
			reminder.appendChild(prop);
			this.getReminderData(this.showReminderCompfunc);
		},
        showReminderCompfunc :function(transport){
        	this.reminderData = eval('(' + transport.responseText + ')');
        	//this.optimizeReminder();
        	this.createReminder();
        },
		createReminder : function(){
			var reminder = $("reminder");
			this.empty(reminder);
			reminder.appendChild(this.createNode("h3", "登録済み通知条件一覧"));
			if(this.reminder.length == 0){
				var data = '<strong><span>条件が登録されていません。</span></strong><br />';
				data += 'ご希望の条件を登録するだけで、新着物件の中から欲しい物件情報だけをいち早くお届け！<strong>利用料無料</strong>の便利なサービスを是非ご活用ください。';
				var prop = this.createNode("p",data);
				prop.className = "unknown";
				
				reminder.appendChild(prop);
				return;
			}
			for(var i=0;i<this.reminder.length;i++){
				if(typeof this.reminderData[this.reminder[i]] != "undefined" && this.reminderData[this.reminder[i]] != ""){
					var prop = this.reminderData[this.reminder[i]];
					if(prop.rent_from.indexOf("なし") == -1){
						prop.rent_from += "/坪"; 
					}
					if(prop.rent_to.indexOf("なし") == -1){
						prop.rent_to += "/坪"; 
					}
					var data = '';
					data += '<dt>希望エリア</dt>';
					data += '<dd>' + prop.areaName + '</dd>';
					data += '<dt>希望駅</dt>';
					data += '<dd>' + prop.stationName + '</dd>';
					data += '<dt>広さ</dt>';
					data += '<dd>' + prop.floor_area_from + '～' + prop.floor_area_to + '</dd>';
					data += '<dt>賃料<span>（共益費込み）</span></dt>';
					data += '<dd>' + prop.rent_from + '～' + prop.rent_to + '</dd>';
					data += '<dt class="bt"><a href="/property/result/index?mode=reminder&hash=' + prop.hash + '"><img src="/imgs/share/bt_mylist_show.gif" width="151" height="24" alt="この条件の物件一覧" /></a></dt>';
					data += '<dd class="bt"><a href="javascript:void(mypage.delAndShowReminder(\'' + prop.hash + '\'));"><img src="/imgs/share/bt_mylist_del.gif" width="67" height="24" alt="この通知条件を削除する" /></a></dd>';
					var prop = this.createNode("dl",data);
					prop.className = "rowList";
					prop.className = "rightList";
					reminder.appendChild(prop);
				}
			}
		},
        
        
        
        
        
        
        /**
         * 物件情報追加
         */
		addProperty : function(id){
			if(this.property.indexOf(id) != -1){
				alert("既に登録されている物件データです。");
				return false;
			}
			if(this.property.length >= 100){
				alert("マイリストの登録は100件までです。");
				return false;
			}
			this.property.unshift(id);
			this.cookieMgr.setCookie("property",this.property.toJSON());
			return true;
		},
		
		
		/**
		 * 履歴追加
		 */
		addHistory : function(id){
			var tmp = [];
			var flg = true;

			if(this.history.indexOf(id) == -1){
				tmp.unshift(id);
			}
			for(var i=0;i<this.history.length;i++){
				if(this.history[i] == id){
					tmp.unshift(this.history[i]);
					flg = false;
				}else{
					tmp.push(this.history[i]);
				}

				if(i>3){
					break;
				}
			}
			if(tmp.length > 5 && flg){
				tmp.pop();
			}
			
			this.history = tmp;
			this.cookieMgr.setCookie("history",this.history.toJSON());
			return true;
		},
		/**
		 * お問い合わせ済み物件追加
		 */
		addInquiry : function(id){
			var tmp = [];
			var flg = true;
			
			if(this.inquiry.indexOf(id) == -1){
				tmp.unshift(id);
			}
			for(var i=0;i<this.inquiry.length;i++){
				if(this.inquiry[i] == id){
					tmp.unshift(this.inquiry[i]);
					flg = false;
				}else{
					tmp.push(this.inquiry[i]);
				}
				
				if(i>18){
					break;
				}
			}
			this.inquiry = tmp;

			
			var date = new Date();
			var now = date.getFullYear()  + "/" + (date.getMonth() + 1) + "/" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();

			this.inquiryDate[String(id)] = now;
			
			if(this.inquiryDate.length > 0){
				var tmp2 = new Hash();
				this.inquiryDate.each(function(pair){
					var n = parseInt(pair["key"]);
					if(this.inquiry.indexOf(n) != -1){
						tmp2[pair["key"]] = pair["value"];
					}
				}.bind(this));
				this.inquiryDate = tmp2;
			}
			
			this.cookieMgr.setCookie("inquiry",this.inquiry.toJSON());
			this.cookieMgr.setCookie("inquiryDate",this.inquiryDate.toJSON());
			return true;
		},
		
		/**
		 * 物件情報を追加して表示
		 */
		addAndShowSubMyList : function(id){
			if(!this.addProperty(id)){
				return false;
			}
			this.showSubMyList();
			this.setMyListButton();
		},
		
		/**
		 * 物件情報削除
		 */
		delProperty : function(id){
			var newProperties = [];
			for(var i=0;i<this.property.length;i++ ){
				if(this.property[i] != id){
					newProperties.push(this.property[i]);
				}
			}
			this.property = newProperties;
			this.cookieMgr.setCookie("property",this.property.toJSON());

		},
		
		/**
		 * 物件情報を削除して表示
		 */
		delAndShowMyList : function(id){
			this.delProperty(id);
			this.createMyList();
		},
		delAndShowSubMyList : function(id){
			this.delProperty(id);
			this.createSubMyList();
			this.setMyListButton();
		},
		
		
		/**
		 * 登録済み通知条件追加
		 */
		addReminder : function(id){
			if(this.reminder.indexOf(id) != -1){
				//alert("既に登録されている登録済み通知条件データです。");
				return false;
			}
			var tmp = [];
			for(var i=0;i<this.reminder.length;i++){
					tmp.push(this.reminder[i]);
				if(i>18){
					break;
				}
			}
			tmp.unshift(id);
			this.reminder = tmp;
			this.cookieMgr.setCookie("reminder",this.reminder.toJSON());
			return true;
		},
		
		/**
		 * 登録済み通知条件削除
		 */
		delReminder : function(id){
			var tmp = [];
			for(var i=0;i<this.reminder.length;i++ ){
				if(this.reminder[i] != id){
					tmp.push(this.reminder[i]);
				}
			}
			this.reminder = tmp;
			this.cookieMgr.setCookie("reminder",this.reminder.toJSON());
		},
		
		/**
		 * 登録済み通知条件を削除して表示
		 */
		delAndShowReminder : function(id){
			if (!window.confirm("データベースからメールアドレスも削除します。\nよろしいですか？")) {
					return false;
			}
			this.delReminder(id);
			location.href="/search/reminder/?d=" + id;
			//this.createReminder();
		},
		
		
		/**
		 * 物件情報をクリア
		 */
		clearProperty : function(){
			this.property = [];
			this.cookieMgr.setCookie("property",this.property.toJSON());
		},
		clearAndShowSubMyList : function(){
			this.clearProperty();
			this.createSubMyList();
		},
		
		
		
		
		getReminderData : function(cmpfunc){
			if(cmpfunc == null || typeof cmpfunc == "undefined"){
				cmpfunc = this.reminderDefaultCompfunc;
			}
			var ajaxFunc = {
					method:'post',
					parameters: {"reminder":this.reminder.toString()},
					onFailure:function(){alert("エラーが起こりました。もう一度操作してください。\nエラーを繰り返す場合は管理者までご連絡ください。");},
					onSuccess: cmpfunc.bind(this)
			};
			var ajax = new Ajax.Request("/property/index/reminder/", ajaxFunc);
			
		},
		getPropertyData : function(cmpfunc){
			if(cmpfunc == null || typeof cmpfunc == "undefined"){
				cmpfunc = this.defaultCompfunc;
			}
			var ajaxFunc = {
                    method:'post',
                    parameters: {"property":this.property.concat(this.history).concat(this.inquiry).toString()},
                    onFailure:function(){alert("エラーが起こりました。もう一度操作してください。\nエラーを繰り返す場合は管理者までご連絡ください。");},
                    onSuccess: cmpfunc.bind(this)
                };
			var ajax = new Ajax.Request("/property/index/mypage/", ajaxFunc);

		},
		optimizePropertis : function(){
			var tmp = [];
			for(var i=0;i<this.property.length;i++){
				if(this.property[i] in this.propertyData){
					tmp.push(this.property[i]);
				}
			}
			this.property = tmp;
			this.cookieMgr.setCookie("property",this.property.toJSON());
		},
		optimizeInquiry : function(){
			var tmp = [];
			for(var i=0;i<this.inquiry.length;i++){
				if(this.inquiry[i] in this.propertyData){
					tmp.push(this.inquiry[i]);
				}
			}
			this.inquiry = tmp;
			this.cookieMgr.setCookie("inquiry",this.inquiry.toJSON());
		},
		optimizeReminder : function(){
			var tmp = [];
			for(var i=0;i<this.reminder.length;i++){
				if(this.reminder[i] in this.reminderData){
					tmp.push(this.reminder[i]);
				}
			}
			this.reminder = tmp;
			this.cookieMgr.setCookie("reminder",this.reminder.toJSON());
		},
		optimizeHistory : function(){
			var tmp = [];
			for(var i=0;i<this.history.length;i++){
				if(this.history[i] in this.propertyData){
					tmp.push(this.history[i]);
				}
			}
			this.history = tmp;
			this.cookieMgr.setCookie("history",this.history.toJSON());
		},
		
		/**
		 * Ajaxで取得した後の処理
		 */
		defaultCompfunc :function(transport){
            this.propertyData = eval('(' + transport.responseText + ')');
        },
        reminderDefaultCompfunc :function(transport){
        	this.reminderData = eval('(' + transport.responseText + ')');
        },
		showSubMyListCompfunc :function(transport){
            this.propertyData = eval('(' + transport.responseText + ')');
            this.optimizePropertis();
            this.createSubMyList();
        },
        showHistoryCompfunc :function(transport){
        	this.propertyData = eval('(' + transport.responseText + ')');
        	this.optimizeHistory();
        	this.createHistory();
        },
		empty : function(elm){
        	if(elm == null || elm == "" || typeof elm == "undefined"){
        		return;
        	}
			while(elm.hasChildNodes()){
				elm.removeChild(elm.firstChild);
			}
		},
		createNode : function(tag,html){
			var result = document.createElement(tag);
			result.innerHTML = html;
			return result;
		},
		setMyListButton : function(){
			var buttonList = document.getElementsByClassName("myListButton");
			buttonList.each(function(obj){
				var id = obj.name;
				if(this.property.indexOf(id) != -1){
					obj.href = 'javascript:void(mypage.delAndShowSubMyList(' + id + '));';
					obj.innerHTML = '<img src="/imgs/search/bt_del.gif" width="120" height="23" alt="マイリストに追加" />';
				}else{
					obj.href = 'javascript:void(mypage.addAndShowSubMyList(' + id + '));';
					obj.innerHTML = '<img src="/imgs/search/bt_add.gif" width="120" height="23" alt="マイリストに追加" />';
				}
				
			}.bind(this));
		},
		numberFormat : function (str) {
			var num = new String(str).replace(/,/g, "");
			while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
			return num;
		},
		appendTd : function(obj,text,cls,css){
		    var td = document.createElement("td");
		    if(cls != ""){
		    	td.className = cls;
		    }
		    td.innerHTML = text;
		    obj.appendChild(td);
		    return td;
		},
		isNotBlank : function (name){
			var elm = $(name);
			if(elm != null && typeof elm != "undefined" && elm != ""){
				return true;
			}
			return false;
		},
		submitInquiry : function(){
			
			
			//var inquiryform = $("inquiryform");
			var inquiryform = document.inquiryform;
			if(inquiryform.elements['id_property[]']){
				var cnt = 0;
				var elms = inquiryform.elements['id_property[]'];
				if(elms.length){
					for(var i=0;i<elms.length;i++){
						if(elms[i].checked){
							cnt++;
						}
					}
				}else{
					if(elms.checked){
						cnt++;
					}
                }
				if(cnt == 0){
					alert("お問い合わせする物件をチェックしてください。");
					return false;
				}else{
					inquiryform.submit();
				}
			}
		}
		
}


Event.observe(window, 'load', function(){
	mypage.init();
	mypage.showSubMyList();
	mypage.showInquiryList();
	mypage.showHistory();
	mypage.showMyList();
	mypage.showReminder();
	if(mypage.isNotBlank("addHistoryIdProperty")){
		mypage.addHistory($("addHistoryIdProperty").value);
	}
	if(mypage.isNotBlank("addReminderHash")){
		mypage.addReminder($("addReminderHash").value);
		mypage.showReminder();
	}
	if(mypage.isNotBlank("addInquiryIdProperty")){
		var tmp = $("addInquiryIdProperty").value.split(",");
		if(tmp.length > 0){
			tmp.each(function(val){
				mypage.addInquiry(val);
			});
		}
		
		
	}
	if(mypage.isNotBlank("submitInquiry")){
		$('submitInquiry').style.cursor = "pointer";
	}
	
	mypage.setMyListButton();
})
