//ロールオーバー
function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}



window.onload = initRollovers;



jQuery(document).ready(function($) {
	jQuery.easing.quart = function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	};  
	
	$(function () {
		$('.pageTop, .link_top a').click(function () {
			$('html,body').animate({ scrollTop: 0 }, 1000, 'quart');
			return false;
		});
	});
});



$(function(){
	$('a.smooth[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body')
				.animate({scrollTop: targetOffset}, 800);
				return false;
			}
		}
	});
});

$(document).ready(function(){
	$('#prefecture_search_select').change(function () {
		prefectureCity("prefecture_search_select", "city_select", "TAccountingFirm", "", "");
	});
	$('#prefecture_list_select').change(function () {
		prefectureCity("prefecture_list_select", "city_select", "", "" ,"");
	});
	$('#prefecture_front_select').change(function () {
		prefectureCity("prefecture_front_select", "city_select", "", "", "市区町村を選んで下さい");
	});
	$('#address_select').click(function () {
		zipcodeCity("zip_code1", "zip_code2", "prefecture_search_select", "city_select", "TAccountingFirm", "town_text")
	});
	$(".kinmukeitai").click(function () {
		kinmukeitaiChange();
	});
	$("#map_open_button").click(function () {
		mapOpen();
	});
	$('#map_regist_button').click(function () {
		setMapInfo();
	});
	$('#map_close_button').click(function () {
		mapClose();
	});
	$('#map_crear_button').click(function () {
		mapCrear();
	});
});
function kinmukeitaiChange() {
	
	$(".kinmukeitai").each(function(){
		if ($(this).attr('checked')) {
			if ($(this).val() == 1) {
				$(".jyoukin").css("display", "block");
				$(".hijyoukin").css("display", "none");
				$(".jyoukin2").css("display", "table-row");
				$(".hijyoukin2").css("display", "none");
			} else {
				$(".jyoukin").css("display", "none");
				$(".hijyoukin").css("display", "block");
				$(".jyoukin2").css("display", "none");
				$(".hijyoukin2").css("display", "table-row");
			}
		}
	});
}
/**
 * 地図クリックするとマーカーを立てる。
 * @return
 */
function mapMarker() {
	
	GEvent.addListener(map, 'click', function(overlay, point) {
		if (marker) {
			// 前回のマーカーを消す
			map.removeOverlay(marker);
		}
		if (point) {
			$("#show_x").val(point.x);
			$("#show_y").val(point.y);
			marker = createMarker(point);
			map.addOverlay(marker);
		}
	});
}

/**
 * 親画面に緯度、経度を設定する。
 * @return
 */
function setMapInfo() {

	window.opener.$("#longitude").val($("#show_x").val());
	window.opener.$("#latitude").val($("#show_y").val());
	
	window.opener.$("#map_area").css("display", "block");
	window.opener.$("#map_clear").css("display", "block");
	
	window.opener.map.setCenter(new GLatLng($("#show_y").val(), $("#show_x").val()), 15);

	var point = new GPoint($("#show_x").val(), $("#show_y").val());
	
	window.opener.marker = createMarker(point);
	
	window.opener.map.addOverlay(window.opener.marker);
	
	window.opener.$("#map_message").css("display", "none");
	
	window.close();
}

/**
 * 地図画面を閉じる。
 * @return
 */
function mapClose() {

	window.close();
}

/**
 * 地図画面を別画面で立ち上げる。
 * @return
 */
function mapOpen() {

	var latitude = $("#latitude").val();
	var longitude = $("#longitude").val();

	var param = "";
	
	if (latitude != "" && longitude != "") {
		param = "?latitude=" + latitude + "&longitude=" + longitude;
	}
	
	window.open("/admin/admin_map/" + param, '_blank', "width=750, height=700,resizable=1,scrollbars=1,status=yes");
}

function mapCrear() {

	$("#latitude").val("");
	$("#longitude").val("");
	
	$("#map_crear_button").css("display", "none");
	
	$("#map_message").css("display", "block");
}
