﻿/**
 * @version 1.0.0.0
 */

var full_path = Kaas.root();
var scure_mode = (window.location.protocol == 'https:') ? true: false;
if ((scure_mode)&&(!window.location.search)) scure_mode = false;

var first_loaded = true;

/**
 * 【重要　必ずお読みください】
 * 2011年12月6日(火)・8日(木) ご入校のお客様
 */
// var attention201012 = '<p id="attention201012"><img src="' + full_path + 'img/attention201112.png" alt="2011年12月6日(火)・8日(木) ご入校のお客様" /></p>'

document.write('<scr'+'ipt type="text/java'+'script" src="'+full_path+'js/pro'+'totype.js"></scr'+'ipt>');

Kaas.ready(function() {
	
//	if (Kaas.isIEVer(6)) Kaas.IE6Fix.init();
	
	if (document.getElementById('col-x')) Kaas.stripeTable('col-x');
	Kaas.stripeTable('col-b');
	Kaas.formControl.init();
	if (document.getElementById('application')) Kaas.imageRollover.set(document.getElementById('application').getElementsByTagName('input')[0]);
	Kaas.imageRollover.init();
	Kaas.externalLink();
	
});

Kaas.formControl = {
	
	init: function() {
		
		colBLoad();
		together.init();
		// license
		this.checkLicense(this.sections('license', 'ul'));
		this.checkLicense2(this.sections('licenseOption', 'ul'));
		leftAct.loadSchedule();
		// date
//		this.date();
		elem('jobSelectArea').innerHTML = htmlMake.jobSelect();
//		elem('dateSend').innerHTML = htmlMake.dateMonthSend();
	},
	
	checkLicense: function(container) {
		
		var li = container.getElementsByTagName('li');
		
		for (var i = 0, l = li.length; i < l; i++) {
			var _c = li[i].getElementsByTagName('input')[0];
			if (_c.checked) Kaas.addClass(_c.parentNode.parentNode, 'checked');
			
			li[i].onclick = function() {
				// console.log(this);
				var c = this.getElementsByTagName('input')[0];
				if (!Kaas.hasClassName(this, 'checked')) {
					Kaas.addClass(this, 'checked');
				}
				c.checked = 'checked';
				for(j=0; j<li.length; j++){
					if (this.id != li[j].id) Kaas.removeClass(li[j], 'checked');
				}
				elem('dateSend').innerHTML = '<p class="aC"><img src="'+full_path+'img/ajax-loader.gif" alt="Loading" /></p>';
				elem('priceList').innerHTML = '';
				now_calender = false;
				leftAct.loadSchedule();
				return false;
			};
		}
		
	},

	checkLicense3: function(container) {
		
		var li = container.getElementsByTagName('li');
		
		for (var i = 0, l = li.length; i < l; i++) {
			var _c = li[i].getElementsByTagName('input')[0];
			if (_c.checked) Kaas.addClass(_c.parentNode.parentNode, 'checked');
			
			li[i].onclick = function() {
				// console.log(this);
				var c = this.getElementsByTagName('input')[0];
				if (!Kaas.hasClassName(this, 'checked')) {
					Kaas.addClass(this, 'checked');
					c.checked = 'checked';
				} else {
					Kaas.removeClass(this, 'checked');
					c.removeAttribute('checked');
					c.checked = '';
				}
				for(j=0; j<li.length; j++){
					if (this.id != li[j].id) Kaas.removeClass(li[j], 'checked');
				}
				leftAct.loadSchedule();
				return false;
			};
		}
		
	},
	
	checkLicense2: function(container) {
		
		var li = container.getElementsByTagName('li');
		
		for (var i = 0, l = li.length; i < l; i++) {
			var _c = li[i].getElementsByTagName('input')[0];
			if (_c.checked) Kaas.addClass(_c.parentNode.parentNode, 'checked');
			
			li[i].onclick = function() {
				// console.log(this);
				var c = this.getElementsByTagName('input')[0];
				if (!Kaas.hasClassName(this, 'checked')) {
					Kaas.addClass(this, 'checked');
					c.checked = 'checked';
				} else {
					Kaas.removeClass(this, 'checked');
					c.checked = '';
				}
				leftAct.loadSchedule();
				return false;
			};
		}
	},
	
	date: function() {
		
		var table = this.sections('date', 'table');
		var tr = table.getElementsByTagName('tr');
		
		for (var i = 0, l = tr.length; i < l; i++) {
			var _c = tr[i].getElementsByTagName('input')[0];
			if (_c.checked) Kaas.addClass(_c.parentNode.parentNode.parentNode, 'checked');
			
			tr[i].onclick = dateSel = function() {
				for(j=0; j<tr.length; j++){
					Kaas.removeClass(tr[j], 'checked');
					var c = tr[j].getElementsByTagName('input')[0];
					c.checked = '';
				}
				Kaas.addClass(this, 'checked');
				var targ_input = this.getElementsByTagName('input')[0];
				targ_input.checked = 'checked';
				leftAct.selectSchedule(targ_input.id.substr(17));
				
				return false;
			};
		};
	},
	
	sections: function(id, element, index) {
		return document.getElementById(id).getElementsByTagName(element)[!index ? 0 : index];
	},
	
	debug: function() {
		var h3 = document.getElementById('col-b').getElementsByTagName('h3')[0];
		var input = document.getElementById('col-b').getElementsByTagName('input');
		h3.onclick = function() {
			var _arr = [];
			for (var i = 0, l = input.length; i < l; i++) {
				if (input[i].checked) {
					_arr.push(input[i].value);
				}
			}
			alert(_arr);
			return false;
		};
	}
	
};

Kaas.IE6Fix = {
	
	init: function() {
		this.ieHoverEvent(Kaas.formControl.sections('license', 'ul').getElementsByTagName('li'));
		this.ieHoverEvent(Kaas.formControl.sections('licenseOption', 'ul').getElementsByTagName('li'));
		this.ieHoverEvent(Kaas.formControl.sections('date', 'table').getElementsByTagName('tr'));
		this.showSubMenu();
	},
	
	/**
	 * マウスオーバーイベント補助
	 */
	ieHoverEvent: function(targets) {
		
		for (var i = 0, l = targets.length; i < l; i++) {
			this.setMouseEvent(targets[i], 'IEhover');
		}
		
	},
	
	/**
	 * li#g0, li#g1 の マウスオーバーイベント補助
	 */
	showSubMenu: function() {
		
		for (var i = 0; i < 2; i++) {
			var target = document.getElementById('g' + i);
			/**
			 * CSS Bug fix
			 * absolute, float で ボックスが消える
			 * <div></div> を <li>に追加
			 * @see http://jmblog.jp/misc/disappearance-of-an-absolute-positioned-box-in-win-ie/index.ja.html#test1c
			 */
			target.appendChild(document.createElement('div'));
			this.setMouseEvent(target, 'showSubMenu');
		}
		
	},
	
	setMouseEvent: function(target, _class) {
		
		target.onmouseover = function(e) {
			Kaas.addClass(this, _class);
		};
		target.onmouseout = function(e) {
			Kaas.removeClass(this, _class);
		};
		
	}
	
};

var now_calender = false;

var loadingImg = '<p class="aC"><img src="'+full_path+'img/ajax-loader.gif" alt="Loading" /></p>';

var elem = function(elemName){
	if (document.getElementById(elemName)) return document.getElementById(elemName);
	else return false;
}

var htmlMake = {
	holdSelectCar: function(){
		var out_html = '';
		out_html += '<select name="holdLic" id="elicense" onchange="leftAct.calcResult();">';
		out_html += '<option value="">▽選択▽</option>';
		out_html += '<option value="1">なし・原付・小型特殊</option>';
		out_html += '<option value="2">大型二輪・普通二輪</option>';
		out_html += '</select>';
		return out_html;
	},
	holdSelectJumbo: function(){
		var out_html = '';
		out_html += '<select name="holdLic" id="elicense" onchange="leftAct.calcResult();">';
		out_html += '<option value="">▽選択▽</option>';
		out_html += '<option value="3">中型一種8t限定</option>';
		out_html += '<option value="5">上記以外の所持免許</option>';
		out_html += '</select>';
		return out_html;
	},
	holdSelectJumboEx: function(){
		var out_html = '';
		out_html += '<select name="holdLic" id="elicense" onchange="leftAct.selectSchedule2();">';
		out_html += '<option value="">▽選択▽</option>';
		out_html += '<option value="3">中型一種8t限定</option>';
//		out_html += '<option value="4">大型一種</option>';
		out_html += '<option value="5">上記以外の所持免許</option>';
		out_html += '</select>';
		return out_html;
	},
	jobSelect: function(){
		var job_datas = ',大学生,高校生,専門学生,予備校生,会社員,自営業,公務員,看護士等,フリーター,主婦,無職,その他'.split(',');
		var out_html = '<select name="ejob" id="select_ejob" onchange="leftAct.calcResult();">';
		out_html += '<option value="">▽選択▽</option>';
		for(i=1; i<job_datas.length; i++){
			out_html += '<option value="'+i+'">'+job_datas[i]+'</option>';
		}
		out_html += '</select>';
		return out_html;
	},
	birthJuniorSelect: function(){
		return htmlMake.birthSub(18, 29);
	},
	birthSeniorSelect: function(){
		return htmlMake.birthSub(21, 56);
	},
	birthSub: function(minBirth, maxBirth){
		var today = new Date();
		var now_year = today.getYear();
		if (now_year < 1900) now_year = (now_year + 1900);
		
		var start_year = now_year - maxBirth;
		var end_year = now_year - minBirth;
		
		var out_html = '西暦<select name="ebirthyY" id="select_ebirthyY" class="select1">';
		out_html += '<option value="">▽選択</option>';
		for(i=start_year; i<=end_year; i++){
			out_html += '<option value="'+i+'">'+i+'</option>';
		}
		out_html += '</select>年';
		out_html += '<select name="ebirthyM" id="select_ebirthyM" class="select2">';
		out_html += '<option value="">▽選択</option>';
		for(i=1; i<=12; i++){
			out_html += '<option value="'+i+'">'+i+'</option>';
		}
		out_html += '</select>月';
		out_html += '<select name="ebirthyD" id="select_ebirthyD" class="select2">';
		out_html += '<option value="">▽選択</option>';
		for(i=1; i<=31; i++){
			out_html += '<option value="'+i+'">'+i+'</option>';
		}
		out_html += '</select>日';
		return out_html;
	},
	dateMonthSend: function(){
		var now_date = new Date();
		var now_year = now_date.getYear();
		if (now_year < 1900) now_year = (now_year + 1900);
		var now_month = now_date.getMonth() + 1;
		
		var make_date = function(yy, mm){
			if (mm == 0){ mm = 12; yy--}
			else if (mm==13){ mm = 1; yy++}
			if (mm < 10) mm = '0'+mm;
			return yy+'-'+mm;
		}
		
		if (now_calender == 'false') now_calender = false;
		if (!now_calender){
			var year = now_year;
			var month = now_month;
		} else {
			var temp = now_calender.split('-');
			var year = temp[0];
			var month = temp[1];
			month *= 1;
		}
		
		var back_month = ((year == now_year)&&(month == now_month)) ? false: true;
		
		var out_html = '<p>';

		if (back_month){
			out_html += '<a href="javascript: leftAct.moveMonth(\''+make_date(year, (month - 1))+'\');"><img src="'+full_path+'img/prev_month_alpha.png" alt="前の月" id="prev" /></a>';
		} else {
			out_html += '<img src="'+full_path+'img/prev_month_alpha.png" alt="前の月" id="prev" />';
			now_calender = false;
		}
		
		out_html += '<a href="javascript: leftAct.moveMonth(\''+make_date(year, (month + 1))+'\');"><img src="'+full_path+'img/next_month_alpha.png" alt="次の月" id="next" /></a>';
		out_html += '<span>'+year+'年'+month+'月</span>';
		out_html += '</p>';
		
		return out_html;
	}
}

var together = {
	mode: 0,
	init: function(){
		elem('radio_epair0').onclick = elem('radio_epair1').onclick = function(){
//			elem('radio_esingle0').checked = 'checked';
//			together.clickAct();
			leftAct.calcResult();
		}
		elem('radio_esingle0').onclick = elem('radio_esingle1').onclick = function(){
//			elem('radio_epair0').checked = 'checked';
			leftAct.calcResult();
		}
//		elem('optSingle').style.display = 'none';
		together.clickAct();
	},
	clickAct: function(){
		if (elem('radio_epair0').checked){
			together.mode = 1;
//			elem('optSingle').style.display = (leftWin.single) ? 'block': 'none';
//			if (!leftWin.single) elem('radio_esingle0').checked = 'checked';
		} else if (elem('radio_epair1').checked){
			together.mode = 2;
//			elem('optSingle').style.display = 'none';
		}
	}
}

var leftWin = {
	pair: false,
	single: false
}

var leftAct = {
	rankSign: Array(
			'',
			'<img src="'+full_path+'img/type_a.png" alt="A plan" />',
			'<img src="'+full_path+'img/type_b.png" alt="B plan" />',
			'<img src="'+full_path+'img/type_c.png" alt="C plan" />',
			'<img src="'+full_path+'img/type_d.png" alt="D plan" />',
			'<img src="'+full_path+'img/type_e.png" alt="E plan" />',
			'<img src="'+full_path+'img/type_f.png" alt="F plan" />'
	),
	rankSignMini: Array(
			'',
			'<img src="'+full_path+'img/type_a_s.png" alt="A plan" />',
			'<img src="'+full_path+'img/type_b_s.png" alt="B plan" />',
			'<img src="'+full_path+'img/type_c_s.png" alt="C plan" />',
			'<img src="'+full_path+'img/type_d_s.png" alt="D plan" />',
			'<img src="'+full_path+'img/type_e_s.png" alt="E plan" />',
			'<img src="'+full_path+'img/type_f_s.png" alt="F plan" />'
	),
	loadSchedule: function(){
		var now_focus = 0;
		for(i=1; i<=6; i++){
			if (elem('hopeLic'+i).checked){
				now_focus = i;
				leftAct.data.estimateElement.cource = i;
				break;
			}
		}
		
		if ((now_focus < 3)||(now_focus > 4)){
			elem('chk_especial').checked = '';
			Kaas.removeClass(elem('cbB2'), 'checked');
			elem('chk_ekenin').checked = '';
			Kaas.removeClass(elem('cbB3'), 'checked');
			elem('licenseOption').style.display = 'none';
		} else elem('licenseOption').style.display = 'block';
		
		if (now_focus == 4){
			elem('birthSelectArea').innerHTML = htmlMake.birthSeniorSelect();
			elem('holdLicArea').innerHTML = htmlMake.holdSelectJumboEx();
		} else if (now_focus > 2){
			elem('birthSelectArea').innerHTML = htmlMake.birthSeniorSelect();
			elem('holdLicArea').innerHTML = htmlMake.holdSelectJumbo();
		} else {
			elem('birthSelectArea').innerHTML = htmlMake.birthJuniorSelect();
			elem('holdLicArea').innerHTML = htmlMake.holdSelectCar();
		}
		
		var opt = 0;
		if ((elem('chk_ekenin').checked)&&(elem('chk_especial').checked)){
			opt = 8;
			leftAct.data.estimateElement.ekenin = leftAct.data.estimateElement.especial = 1;
		} else if (elem('chk_especial').checked){
			leftAct.data.estimateElement.ekenin = 0;
			leftAct.data.estimateElement.especial = 1;
			opt = 6;
		} else if (elem('chk_ekenin').checked){
			leftAct.data.estimateElement.ekenin = 1;
			leftAct.data.estimateElement.especial = 0;
			opt = 7;
		}
		leftAct.data.estimateElement.option = opt;
		
		var getParam = 'mode=calendar&cource='+now_focus;
		if (opt) getParam += '&option='+opt;
		if (now_calender){
			var temp = now_calender.split('-');
			getParam += '&year='+temp[0]+'&month='+(temp[1] * 1);
		}

		var sendData = full_path + 'cgi-bin/front/front.cgi?'+getParam+plusRand();
		var sendParam = {
			method: 'get',
			onComplete: leftAct.mountSchedule
		};
		elem('entrySchedule').innerHTML = loadingImg;
		if (now_focus) new Ajax.Request(sendData, sendParam);
	},
	selected_calendar: 0,
	selectSchedule: function(sel_num){
		leftAct.selected_calendar = sel_num;
		var dayData = leftAct.data.calendar[sel_num];
		elem('hidden_estartdateJp').value = dayData.ldate;
		var mount_targ = leftAct.data.estimateElement;
		mount_targ.lrank = dayData.lrank;
		mount_targ.lid = dayData.lid;
		mount_targ.mstate = dayData.mstate;
		mount_targ.wstate = dayData.wstate;
		var getParam = 'mode=price&lid='+mount_targ.lid+'&cource='+mount_targ.cource;
		if ((mount_targ.cource == 4)&&(elem('elicense').value == 4)) getParam += '&holder=3';	//	20090805
		if (mount_targ.option) getParam += '&option='+mount_targ.option;

		var sendData = full_path + 'cgi-bin/front/front.cgi?'+getParam+plusRand();
		var sendParam = {
			method: 'get',
			onComplete: leftAct.mountCalc
		};
		new Ajax.Request(sendData, sendParam);
	},
	selectSchedule2: function(){
		var dayData = leftAct.data.calendar[leftAct.selected_calendar];
		elem('hidden_estartdateJp').value = dayData.ldate;
		var mount_targ = leftAct.data.estimateElement;
		mount_targ.lrank = dayData.lrank;
		mount_targ.lid = dayData.lid;
		mount_targ.mstate = dayData.mstate;
		mount_targ.wstate = dayData.wstate;
		var getParam = 'mode=price&lid='+mount_targ.lid+'&cource='+mount_targ.cource;
		if ((mount_targ.cource == 4)&&(elem('elicense').value == 4)) getParam += '&holder=3';	//	20090805
		if (mount_targ.option) getParam += '&option='+mount_targ.option;

		var sendData = full_path + 'cgi-bin/front/front.cgi?'+getParam+plusRand();
		var sendParam = {
			method: 'get',
			onComplete: leftAct.mountCalc
		};
		new Ajax.Request(sendData, sendParam);
	},
	data: { calendar: Array(), fee: Array(), option: Array(), estimateElement: Array()},
	mountCalc: function(str){
		var result = str.responseText;
		var result_data = eval("(" + result + ")");
		
		var option_data = result_data.option;
		var graduation_data = result_data.graduation;
		var temp_option = Array();
		for(i=0; i<option_data.length; i++){
			temp_option[option_data[i].name] = {
				price: option_data[i].price,
				no: option_data[i].no
			}
		}
		leftAct.data.option = temp_option;
		leftWin.single = (((elem('radio_esex1').checked)&&(leftAct.data.option.msingle))||((elem('radio_esex2').checked)&&(leftAct.data.option.wsingle))) ? true: false;
		elem('optSingle').style.display = (leftWin.single) ? 'block': 'none';

		var discount_data = result_data.discount;
		var temp_discount = Array();
		for(i=0; i<discount_data.length; i++){
			temp_discount[discount_data[i].name] = {
				price: discount_data[i].price,
				no: discount_data[i].no
			}
		}
		leftAct.data.discount = temp_discount;
		together.mode = 1;

/*
		if (leftAct.data.discount.pair){
			elem('optTogether').style.display = 'block';
			leftWin.pair = true;
		} else elem('optTogether').style.display = 'none';
*/
		elem('graduation').value = graduation_data;
		
		together.clickAct();
		leftAct.calcResult();
	},
	calcResult: function(){
		var mount_targ = leftAct.data.estimateElement;
		var feeList = leftAct.data.fee;
		var opion_data = leftAct.data.option;
		var discount_data = Array();
		if (leftAct.data.discount) discount_data = leftAct.data.discount;
		
		var err = '';
		var estimate_inner = Array();
		
		if (mount_targ.lrank){
			estimate_inner.basic_price = feeList['mprice'+mount_targ.lrank];
			estimate_inner.full_price = estimate_inner.basic_price;
		}
		
		estimate_inner.elicense = elem('elicense').value;
		if (!estimate_inner.elicense) err += '<li>所持免許を選択してください。</li>';
		
		if (elem('radio_epair0').checked) estimate_inner.epair = 0;
		else if (elem('radio_epair1').checked) estimate_inner.epair = 1;
		else err += '<li>入校スタイルを選択してください。</li>';
		
		if (elem('radio_esingle0').checked) estimate_inner.esingle = 0;
		else if (elem('radio_esingle1').checked) estimate_inner.esingle = 1;
		else err += '<li>一人部屋を選択してください。</li>';
		
		estimate_inner.ejob = elem('select_ejob').value;
		if (!estimate_inner.ejob) err += '<li>職業を選択してください。</li>';
		
		var allClose = function(){
			elem('application').style.display = 'none';
			elem('entryMode').style.display = 'none';
			elem('estimateMode').style.display = 'none';
		}
		
		var out_html = '<h3><img src="'+full_path+'img/f7.png" alt="結果:Result" /></h3>';

		if (((mount_targ.mstate == 3)&&(elem('radio_esex1').checked))||((mount_targ.wstate == 3)&&(elem('radio_esex2').checked))){
			allClose();
			out_html += '<p><strong>空部屋がないためお申し込みできません。</strong></p>'
		} else if (err){
			allClose();
			out_html += '<ul class="alert">'+err+'</ul>';
			if (elem('lockWindowRight')) elem('lockWindowRight').style.display = 'none';
		} else if (estimate_inner.elicense == 5){
			elem('optTogether').style.display = 'none';
			out_html += '<p>※お客様の所持免許の詳細をお聞きし、別途お見積もりを差し上げます。</p>';
			elem('application').style.display = 'block';
			elem('entryMode').style.display = 'none';
			elem('estimateMode').style.display = 'block';
			if (elem('lockWindowRight')) elem('lockWindowRight').style.display = 'block';
		} else if (!mount_targ.lrank){
			out_html += '<p>お見積もりできません。</p>'
		} else {
			elem('optTogether').style.display = 'block';
			elem('application').style.display = 'block';
			
			out_html += '<table>';
			out_html += '<tbody>';
			out_html += '	<tr><th scope="row">基本価格</th><td>'+myFormatNumber(estimate_inner.basic_price);
			out_html += '<input type="hidden" name="basic_price" value="'+estimate_inner.basic_price+'" /></th></tr>';

			var empty_html = '';
			var emptyHiddenHtml = function(data_name, data_value){
				var temp_html = '<input type="hidden" name="'+data_name+'" value="" />';
				temp_html += '<input type="hidden" name="'+data_value+'" value="" />';
				return temp_html;
			}
			
			var optHiddenHtml = function(data_num, title, price){
				var temp_html = '<tr><th scope="row">'+title+'</th><td>'+myFormatNumber(price);
				temp_html += '<input type="hidden" name="optPriceName'+data_num+'" value="'+title+'" />';
				temp_html += '<input type="hidden" name="optPriceValue'+data_num+'" value="'+price+'" /></td></tr>';
				return temp_html;
			}

			if (opion_data.double){
				out_html += optHiddenHtml(1, '大特・けん引', opion_data.double.price);
				estimate_inner.full_price = ((estimate_inner.full_price * 1) + (opion_data.double.price * 1));
			} else if (opion_data.daitoku){
				out_html += optHiddenHtml(1, '大型特殊', opion_data.daitoku.price);
				estimate_inner.full_price = ((estimate_inner.full_price * 1) + (opion_data.daitoku.price * 1));
			} else if (opion_data.kenin){
				out_html += optHiddenHtml(1, 'けん引', opion_data.kenin.price);
				estimate_inner.full_price = ((estimate_inner.full_price * 1) + (opion_data.kenin.price * 1));
			} else 	empty_html += emptyHiddenHtml('optPriceName1', 'optPriceValue1');
			
			if ((opion_data.msingle)&&(elem('radio_esingle1').checked)&&(elem('radio_esex1').checked)){
				out_html += optHiddenHtml(2, '一人部屋', opion_data.msingle.price);
				estimate_inner.full_price = ((estimate_inner.full_price * 1) + (opion_data.msingle.price * 1));
			} else if ((opion_data.wsingle)&&(elem('radio_esingle1').checked)&&(elem('radio_esex2').checked)){
				out_html += optHiddenHtml(2, '一人部屋', opion_data.wsingle.price);
				estimate_inner.full_price = ((estimate_inner.full_price * 1) + (opion_data.wsingle.price * 1));
			} else 	{
				elem('radio_esingle0').checked = 'checked';
				empty_html += emptyHiddenHtml('optPriceName2', 'optPriceValue2');
			}

			var disHiddenHtml = function(data_num, title, price){
				var temp_html = '<tr class="reduction"><th scope="row">'+title+'</th><td>-'+myFormatNumber(price);
				temp_html += '<input type="hidden" name="disPriceName'+data_num+'" value="'+title+'" />';
				temp_html += '<input type="hidden" name="disPriceValue'+data_num+'" value="'+price+'" /></td></tr>';
				return temp_html;
			}

			if (discount_data.hayawari){
				out_html += disHiddenHtml(1, '早割', discount_data.hayawari.price);
				estimate_inner.full_price -= discount_data.hayawari.price;
			} else 	empty_html += emptyHiddenHtml('disPriceName1', 'disPriceValue1');
			
			var job_num = elem('select_ejob').value;
			if ((discount_data.student)&&(job_num == 1||job_num == 2||job_num == 3||job_num == 4)){
				out_html += disHiddenHtml(2, '学割', discount_data.student.price);
				estimate_inner.full_price -= discount_data.student.price;
			} else 	empty_html += emptyHiddenHtml('disPriceName2', 'disPriceValue2');
			
			if ((discount_data.ladys)&&(elem('radio_esex2').checked)){
				out_html += disHiddenHtml(3, 'レディース割', discount_data.ladys.price);
				estimate_inner.full_price -= discount_data.ladys.price;
			} else 	empty_html += emptyHiddenHtml('disPriceName3', 'disPriceValue3');
			
			var lic_num = elem('elicense').value;
			if ((discount_data.bike)&&(lic_num == 2)){
				out_html += disHiddenHtml(4, '二輪所持割', discount_data.bike.price);
				estimate_inner.full_price -= discount_data.bike.price;
			} else if ((lic_num == 4)&&(elem('hopeLic4').checked)){
				if (discount_data.holder_1){
					out_html += disHiddenHtml(4, '大型一種所持', discount_data.holder_1.price);	//	20090805
					estimate_inner.full_price -= discount_data.holder_1.price;
				}
			} else 	empty_html += emptyHiddenHtml('disPriceName4', 'disPriceValue4');
			
			if ((discount_data.pair)&&(elem('radio_epair1').checked)){
				out_html += disHiddenHtml(5, 'グループ割', discount_data.pair.price);
				estimate_inner.full_price -= discount_data.pair.price;
			} else 	empty_html += emptyHiddenHtml('disPriceName5', 'disPriceValue5');
			
			out_html += '</tbody>';
			out_html += '<tfoot>';
			out_html += '	<tr><th scope="col">合計金額</th><th scope="col">'+myFormatNumber(estimate_inner.full_price);
			out_html += '<input type="hidden" name="full_price" value="'+estimate_inner.full_price+'" /></th></tr>';
			out_html += '</tfoot>';
			out_html += '</table>';
			if (empty_html) out_html += '<p>'+empty_html+'</p>';
			elem('entryMode').style.display = 'block';
			elem('estimateMode').style.display = 'none';
			
			if (first_loaded) first_loaded = false;
			else if (elem('lockWindowRight')) elem('lockWindowRight').style.display = 'block';
		}
		elem('result').innerHTML = out_html;
		elem('result').style.display = 'block';
		if (scure_mode) winMask.sizeAdjust();
	},
	mountSchedule: function(str){
		var result = str.responseText;
		var resultData = eval("(" + result + ")");
	
		if ((!now_calender)&&(resultData.date.length == 0)){
			var temp_date = new Date();
			var temp_year = temp_date.getYear();
			if (temp_year < 1900) temp_year = (temp_year + 1900);
			var temp_month = temp_date.getMonth() + 2;
			if (temp_month > 12){
				temp_year++;
				temp_month = 1;
			}
			var make_date = function(yy, mm){
				if (mm == 0){ mm = 12; yy--}
				else if (mm==13){ mm = 1; yy++}
				if (mm < 10) mm = '0'+mm;
				return yy+'-'+mm;
			}
			leftAct.moveMonth(make_date(temp_year, temp_month));
		} else {
			leftAct.data.calendar = resultData.date;
		　　leftAct.data.fee = resultData.fee;
	
			elem('application').style.display = 'none';

			var actPrice = leftAct.mountCalender(leftAct.data.calendar);
			leftAct.mountPrice(leftAct.data.fee, actPrice);
			if (scure_mode){
				if (load_datas.estartdate){
					for (i=0; i<leftAct.data.calendar.length; i++){
						if (leftAct.data.calendar[i].lid == load_datas.estartdate){
							elem('select_estartdate'+i).checked = 'checked';
							Kaas.addClass(elem('select_estartdate'+i).parentNode.parentNode.parentNode, 'checked');
							if (!load_datas.halfway) leftAct.selectSchedule(i);
							break;
						}
					}
					elem('elicense').value = load_datas.holdLic;
					elem('radio_esex'+load_datas.esex).checked = 'checked';
					elem('select_ebirthyY').value = load_datas.ebirthyY;
					elem('select_ebirthyM').value = load_datas.ebirthyM;
					elem('select_ebirthyD').value = load_datas.ebirthyD;
					elem('select_ejob').value = load_datas.ejob;
					elem('radio_epair'+load_datas.epair).checked = 'checked';
					if (load_datas.epair){
						together.clickAct();
						elem('input_epairnameF').value = load_datas.epairnameF;
						elem('input_epairnameN').value = load_datas.epairnameN;
						elem('input_epairname2F').value = load_datas.epairname2F;
						elem('input_epairname2N').value = load_datas.epairname2N;
					}
					elem('radio_esingle'+load_datas.esingle).checked = 'checked';
				}
			}
		}
	},
	mountCalender: function(loadData){
		var emptySign = Array(
			'',
			'<span class="vacancy" title="空部屋あり">○</span>',
			'<span class="onlyRemaining" title="空部屋わずか">△</span>',
			'<span class="noRoom" title="空部屋なし">×</span>'
		);
		
		var activeRank = Array();
		var activeRankChk = Array();
		
		var out_html = '<table>';
		for(i=0; i<loadData.length; i++){
			var dayData = loadData[i];
			if (!activeRankChk[dayData.lrank]){
				activeRankChk[dayData.lrank] = true;
				activeRank.push(dayData.lrank);
			}
			out_html += '<tr><td>'+leftAct.rankSign[dayData.lrank]+'</td>';
			out_html += '<td>'+dayData.ldate+'</td>';
			out_html += '<td>男'+emptySign[dayData.mstate]+'</td>';
			out_html += '<td>女'+emptySign[dayData.wstate]+'</td>';
			out_html += '<td><span class="radio">';
			out_html += '<input type="radio" name="estartdate" id="select_estartdate'+i+'" value="'+dayData.lid+'" />';
			out_html += '</span></td></tr>';
		}
		out_html += '</table>';
		if (loadData.length == 0){
			out_html = '<p><strong>《日程がありません》<br />お電話又はメールにてお問い合わせください。</strong></p>';
			elem('priceList').innerHTML = '';
		}
		elem('entrySchedule').innerHTML = out_html;
		elem('dateSend').innerHTML = htmlMake.dateMonthSend();
		Kaas.formControl.date();
//		if (window.location.protocol == 'https:') elem('lockWindowRight').style.display = 'block';
		return activeRank;
	},
	mountPrice: function(feeList, activeRank){
		var out_html = '<p>';
		for(i=0; i<activeRank.length; i++){
			out_html += leftAct.rankSignMini[activeRank[i]]+' '+ myFormatNumber(feeList['mprice'+activeRank[i]])+'円 ';
		}
		out_html += '<p>';
		elem('priceList').innerHTML = out_html;
	},
	moveMonth: function(temp_date){
		now_calender = temp_date;
		elem('dateSend').innerHTML = htmlMake.dateMonthSend();
		elem('hidden_focus_month').value = now_calender;
		leftAct.loadSchedule();
		leftAct.clearData();
	},
	mountEstimate: function(){
		if (load_datas.focus_month) leftAct.moveMonth(load_datas.focus_month);
		
		elem('hopeLic'+load_datas.license).checked = 'checked';
		Kaas.addClass(elem('hopeLic'+load_datas.license).parentNode.parentNode, 'checked');
		if (load_datas.ekenin == 1){
			elem('chk_ekenin').checked = 'checked';
			Kaas.addClass(elem('chk_ekenin').parentNode.parentNode, 'checked');
		}
		if (load_datas.especial == 1){
			elem('chk_especial').checked = 'checked';
			Kaas.addClass(elem('chk_especial').parentNode.parentNode, 'checked');
		}
		
		leftAct.loadSchedule();
	},
	clearData: function(){
		leftAct.data.estimateElement.lrank = 0;
		elem('result').style.display = 'none';
	}
}

var plusRand = function(){
	return '&rand='+Math.floor(Math.random() * 1000000);
}

var allReplace = function(text, sText, rText){
	while (true){
		dummy = text;
		text = dummy.replace(sText, rText);
		if (text == dummy) {
			break;
		}
	}
	return text;
}

var myFormatNumber = function(x) {
	var s = "" + x;
	var p = s.indexOf(".");
	if (p < 0) {
		p = s.length;
	}
	var r = s.substring(p, s.length);
	for (var i = 0; i < p; i++) {
		var c = s.substring(p - 1 - i, p - 1 - i + 1);
		if (c < "0" || c > "9") {
			r = s.substring(0, p - i) + r;
			break;
		}
		if (i > 0 && i % 3 == 0) {
			r = "," + r;
		}
		r = c + r;
	}
	return r;
}

var gotoEntry = function(){
	var err = '';
	if ((!elem('select_ebirthyY').value)||(!elem('select_ebirthyM').value)||(!elem('select_ebirthyD').value)) err += '生年月日は入力必須項目です。'+"\n";

	if (err) alert(err);
	else {
		if (!elem('user_id').value){
			elem('user_id').value = Math.floor(Math.random() * 1000000);
		}
		elem('estimateForm').submit();
	}
}

var gotoEstimate = function(){
	var err = '';
	if ((!elem('select_ebirthyY').value)||(!elem('select_ebirthyM').value)||(!elem('select_ebirthyD').value)) err += '生年月日は入力必須項目です。'+"\n";
	if (err) alert(err);
	else {
		if (!elem('user_id').value){
			elem('user_id').value = Math.floor(Math.random() * 1000000);
		}
		elem('send_mode').value = 'extra';
		elem('estimateForm').submit();
	}
}

var colBLoad = function(){
	var out_html = '<h2><img src="'+full_path+'img/f0.png" alt="空き状況や料金をチェックしよう！" /></h2>';
	
	out_html += '<form action="https://sec19.alpha-lt.net/gasshuku-menkyo.co.jp/admission/" method="post" id="estimateForm">';
	out_html += '<fieldset>';
	
	out_html += '<div class="section" id="license">';
	out_html += '<h3><img src="'+full_path+'img/f1.png" alt="取得希望免許" /></h3>';
	out_html += '<ul class="checkboxes">';
	if (scure_mode) out_html += '<li id="cbA1"><label><input type="radio" name="license" id="hopeLic1" value="1" />普通自動車科 AT</label></li>';
	else out_html += '<li id="cbA1"><label><input type="radio" name="license" id="hopeLic1" value="1" checked="checked" />普通自動車科 AT</label></li>';
	out_html += '<li id="cbA0"><label><input type="radio" name="license" id="hopeLic2" value="2" />普通自動車科 MT</label></li>';
	out_html += '<li id="cbA2"><label><input type="radio" name="license" id="hopeLic3" value="3" />大型一種</label></li>';
	out_html += '<li id="cbA3"><label><input type="radio" name="license" id="hopeLic4" value="4" />大型二種</label></li>';
	out_html += '<li id="cbA4"><label><input type="radio" name="license" id="hopeLic6" value="6" />普通二種 MT</label></li>';
	out_html += '<li id="cbA5"><label><input type="radio" name="license" id="hopeLic5" value="5" />普通二種 AT</label></li>';
	out_html += '</ul>';
	out_html += '</div>';
	
	out_html += '<div class="section" id="licenseOption">';
	out_html += '<h3><img src="'+full_path+'img/f2.png" alt="取得希望免許 オプション" /></h3>';
	out_html += '<ul class="checkboxes">';
	out_html += '<li id="cbB2"><label><input type="checkbox" name="especial" id="chk_especial" value="1" />大型特殊</label></li>';
	out_html += '<li id="cbB3"><label><input type="checkbox" name="ekenin" id="chk_ekenin" value="1" />けん引</label></li>';
	out_html += '</ul>';
	out_html += '</div>';
	
	//	入校希望月選択
	out_html += '<div class="section" id="date">';
	out_html += '<h3><img src="'+full_path+'img/f3.png" alt="入校希望日" /></h3>';
	out_html += '<div id="dateSend"><p class="aC"><img src="'+full_path+'img/ajax-loader.gif" alt="Loading" /></p></div>';
	out_html += '<p><input type="hidden" name="focus_month" id="hidden_focus_month" value="" /></p>';

	//	スケジュール読み込み
	out_html += '<div id="entrySchedule"><p class="aC"><img src="'+full_path+'img/ajax-loader.gif" alt="Loading" /></p></div>';
	out_html += '<div><input type="hidden" id="hidden_estartdateJp" name="estartdateJp" value="" /></p></div>';
	
	//	料金リスト
	out_html += '<div class="explanation">';
	out_html += '<div id="priceList"><p class="aC"><img src="'+full_path+'img/ajax-loader.gif" alt="Loading" /></p></div>';
	out_html += '<ul>';
	out_html += '<li class="vacancy">○:空部屋あり</li>';
	out_html += '<li class="onlyRemaining">△:空部屋わずか</li>';
	out_html += '<li class="noRoom">×:空部屋なし</li>';
	out_html += '</ul>';
	out_html += '</div>';
	out_html += '</div>';
	
	out_html += '<div class="section">';
	out_html += '<h3><img src="'+full_path+'img/f4.png" alt="所持免許" /></h3>';
	out_html += '<div id="holdLicArea">'+loadingImg+'</div>';
	out_html += '</div>';
	
	out_html += '<div class="section">';
	out_html += '<h3><img src="'+full_path+'img/f5.png" alt="性別" /></h3>';
	out_html += '<p>';
	out_html += '<input type="radio" name="esex" value="1" checked="checked" id="radio_esex1" onclick="leftAct.calcResult();" /><label for="radio_esex1">男</label> ';
	out_html += '<input type="radio" name="esex" value="2" id="radio_esex2" onclick="leftAct.calcResult();" /><label for="radio_esex2">女</label>';
	out_html += '</p>';
	out_html += '</div>';
	
	out_html += '<div class="section">';
	out_html += '<h3><img src="'+full_path+'img/f8.png" alt="生年月日" /></h3>';
	out_html += '<div id="birthSelectArea"><p class="aC"><img src="'+full_path+'img/ajax-loader.gif" alt="Loading" /></p></div>';
	
	out_html += '</p>';
	out_html += '<p><strong>※お間違えのないよう、ご確認ください。</strong></p>';
	out_html += '</div>';
	
	out_html += '<div class="section">';
	out_html += '<h3><img src="'+full_path+'img/f6.png" alt="ご職業" /></h3>';
	out_html += '<div id="jobSelectArea"><p class="aC"><img src="'+full_path+'img/ajax-loader.gif" alt="Loading" /></p></div>';
	out_html += '</div>';
	
	out_html += '<div class="section" id="optTogether">';
	out_html += '<h3><img src="'+full_path+'img/f9.png" alt="入校スタイル" /></h3>';
	out_html += '<p>';
	out_html += '<input type="radio" name="epair" value="0" checked="checked" id="radio_epair0" /><label for="radio_epair0">お一人様</label> ';
	out_html += '<input type="radio" name="epair" value="1" id="radio_epair1" /><label for="radio_epair1">グループ(お二人様以上)</label>';
	out_html += '</p>';
	out_html += '</div>';

	out_html += '<div class="section" id="optSingle">';
	out_html += '<h3><img src="'+full_path+'img/f10.png" alt="一人部屋" /></h3>';
	out_html += '<p>';
	out_html += '<input type="radio" name="esingle" value="0" checked="checked" id="radio_esingle0" /><label for="radio_esingle0">希望しない</label> ';
	out_html += '<input type="radio" name="esingle" value="1" id="radio_esingle1" /><label for="radio_esingle1">希望する</label>';
	out_html += '</p>';
	out_html += '</div>';

	out_html += '<div class="section" id="result"></div>';
	
	out_html += '<p id="application">';
	out_html += '<span id="entryMode"><a href="javascript: gotoEntry();"><img src="'+full_path+'img/application_rollover.png" alt="申し込み" /></a></span>';
	out_html += '<span id="estimateMode"><a href="javascript: gotoEstimate();"><img src="'+full_path+'img/estimate_rollover.png" alt="見積依頼" /></a></span>';
	out_html += '<input type="hidden" name="md" value="estimate" id="send_mode" />';
	out_html += '<input type="hidden" name="graduation" value="" id="graduation" />';
	out_html += '<input type="hidden" name="uid" id="user_id" /></p>';
	
	out_html += '</fieldset>';
	out_html += '</form>';
	
	out_html += '<div id="lockWindowLeft">lockWindowLeft</div>';
	
	// if (attention201012) out_html += attention201012;

	elem('col-b').innerHTML = out_html;
}

