function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var move = 1;
function scroll() {
if(navigator.appName == "Microsoft Internet Explorer" && document.compatMode == "CSS1Compat") {
var height = document.body.parentNode.scrollTop;
} else {
var height = document.body.scrollTop;
}
if(move<30 && height) {
height = (height>2) ? Math.ceil(height*.2) : 1;
move++;
scrollBy(0,-height);
setTimeout("scroll()",20);
} else {
scrollTo(0,0);
move = 1;
}
}

function clickHeaderTab(sName){
    var frm = document.headerfrm;
    switch(sName){
        case "keyword":
            //frm.action = "/search/stock/stock_list.php";
            break;
        case "top":
            frm.action = "/index.php";
    		frm.target="_self";
            break;
        case "search":
            frm.action = "/search/stock/stock_list.php";
    		frm.target="_self";
            break;
        default:
            break;
    }
    frm.submit();
}

function clickFooterTab(sName){
    var frm=document.footerfrm;
    switch(sName){
        case "keyword":
            //frm.action = "/search/stock/stock_list.php";
            break;
        case "top":
            frm.action = "/index.php";
            frm.target="_self";
            break;
        case "search":
            frm.action = "/search/stock/stock_list.php";
            frm.target="_self";
            break;
        default:
            break;
    }
    frm.submit();
}

function closeMe(){
    window.close();
}

// 画像高さ取得
function getHeightPx (img_src, pic_num) {

    var height_do = new AjaxAction();
    height_do.url = "/search/detail/getHeightPx.php";

	// ２バイト文字をパラメータに渡す場合は encode を行う！
    height_do.params = {"img_src" : img_src,
                        "pic_num" : pic_num
                 };

    // イベント処理をオーバーライドする
    // Ajax通信が終わった際にコールされます
    height_do.doAction = function(res) {
		//alert(document.getElementById('search_detail_room_03_02_img_99').style.marginTop);
		//alert(res);
		document.getElementById('search_detail_room_03_02_img_99').style.marginTop = res + 'px';
	//	alert(document.getElementById('search_detail_room_03_02_img_99').style.marginTop);
    };

    execAjax(height_do);
}

/**
 *物件サブ画像切替
 */
function photo_change_detail(sub_num, id,img_src,pic_num) {

    var frm = document.frm;
    // IMG
    var img_item = "";
    var img_obj = "";
    var sub_src = ""
    var main_src = frm.l_photo_0.value;

    var sub_main_src = frm.s_photo_0.value;
	
	var comment = "";

	// 画像
    for (var i = 0; i <= sub_num ; i++) {
        img_item = "img" + i;
        img_obj = "l_photo_" + i;
        sub_src = document.getElementById(img_obj);

        img_obj_s = "s_photo_" + i;
        sub_src_s = document.getElementById(img_obj_s);

        if (id == i) {  // 画像を入れ替わる
            if (document.getElementById(img_item).src != sub_main_src && document.getElementById(img_item).src != main_src) {
                // IMG
                img0_obj = document.getElementById('img0');
                img0_obj.src = sub_src.value;
            } else {
                // IMG
                document.getElementById(img_item).src = sub_src_s.value;
            }
        }
    }

	getHeightPx(img_src, pic_num);
	
	// コメント
	if (id == 0) {
		comment = frm.exterior_image_name.value;
	}
	if (id == 1) {
		comment = frm.living_image_name.value;
	}
	if (id == 2) {
		comment = frm.bathroom_image_name.value;
	}
	if (id == 3) {
		comment = frm.balcony_image_name.value;
	}
	if (id == 4) {
		comment = frm.bedroom_image_name.value;
	}
	if (id == 5) {
		comment = frm.kitchen_image_name.value;
	}
	if (id == 6) {
		comment = frm.entrance_image_name.value;
	}
	if (id == 7) {
		comment = frm.other1_image_name.value;
	}
	if (id == 8) {
		comment = frm.other2_image_name.value;
	}
	if (id == 9) {
		comment = frm.other3_image_name.value;
	}
	if (id == 10) {
		comment = frm.other4_image_name.value;
	}
	if (id == 11) {
		comment = frm.other5_image_name.value;
	}
	if (id == 12) {
		comment = frm.other6_image_name.value;
	}
	if (id == 19) {
		comment = frm.plan_image_name.value;
	}

	document.getElementById('sub_comment_0').innerHTML = comment;
}

function Print() {
    window.print();
}


/* 
 * クッキー保存
 * setCookie(クッキー名, クッキーの値, クッキーの有効日数);
*/
/*
function setCookie(c_name,value,expiredays){
    // 有効期限の日付
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    // クッキーに保存する文字列を生成
    var s="";
    s+=c_name+"="+escape(value);
    //s+=(expiredays==null)?"":";path=/search;expires="+exdate ;

    s+=(expiredays==null)?"":";expires="+exdate ;

    // クッキーに保存
    document.cookie=s;
}
*/

function setCookie(c_name,value,exdays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : ";path=/; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

/* 保存されているクッキーから、指定したクッキー名の値を取得
 * getCookie(クッキー名)
*/
function getCookie(c_name){
    var st="";
    var ed="";
    if (document.cookie.length>0){
        st=document.cookie.indexOf(c_name + "=");
        if (st!=-1){ 
            st=st+c_name.length+1;
            ed=document.cookie.indexOf(";",st);
            if (ed==-1) ed=document.cookie.length;
            return unescape(document.cookie.substring(st,ed));
        } 
    }
    return "";
}

function trim(_str) {
	var length = 0;
	do {
		length = _str.length;
		// 先頭、末尾の半角空白文字の削除
		_str = _str.replace(/^[ ]+|[ ]+$/g, '');
		// 先頭、末尾の全角空白文字の削除
		_str = _str.replace(/^[　]+|[　]+$/g, '');
		// 先頭、末尾の改行コードの削除
		_str = _str.replace(/^[\r\n]+|[\r\n]+$/g, '');
	} while (length!=_str.length)
 
	return _str;
}

