function google_map(ido, keido, mode){
	this.mode = mode;
	this.ido = ido;
	this.keido = keido;
	this.markers = new Array();
	this.all_tabs = new Array();
	this.div = document.getElementById("map");

	this.map=new GMap2(this.div);
	this.geocoder = new GClientGeocoder();
	if (!this.ido && !this.keido){
		this.ido = 33.5525090;
		this.keido = 130.4364570;
		//alert("検索結果がありません");
	}
	this.init_point = new GLatLng(this.ido, this.keido);
	this.map.setCenter(this.init_point);
	this.map.setZoom(17);
	this.map.addControl(new GSmallMapControl());
	//this.map.addControl(new GLargeMapControl());
	//this.map.addControl(new GMapTypeControl());
	

	//１部屋の賃貸物件に使うアイコン
	//1R 1K 1DK 1LDK
	this.icon = new GIcon();
	this.icon.image = "/rmap/images/gs_pin_green.png";
	this.icon.shadow = "/rmap/images/gs_pin_shadow.png";
	this.icon.iconSize = new GSize(32, 38);
	this.icon.shadowSize = new GSize(61, 38);
	this.icon.iconAnchor = new GPoint(15, 36);
	this.icon.infoWindowAnchor = new GPoint(15, 0);

	//２部屋の賃貸物件に使うアイコン
	//2K 2DK 2LDK
	this.icon2 = new GIcon();
	this.icon2.image = "/rmap/images/gs_pin_blue.png";
	this.icon2.shadow = "/rmap/images/gs_pin_shadow.png";
	this.icon2.iconSize = new GSize(32, 38);
	this.icon2.shadowSize = new GSize(61, 38);
	this.icon2.iconAnchor = new GPoint(15, 36);
	this.icon2.infoWindowAnchor = new GPoint(15, 0);

	//３部屋の賃貸物件に使うアイコン
	//3K 3DK 3LDK
	this.icon3 = new GIcon();
	this.icon3.image = "/rmap/images/gs_pin_orange.png";
	this.icon3.shadow = "/rmap/images/gs_pin_shadow.png";
	//this.icon3.shadow = "/rmap/images/pin_shade_bukken.png";
	this.icon3.iconSize = new GSize(32, 38);
	this.icon3.shadowSize = new GSize(61, 38);
	this.icon3.iconAnchor = new GPoint(15, 36);
	this.icon3.infoWindowAnchor = new GPoint(15, 0);

	//４部屋の賃貸物件に使うアイコン
	//4K 4DK 4LDK
	this.icon4 = new GIcon();
	this.icon4.image = "/rmap/images/gs_pin_red.png";
	this.icon4.shadow = "/rmap/images/gs_pin_shadow.png";
	this.icon4.iconSize = new GSize(32, 38);
	this.icon4.shadowSize = new GSize(61, 38);
	this.icon4.iconAnchor = new GPoint(15, 36);
	this.icon4.infoWindowAnchor = new GPoint(15, 0);


	//マップを目的地までずらす関数
	this.center_map = function(center) {
		this.map.panTo(center);
		//alert("ok "+center.toString());
		if (this.mode == "edit") {
			this.markers[0].setPoint(center);
		}
	};

	//登録時の「ズレ過ぎ」の計算に使用されるマップの中心を更新。
	this.set_hardcenter = function(center) {
		this.ido=center.lat();
		this.keido=center.lng();
	};

	this.autozoom = function() {
		//bounds = new GBounds(this.markers);
		var bounds = new GLatLngBounds();
		for (var i = 0; i < this.markers.length; i+=1) {
			bounds.extend(this.markers[i].getPoint());
		}
		var zoom = this.map.getBoundsZoomLevel(bounds);
		var bounds_center = bounds.getCenter();
		//alert(zoom+" "+bounds.getCenter().toString());
		this.center_map(bounds_center);
		//this.add_marker(bounds_center);
		this.map.setZoom(zoom);
	};

	this.get_results_data = function() {
		if (document.getElementById("map_mode")) {
			this.map_mode=document.getElementById("map_mode").innerHTML;
		}
		if (document.getElementById("map_search")) {
			this.map_search=document.getElementById("map_search").innerHTML;
		}
		if (document.getElementById("map_ido")) {
			this.map_ido=document.getElementById("map_ido").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_ido.pop(); }
		}
		if (document.getElementById("map_keido")) {
			this.map_keido=document.getElementById("map_keido").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_keido.pop(); }
		}
		if (document.getElementById("map_name")) {
			this.map_name=document.getElementById("map_name").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_name.pop(); }
		}
		if (document.getElementById("map_jusho")) {
			this.map_jusho=document.getElementById("map_jusho").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_jusho.pop(); }
		}
		if (document.getElementById("map_madori")) {
			this.map_madori=document.getElementById("map_madori").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_madori.pop(); }
		}
		if (document.getElementById("map_price")) {
			this.map_price=document.getElementById("map_price").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_price.pop(); }
		}
		if (document.getElementById("map_kakaku")) {
			this.map_kakaku=document.getElementById("map_kakaku").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_kakaku.pop(); }
		}
		if (document.getElementById("map_id")) {
			this.map_id=document.getElementById("map_id").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_id.pop(); }
		}
		if (document.getElementById("map_chintaibaibai")) {
			this.map_chintaibaibai=document.getElementById("map_chintaibaibai").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_chintaibaibai.pop(); }
		}
		if (document.getElementById("map_fudosan_id")) {
			this.map_fudosan_id=document.getElementById("map_fudosan_id").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_fudosan_id.pop(); }
		}
		if (document.getElementById("map_fudosan_user")) {
			this.map_fudosan_user=document.getElementById("map_fudosan_user").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_fudosan_user.pop(); }
		}
		if (document.getElementById("map_fudosan_name")) {
			this.map_fudosan_name=document.getElementById("map_fudosan_name").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_fudosan_name.pop(); }
		}
		if (document.getElementById("map_fudosan_jusho")) {
			this.map_fudosan_jusho=document.getElementById("map_fudosan_jusho").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_fudosan_jusho.pop(); }
		}
		if (document.getElementById("map_fudosan_phone")) {
			this.map_fudosan_phone=document.getElementById("map_fudosan_phone").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_fudosan_phone.pop(); }
		}
		if (document.getElementById("map_fudosan_mail")) {
			this.map_fudosan_mail=document.getElementById("map_fudosan_mail").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_fudosan_mail.pop(); }
		}
		if (document.getElementById("map_pictures")) {
			this.map_pictures=document.getElementById("map_pictures").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_pictures.pop(); }
		}
		if (document.getElementById("map_logos")) {
			this.map_logos=document.getElementById("map_logos").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_logos.pop(); }
		}
	};


	this.attach_click = function(pointer) {
		GEvent.addListener(this.map, "click", function(click_overlay, click_point) {
			if ( click_overlay !== null ) { return; }
			map1.center_map(click_point);
			var field_ido = document.getElementById("ido");
			if(field_ido) {
				field_ido.value = click_point.lat();
			}
			var field_keido = document.getElementById("keido");
			if(field_keido) {
				field_keido.value = click_point.lng();
			}
			if(map1.markers[0]) {
				var point_backup = new GLatLng(map1.ido,map1.keido);
				if (click_point.distanceFrom(point_backup)>1000) {
					//document.getElementById("idokeido_msg").innerHTML = "計算した緯度経度から１キロも外れるが、いいですか？";
					//alert(document.getElementById("idokeido_msg"));
					my_form.idokeido_msg.id.innerHTML = "計算した緯度経度から１キロも外れるが、いいですか？";
				} else { document.getElementById("idokeido_msg").innerHTML = ""; }
			}
		});
	};
	//pont：位置 i:配列番号
	this.add_marker = function(point,i) {
		/*
		if (this.map_search == 'mixed') {
			if (this.markers.length === 0) {
				this.markers.push(new GMarker(point, this.icon2));
			} else if (this.map_chintaibaibai[this.markers.length] == '売買') {
				this.markers.push(new GMarker(point, this.icon3));
			} else {
				this.markers.push(new GMarker(point, this.icon));
			}
		}else if (this.map_search == 'fudosan') {
			this.markers.push(new GMarker(point, this.icon2));
		}else if (this.map_mode == 'home') {
			this.markers.push(new GMarker(point, this.icon2));
		} else if (this.map_chintaibaibai) {
			//alert(this.map_id[this.markers.length]);
			if (this.map_chintaibaibai[this.markers.length] == '売買') {
				this.markers.push(new GMarker(point, this.icon3));
			} else {
				this.markers.push(new GMarker(point, this.icon));
			}
		} else {
			this.markers.push(new GMarker(point, this.icon));
		}
		*/
	
		if(this.map_mode == 'search' || this.map_mode == 'view'){
			if(this.map_madori[i].substring(0,1) == 1){
				this.markers.push(new GMarker(point, this.icon));
			}else if(this.map_madori[i].substring(0,1) == 2){
				this.markers.push(new GMarker(point, this.icon2));
			}else if(this.map_madori[i].substring(0,1) == 3){
				this.markers.push(new GMarker(point, this.icon3));
			}else {
				this.markers.push(new GMarker(point, this.icon4));
			}
		}else{
			this.markers.push(new GMarker(point, this.icon));
		}
		
		this.map.addOverlay(this.markers[this.markers.length-1]);
	};

	this.tabbed_info = function() {
		if (this.map_jusho.length != this.markers.length) {
			alert ("インフォウィンドーのデータは正しく読み込む事が出来ませんでした");
			return 1;
		}
		this.tabs = new Array();
		var i = 0;
		var bukken_info = "";
		var fudosan_info = "";
		if (this.map_search == 'fudosan') {
			for (i = 0; i < this.map_jusho.length; i+=1) {
				fudosan_info  = "<div class=\"balloon\">";
				if (this.map_logos[i]) {
					fudosan_info += "<div class=\"balloon_img\"><img src=\"http://www.movimap.net/pictures/" + this.map_logos[i] + "\" alt=\"" + this.map_fudosan_name[i] + "ロゴ\" width=\"80\" height=\"60\" /></div>";
				}
				fudosan_info += "<div class=\"balloon_right\">";
				fudosan_info += "<h2>" + this.map_fudosan_name[i] + "</h2>";
				fudosan_info += "<h3>" + this.map_jusho[i] + "</h3>";
				fudosan_info += "<p class=\"balloon_tel\">TEL " + this.map_fudosan_phone[i] + "</p>";
				fudosan_info += "<p class=\"balloon_detail\"><a href=\"http://users.movimap.net/" + this.map_fudosan_user[i] + "\"><strong>会社の詳細</strong></a></p>";
				fudosan_info += "<p class=\"balloon_contact\"><a href=\"http://www.movimap.net/contact/fudosan/" + this.map_id[i] + "\"><strong>お問合せ</strong></a></p>";
				fudosan_info += "<br class=\"close\" /></div><br class=\"close\" /></div>";
				this.tabs.push(fudosan_info);
				this.add_window(i);
			}
		} else if (this.map_search == 'mixed') {
			for (i = 0; i < 1; i+=1) {
				fudosan_info  = "<div class=\"balloon\">";
				if (this.map_logos[i]) {
					fudosan_info += "<div class=\"balloon_img\"><img src=\"http://www.movimap.net/pictures/" + this.map_logos[i] + "\" alt=\"" + this.map_fudosan_name[i] + "ロゴ\" width=\"80\" height=\"60\" /></div>";
				}
				fudosan_info += "<div class=\"balloon_right\">";
				fudosan_info += "<h2>" + this.map_fudosan_name[i] + "</h2>";
				fudosan_info += "<h3>" + this.map_jusho[i] + "</h3>";
				fudosan_info += "<p class=\"balloon_tel\">TEL " + this.map_fudosan_phone[i] + "</p>";
				fudosan_info += "<p class=\"balloon_detail\"><a href=\"http://users.movimap.net/" + this.map_fudosan_user[i] + "\"><strong>会社の詳細</strong></a></p>";
				fudosan_info += "<p class=\"balloon_contact\"><a href=\"http://www.movimap.net/contact/fudosan/" + this.map_id[i] + "\"><strong>お問合せ</strong></a></p>";
				fudosan_info += "<br class=\"close\" /></div><br class=\"close\" /></div>";
				this.tabs.push(fudosan_info);
				this.add_window(i);
			}
			for (i = 1; i < this.map_jusho.length; i+=1) {
				bukken_info  = "<div class=\"balloon\">";
				if (this.map_pictures[i]) {
					bukken_info += "<div class=\"balloon_img\"><img src=\"http://www.movimap.net/thumbs/" + this.map_pictures[i] + "\" alt=\"" + this.map_name[i] + "\" width=\"80\" height=\"60\" /></div>";
				}
				bukken_info += "<div class=\"balloon_right\">";
				bukken_info += "<h2>" + this.map_name[i] + "</h2>";
				//bukken_info += "<h3>" + this.map_jusho[i] + "</h3>";
				bukken_info += "<p class=\"balloon_tel\">間取り：" + this.map_madori[i] + "｜賃料：￥" + this.map_price[i] + "</p>";
				if (this.map_chintaibaibai[i]=="賃貸") {
					bukken_info += "<p class=\"balloon_bukken_detail\"><a href=\"http://rental.movimap.net/" + this.map_id[i] + "\"><strong>物件の詳細</strong></a></p>";
				} else if (this.map_chintaibaibai[i]=="売買") {
				bukken_info += "<p class=\"balloon_bukken_detail\"><a href=\"http://sale.movimap.net/" + this.map_id[i] + "\"><strong>物件の詳細</strong></a></p>";
				}
				bukken_info += "<p class=\"balloon_contact\"><a href=\"http://www.movimap.net/contact/bukken/" + this.map_id[i] + "\"><strong>お問合せ</strong></a></p>";
				bukken_info += "<br class=\"close\" /></div><br class=\"close\" /></div>";
				fudosan_info  = "<div class=\"balloon\">";
				if (this.map_logos[i]) {
					fudosan_info += "<div class=\"balloon_img\"><img src=\"http://www.movimap.net/pictures/" + this.map_logos[i] + "\" alt=\"" + this.map_fudosan_name[i] + "ロゴ\" width=\"80\" height=\"60\" /></div>";
				}
				fudosan_info += "<div class=\"balloon_right\">";
				fudosan_info += "<h2>" + this.map_fudosan_name[i] + "</h2>";
				fudosan_info += "<h3>" + this.map_jusho[i] + "</h3>";
				fudosan_info += "<p class=\"balloon_tel\">TEL " + this.map_fudosan_phone[i] + "</p>";
				fudosan_info += "<p class=\"balloon_detail\"><a href=\"http://users.movimap.net/" + this.map_fudosan_user[i] + "\"><strong>会社の詳細</strong></a></p>";
				fudosan_info += "<p class=\"balloon_contact\"><a href=\"http://www.movimap.net/contact/fudosan/" + this.map_fudosan_id[i] + "\"><strong>お問合せ</strong></a></p>";
				fudosan_info += "<br class=\"close\" /></div><br class=\"close\" /></div>";
				//this.tabs.push(new info_tabs("物件",	bukken_info, "不動産", fudosan_info ));
				this.tabs.push(new info_tabs("物件",	bukken_info));
				this.add_tabs(i);
			}
		} else {
			for (i = 0; i < this.map_jusho.length; i+=1) {
				bukken_info  = "<div class=\"balloon\">";
				if (this.map_pictures[i]) {
					bukken_info += "<div class=\"balloon_img\"><img src=\"http://rmap-n.com/rmap/thumbs/" + this.map_pictures[i] + "\" alt=\"" + this.map_name[i] + "\" width=\"80\" height=\"60\" /></div>";
				}
				bukken_info += "<div class=\"balloon_right\">";
				bukken_info += "<div class=\"balloon_tel\">" + this.map_name[i] + "</div>";
				//bukken_info += "<h3>" + this.map_jusho[i] + "</h3>";
				bukken_info += "<p class=\"balloon_tel\">間取り：" + this.map_madori[i] + "｜賃料：￥" + this.map_price[i] + "</p>";

				bukken_info += "<p class=\"balloon_bukken_detail\"><a href=\"http://rmap-n.com/rmap/bukken/" + this.map_id[i] + "\"><strong>物件の詳細</strong></a>";
				bukken_info += "<p class=\"balloon_contact\"><a href=\"http://rmap-n.com/rmap/contact/bukken/" + this.map_id[i] + "\"><strong>お問合せ</strong></a></p>";
				bukken_info += "</div></div>";
				
				/*
				fudosan_info  = "<div class=\"balloon\">";
				if (this.map_logos[i]) {
					fudosan_info += "<div class=\"balloon_img\"><img src=\"http://rmap-n.com/rmap/pictures/" + this.map_logos[i] + "\" alt=\"" + this.map_fudosan_name[i] + "ロゴ\" width=\"80\" height=\"60\" /></div>";
				}
				fudosan_info += "<div class=\"balloon_right\">";
				fudosan_info += "<h2>" + this.map_fudosan_name[i] + "</h2>";
				fudosan_info += "<h3>" + this.map_fudosan_jusho[i] + "</h3>";
				fudosan_info += "<p class=\"balloon_tel\">TEL " + this.map_fudosan_phone[i] + "</p>";
				fudosan_info += "<p class=\"balloon_detail\"><a href=\"http://users.movimap.net/" + this.map_fudosan_user[i] + "\"><strong>会社の詳細</strong></a></p>";
				fudosan_info += "<p class=\"balloon_contact\"><a href=\"http://www.movimap.net/contact/fudosan/" + this.map_fudosan_id[i] + "\"><strong>お問合せ</strong></a></p>";
				fudosan_info += "<br class=\"close\" /></div><br class=\"close\" /></div>";
				*/
				//this.tabs.push(new info_tabs("物件",	bukken_info, "不動産", fudosan_info ));
				this.tabs.push(new info_tabs("物件",	bukken_info));
				this.add_tabs(i);
			}
		}
	};

	this.add_tabs = function(index) {
		GEvent.addListener(this.markers[index], "click", function() {
			this.openInfoWindowTabsHtml(map1.tabs[index].tabs);
			for (i=0; i<results.length; i=i+1) {
				if (i != index)
				//results[i].className = 'results';
				results[i].className = 'clickable_list_item';
			}
			//return this.className = 'results_selected';
			return results[index].className = 'clickable_list_item_selected';
		});
	};

	this.add_window = function(index) {
		GEvent.addListener(this.markers[index], "click", function() {
			this.openInfoWindowHtml(map1.tabs[index]);
			for (i=0; i<results.length; i=i+1) {
				if (i != index)
				//results[i].className = 'results';
				results[i].className = 'clickable_list_item';
			}
			//return this.className = 'results_selected';
			return results[index].className = 'clickable_list_item_selected';
		});
	};

	this.attach_click_to_result = function(element, counter) {
		element.style.cursor = 'pointer';
		//element.onmouseover = function(){ return this.className = 'results_over'; };
		//element.onmouseout = function(){ return this.className = 'results'; };
		element.onclick = function(counter){ 
			for (i=0; i<results.length; i=i+1) {
				if (i != counter)
				//results[i].className = 'results';
				results[i].className = 'clickable_list_item';
			}
			//return this.className = 'results_selected';
			return this.className = 'clickable_list_item_selected';
		};
		//element.className = 'results_selected';
		GEvent.addDomListener(element, "click", function() {
			//map1.center_map(map1.markers[counter].getPoint());
			if (map1.map_search == 'fudosan') {
				map1.markers[counter].openInfoWindowHtml(map1.tabs[counter]);
			} else if (map1.map_search == 'mixed') {
				if (counter === 0) {
					map1.markers[counter].openInfoWindowHtml(map1.tabs[counter]);
				} else {
					map1.markers[counter].openInfoWindowTabsHtml(map1.tabs[counter].tabs);
				}
			} else {
				map1.markers[counter].openInfoWindowTabsHtml(map1.tabs[counter].tabs);
			}
		});
	};

	//右下インデックスマップ表示関数(縦、横)
	this.index_map = function(height,width) {
		this.map.addControl(new GOverviewMapControl(new GSize(height,width)));
	};

	return true;
}
/*
function info_tabs(label1, body1, label2, body2){
	this.label1 = label1;
	this.label2 = label2;
	this.body1 = body1;
	this.body2 = body2;
	this.tab1 = new GInfoWindowTab(this.label1,this.body1);
	this.tab2 = new GInfoWindowTab(this.label2,this.body2);
	this.tabs = [ this.tab1, this.tab2 ];

	return true;
}
*/
function info_tabs(label1, body1){
	this.label1 = label1;
	this.body1 = body1;
	this.tab1 = new GInfoWindowTab(this.label1,this.body1);
	this.tabs = [ this.tab1];

	return true;
}


function form(){
	//take names（フィールドなどの使えるidをオブジェクトで登録）

	//if (typeof map1 != "undefined") { this.map = map1; }
	this.form = new form_field(document.getElementById('form1'));
	this.msgid = new form_field(document.getElementById('form_msg'));
	this.todofuken = new form_field(document.getElementById('todofuken'));
	this.todofuken.msgid = new form_field(document.getElementById('todofuken_msg'));
	this.shikuchoson = new form_field(document.getElementById('shikuchoson'));
	this.shikuchoson.msgid = new form_field(document.getElementById('shikuchoson_msg'));
	this.ooazamachichome = new form_field(document.getElementById('ooazamachichome'));
	this.ooazamachichome.msgid = new form_field(document.getElementById('ooazamachichome_msg'));
	this.gaikufugochiban = new form_field(document.getElementById('gaikufugochiban'));
	this.gaikufugochiban.msgid = new form_field(document.getElementById('gaikufugochiban_msg'));
	this.get_idokeido = new form_field(document.getElementById('get_idokeido'));
	this.price = new form_field(document.getElementById('price'));

	//this.ct_sonota = new form_field(document.getElementById('ct_sonota'));

	this.bukken_option = new form_field(document.getElementById('bukken_option'));
	this.idokeido_msg = new form_field(document.getElementById('idokeido_msg'));
	this.ido = new form_field(document.getElementById('ido'));
	this.keido = new form_field(document.getElementById('keido'));
	this.input_fields = new Array();
	this.input_array = document.getElementsByTagName('input');
	for (i=0; i<this.input_array.length; i=i+1) {
		this.input_fields.push(new form_field(this.input_array[i]));
	}
	this.select_boxes = new Array();
	this.select_array = document.getElementsByTagName('select');
	for (i=0; i<this.select_array.length; i=i+1) {
		this.select_boxes.push(new form_field(this.select_array[i]));
	}
	this.table_tds = new Array();
	this.td_array = document.getElementsByTagName('td');
	for (i=0; i<this.td_array.length; i=i+1) {
		this.table_tds.push(new form_field(this.td_array[i]));
	}
	this.sample_text = new Array();
	this.sample_text_array = document.getElementsByTagName('input');
	for (i=0; i<this.sample_text_array.length; i=i+1) {
		if (this.sample_text_array[i].className == 'sample_text') {
			this.sample_text.push(new form_field(this.sample_text_array[i]));
		}
	}
	this.form_error_table = document.getElementById('form_error_table');
	if (this.form_error_table) {
		if (this.form_error_table.rows.length < 1) {
			this.form_error_table.className = "invisible";
		}
	}


	//色々とイベント・ハンドラーを付ける
	this.attach_events=function() {
		for (i = 0; i < this.input_fields.length; i=i+1) {
			if (this.input_fields[i].id.name != "get_idokeido") {
				this.input_fields[i].id.onkeyup = function(){ return validate_input(this); };
				this.input_fields[i].id.onblur  = function(){ return validate_input(this); };
				this.input_fields[i].id.onclick = function(){ return validate_input(this); };
			}
		}
		for (i = 0; i < this.select_boxes.length; i=i+1) {
			//alert(this.select_boxes[i].id);
			this.select_boxes[i].id.onkeyup = function(){ return validate_input(this); };
			this.select_boxes[i].id.onblur  = function(){ return validate_input(this); };
			this.select_boxes[i].id.onclick = function(){ return validate_input(this); };
		}
		if(this.form.id) {
			this.form.id.onsubmit = function(){
				if(my_form.msgid.id) {
					my_form.msgid.id.innerHTML = "";
					my_form.msgid.id.innerHTML = "ご入力を確認中・・・";
					my_form.msgid.id.style.color = '#e60012';
				}
			};
		}
		if (this.get_idokeido.id) {
			this.get_idokeido.id.style.cursor = 'pointer';
			this.get_idokeido.id.onclick = function(){ 
				return my_form.get_idokeido_by_jusho(this);
			};
		}
		for (i = 0; i < this.sample_text.length; i=i+1) {
			this.sample_text[i].id.onfocus = function (){ 
				this.value = "";
				this.onfocus = function(){ return; };
			};
		}
	};

	//ジュウショから緯度経度を計算
	this.get_idokeido_by_jusho = function(the_input) {
		//バリデーションではなく住所から緯度経度を調べる
		//引数名が解りにくくて申し訳ないです
		var input_value = this.todofuken.id.value;
		var input_required = this.shikuchoson.id.value;
		var input_type = this.ooazamachichome.id.value;
		var input_error_id = 'idokeido';
		this.idokeido_msg.id.innerHTML = "";
		//make_request(input_value, input_required, input_type, input_error_id);
		var address = this.todofuken.id.value+this.shikuchoson.id.value+this.ooazamachichome.id.value+this.gaikufugochiban.id.value;
		map1.geocoder.getLatLng(
			address,
			function(point) {
				if (!point) {
					my_form.idokeido_msg.id.innerHTML = "「" + address + "」は認識出来ませんでした。";
					//alert("「" + address + "」は認識出来ませんでした。");
				} else {
// 					map.setCenter(point, 13);
// 					var marker = new GMarker(point);
// 					map.addOverlay(marker);
// 					marker.openInfoWindowHtml(address);
					if (map1) {
						map1.center_map(point);
						map1.set_hardcenter(point);
					}
					my_form.ido.id.value = point.y;
					my_form.keido.id.value = point.x;
				}
			}
		);

	};

	this.validate_all = function() {
		alert("validate all");
		var number_of_errors = 0;
		for (table_td in this.table_tds) {
			if (table_td.id.className == "rules"){
				if (table_td.id.innerHTML == '確認済み' || table_td.id.innerHTML === '' ) {
					table_td.id.style.color = '#000000';
				} else {
					number_of_errors = number_of_errors + 1; 
					table_td.id.style.color = '#e60012';
				}
			}
		}
		if (number_of_errors > 0) {
			form_error = "入力された項目を全て再確認下さい。受け取れない値のとなりに赤字の警告が出ています";
			if(this.msgid.id) {
				this.msgid.id.innerHTML = "";
				this.msgid.id.innerHTML = form_error;
				this.msgid.id.style.color = '#e60012';
			}
			number_of_errors = 0;
			return false;
		} else {
			return true;
		}
	};

	return true;
}

function form_field(id) {
	this.id = id;
	this.msgid = null;
	//触ったら１回消えるフィールド用のカウンター
	this.delete_count = 0;
	
	return true;
}

function validate_input(the_input) {
	var input_value = "";
	var input_class = "";
	var input_required = "";
	var input_type = "";
	var input_error_id = "";
	//alert("validating input");
	if(the_input.name=="yuubin" && the_input.value.length==7) {
		//バリデーションではなく郵便番号から住所を調べましょう
		//引数名が解りにくくて申し訳ないです
		input_value = the_input.value;
		input_class = "";
		input_required = "";
		input_type = "";
		input_error_id = "jusho";
		make_request(input_value, input_required, input_type, input_error_id);
		
		//緯度経度取得
		/*var input_error_id = 'idokeido';
		var input_value = my_form.todofuken.id.value;
		var input_required = my_form.shikuchoson.id.value;
		var input_type = my_form.ooazamachichome.id.value;
		make_request(input_value, input_required, input_type, input_error_id);
		*/
			var address = my_form.todofuken.id.value+my_form.shikuchoson.id.value+my_form.ooazamachichome.id.value+my_form.gaikufugochiban.id.value;
			my_form.idokeido_msg.id.innerHTML = "";
			//make_request(input_value, input_required, input_type, input_error_id);
			map1.geocoder.getLatLng(
				address,
				function(point) {
					if (!point) {
						my_form.idokeido_msg.id.innerHTML = "「" + address + "」は認識出来ませんでした。";
						//alert("「" + address + "」は認識出来ませんでした。");
					} else {
	// 					map.setCenter(point, 13);
	// 					var marker = new GMarker(point);
	// 					map.addOverlay(marker);
	// 					marker.openInfoWindowHtml(address);
						if (map1) {
							map1.center_map(point);
							map1.set_hardcenter(point);
						}
						my_form.ido.id.value = point.y;
						my_form.keido.id.value = point.x;
					}
				}
			);
	}
	var error=0;
	input_value = the_input.value;
	input_class = the_input.className.split(' ');
	input_required = input_class[1];
	input_type = input_class[2];
	input_error_id = input_class[3];
	if(input_error_id=="password2_msg" && document.getElementById("password")){
		if(the_input.value!=document.getElementById("password").value) {
			reply_text = "パスワードが一致していません";
			document.getElementById(input_error_id).innerHTML = "";
			document.getElementById(input_error_id).innerHTML = reply_text;
			//document.getElementById(input_error_id).appendChild(document.createTextNode(reply_text));
			error=1;
			//alert(the_input.value+document.getElementById("password").value);
		} else {
			document.getElementById(input_error_id).innerHTML = "";
		}
	}
	if(error!=1) {
		make_request(input_value, input_required, input_type, input_error_id);
	}
}

function make_request(input_value, input_required, input_type, input_error_id) {
	var http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('XMLHTTPインスタンスを作成出来なかった為、AJAXを諦めます。');
		return false;
	}
	http_request.onreadystatechange = function() {
		handle_validation_response(http_request, input_required, input_type, input_error_id);
	};
	//alert(input_error_id);
	if (input_error_id =="jusho") {
		//url = "/?action=get_jusho_by_yuubin&input_value=";
		url = "/rmap/?action=get_jusho_by_yuubin&input_value=";
	}else if (input_error_id =="idokeido") {
		url = "/rmap/?action=get_idokeido_by_jusho&input_value=";
	}else{
		//郵便番号以外のバリデーションは行わない
		//url = "/?action=validate_ajax&input_value=";
		return false;
	}
	url = encodeURI(url+input_value+"&input_required="+input_required+"&input_type="+input_type+"&input_error_id="+input_error_id);
	//my_form.idokeido_msg.id.innerHTML = encodeURI(url);
	//alert(url);
	//if (input_error_id == 'idokeido') alert(url);
	http_request.open('GET', url, true);
	http_request.send(null);
}

function handle_validation_response(http_request, input_required, input_type, input_error_id) {
	if (http_request.readyState == 4) {
		//alert("handle_validation_response");
		if (http_request.status == 200) {
			var response_hairetsu = http_request.responseText.split("|");
			var reply = response_hairetsu[1];
			var reply_text = "";
			//my_form.idokeido_msg.id.innerHTML = "input_error_id:"+input_error_id+" | "+response_hairetsu[1]+" | "+response_hairetsu[2];
			//my_form.idokeido_msg.id.innerHTML = "input_error_id:"+input_error_id+" | http_request.responseText="+http_request.responseText;
			//alert("input_error_id:"+input_error_id+" | http_request.responseText="+http_request.responseText);
			if (input_error_id =="jusho") {
				if(typeof response_hairetsu[1] =="undefined") { response_hairetsu[1] = ""; }
				if(typeof response_hairetsu[2] =="undefined") { response_hairetsu[2] = ""; }
				if(typeof response_hairetsu[3] =="undefined") { response_hairetsu[3] = ""; }
				//alert(http_request.responseText);
				my_form.todofuken.id.value = response_hairetsu[1];
				my_form.shikuchoson.id.value = response_hairetsu[2];
				my_form.ooazamachichome.id.value = response_hairetsu[3];
				var gaikufugochiban = my_form.gaikufugochiban.id.value;
				//my_form.jusho.value = response_hairetsu[1]+response_hairetsu[2]+response_hairetsu[3]+gaikufugochiban;
			} else if (input_error_id =="idokeido" && typeof response_hairetsu[1] != "undefined" && typeof response_hairetsu[2] != "undefined") {
					//alert(response_hairetsu[1]+" "+response_hairetsu[2]);
					//alert(http_request.responseText);
					my_form.ido.id.value = response_hairetsu[1];
					my_form.keido.id.value = response_hairetsu[2];
					
					if (map1) {
						var point_backup = new GLatLng(response_hairetsu[1], response_hairetsu[2]);
						map1.center_map(point_backup);
						map1.set_hardcenter(point_backup);
					}
			}else{
				if(document.getElementById(input_error_id)) {
					
					document.getElementById(input_error_id).innerHTML = "";
					switch(reply) {
					case "ok":
						reply_text = "確認済み";
						break;
					case "required":
						reply_text = "必須";
						break;
					case "7figures":
						reply_text = "半角７桁をハイフン無しで入力下さい";
						break;
					case "badmail":
						reply_text = "入力されたメールアドレスを再確認下さい";
						break;
					case "badphone":
						reply_text = "半角の数字とハイフンのみでご入力下さい";
						break;
					case "badnumber":
						reply_text = "半角数字とドット一つでご入力下さい";
						break;
					case "not_int":
						reply_text = "半角数字でご入力下さい";
						break;
					case "headtail0-9a-zA-Z":
						reply_text = "頭と尻は半角英数か数字にして下さい";
						break;
					case "2symbol":
						reply_text = "連続記号はご入力しないで下さい";
						break;
					case "^a-zA-Z":
						reply_text = "頭は半角英数にして下さい";
						break;
					case "0-9a-zA-Z-_":
						reply_text = "半角英数、数字、「_-」記号でご入力下さい";
						break;
					case "2-64":
						reply_text = "半角２〜６４文字でご入力下さい";
						break;
					case "6-64":
						reply_text = "半角６〜６４文字でご入力下さい";
						break;
					case "10-16":
						reply_text = "半角１０〜１６文字でご入力下さい";
						break;
					case "no_http":
						reply_text = "「http://」からURLをご入力下さい";
						break;
					case "bad_url":
						reply_text = "正しいURLをご入力下さい";
						break;
					case "kanjichoume":
						reply_text = "◯丁目は漢字でご入力下さい";
						break;
					default:
						reply_text = reply;
					}
					//document.getElementById(input_error_id).appendChild(document.createTextNode(reply_text));
					document.getElementById(input_error_id).innerHTML = reply_text;
				}
			}
		//} else {
		//	alert('AJAXリクエストで問題がありました。');
		}
	}
}

function show_embed_video(embed_div) {
	if (document.getElementById("video_url")) {
		//var video_url="http://www.unitedrooms.tv/0078/0078_000001_8100022.wmv";
		var video_url=document.getElementById("video_url").innerHTML;
	}
	object = '<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" width="320" height="280" ';
	object += 'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ';
	object += 'id="WinMediPlay" type="application/x-oleobject">';
	object += '<param name="src" value="' + video_url + '" />';
	object += '<param name="autoStart" value="false" />';
	object += '<param name="showControls" value="true" />';
	object += '<embed type="video/x-ms-asf-plugin" ';
	object += 'pluginspace="http://www.microsoft.com/windows95/downloads/contents/wurecommended/s_wufeatured/mediaplayer/default.asp" ';
	object += 'src="' + video_url + '" name="mediaplayer" showcontrols=2 showdisplay=0 showstatusbar=0 autostart=0 width="320" height="280"></embed>';
	object += '</object>';
	embed_div.innerHTML = object;
	embed_div.onclick = function(){ 
		return;
	};
}

function start_slideshow() {
	this.id_current = 0;
	//this.slideshow_width = 320;
	this.slideshow_width = 240;
	//this.slideshow_height = 280;
	this.slideshow_height = 200;
	this.slideshow_delay = 5000;
	this.pictures = new Array();
	if (document.getElementById("slideshow_urls")) {
		this.slideshow_urls=document.getElementById("slideshow_urls").innerHTML.split("|");
		this.slideshow_urls.pop();
	}
	this.movie_div = document.getElementById("slideshow");
	if (this.slideshow_urls.length > 0) {
		//this.movie_div.innerHTML = '<div style="width:320px; height:280px; background-color:#000;" align="center"><img src="" alt="スライドショー" id="imageDiaporama" /></div>';
		//this.movie_div.innerHTML = '<div style="width:320px; height:280px; background-color:#000;" align="center"><table width="320" height="280" cellpadding="0" cellspacing="0" bgcolor="#000000"><tr><th><img src="" alt="スライドショー" id="imageDiaporama" /></th></tr></table></div>';
		this.movie_div.innerHTML = '<div style="width:240px; height:200px; background-color:#000;" align="center"><table width="240" height="200" cellpadding="0" cellspacing="0" bgcolor="#000000"><tr><th><img src="" alt="スライドショー" id="imageDiaporama" /></th></tr></table></div>';
	}
	for (counter=0; counter<this.slideshow_urls.length; counter+=1) {
		this.pictures.push(new Image());
	}
	for (counter=0; counter<this.slideshow_urls.length; counter+=1) {
		this.pictures[counter].src = "http://rmap-n.com/rmap/pictures/" + this.slideshow_urls[counter];
	}
	/*
	if (this.pictures.length > 1) {
		this.pictures.push(new Image());
		this.pictures[this.pictures.length-1].src = "http://rmap-n.com/rmap/images/no_movie.jpg";
	}
	*/
	this.next_slide = function() {
		var img = $('imageDiaporama');
		img.src = this.pictures[this.id_current].src;
		Element.hide('imageDiaporama');
		img.src = this.pictures[this.id_current].src;
		new Effect.Appear('imageDiaporama');
		//alert("antes: "+img.width+"x"+img.height);
		if (this.pictures[this.id_current].width / this.pictures[this.id_current].height >= this.slideshow_width / this.slideshow_height) {
			img.width = slideshow_width;
			img.height = this.pictures[this.id_current].height * (this.slideshow_width / this.pictures[this.id_current].width);
		} else {
			img.height = slideshow_height;
			img.width = this.pictures[this.id_current].width * (this.slideshow_height / this.pictures[this.id_current].height);
		}
		//alert("después: "+img.width+"x"+img.height);
		if (this.pictures.length > 1) {
			window.setTimeout("this.next_slide()",this.slideshow_delay);
		}
		if (this.id_current < (this.pictures.length-1)) this.id_current++;
		else this.id_current = 0;
	};

	if (this.pictures.length > 0) {
		this.next_slide();
	}
}

function minimap() {
	//get data from xhtml
	var map_ido = new Array();
	var map_keido = new Array();
	var map_mode = "";
	if (document.getElementById("map_mode")) {
		map_mode=document.getElementById("map_mode").innerHTML;
	}
	if (document.getElementById("map_ido")) {
		map_ido=document.getElementById("map_ido").innerHTML.split("|");
		if (map_mode == "search") { map_ido.pop(); }
	}
	if (document.getElementById("map_keido")) {
		map_keido=document.getElementById("map_keido").innerHTML.split("|");
		if (map_mode == "search") { map_keido.pop(); }
	}
	//create map
	if (GBrowserIsCompatible() && map_ido && map_keido && map_mode) {
		map1 = new google_map(map_ido[0], map_keido[0], map_mode);
		//add map_mode == "view" 06/10/30 sugi
		if (map_mode == "search" || map_mode == "home" || map_mode == "view") {
			map1.get_results_data();
		}
		for (var i = 0; i < map_ido.length; i+=1) {
			var point = new GLatLng(map_ido[i],map_keido[i]);
			map1.add_marker(point,i);
		}
		//if (map_mode == "search" || map_mode == "search_map") {
		if (map_mode == "search") {
			map1.autozoom();
			map1.tabbed_info();
			
			//右下のインデックスマップ表示
			map1.index_map(130,120);
			
			//ピン説明
			this.pin_about = document.getElementById('pin_about');
			var d = document.createElement('div');
			//IEの場合
			if(d && d.runtimeStyle){
				var tag = '<img src="http://rmap-n.com/rmap/images/spacer.gif" width="1" height="1" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://rmap-n.com/rmap/images/gs_pin_green.png,sizingmethod=image);" />';
				tag += '：1R,1K,1DK,1LDK　';
				tag += '<img src="http://rmap-n.com/rmap/images/spacer.gif" width="1" height="1" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://rmap-n.com/rmap/images/gs_pin_blue.png,sizingmethod=image);" />';
				tag += '：2K,2DK,2LDK　';
				tag += '<img src="http://rmap-n.com/rmap/images/spacer.gif" width="1" height="1" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://rmap-n.com/rmap/images/gs_pin_orange.png,sizingmethod=image);" />';
				tag += '：3K,3DK,3LDK　';
				tag += '<img src="http://rmap-n.com/rmap/images/spacer.gif" width="1" height="1" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://rmap-n.com/rmap/images/gs_pin_red.png,sizingmethod=image);" />';
				tag += '：4K～';
				this.pin_about.innerHTML = tag;
			//それ以外
			}else{
				var tag = '<img src="http://rmap-n.com/rmap/images/gs_pin_green.png" />';
				tag += '：1R,1K,1DK,1LDK　';
				tag += '<img src="http://rmap-n.com/rmap/images/gs_pin_blue.png" />';
				tag += '：2K,2DK,2LDK　';
				tag += '<img src="http://rmap-n.com/rmap/images/gs_pin_orange.png" />';
				tag += '：3K,3DK,3LDK　';
				tag += '<img src="http://rmap-n.com/rmap/images/gs_pin_red.png" />';
				tag += '：4K～';
				this.pin_about.innerHTML = tag;
			}
		}
		if (map_mode == "edit") {
			map1.attach_click(map1.markers[0], 0);
			var marker = map1.markers[0];
		}
	}
	//validate form
	if(document.getElementById("form1")) {
		my_form = new form();
		if (my_form.input_fields.length>0) {
			my_form.attach_events();
		}
	}
	if(document.getElementById("embed_video")) {
		document.getElementById("embed_video").style.cursor = 'pointer';
		document.getElementById("embed_video").onclick = function(){ 
			return show_embed_video(this);
		};
	} else if (document.getElementById("movie") && document.getElementById("slideshow_urls")) {
		start_slideshow();
	}

	divs = document.getElementsByTagName('div');
	if (divs) {
		results = new Array();
		for (i=0; i<divs.length; i=i+1) {
			//if (divs[i].className == 'results') {
			if (divs[i].className == 'clickable_list_item') {
				results.push(divs[i]);
			}
		}
		for (i=0; i<results.length; i=i+1) {
			map1.attach_click_to_result(results[i], i);
		}
	}

}

window.onload = function() {
	minimap();
};
