// ブラウザ依存解消の為のID取得関数
function get_Browser(id){
if (document.getElementById) return document.getElementById(id);
else if (document.all) return document.all[id];
else if (document.layers) return document[id];
}

// 小窓を開く
var subWin;
function popWin(url,width,height){
	subWin = window.open(url,'win','width=100,height=100,status=no,menubar=no,directories=no,location=no,toolbar=no,resizable=yes,scrollbars=no');

	subWin.resizeTo( width , height ) ;
	
	subWin.moveTo( 100 , 200 );
	subWin.focus();
}

/*
 * フォームのaction切り替え
 * buttonのonclickイベントに設置
 * @param elem : フォームのオブジェクト（this.form）
 * @param url : 送信先のurl
 */
function chgAct(elem, url){
	
	elem.action = url;
	elem.submit();
}

/*
 * selectmenu で年月日の連動(年)
 * get_Browser必須
 * フォーム内、selectのonchangeイベントに設置
 * @param string year : 変更基準となるフォームのID（年）
 * @param string month : 変更するフォームのID（月）
 * @param string day : 変更するフォームのID（日）
 */
function selectYear( year, month, day ) {
	// 現在時刻を取得
	myD       = new Date();
	myYear    = myD.getYear();
	myYear4   = (myYear < 2000) ? myYear+1900 : myYear;
	myMonth   = myD.getMonth() + 1;
	//myDate    = myD.getDate();

	objY = get_Browser(year);
	objM = get_Browser(month);
	
	for(i=objM.options.length;i>0;i--){
		objM.options[i] = null;
	}
	
	n = objY[objY.selectedIndex].value;
	if(n==myYear4){
		// 選択年と当年が同じだったら、終了月は当月
		var endMonth = myMonth;
	} else {
		// それ以外は12月まで
		var endMonth = 12;
	}
	if(n=='2007'){
		// 2007年が選択されていたら、開始月は4月
		var srtMonth = 4;
	} else {
		// それ以外は1月
		var srtMonth = 1;
	}
	// プルダウンの中身をセット
	for (i=0; i<=(endMonth-srtMonth); i++){
		objM.options[i] = new Option((i+srtMonth),(i+srtMonth));
	}
	
	selectMonth(year, month, day);
}

/*
 * selectmenu で年月日の連動(月)
 * get_Browser必須
 * フォーム内、selectのonchangeイベントに設置
 * @param string year : 変更基準となるフォームのID（年）
 * @param string month : 変更するフォームのID（月）
 * @param string day : 変更するフォームのID（日）
 */
/*
function selectMonth( year, month, day ) {
	// 現在時刻を取得
	myD       = new Date();
	myYear    = myD.getYear();
	myYear4   = (myYear < 2000) ? myYear+1900 : myYear;
	myMonth   = myD.getMonth() + 1;
	myDate    = myD.getDate();

	objY = get_Browser(year);
	objM = get_Browser(month);
	obj = get_Browser(day);
	if(objY.value % 4 == 0){
	    monthday = [ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
	} else {
	    monthday = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
	}
	// 初期化
	for(i=obj.options.length;i>0;i--){
		obj.options[i] = null;
	}
	n = objM[objM.selectedIndex].value;
	if(objY.value == myYear4 && n == myMonth){
		// 当年当月が選択されていたら、当日まで
		var endDay = myDate;
	} else {
		// それ以外は該当月の最終日まで
		var endDay = monthday[n-1];
	}
	var srtDay = 1;
	
	// プルダウンの中身をセット
	for (i=0; i<=(endDay-srtDay); i++)
	{
		obj.options[i] = new Option((i+srtDay),(i+srtDay));
	}
}
*/

/**
 * テキストのバイト数を取得
 * @param string text 文字列
 * @return int count  文字列のバイト数
 */
function getByte(text)
{
	count = 0;
	for (i=0; i<text.length; i++)
	{
		n = escape(text.charAt(i));
		if (n.length < 4) count++; else count+=2;
	}
	return count;
}



/**
 * flash 表示用関数
 * @param array arg	uri等パラメータ
 * 'url','_width=','_height=',"_flashvars="
 */
function flash_write( arg )
{
	var parm = []
	for( i = 0 ; i < arguments.length ; i++ ){
		parm[i] = arguments[i].split(' ').join('').split('=')
		
		switch (parm[i][0]) {
			case '_swf'     : var _swf     = parm[i][1] ; break ;
			case '_quality' : var _quality = parm[i][1] ; break ;
			case '_loop'    : var _loop    = parm[i][1] ; break ;
			case '_bgcolor' : var _bgcolor = parm[i][1] ; break ;
			case '_wmode'   : var _wmode   = parm[i][1] ; break ;
			case '_play'    : var _play    = parm[i][1] ; break ;
			case '_menu'    : var _menu    = parm[i][1] ; break ;
			case '_scale'   : var _scale   = parm[i][1] ; break ;
			case '_salign'  : var _salign  = parm[i][1] ; break ;
			case '_height'  : var _height  = parm[i][1] ; break ;
			case '_width'   : var _width   = parm[i][1] ; break ;
			case '_hspace'  : var _hspace  = parm[i][1] ; break ;
			case '_vspace'  : var _vspace  = parm[i][1] ; break ;
			case '_align'   : var _align   = parm[i][1] ; break ;
			case '_class'   : var _class   = parm[i][1] ; break ;
			case '_id'      : var _id      = parm[i][1] ; break ;
			case '_name'    : var _name    = parm[i][1] ; break ;
			case '_style'   : var _style   = parm[i][1] ; break ;
			case '_declare' : var _declare = parm[i][1] ; break ;
			default        :;
		}
	}
	var htm = ""
	
	htm+="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='" + _width + "' height='" + _height + "'>"

	if(!!_swf)     htm+="<param  name     = 'movie'   value ='" + _swf     + "'>"
	if(!!_quality) htm+="<param  name     = 'quality' value ='" + _quality + "'>"
	if(!!_loop)    htm+="<param  name     = 'loop'    value ='" + _loop    + "'>"
	if(!!_bgcolor) htm+="<param  name     = 'bgcolor' value ='" + _bgcolor + "'>"
	if(!!_play)    htm+="<param  name     = 'play'    value ='" + _play    + "'>"
	if(!!_menu)    htm+="<param  name     = 'menu'    value ='" + _menu    + "'>"
	if(!!_scale)   htm+="<param  name     = 'scale'   value ='" + _scale   + "'>"
	if(!!_salign)  htm+="<param  name     = 'salign'  value ='" + _salign  + "'>"
	if(!!_wmode)   htm+="<param  name     = 'wmode'   value ='" + _wmode   + "'>"
	htm+=""
	htm+="<embed                          "
	htm+="        pluginspage='https://www.macromedia.com/go/getflashplayer'"
	if(!!_width)   htm+="        width    = '" + _width   + "'"
	if(!!_height)  htm+="        height   = '" + _height  + "'"
	if(!!_hspace)  htm+="        hspace   = '" + _hspace  + "'"
	if(!!_vspace)  htm+="        vspace   = '" + _vspace  + "'"
	if(!!_align)   htm+="        align    = '" + _align   + "'"
	
	if(!!_class)   htm+="        class    = '" + _class   + "'"
	if(!!_id)      htm+="        id       = '" + _id      + "'"
	if(!!_name)    htm+="        name     = '" + _name    + "'"
	if(!!_style)   htm+="        style    = '" + _style   + "'"
	htm+="        type     = 'application/x-shockwave-flash' "
	if(!!_declare) htm+="                    " + _declare  
	if(!!_swf)     htm+="        src      = '" + _swf     + "'"
	if(!!_quality) htm+="        quality  = '" + _quality + "'"
	if(!!_loop)    htm+="        loop     = '" + _loop    + "'"
	if(!!_bgcolor) htm+="        bgcolor  = '" + _bgcolor + "'"
	if(!!_play)    htm+="        play     = '" + _play    + "'"
	if(!!_menu)    htm+="        menu     = '" + _menu    + "'"
	if(!!_scale)   htm+="        scale    = '" + _scale   + "'"
	if(!!_salign)  htm+="        salign   = '" + _salign  + "'"
	htm+="></embed>"
	htm+="</object>"

	document.write(htm);
}

/* 一行フォームでエンターキーでの送信を禁止する
 * BlockEnter必須
 * htmlタグ中に<script>attachBlockEnter('formid');</script> と記載
 * formid にはフォームのidを入れる
 */
function attachBlockEnter(formid) {
	var elements = document.forms[formid].elements;
	for (var j=0; j < elements.length; j++) {
		var e = elements[j];	
		if (e.type == "text"){
			e.onkeypress=BlockEnter;
		}
	}
}
function BlockEnter(evt){
	evt = (evt) ? evt : event; 
	var charCode=(evt.charCode) ? evt.charCode : 
		((evt.which) ? evt.which : evt.keyCode);
	if ( Number(charCode) == 13 || Number(charCode) == 3) {
		return false;
	} else {
		return true;
	}
}


/**
 *javascript動的読み込み２
 * 出典元（http://sagittarius.dip.jp/~toshi/Ajax/yui.html）
 */
function load( url ) {
	try {
		xhr = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			xhr = false;
		}
	}
	if (!xhr && typeof XMLHttpRequest!='undefined') {
		xhr = new XMLHttpRequest();
	}
	i = 0;
	var str = "";
	if (xhr) {
		if(CheckBrowser() == true){
			// IEでは onload はない
			xhr.onload = function(){
				if (xhr.readyState == 4 && xhr.status == 200) {
					str = xhr.responseText;
				}
			}
		} else {
			// FireFoxでは onreadystatechange が入ってこない
			xhr.onreadystatechange = function() {
				if (xhr.readyState == 4 && xhr.status == 200) {
					str = xhr.responseText;
				}
			}
		}
		
		//HTTPリクエストを送ったりするとこここから 
		//xhr.open('GET', url);
		xhr.open('GET', url, false);
		xhr.send(null);
	}
	return str;
}
/**
 * onlaodをサポートしているブラウザならtrue
 */
function CheckBrowser(){
	var ua = navigator.userAgent
	var safari    = ua.indexOf("Safari")!=-1
	var konqueror = ua.indexOf("Konqueror")!=-1
	var mozes     = ((a=navigator.userAgent.split("Gecko/")[1] )?a.split(" ")[0]:0) >= 20011128 
	
	if(window.opera || safari || konqueror || mozes){
		return true;
	} else {
		return false;
	}
}


// ------------------------------------------------------------------

jQuery.noConflict();
var $j = jQuery;

$j(document).ready(function() {
	/**
	 * for QA
	 */
	$j("div.tabContainer dd").css("display","none");
	$j("div.tabContainer dt").click(function(){
		$j(this).next().slideToggle("fast");
		});
	
	// MAC SafariとFireFoxの表示調整
	var os, ua = navigator.userAgent;
	if (ua.match(/Mac|PPC/)) {
		// Macintosh の処理
		$j("*").each(function(){
			var size = $j(this).css("font-size");
			size = size.replace("px", "");
			var IntSize = parseInt(size, 10);
			if(IntSize >= 12){
				IntSize = IntSize-2;
				$j(this).css("font-size", IntSize+"px");
			} else {
				//$j(this).css("font-size", "10px");
			}
			return;
		});
	}
	
	// 別窓で開くスクリプト
	$j(".popWin").click(function(){
		var Popurl = $j(this).attr('href');
		window.open(Popurl);
		return false;
	});
	
	// 別窓で開くスクリプト 2010.06.22 add for tenant
	$j(".popWin2").click(function(){
		var w = $j(this).attr('width');
		var h = $j(this).attr('height');
		if(w == undefined) w = 400;
		if(h == undefined) h = 400;
		var Popurl = $j(this).attr('href');
		window.open(Popurl,null,'width='+w+',height='+h+',status=no,menubar=no,directories=no,location=no,toolbar=no,resizable=yes,scrollbars=no');
		return false;
	});
	
	// 2010.06.17 お問い合わせに飛ばす
	$j(".GoContact").click(function(){
		var Popurl = $j(this).attr('href');
		nowPage = location.href;
		// ページ内リンクは削除
		var LocateUrl = nowPage.split("#");
		sslPage = LocateUrl[0].replace("http://", "https://");
		location.href = sslPage+"../../"+Popurl;
		return false;
	});
	
});


/**
 * for hikaku
 */
function changeTab( ele ) {
	
	var area_name = $j( ele ).html();
	
	// change tab
	$j( ".tab_list" ).children(".on").removeClass("on");
	$j( ele ).parent().addClass("on");
	
	// change table
	var area = $j( ele ).attr( "class" );
	$j( ".tbl_hikaku" ).css( "display", "none" );
	$j( "."+area ).css( "display", "block" );
	
	// change heading
	$j( "#anchor_buildin" ).html( area_name+"のルームタイプ（ビルイン）" );
	$j( "#anchor_container" ).html( area_name+"の屋内コンテナボックス" );
}

/**
 * 
 */
function changeTab2( ele, type ) {
	
	var area_name = $j( ele ).html();
	
	// change tab
	$j( ".tab_list" ).children(".on").removeClass("on");
	$j( ele ).parent().addClass("on");
	
	// change list
	var area = $j( ele ).attr( "class" );
	$j( ".trunk_list" ).css( "display", "none" );
	$j( ".nolist_txt" ).css( "display", "none" );
	$j( "."+area ).css( "display", "block" );
}


/**
 * 
 */
var Img = new Array;
function selectStore( ele, name, img, link, sid, type ) {
	var imgCnt = img.split('/');
	var path;
	
	// image url
	path = $j( "#unsou_map" ).attr( "src" );
	var img_path = path.substr( 0, path.indexOf('/store') );
	img_path += '/store/'+img;
	// link url
	path = $j( "#trunk_url" ).attr( "href" );
	var link_path = path.substr( 0, path.indexOf('/area') );
	link_path += '/area/'+link;
	// contact url
	path = $j( "#contact_url" ).attr( "href" );
	var contact_path = path.substr( 0, path.indexOf('/contact') );
	contact_path += '/contact/index.php?sid='+sid+'&type='+type;
	// contact/concierge url
	path = $j( "#concierge_url" ).attr( "href" );
	var concierge_path = path.substr( 0, path.indexOf('/concierge') );
	concierge_path += '/concierge/index.php?sid='+sid+'&type='+type;
	
	// select
	$j( ".selected" ).removeClass("selected");
	$j( ele ).parent("li").addClass("selected");
/*	$.ajaxSetup({
		error:errFunc
	});/**/
	// set
	rand = Math.random();
	$j(".trunkmap").html("<img src=\"/lib/js/loading.gif\">");
	var Image = $j.get('/lib/js/getImage.php?img='+img_path, {}, ImgComp);
	function ImgComp(gData){
		$j(".trunkmap").html(gData);
		$j( ".trunk_name" ).text( name );
		$j( "#trunk_url" ).attr( "href", link_path );
		$j( "#contact_url" ).attr( "href", contact_path );
		$j( "#concierge_url" ).attr( "href", concierge_path );
	}
	/**/
}

function errFunc(xmlHttp, stat){
	alert('error : ' + stat);
}

$j(document).ready(function() {
	
	// 比較
	if( document.URL.indexOf('hikaku') > 0 ) {
		
		// 運送料一覧
		if( document.URL.indexOf('unsou') > 0 ) {
			
			var class_name = "."+$j( "[name=RPATH]" ).val();
			$j( class_name ).css( "display", "block" );
		}
		// 料金一覧
		else if( document.URL.indexOf('ryokin') > 0 ) {
			
			$j( "a.tokyo" ).parent().addClass( "on" );
			$j( ".tokyo" ).css( "display", "block" );
		}
	}
	
});


/**
 * for ContactPage
 */
function moveForm( id, url ) {
	var ele = $j( "#"+id );
	ele.attr( "action", url );
	ele.submit();
}
/*
 jQuery で処理するため不要
function multiChecked( obj ) {
	var ele		= $j( obj );
	var check	= ( ele.attr( "checked" ) )? true: false;
	
	ele.parents("li").children("label").children(":checkbox").attr( "checked", check );
}*/


/**
 * DBからリスト作成（お問い合わせページのみ）
 */
$j( document ).ready( function() {
	
	if( document.URL.indexOf('contact') > 0 ) {
		
		var url = document.URL.substr( 0, document.URL.indexOf('/contact') );
		
		var rand	= Math.random();
		$j.get( url+'/lib/getSizeList.php',{ ran: rand }, makeSizeList);
	}
	else {
		;
	}
});


/**
 * DBから読み込んだ情報でリスト作成
 */
var SizeList = new Array();

function makeSizeList( gData ) {
	
	/*
	if( gData != '' ) {
		var data;
		var tmp_array = new Array();
		var list		= gData.split( '\n' );
		var len			= list.length;
		for( i = 0; i < len; i++ ) {
			data		= list[i].split( ',' );
			tmp_array[ data[1] ]	= new Array( data[1], data[2] );
			SizeList[ data[0] ]		= tmp_array;
		}
	}
	
	alert( SizeList[7][1] );
	
	// デフォルト値をセット
	var sid		= $j( "[name=SID]" ).val();
	var type	= $j( "[name=TYPE]" ).val();
	
	// 
	changeSizeField( sid )
	
	//alert( sid, type );
	*/
}

/**
 * 希望サイズ／目安分量を変更する
 * 
 * @param	sid			店舗のID
 */
function changeSizeField( sid ) {
	
	/*
	if( sid < 1 )	return false;
	
	var ele		= $j( "#size" );
	var options	= "<option value=\"0\">-- ▼選択してください --</option>";
	
	// セレクトボックスの内容を空にする
	ele.html("");
	
	// 項目のセット
	var data	= SizeList[sid];
	var len		= data.length;
	//for( i = 0; i < len; i++ ) {
	for( i = 0; i < 5; i++ ) {
		options += "<option value=\""+ test +"\">"+ test +"</option>";
	}
	
	alert( options );
	
	// セレクトボックスに項目を表示する
	ele.html( options );
	*/
}


/**
 * 物別保管サービス - タイヤ保管
 * タイヤが保管可能かどうか判断する
 */
function checkTaiyaSize(){
	
	var ele		= document.getElementById( "size" );
	var wide	= ele.wide.value;
	var re		= ele.re.value;
	var wheel	= ele.wheel.value;
	var wide2	= Math.round( ( (wide * re / 100) * 2 ) + ( 25.4 * wheel ) );
	
	if( ( wide == 0 ) || ( re == 0 ) || ( wheel == 0 ) ) {
		res = "選択してください";
	}
	else if( ( wide * 4 ) > 1100 && wide2 > 670) {
		res = "タイヤ幅オーバー、直径オーバー";
	}
	else if( wide * 4 > 1100 ) {
		res = "タイヤ幅オーバー";
	}
	else if( wide2 > 670 ) {
		res="直径オーバー";
	}
	else {
		res="収納可能";
	}
	
	ele.output.value	= res;
	ele.output1.value	= wide2;
	ele.output2.value	= wide * 4;
}


/* -------------------------------------------------------- */



