function bind_print() {
    $("a#print_").bind(
        "click",
         function() {
            var url = $(this).attr("href");
            window.open(url);
            return false; 
        } 
    );
}

function bind_map() {
    $("a.map_").bind(
        "click",
        function() {
            var url = $(this).attr("href");
            window.open(url, null, "height=508, width=570, top=126, left=142");
            return false; 
        } 
    );
}

function bind_add_scrap() {
    $("a.add_scrap").bind(
        "click",
        function() {
            //var r = confirm("この物件を検討中リストに追加します");
            //if (r == true) {
            //    window.open($(this).attr("href"), null);
            //}
            //return false;
            var url = $(this).attr("href"); 
            $.ajax({
                type: "GET",
                url: url, 
                dataType: "text",
                success: function(data, dataType){
                    if (data == "1") {
                        alert("検討中リストに登録しました");
                    } else {
                        alert("エラー: 検討中リストへの追加に失敗しました");
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    alert("エラー: 検討中リストへの追加に失敗しました");
                }
            });
            return false;
        } 
    );
    $("a.add_scrap_all").bind(
        "click",
        function() {
            // var form = $(this).parent('form');
            var codes = $("input:checked[name='code']");
            if (codes.length == 0) {
                alert("物件を1つ以上チェックしてください。");
                return false; 
            }

            var params = {
                code: $.map(codes, function(node, i) { return $(node).val() })
            };

            var url = $(this).attr("href");
            $.ajax({
                type: "POST",
                url: url, 
                data: params,
                dataType: "text",
                success: function(data, dataType){
                    if (data == "1") {
                        alert("検討中リストに登録しました");
                    } else {
                        alert("エラー: 検討中リストへの追加に失敗しました");
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    alert("エラー: 検討中リストへの追加に失敗しました");
                }
            });
            return false;
        } 
    );
}

function bind_delete_scrap() {
    $("a.delete_scrap").bind(
        "click",
        function() {
            return confirm("この物件を検討中リストから削除します");
        } 
    );
}

function bind_contact_all() {
    $("#contact_all").bind(
        "submit",
        function() {
            if ($("input:checked[name='code']").length > 10) {
                alert("物件が11件以上チェックされています。まとめてお問合せできるのは10件までです。");
                return false; 
            } else if ($("input:checked[name='code']").length == 0) {
                alert("物件を1つ以上チェックしてください。");
                return false; 
            }
        }
    );
}

function bind_search(form){
    form.bind(
        "submit",
        function() {
            var rent_min = $(":input[name='rent_min'] > option:selected").attr("value");
            var rent_max = $(":input[name='rent_max'] > option:selected").attr("value");
            var footprint_min = $(":input[name='footprint_min'] > option:selected").attr("value");
            var footprint_max = $(":input[name='footprint_max'] > option:selected").attr("value");

            if (rent_min == "") { rent_min = null; }
            if (rent_max == "") { rent_max = null; }
            if (footprint_min == "") { footprint_min = null; }
            if (footprint_max == "") { footprint_max = null; }

            if (rent_min != null) { rent_min = parseInt(rent_min); }
            if (rent_max != null) { rent_max = parseInt(rent_max); }
            if (footprint_min != null) { footprint_min = parseInt(footprint_min); }
            if (footprint_max != null) { footprint_max = parseInt(footprint_max); }

            msg = new Array;
            if (rent_min != null && rent_max != null && rent_min > rent_max) {
              msg.push("賃料の設定を変更してください");
            }
            if (footprint_min != null && footprint_max != null && footprint_min > footprint_max) {
              msg.push("占有面積の設定を変更してください");
            }
            if (msg.length > 0) {
              alert(msg.join("\n"));
              return false;
            }
        }   
    );
}


function bind_panorama() {
    $("#panorama_").bind(
        "click",
        function() {
            var url = $(this).attr("href");
            window.open(url, null, 'width=780, height=580, screenX=10, screenY=10, left=10, top=10, menubar=no, location=no, toolbar=no, scrollbars=no, status=no, directories=no, resizable=no');
            return false;
        }
    );
}

function bind_send_url_link(){
	hs.graphicsDir = '/js/highslide/graphics/';
//	hs.transitions = [];
	hs.expandDuration = 10;
	hs.restoreDuration = 10;
	hs.align = 'left';
	$('a#send_url_link').each(function() { 
		this.onclick = function(){
			var frame_contents = $('iframe:first').contents();
			if(frame_contents.get(0) && frame_contents.find('a#close').length > 0){
				frame_contents.get(0).location = $('a#send_url_link').attr('href');
			}
			return hs.htmlExpand(this, {
				contentId: 'send_url_content',
				objectType: 'iframe',
				outlineType: null,
				dimmingOpacity: 0.75,
				targetY: 'content-inner',
				targetX: 'content-inner 100px'
			});
		};
	});
	$('a#send_url_close').each(function(){
		this.onclick = function(){
			return hs.close(this);
		};
	});
}


