﻿/**
* common.js
*
* @version		1.0.1.3
* @update		19:25 2008/04/08
* @lastupdate	----
* @extends		----
*
*/

/* ============================================================================== colorRows - 'rowTint'
	Automatic coloured rows | Bite Size Standards
	http://bitesizestandards.com/bites/automatic-coloured-rows
*/
var colorRows = function() {
	var myTR = document.getElementsByTagName('tr');
	for (var i=0;i<myTR.length;i++) {
		if (i%2) {
			myTR[i].className = 'rowTint';
		}
	}
};

/* ============================================================================== initRollovers - 'imgover'
	Standards Compliant Rollover Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php
*/

var initRollovers = function() {
	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);
			}
		}
	}
};

/* ============================================================================== createExternalLink - 'external'
	Author : Sakai
	Date   : 2008-01-19
*/

var createExternalLink = function() {
	var externalLink = document.getElementsByTagName('a');
	for (var i = 0, len = externalLink.length; i < len; i++) {
		var a = externalLink[i];
		if (a.getAttribute('rel') == 'external') {
			a.title += ' : Open in a New Window';
			a.target = '_blank';
		}
	}
};

/* ============================================================================== formAdjust
	Author : Sakai
	Date   : 2008-03-10
*/

var formAdjust = function() {
	var inputForm = document.getElementsByTagName('input');
	for (var i = 0, len = inputForm.length; i < len; i++) {
		if (inputForm[i].getAttribute('type') == 'text') {
			var inputSize = inputForm[i].size;
			if ((0 < inputSize) && (inputSize <= 5)) {
				inputForm[i].className = 'level1 typeText';
			}
			else if ((5 < inputSize) && (inputSize <= 10)) {
				inputForm[i].className = 'level2 typeText';
			}
			else if ((10 < inputSize) && (inputSize <= 40)) {
				inputForm[i].className = 'level3 typeText';
			}
			else {
				inputForm[i].className = 'level4 typeText';
			}
		}
	}
};

var extra_skip = false;

var font_size = 0;
var main_domain = 'www.avanty-wj.com';

if (document.cookie.indexOf('font_size')>-1){
	font_size = getCookie('font_size');
} else {
	setCookie('font_size', font_size);
}

document.write('<link rel="stylesheet" type="text/css" href="http://www.avanty-wj.com/css/common'+font_size+'.css" media="screen, print" title="default" />');

function setCookie(key, val, tmp) {
	tmp = key + "=" + escape(val) + "; ";
	tmp += "path=/; ";
	document.cookie = tmp;
}

function getCookie(key,  tmp1, tmp2, xx1, xx2, xx3) {
	tmp1 = " " + document.cookie + ";";
	xx1 = xx2 = 0;
	len = tmp1.length;
	while (xx1 < len){
		xx2 = tmp1.indexOf(";", xx1);
		tmp2 = tmp1.substring(xx1 + 1, xx2);
		xx3 = tmp2.indexOf("=");
		if (tmp2.substring(0, xx3) == key) return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
		xx1 = xx2 + 1;
	}
	return("");
}

function font_change(size_num){
	setCookie('font_size', size_num);
	var query = window.location;
	window.location = query;
}

function font_size_html(){
	var out_html = '';
	out_html += '<img src="http://www.avanty-wj.com/img/txtsize.gif" alt="文字サイズ" />';
	out_html += '<img onclick="font_change(0);" class="btn" src="http://www.avanty-wj.com/img/ts0.gif" alt="標準" />';
	out_html += '<img onclick="font_change(1);" class="btn" src="http://www.avanty-wj.com/img/ts1.gif" alt="中" />';
	out_html += '<img onclick="font_change(2);" class="btn" src="http://www.avanty-wj.com/img/ts2.gif" alt="大" />';
	elem('txtSize').innerHTML = out_html;
}

function limit_make(){
	var today = new Date();
	var temp = (today.getTime() + (day_limit * 24 * 3600 * 1000));
	today.setTime(temp);
	var yy = today.getFullYear();
	if (yy < 2000) yy += 1900;
	var mm = (today.getMonth() + 1);
	var dd = today.getDate();
	return date_format(yy, mm, dd);
}

var today_date = function(){
	var result = Array();
	var today = new Date();
	result.yy = today.getFullYear();
	if (result.yy < 2000) result.yy += 1900;
	result.mm = (today.getMonth() + 1);
	result.dd = today.getDate();
	return result;
}

function plus_rand(){
	return '&rand='+Math.floor(Math.random() * 1000000);
}

function calender_init(){
	change_month(year+'-'+month);
}

function make_calender(){
	var just_today = today_date();
	var out_html = '';
	out_html += '<table id="tour4" summary="ツアーカレンダー">';
	out_html += '<tr><th class="mainTh" colspan="3">ツアーカレンダー</th></tr>';
	out_html += '<tr><td id="prevMonth">';
	if ((just_today.yy == year)&&(just_today.mm == month)) out_html += '&nbsp;';
	else out_html += '<a href="javascript: change_month(\''+next_month_calc('back', year, month)+'\');">前月</a>';
	out_html += '</td>';
	
	out_html += '<td id="thisMonth">色のついている部分をクリックするとお問い合わせ画面にリンクします。</td>';
	
	out_html += '<td id="nextMonth">';
	if ((load_lists_next.length > 0)||(extra_skip)) out_html += '<a href="javascript: change_month(\''+next_month_calc('next', year, month)+'\');">翌月</a>';
	else out_html += '&nbsp;';
	out_html += '</td></tr>';
	out_html += '</table>';

	out_html += '<table class="tourCal fL">';
	out_html += '<tr><th colspan="7">'+year+'年'+month+'月</th></tr>';
	out_html += '<tr>';
	out_html += '<th class="calDay" scope="col" style="width: 16%;">日</th>';
	out_html += '<th class="calDay" scope="col" style="width: 14%;">月</th>';
	out_html += '<th class="calDay" scope="col" style="width: 14%;">火</th>';
	out_html += '<th class="calDay" scope="col" style="width: 14%;">水</th>';
	out_html += '<th class="calDay" scope="col" style="width: 14%;">木</th>';
	out_html += '<th class="calDay" scope="col" style="width: 14%;">金</th>';
	out_html += '<th class="calDay" scope="col" style="width: 14%;">土</th>';
	out_html += '</tr>';

	var full_years = ',31,28,31,30,31,30,31,31,30,31,30,31'.split(',');
	if (((year % 4 == 0)&&(year % 100 != 0))||(year % 400 == 0)) full_years[2] = 29;

	var start_day = get_day(year, month, 1);
	var sub_html = '';

	if (start_day > 0){
		out_html += '<tr>';
		sub_html += '<tr>';
		for(temp=0; temp<start_day; temp++){
			out_html += '<td rowspan="2">&nbsp;</td>';
		}
	}

	for(dat_ct=1; dat_ct<=full_years[month]; dat_ct++){
		var youbi = '';
		if (start_day==0){
			out_html += '<tr>';
			sub_html += '<tr>';
			youbi = ' sun';
		}
		if ((year == today_y)&&(month == today_m)&&(dat_ct == today_d)) youbi = ' sat';
		out_html += '<td class="calDate'+youbi+'">'+dat_ct+'</td>';
		
		sub_html += chk_date(year, month, dat_ct);

		if (start_day == 6){
			out_html += '</tr>'+sub_html+'</tr>';
			sub_html = '';
		}
		start_day++;
		if (start_day > 6) start_day = 0;
	}

	if (start_day>0){
		for(temp=start_day; temp<=6; temp++){
			out_html += '<td rowspan="2">&nbsp;</td>';
		}
		out_html += '</tr>'+sub_html+'</tr>';
	}

	out_html += '</table>';

	if ((load_lists_next.length > 0)||(extra_skip)){
	//	ここから次月

		out_html += '<table class="tourCal fR">';
		month = next_month_num('next', month);
		if (month == 1) year++;
		
		out_html += '<tr><th colspan="7">'+year+'年'+month+'月</th></tr>';
		out_html += '<tr>';
		out_html += '<th class="calDay" scope="col" style="width: 16%;">日</th>';
		out_html += '<th class="calDay" scope="col" style="width: 14%;">月</th>';
		out_html += '<th class="calDay" scope="col" style="width: 14%;">火</th>';
		out_html += '<th class="calDay" scope="col" style="width: 14%;">水</th>';
		out_html += '<th class="calDay" scope="col" style="width: 14%;">木</th>';
		out_html += '<th class="calDay" scope="col" style="width: 14%;">金</th>';
		out_html += '<th class="calDay" scope="col" style="width: 14%;">土</th>';
		out_html += '</tr>';

		load_lists = load_lists_next;
	
		var start_day = get_day(year, month, 1);
		var sub_html = '';
	
		if (start_day > 0){
			out_html += '<tr>';
			sub_html += '<tr>';
			for(temp=0; temp<start_day; temp++){
				out_html += '<td rowspan="2">&nbsp;</td>';
			}
		}
	
		for(dat_ct=1; dat_ct<=full_years[month]; dat_ct++){
			var youbi = '';
			if (start_day==0){
				out_html += '<tr>';
				sub_html += '<tr>';
				youbi = ' sun';
			}
			if ((year == today_y)&&(month == today_m)&&(dat_ct == today_d)) youbi = ' sat';
			out_html += '<td class="calDate'+youbi+'">'+dat_ct+'</td>';
			
			sub_html += chk_date(year, month, dat_ct);
	
			if (start_day == 6){
				out_html += '</tr>'+sub_html+'</tr>';
				sub_html = '';
			}
			start_day++;
			if (start_day > 6) start_day = 0;
		}
	
		if (start_day>0){
			for(temp=start_day; temp<=6; temp++){
				out_html += '<td rowspan="2">&nbsp;</td>';
			}
			out_html += '</tr>'+sub_html+'</tr>';
		}
		out_html += '</table>';
	}
	elem('tour_calender').innerHTML = out_html;
}

function date_format(temp_y, temp_m, temp_d){
	if (temp_m < 10) temp_m = '0'+temp_m;
	if (temp_d < 10) temp_d = '0'+temp_d;
	return temp_y+'-'+temp_m+'-'+temp_d;
}

function detail_contact(rank_num, tdate){
	if (window.confirm('出発日：'+tdate+' でのお問い合わせを行いますか？')){
		window.location = 'http://www.avanty-wj.com/contact/detail.php?md='+view_mode+'&rank='+rank_num+'&tdate='+tdate+'&sid='+data_id;
	}
}

function chk_date(yy, mm, dd){
	var temp = date_format(yy, mm, dd);
	var none_data = '<td>&nbsp;</td>';
	if (temp < limit_date) return none_data;
	else {
		if ((load_lists[(dd - 1)])&&(load_lists[(dd - 1)]!='N')){
			var part_html = '<td class="rank" style="cursor: pointer; background: '+color_list[load_lists[(dd - 1)]]+';" onclick="detail_contact(\''+load_lists[(dd - 1)]+'\', \''+yy+'-'+mm+'-'+dd+'\');">';
			part_html += color_name[load_lists[(dd - 1)]]+'</td>';
			return part_html;
		} else return none_data;
	}
}

function next_month_num(func, mm){
	if (func == 'next') mm++;
	else if (func == 'back') mm--;
	if (mm>12) mm=1;
	else if (mm<1) mm=12;
	return mm;
}

function next_month_calc(func, yy, mm){
	if (func == 'next') mm++;
	else if (func == 'back') mm--;
	if (mm>12){
		mm=1;
		yy++;
	} else if (mm<1){
		mm=12;
		yy--;
	}
	return yy+'-'+mm;
}

function get_day(yy, mm, dd){
	var temp_d = new Date(yy, (mm - 1), dd);
	return temp_d.getDay();
}

function elem(elem_name){
	if (document.getElementById(elem_name)) return document.getElementById(elem_name);
}

function ajax_req(sendData, pg_name){
	new Ajax.Request('./'+pg_name+'?'+sendData+plus_rand(), { method:'get', onComplete: eval_response });
}

function eval_response(response){
	var text = response.responseText;
	if (navigator.appVersion.indexOf( "KHTML" ) > -1 ){
		var esc = escape(text);
		if ( esc.indexOf("%u") < 0 && esc.indexOf("%") > -1 ){
			text = decodeURIComponent(esc);
		}
	}
	var res = eval(text);
}

function side_banners(){
	if (elem('side_banners_area')){
		var link_list = [
			{
				title: '春の旅のページへ',
				url: '/campaign/camp_sp4.html',
				img: '/img/bnr13.jpg'
			},{
				title: '売れ筋商品No.1！グアム',
				url: '/asiatour/search.php?area_seek=605&pg=1&extra=1',
				img: '/img/bnr7.jpg'
			},{
				title: '国内ツアー特集',
				url: '/campaign/camp_sp5.html',
				img: '/img/bnr19.jpg'
			},{
				title: 'こだわりのツアー',
				url: '/original/',
				img: '/img/bnr18.jpg'
			},{
				title: 'こだわりの韓国オリジナルツアー',
				url: '/original/korea0.html',
				img: '/img/bnr20.jpg'
			},{
				title: 'シルクロードの旅 オリジナルツアー',
				url: '/original/uz0.html',
				img: '/img/bnr21.jpg'
			},{
				title: '韓の国 三十三観音聖地',
				url: 'http://www.korea33kannon.com/',
				img: '/img/bnr_korea33.jpg'
			}
		];
		
	var out_html = '';
	out_html = '<h2 id="bannersTitle"><img src="http://www.avanty-wj.com/img/banners_title.gif" alt="シーズン・人気の特集" /></h2>';
	out_html += '<ul id="banners">';
	for(i=0; i<link_list.length; i++){
		var temp = link_list[i];
		out_html += '<li>';
		out_html += '<a href="'+temp.url+'"><img src="'+temp.img+'" alt="'+temp.title+'" /></a>';
		out_html += '<a class="bnrCaption" href="'+temp.url+'" >'+temp.title+'</a>';
		out_html += '</li>';
	}

	out_html += '</ul>';
	elem('side_banners_area').innerHTML = out_html;
	side_arrive();
	}
}

var full_path = '../';

var side_arrive = function(){
	var out_html = '';
	var area_datas = [
		{
		name: '東アジア',
		img: full_path+'img/areaselect_east_asia.jpg',
		arrive: [
			{title: '中国', num: 508},
			{title: '香港&amp;マカオ', num: 511},
			{title: '台湾', num: 510},
			{title: '韓国', num: 509}
		]
		},
/*		{
		name: '中央アジア&amp;中近東',
		img: full_path+'img/areaselect_central_asia.jpg',
		arrive: [
			{title: 'モンゴル', num: 0},
			{title: 'ウズベキスタン', num: 0}
		]
		},
		{
		name: '南西アジア',
		img: full_path+'img/areaselect_southwest_asia.jpg',
		arrive: [
			{title: 'インド', num: 493},
			{title: 'ネパール', num: 494},
			{title: 'スリランカ', num: 707}
		]
		},*/
		{
		name: '東南アジア',
		img: full_path+'img/areaselect_southeast_asia.jpg',
		arrive: [
			{title: 'タイランド', num: 503},
			{title: 'ベトナム', num: 499},
			{title: 'カンボジア', num: 500},
			{title: 'ラオス', num: 501},
			{title: 'ミャンマー', num: 502},
			{title: 'シンガポール', num: 504},
//			{title: 'マレーシア', num: 505},
			{title: 'インドネシア', num: 607}
		]
		}
	];
	
	out_html += '<h2 id="areaSelectTitle"><img src="'+full_path+'img/areaselect_title.gif" alt="目的地からさがす" /></h2>';
	
	out_html += '<dl id="areaSelect">';
	for(i=0; i<area_datas.length; i++){
		var big_area = area_datas[i];
		out_html += '<dt><img src="'+big_area.img+'" alt="'+big_area.name+'" /></dt>';
		if (big_area.arrive.length){
			out_html += '<dd>';
			out_html += '<ul class="clearfix">';
		}
		for(j=0; j<big_area.arrive.length; j++){
			var mid_area = big_area.arrive[j];
			out_html += '<li><a href="'+full_path+'asiatour/index.html?cd='+mid_area.num+'">'+mid_area.title+'</a></li>';
		}
		if (big_area.arrive.length){
			out_html += '</ul>';
			out_html += '</dd>';
		}
	}

	out_html += '</dl>';
	elem('side_arrive_area').innerHTML = out_html;
}

/* ============================================================================== addEvent
*/

function addEvent(elm, listener, fn){
	try{
		elm.addEventListener(listener, fn, false);
	}catch(e){
		elm.attachEvent('on' + listener, fn);
	}
}

addEvent(window, 'load', function(){
//	colorRows();
	initRollovers();
//	formAdjust();
	createExternalLink();
	font_size_html();
	side_banners();
	load_acc_tag();
	if (elem('detailBox0')) originalContentsCount();
});

function load_acc_tag(){
	var out_html = '<img src="/acc/acclog.cgi?';
	out_html += 'referrer='+document.referrer+'&';
	out_html += 'width='+screen.width+'&';
	out_html += 'height='+screen.height+'&';
	out_html += 'color='+screen.colorDepth+'" />';
//	var body_htmls = document.getElementsByTagName('footer');
//	body_htmls[0].innerHTML += out_html;
}

var changeDivs = 0;

var originalContentsCount = function(){
	var tempDivs = elem('details').getElementsByTagName('div');
	changeDivs = tempDivs.length;
}

var changeTour = function(sel_num){
	for(i=0; i<changeDivs; i++){
		elem('detailBox'+i).style.display = (i == sel_num) ? 'block': 'none';
	}
}

try {
    document.execCommand('BackgroundImageCache' , false, true);
} catch(e){}