var	c_f_ord					=	"fm_ord";
var	c_s_qty1				=	"s_qty1";
var	c_s_qty2				=	"s_qty2";
var	c_s_qty3				=	"s_qty3";
var	c_s_qty4				=	"s_qty4";

var c_price_ship		=	300;
var c_price_pay			=	250;
var c_tax_rate			=	"0.05";
var c_i_tax					=	"i_tax";
var c_i_price_tot		=	"i_price_tot";
var c_i_price_sum		=	"i_price_sum";
var c_i_cahrge_ship	=	"i_charge_ship";
var c_i_cahrge_pay	=	"i_charge_pay";
var c_ship_free			= 2500;
var c_pay_free			= 5000;

var hada_price =		0;
var kami_price =		0;
var KomaS_price=		0;
var KomaL_price=		0;

function calc()
{
//小計-はだうるん@3800
hada_price = eval(document.forms[c_f_ord].elements[c_s_qty1].value) * 3800;
//小計-かみうるん@2800
kami_price = eval(document.forms[c_f_ord].elements[c_s_qty2].value) * 2800;
//小計-こまち単品@250
KomaS_price = eval(document.forms[c_f_ord].elements[c_s_qty3].value) * 250;
//小計-こまちセット@2500
KomaL_price = eval(document.forms[c_f_ord].elements[c_s_qty4].value) * 2500;
//sum(小計)
document.forms[c_f_ord].elements[c_i_price_tot].value 
= hada_price + kami_price + KomaS_price + KomaL_price;

//税
document.forms[c_f_ord].elements[c_i_tax].value 
=
document.forms[c_f_ord].elements[c_i_price_tot].value * 0.05;

document.forms[c_f_ord].elements[c_i_tax].value 
=
mask_money(document.forms[c_f_ord].elements[c_i_tax].value,0)

//送料設定
ship_charge_set(document.forms[c_f_ord].elements[c_i_price_tot].value);

//代金引換割引5000円以上
cahrge_pay_set(document.forms[c_f_ord].elements[c_i_price_tot].value);

//合計
document.forms[c_f_ord].elements[c_i_price_sum].value 
=
eval(document.forms[c_f_ord].elements[c_i_price_tot].value) +
eval(document.forms[c_f_ord].elements[c_i_cahrge_ship].value)+
eval(document.forms[c_f_ord].elements[c_i_cahrge_pay].value)+
eval(document.forms[c_f_ord].elements[c_i_tax].value);

}

function cahrge_pay_set(amount)
{
	if(amount >= c_pay_free)
	{//0yen
		document.forms[c_f_ord].elements[c_i_cahrge_pay].value = 0;
	}
	else
	{//250yen
		document.forms[c_f_ord].elements[c_i_cahrge_pay].value = c_price_pay;
	}
}

function ship_charge_set(amount)
{
	if(amount >= c_ship_free)
	{//0yen
	document.forms[c_f_ord].elements[c_i_cahrge_ship].value = 0;
	}
	else
	{//300yen
	document.forms[c_f_ord].elements[c_i_cahrge_ship].value = c_price_ship;
	}
}

function mask_money(amount,Keta)
{//左寄せ
	Atai=1;
	for(i=0;i<Keta; i++)Atai=Atai*10;
	amount=Math.floor(Math.round(amount*Atai));
	amount/=Atai;
	return amount;
}

function input_check()
{//必須項目の入力チェック
	name 	= document.fm_ord.ctm_name.value;
	zip	= document.fm_ord.ctm_zip.value;
	address	= document.fm_ord.ctm_add.value;
	phone	= document.fm_ord.ctm_phone.value;
	mail 	= document.fm_ord.ctm_mail.value;

	if(name == ""||address == ""||phone == ""||mail == ""||zip == "")
	{
		alert("お届け先情報を全て入力してください");
		document.fm_ord.ctm_name.focus();
		return false;
	}
}


function mask_keta(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;
}

function mask_money(amount,Keta)
{//左寄せ
	Atai=1;
	for(i=0;i<Keta; i++)Atai=Atai*10;
	amount=Math.floor(Math.round(amount*Atai));
	amount/=Atai;
	return amount;
}



function ship_charge_set(amount)
{
	//送料無料
	if(amount >= c_ship_free)
	{//0yen
		document.forms[c_f_ord].elements[c_i_cahrge_ship].value = 0;
	}
	else
	{//300yen
		document.forms[c_f_ord].elements[c_i_cahrge_ship].value = c_price_ship;
	}
}

function cahrge_pay_set(amount)
{
	if(amount >= c_pay_free)
	{//0yen
		document.forms[c_f_ord].elements[c_i_cahrge_pay].value = 0;
	}
	else
	{//250yen
		document.forms[c_f_ord].elements[c_i_cahrge_pay].value = c_price_pay;
	}
}

