/* ============================================================
y100.js
 javascript for http://books.livedoor.com/y100
  created: 2006-04-01
  modified:
  $Date:: 2009-09-08 15:45:20#$
  $Author: edge-dev $
  $Revision: 94129 $
============================================================ */
var booksPrc1 = Number(105);//種類1 105円
var booksCnt1 = Number(18);// 種類1 18冊
var booksPrc2 = Number(158);//種類2 158円
var booksCnt2 = Number(12);// 種類2 12冊
var booksPrc3 = Number(210);//種類3 210円
var booksCnt3 = Number(12);// 種類3 12冊
var priceNow = Number(0);
var load = $("<p>").css("text-align","center").text('Now Loading...');
function calcPrice() {
  var num1 = $(".chk1:checked").length * 105;
  var num2 = $(".chk2:checked").length * 158;
  var num3 = $(".chk3:checked").length * 210;
  $("#priceAreaTop").text(num1+num2+num3 + '円');
}
function load105() {
  $("#y105").html(load);
  $("#y105").load("/y100_data?type=1&price=105&limit=18");
  calcPrice();
}
function load158() {
  $("#y158").html(load);
  $("#y158").load("/y100_data?type=2&price=158&limit=12");
  calcPrice();
}
function load210() {
  $("#y210").html(load);
  $("#y210").load("/y100_data?type=3&price=210&limit=12");
  calcPrice();
}

$(function() {
  load105();
  load158();
  load210();
  calcPrice();
});

var isSubmitting = false;
$("#bookListForm").submit(checkSubmit);
//from common.js
function isInputed (_form,_className){
	var flg = new Boolean (false);
	var inputs = _form.getElementsByTagName('input');
	for (var i=0;i<inputs.length;i++) {
		if (_className && RegExp(_className).test(inputs[i].className) == false) {
			continue;
		}
		if (inputs[i].checked) {
			flg = true;
		}
		if (flg == true) break;
	}
	return (flg);
}
function checkSubmit (evt) {
	var targetForm = this;
	//入力チェックして送信
	if (isInputed(targetForm) == true) {
		isSubmitting = true;
	} else {
		alert ("商品が選択されておりません。もう一度、選択し直してください。");
		return false;
	}
}
window.onbeforeunload= function () {
	try {
		if (isSubmitting == false && isInputed(document.forms.bookListForm) == true ) {
			return "商品のチェック状態は保持されません";
		}
	} catch (e) {}
}

function getRandom (maxNum) {//ランダム値作成
	return Math.floor(Math.random()*maxNum);
}

function inputCheck (_class) {
	if (isInputed(document.forms.bookListForm,_class) == true) {
		return (window.confirm ("現在チェックされた商品が取り消されます。よろしいですか？"));
	} else {
		return true;
	}
}



function calc (type,flg){
	if (type==1) {priceNow += (flg) ? booksPrc1 : -booksPrc1;}
	if (type==2) {priceNow += (flg) ? booksPrc2 : -booksPrc2;}
	if (type==3) {priceNow += (flg) ? booksPrc3 : -booksPrc3;}
	
	document.getElementById("priceAreaTop").innerHTML = (priceNow+"円");
	//document.getElementById("priceAreaBtm").innerHTML = (priceNow+"円");
}

