
jQuery(function($){
	$.datepicker.regional['ja'] = {
		closeText: '閉じる',
		prevText: '&#x3c;前',
		nextText: '次&#x3e;',
		currentText: '今日',
		monthNames: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
		monthNamesShort: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
		dayNames: ['日曜日','月曜日','火曜日','水曜日','木曜日','金曜日','土曜日'],
		dayNamesShort: ['日','月','火','水','木','金','土'],
		dayNamesMin: ['日','月','火','水','木','金','土'],
		weekHeader: '週',
		dateFormat: 'yy/mm/dd',
		firstDay: 0,
		isRTL: false,
		showMonthAfterYear: true,
		yearSuffix: ''};
	$.datepicker.setDefaults($.datepicker.regional['ja']);
});

/* jqueryベースの関数 */
$(function() {
	/* 時間絞込み */
	$('#type').bind('change ready',function(){
		var display = ($(this).val() == '2') ? 'none' : 'inline';
		$('#time').css('display',display);
	}).ready(function(){
		var display = ($(this).val() == '2') ? 'none' : 'inline';
		$('#time').css('display',display);
	});

	/* 検索対象の航空会社絞込み */
	$('#arrow-com-view').toggle(
		function(){
			$('#arrow-com').css('left', $(this).position().left ).css('top',$(this).position().top + 20 ).slideDown();
		},
		function(){
			$('#arrow-com').slideUp();
		}
	);

	/* エリア別一覧レイヤーの表示 */
	$("#deap,#arap").bind('click', $(this), lfOpenDeap);

	/* エリア別一覧レイヤーからの選択 */
	$("#airport-box > dd").click(function(){
		$("#" + $('#airport-box').attr('class') + '-select').val($(this).attr("title"));
		$("#airport-box").fadeOut('slow');
		$("#delete").hide();
	});

	/* エリア別一覧レイヤーの消去 */
	$("#delete").bind("click", function() {
		$("#airport-box").fadeOut('slow');
		$(this).hide();
	});

	/* lfSendMode(any, any)の代替 */
	$('.submit-mode').click(function(){

		if($(this).attr('name') == '') return false;
		if($(this).attr('title') == '') return false;

		var result = confirm ("こちらでよろしいですか？");

		if(result){
			$('#mode').val($(this).attr('name'));
			$('#ticket').attr('action',$(this).attr('title')+'.php').submit();
		}
		return false;
	});
});

function lfOpenDeap(e) {

	var height = $(document).height();
	var width = $(document).width();

	var box_height = ( $(window).height() / 2 ) - ( $("#airport-box").height() / 2 );
	var box_width = ( $(window).width() / 2 ) - ( $("#airport-box").width() / 2 );

	$("#airport-box").attr('class',$(this).attr('id')).css('left', box_width ).css('top', box_height ).fadeIn('slow');
	$("#delete").css({"width":width,"height":height,"top":0,"left":0});
	$("#delete").show();

}

/* ここから古い関数 */
function lfExplodeDate(){

	val = document.seacher.datepicker.value;
	array = val.split('/');

	document.seacher.mon.value = Number(array[1]);
	document.seacher.day.value = Number(array[2]);
}

function lfChangePage(page){

	document.page.mode.value = 'other';
	document.page.page.value = page;
	document.page.action = 'search.php';
	document.page.submit();

}
function lfOpenWindow(url){

	window.open(url,'subWindow','width=600, height=600, menubar=no, toolbar=no, scrollbars=yes');

}
function lfSubmitback(){

	document.back.submit();

}
function lfSubmitSearch(){

	document.seacher.submit();

}
function lfSubmitList(){

	document.ticket.submit();

}
function lfSendMode(mode,target){
	/* 確認ダイアログ表示 */
	var result = confirm ("こちらでよろしいですか？");
	/* send_flg が TRUEなら送信、FALSEなら送信しない */
	if(result){
		document.ticket.mode.value = mode;
		file = target + '.php';
		document.ticket.action = file;
		document.ticket.submit();
	} else {
		return result;
	}
}
/* 日付の切替 */
function lfSetDay(mode){

	mon = parseInt(document.seacher.mon.value);
	day = parseInt(document.seacher.day.value);

	if((mon) || (day)){

		nowDate = new Date();

		var newDate = new Date(nowDate.getFullYear(),mon - 1,day);

		if(mode == "next"){
			newDate.setTime(newDate.getTime() + 24 * 60 * 60 * 1000 * 1 );
		} else if (mode == "back"){
			newDate.setTime(newDate.getTime() - 24 * 60 * 60 * 1000 * 1 );
		}
		document.seacher.mon.value = newDate.getMonth() + 1;
		document.seacher.day.value = newDate.getDate();

	} else {
		return flag;
	}
}
/* 区間の切替 */
function lfChangePort(){

	var deap = document.seacher.deap.value;
	var arap = document.seacher.arap.value;

	if((deap) || (arap)){
		document.seacher.deap.value = arap;
		document.seacher.arap.value = deap;
	} else {
		return flag;
	}
}
/* 航空券（乗継）のセット */
function lfPutTransitTicket(hash){

	file_url = location.href;
	file_url = file_url.substring(file_url.lastIndexOf("/")+1,file_url.length);

	/* 確認ダイアログ表示 */
	var flag = confirm ("こちらでよろしいですか？");
	/* send_flg が TRUEなら送信、FALSEなら送信しない */
	if(flag){
		document.ticket.mode.value = 'transit';
		document.ticket.hash.value = hash;
		if(file_url == 'CopyOfsearch.php'){
			document.ticket.action = 'CopyOfsearch.php';
		} else {
			document.ticket.action = 'search.php';
		}
		document.ticket.submit();
	} else {
		return flag;
	}
}
/* 航空券のセット */
function lfPutTicket(hash){
	/* 確認ダイアログ表示 */
	var flag = confirm ("こちらでよろしいですか？");
	/* send_flg が TRUEなら送信、FALSEなら送信しない */
	if(flag){
		document.ticket.mode.value = 'put';
		document.ticket.hash.value = hash;
		document.ticket.action = 'list.php';
		document.ticket.submit();
	} else {
		return flag;
	}
}
/* 航空券の削除 */
function lfDelTicket(hash){
	/* 確認ダイアログ表示 */
	var flag = confirm ("削除してよろしいですか？");
	/* send_flg が TRUEなら送信、FALSEなら送信しない */
	if(flag){
		document.ticket.mode.value = 'del';
		document.ticket.hash.value = hash;
		document.ticket.action = 'list.php';
		document.ticket.submit();
	} else {
		return flag;
	}
}
/* 画面サイズの取得 */
function getBrowserWidth ( ) {
	if ( window.innerWidth ) { return window.innerWidth; }
	else if ( document.documentElement && document.documentElement.clientWidth != 0 ) { return document.documentElement.clientWidth; }
	else if ( document.body ) { return document.body.clientWidth; }
	return 0;
}
/* 子ウィンドウを閉じる */
function close_window(){
	window.close();
	window.opener.location.reload();
	return false;
}
/* 全てのチェックボックスをつける */
function checkall(){
	var inputs = document.getElementsByTagName('input');
	for (var j=0; j < inputs.length; j ++) {
		var e = inputs[j];
		if (e.type == 'checkbox')
			e.checked = true;
	}
}
/* 全てのチェックボックスをはずす */
function uncheckall(){
	var inputs = document.getElementsByTagName('input');
	for (var j=0; j < inputs.length; j ++) {
		var e = inputs[j];
		if (e.type == 'checkbox')
			e.checked = false;
	}
}
/* 送信の可否の確認 */
function disp(){

	/* 確認ダイアログ表示 */
	var flag = confirm ("送信してよろしいですか？");
	/* send_flg が TRUEなら送信、FALSEなら送信しない */

	return flag;
}
/* 入力フォームの人数をオンロードで変更する */
function lfSetMember(num){

	if(num == null || num == undefined){num = 1;}

	for(i = 1; i <= 5; i++) {
		if(i <= num){
			name = "mem" + i;
			tr = document.getElementById(name);
			tr.style.height = "100%";
			tr.style.display = "";
		} else {
			name = "mem" + i;
			tr = document.getElementById(name);
			tr.style.height = "0px";
			tr.style.display = "none";
		}

	}
}
/* 入力フォームの人数を変更する */
function lfChangeView(obj){

	value = obj.options[obj.selectedIndex].value;

	for(i = 1; i <= 5; i++) {
		if(i <= value){
			name = "mem" + i;
			tr = document.getElementById(name);
			tr.style.height = "100%";
			tr.style.display = "";
		} else {
			name = "mem" + i;
			tr = document.getElementById(name);
			tr.style.height = "0px";
			tr.style.display = "none";
		}

	}
}
/* 文字を変換 */
function num_convert(num){

	var num;
	var conv = "";
	var fulls = "０１２３４５６７８９?ー（）";
	var basics = "0123456789--()";
	var ch;
	var pos;
	for(i = 0; i < num.length; i++) {
		conv += (pos = fulls.indexOf(ch = num.charAt(i))) >= 0
		? basics.charAt(pos) : ch;
	}
	return(conv);
}
/* 郵便番号から市区町村を取得 */
function lfGetAddress(zip,pref,add){

	objZip = document.getElementById(zip);
	/* objZip = document.getElementById("zip").value; */

	zipcode = encodeURIComponent(num_convert(objZip.value));
	/*var url = "http://localhost/mayuge_mirror_clara/include/zipcode.php"*/
	var url = "../include/zipcode.php"
	+ "?zipcode=" + zipcode
    + "&callback={callback}";

	$.getJSONP( url, function(json) {
		/*	// リクエスト成功時に実行したい処理をここに定義。 */
		/*	// 変数 json = サーバが返したレスポンスオブジェクト。 */

		var objPerf = document.getElementById(pref);
		objPerf.selectedIndex = json.zipcode.a1.pref_code;

		var objAdd1 = document.getElementById(add);
		objAdd1.value = json.zipcode.a1.city + json.zipcode.a1.town;

		objZip.value = json.zipcode.a1.zipcode;

	});
}
