// 全ページ共通Javascript

// 文字サイズ変更
jQuery(document).ready( function() {
	jQuery( "#textsizer a" ).textresizer({
		target: "#contents",
		type: "fontSize",
		sizes: [ "0.9em", "1em", "1.2em", "17px" ],
		selectedIndex: 1
	});
});

// ページャー用
$(function() {
	var $tabs = $('#tabs').tabs();
	$(".ui-tabs-panel").each(function(i){
		var totalSize = $(".ui-tabs-panel").size() - 1;
		if (i != totalSize) {
			next = i + 2;
			$(this).append("<a href='#' class='next-tab mover' rel='" + next + "'>Next Page &#187;</a>");
		}
		if (i != 0) {
			prev = i;
			$(this).append("<a href='#' class='prev-tab mover' rel='" + prev + "'>&#171; Prev Page</a>");
		}
	});
	$('.next-tab, .prev-tab').click(function() {
		$tabs.tabs('select', $(this).attr("rel"));
		return false;
	});
});

// モードを指定してSubmit
function submit(mode) {
	document.form1.mode.value = mode;
	document.form1.submit();
}

// 入力欄クリア
function clear() {
	var ret = confirm('入力内容を全てクリアしてもよろしいですか？');
	if(ret) {
		for(var index = 0 ; index < document.form1.elements.length ; index++) {
			switch(document.form1.elements[index].type) {
				case "text":
				case "textarea":
					document.form1.elements[index].value = "";
					break;
				case "checkbox":
				case "radio":
					document.form1.elements[index].checked = false;
					break;
				case "select-one":
					document.form1.elements[index].selectedIndex = false;
					break;
				default:
					break;
			}
		}
	}
}

// 指定サイズでウィンドウオープン
function popup(url, width, height, scroll){
	var popup;
	popup = window.open(url, "popup", "width=" + width + ", height=" + height + ", scrollbars=" + scroll + ", resizable=no, toolbar=no, location=no, directories=no, status=no");
	popup.focus();
}

// 郵便番号から住所を取得
function zip_to_address(zip01, zip02, pref, addr01) {
	if(document.form1[zip01].value.length == 3 && document.form1[zip02].value.length == 4) {
		var url = "/zip_to_address.php?zip_code=" + document.form1[zip01].value + document.form1[zip02].value + "&pref=" + pref + "&addr01=" + addr01;
		window.open(url, "nomenu", "width=400, height=100, scrollbars=yes, resizable=yes, toolbar=no, location=no, directories=no, status=no");
	} else {
		alert("郵便番号を正しく入力してください。");
	}
}

// 親ウィンドウの存在確認
function check_parent() {
	var result = false;
	var ua = navigator.userAgent;

	if(!!window.opener) {
		if(ua.indexOf("MSIE 4") != -1 && ua.indexOf("Win") != -1) {
			result = !window.opener.closed;
		} else {
			result = typeof window.opener.document == "object";
		}
	}

	return result;
}

// 郵便番号から住所を検索した結果を反映
function set_address(pref, addr01) {
	if(check_parent()) {
		if(document.form1['prefecture'].value != "") {
			window.opener.document.form1[pref].selectedIndex = document.form1['prefecture'].value;
			window.opener.document.form1[addr01].value = document.form1['city'].value + document.form1['town'].value;
		}
	} else {
		window.close();
	}
}

// 指定IDのCLASS属性を変更
function change_size(size) {
	document.getElementById("contents").className = "clearfix " + size;
}

// サイト内検索
function site_search() {
	if(document.search_form.q.value.length > 0) {
		document.search_form.submit();
	} else {
		alert("検索するキーワードを入力してください。");
	}
}

