var post_addr = {
	current_id: "",
	addr1: "",
	select_aid: 0,
	top: 0,
	left: 0,
	iframe_src: "/_resource/ifrm.html",
	init: function(id){
		if($(id)){
			Event.observe($(id), "click", post_addr.get, false);
		}
		if(!$("post_addr01") && !$("post_addr01_ifrm")){
			d = document.createElement("div");
			d.setAttribute("id", "post_addr01");
			document.body.appendChild(d);
			
			d = document.createElement("iframe");
			d.setAttribute("id", "post_addr01_ifrm");
			d.setAttribute("src", post_addr.iframe_src);
			document.body.appendChild(d);
			$("post_addr01_ifrm").setStyle({
				opacity: "0.0"
			});
		}
	},
	get: function(e){
		post_addr.current_id = Event.element(e).id
		post_addr.top = Event.pointerY(e);
		post_addr.left = Event.pointerX(e);
		if($($(post_addr.current_id+"_0").value)){
			post_data = "postnum="+encodeURI($($(post_addr.current_id+"_0").value).value);
		}else{
			alert("郵便番号が取得できません。");
		}
		if ($("post_addr01") && $("post_addr01_ifrm")) {
			new Ajax.Request("/_resource/postaddr.php", {
				method: "POST",
				requestHeaders: ["Content-Type", "application/x-www-form-urlencoded charset=UTF-8", "If-Modified-Since", "Mon, 21 Nov 2006 00:00:00 GMT"],
				parameters: post_data,
				onSuccess: function(httpObj){
					$("post_addr01").innerHTML = httpObj.responseText;
					$("post_addr01").setStyle({
						top: post_addr.top+"px",
						left: post_addr.left+"px",
						display: "block"
					});
					$("post_addr01_ifrm").setStyle({
						top: post_addr.top+"px",
						left: post_addr.left+"px",
						display: "block"
					});
				},
				onFailure: function(httpObj){
					alert("住所が取得できませんでした。");
				}
			});
		}
	},
	addr_in: function(){
		psid = $("postaddr_select").options[$("postaddr_select").selectedIndex].value;
		this.addr1 = $(this.current_id+"_1").value;
		this.select_aid = $("postaddr_select_1_"+psid).value;
		select_count2 = 0;
		for(i = 0; i < $(this.addr1).childNodes.length; i++){
			if($(this.addr1).childNodes[i].nodeName == "OPTION"){
				if($(this.addr1).childNodes[i].value == this.select_aid){
					$(this.addr1).selectedIndex = select_count2;
					break;
				}
				select_count2++;
			}
		}
		$($(this.current_id+"_2").value).value = $("postaddr_select_2_"+psid).value;
		this.close();
	},
	close: function(){
		$("post_addr01").setStyle({
			display: "none"
		});
		$("post_addr01_ifrm").setStyle({
			display: "none"
		});
	}
};